magic powers refactor WIP
This commit is contained in:
80
Assets/Scripts/Characters/Skills/DurationSpell.cs
Normal file
80
Assets/Scripts/Characters/Skills/DurationSpell.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Beyond
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Magic/Spells/Duration Effect (Shield, Push, Flame)")]
|
||||
public class DurationSpell : SpellDefinition
|
||||
{
|
||||
public enum DurationType { Simple, Shield, Flamethrower }
|
||||
public DurationType type = DurationType.Simple;
|
||||
|
||||
public GameObject effectPrefab;
|
||||
public float preCastDelay = 0f; // Matches 'startTime'
|
||||
public float duration = 2f; // Matches 'endTime'
|
||||
public float postEndDelay = 0f; // Matches 'delay'
|
||||
|
||||
public override void Cast(MagicAttacks caster, Transform target)
|
||||
{
|
||||
caster.StartCoroutine(CastRoutine(caster, target));
|
||||
}
|
||||
|
||||
private IEnumerator CastRoutine(MagicAttacks caster, Transform target)
|
||||
{
|
||||
// 1. Rotation (Only Push and Flame used rotation in your old script)
|
||||
if (type != DurationType.Shield)
|
||||
{
|
||||
yield return caster.RotateTowardsTargetRoutine(target, rotationDuration);
|
||||
}
|
||||
|
||||
// 2. Pre-cast Delay
|
||||
if (preCastDelay > 0) yield return new WaitForSeconds(preCastDelay);
|
||||
|
||||
// 3. Instantiate attached to player
|
||||
GameObject instance = Instantiate(effectPrefab, caster.transform);
|
||||
// Reset local position/rotation to ensure it aligns with player
|
||||
instance.transform.localPosition = Vector3.zero;
|
||||
instance.transform.localRotation = Quaternion.identity;
|
||||
|
||||
// 4. Initialize Specific Logic
|
||||
if (type == DurationType.Shield)
|
||||
{
|
||||
var shieldCtrl = instance.GetComponent<ShieldEffectController>();
|
||||
if (shieldCtrl) shieldCtrl.InitializeEffect();
|
||||
}
|
||||
else if (type == DurationType.Flamethrower)
|
||||
{
|
||||
var ps = instance.GetComponent<ParticleSystem>();
|
||||
if (ps) ps.Play();
|
||||
}
|
||||
|
||||
caster.ApplyDamageModifiers(instance);
|
||||
|
||||
// 5. Wait Duration (With Trinket Mods)
|
||||
float finalDuration = duration;
|
||||
if (type == DurationType.Shield && Player.Instance.CurrentTrinketStats.effectCalmness)
|
||||
{
|
||||
finalDuration *= 1.5f;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(finalDuration);
|
||||
|
||||
// 6. Cleanup Logic
|
||||
if (type == DurationType.Flamethrower)
|
||||
{
|
||||
var ps = instance.GetComponent<ParticleSystem>();
|
||||
if (ps) ps.Stop();
|
||||
}
|
||||
else if (type == DurationType.Shield)
|
||||
{
|
||||
var shieldCtrl = instance.GetComponent<ShieldEffectController>();
|
||||
if (shieldCtrl) shieldCtrl.DisableEffect();
|
||||
}
|
||||
|
||||
// 7. Post Delay
|
||||
if (postEndDelay > 0) yield return new WaitForSeconds(postEndDelay);
|
||||
|
||||
Destroy(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user