/// <summary> /// Updates the spell logic /// </summary> /// <param name="elapsedTime">Elapsed time in milleseconds</param> internal void Update(float elapsedTime) { //Clearing the spell-list from spells where: _activeSpells.RemoveAll(Spell => (Spell.Duration == 0 && Spell.CoolDown <= 0) || //Duration and Cooldown is zero (!Spell.Caster.IsAlive()) || //Caster is dead (Spell.Caster.Target != null && (Spell.GetType() == FIRE_BALL && !Spell.Caster.Target.IsAlive())) || (Spell.GetType() == FIRE_BALL && Spell.Caster.Target == null)); //Fireball target is dead or null //Uppdating active Instant heals foreach (Spell spell in _activeSpells) { #region InstanHeal if (spell.GetType() == SpellSystem.INSTANT_HEAL) { InstantHeal instantHeal = spell as Model.InstantHeal; //If cast time is done and the spell is not yet started if (instantHeal.CastTime <= 0 && instantHeal.Duration != 0) { //Cast heal instantHeal.Caster.IsCastingSpell = false; CastInstantHeal(instantHeal); } //Else if cast time exists: reduce it else if (spell.CastTime > 0) { if (spell.Caster.GetType() == GameModel.ENEMY_NPC) { spell.Caster.UnitState = Model.State.IS_CASTING_HEAL; } instantHeal.CastTime -= elapsedTime; } //Else, reduce spell cd else { instantHeal.CoolDown -= elapsedTime; } } #endregion #region FireBall else if (spell.GetType() == SpellSystem.FIRE_BALL) { Fireball fireBall = spell as Model.Fireball; //Updating fireball target. fireBall.Update(spell.Caster.Target); //If casttimem is done whilst the spell have not yet hit the target if (fireBall.CastTime <= 0 && spell.Duration != 0) { //Set status to "was casted" if (!fireBall.WasCasted) { CastFireBall(fireBall); fireBall.WasCasted = true; } //If the spell hit its target if (fireBall.Target.ThisUnit.Bounds.Intersects(fireBall.FireBallArea) && fireBall.Duration > 0) { //Do dmg fireBall.Caster.Target.CurrentHp -= (int)fireBall.Damage + fireBall.Caster.SpellPower; //Declare spell hit spell.Duration = 0; } //Updating spell fireBall.Direction = new Vector2(fireBall.Target.ThisUnit.Bounds.X, fireBall.Target.ThisUnit.Bounds.Y) - fireBall.Position; Vector2 newCordinates = new Vector2(); newCordinates = fireBall.Direction; newCordinates.Normalize(); fireBall.Position += newCordinates * 5; fireBall.Caster.IsCastingSpell = false; } //If cast time exists: reduce it if (spell.CastTime > 0) { //Whilst player is casting: Facing camera spell.Caster.UnitState = Model.State.IS_CASTING_FIREBALL; fireBall.CastTime -= elapsedTime; } //Else, reduce cd else { fireBall.CoolDown -= elapsedTime; } } #endregion #region Smite else if (spell.GetType() == SpellSystem.SMITE) { Smite smite = spell as Model.Smite; if (smite.CastTime <= 0 && spell.Duration != 0) { CastSmite(smite); } if (spell.CastTime > 0) { if (spell.Caster.GetType() == GameModel.PLAYER) { spell.Caster.UnitState = State.FACING_CAMERA; } smite.CastTime -= elapsedTime; } else { smite.CoolDown -= elapsedTime; } } #endregion } }