/// <summary> /// Casts the spell on a(n) <see cref="MmoObject"/> /// </summary> public CastResults Cast(MmoObject victim) { if (victim == null) { victim = this.caster; } var result = this.CheckSpell(victim); if (result == CastResults.Ok) { this.target = victim; this.caster.DrainVitalPower(this.powerType, this.powerCost); if (castTime > 0) { this.state = SpellStates.Casting; this.castingTimer = 0; this.spellManager.OnBeginCasting(this); } else { this.state = SpellStates.CastFinished; } this.lastCasterPosition = caster.Position; this.spellManager.AddSpellUpdateEvent(this); } return(result); }
/// <summary> /// Creates an instance of <see cref="Spell"/> from <see cref="SpellData"/>. /// </summary> /// <param name="spellData"> RavenItem which contains the spell info. </param> /// <param name="caster"></param> public Spell(SpellData spellData, Character caster) { this.caster = caster; this.id = spellData.SpellId; this.school = (SpellSchools)spellData.School; this.requiredTargetType = (SpellTargetTypes)spellData.RequiredTargetType; this.targetSelectionMethod = (SpellTargetSelectionMethods)spellData.TargetSelectionMethod; this.spellAffectionMethod = (SpellAffectionMethod)spellData.AffectionMethod; this.requiredWeaponType = (WeaponTypes)spellData.RequiredWeaponType; this.flags = (SpellFlags)spellData.Flags; this.powerType = (Vitals)spellData.PowerType; this.powerCost = spellData.PowerCost; this.cooldown = spellData.Cooldown; this.minCastRadius = spellData.MinCastRadius; this.maxCastRadius = spellData.MaxCastRadius; this.castTime = spellData.CastTime; this.affectedByGcd = spellData.AffectedByGCD; this.isProc = spellData.IsProc; this.triggersGcd = spellData.TriggersGCD; var spellEffects = spellData.Effects; this.effects = spellEffects != null?spellEffects.Select(i => (SpellEffects)i).ToArray() : null; this.effectBaseValues = spellData.EffectBaseValues; this.state = SpellStates.Null; }
/// <summary> /// Initializes the spell. This MUST be called before the spell can be casted. /// </summary> public void Initialize(ISpellController mgr) { this.spellManager = mgr; this.LoadHandlers(); this.state = this.isProc ? SpellStates.WaitingForProc : SpellStates.Idle; this.IsReady = true; }
public void GenerateStateName() { string n = string.Format("{0}:{1}", TidalWavesBuff, ManaPool); foreach (SpellState ss in SpellStates.Where(i => i.HasCooldown).OrderBy(i => i.TrackedSpell.SpellId)) { n = string.Format("{0}:{1}", n, ss.IsOnCooldown ? 0 : 1); } this.Name = n; }
/// <summary> /// Interupts the spell casting /// </summary> public void InteruptCast() { if (state == SpellStates.Casting) { this.spellManager.RemoveSpellUpdateEvent(this); this.spellManager.OnEndCasting(this, true); this.castingTimer = 0; this.target = null; this.state = this.isProc ? SpellStates.WaitingForProc : SpellStates.Idle; } }
/// <summary> /// Resets the spell /// </summary> void ResetSpell() { this.target = null; if (cooldown > 0) { this.state = SpellStates.Cooldown; this.cooldownTimer = 0; this.spellManager.OnBeginCooldown(this); } else { this.state = this.isProc ? SpellStates.WaitingForProc : SpellStates.Idle; this.spellManager.RemoveSpellUpdateEvent(this); } }
internal IEnumerable <SpellState> GetNonPrioritySpellStates() { return(SpellStates.Where(i => !i.HasHot && !i.HasCooldown && i.TrackedSpell is HealingSpell && i.TrackedSpell.ManaCost < ManaPool)); }
internal IOrderedEnumerable <SpellState> GetPrioritySpellStates() { return(SpellStates.Where(i => (i.HasHot || i.HasCooldown) && i.TrackedSpell.ManaCost < ManaPool).OrderBy(i => i.Priority)); }
private SpellState GetSpellState(int spellId) { return(SpellStates.FirstOrDefault(i => i.TrackedSpell.SpellId == spellId)); }
/// <summary> /// Updates the spell. /// </summary> public void Update(float deltaTime) { // NOTE: deltaTime is in seconds switch (state) { case SpellStates.Casting: { // checking for movement if ((flags & SpellFlags.FLAG_MOVEMENT_BREAKS_CAST) == SpellFlags.FLAG_MOVEMENT_BREAKS_CAST) { if (lastCasterPosition != caster.Position) { this.InteruptCast(); return; } } this.castingTimer += deltaTime; if (castingTimer >= castTime) { this.state = SpellStates.CastFinished; this.castingTimer = 0; } } break; case SpellStates.CastFinished: { if (castTime > 0) { this.spellManager.OnEndCasting(this, false); } switch (spellAffectionMethod) { case SpellAffectionMethod.Instant: { this.ApplyEffect(target); } break; case SpellAffectionMethod.OnHit: { var spellObject = Dynamic.CreateNew(caster.CurrentZone, this.id); spellObject.InitializeNewSpellObject(); // offsetting the spell position to that of the character's center var position = caster.Position + caster.Bounds.Center; spellObject.Spawn(position, Quaternion.FromToRotation(Vector3.Forward, target.Position - position)); var mTarget = target; spellObject.SpellChase(target, caster, 15, () => this.ApplyEffect(mTarget)); } break; } this.ResetSpell(); } break; case SpellStates.Cooldown: { this.cooldownTimer += deltaTime; if (cooldownTimer >= cooldown) { this.spellManager.RemoveSpellUpdateEvent(this); this.state = this.isProc ? SpellStates.WaitingForProc : SpellStates.Idle; this.spellManager.OnEndCooldown(this); } } break; } }