Exemple #1
0
        public void CastInstantHeal(InstantHeal a_instantHeal)
        {
            //Sätter kastarens global cooldown
            a_instantHeal.Caster.GlobalCooldown = m_globalCd;

            //Healar
            a_instantHeal.Caster.CurrentHp += (int)a_instantHeal.Heal + a_instantHeal.Caster.SpellPower;

            //Sänker spelarens mana.
            a_instantHeal.Caster.CurrentMana -= a_instantHeal.ManaCost;

            //Kontrollerar att spelaren inte har mer hp än hans max. Om det är över så sätts livet till max hp.
            if (a_instantHeal.Caster.CurrentHp > a_instantHeal.Caster.TotalHp)
            {
                a_instantHeal.Caster.CurrentHp = a_instantHeal.Caster.TotalHp;
            }

            //Deklarrerar att spellen har uppdaterats färdigt
            a_instantHeal.Duration = 0;
        }
        /// <summary>
        /// Methoid for casting InstantHeal
        /// </summary>
        /// <param name="instantHeal">InstantHeal object</param>
        public void CastInstantHeal(InstantHeal instantHeal)
        {
            //Setting caster global cd
            instantHeal.Caster.GlobalCooldown = _globalCd;

            //Heals
            instantHeal.Caster.CurrentHp += (int)instantHeal.Heal + instantHeal.Caster.SpellPower;

            //Reduce caster mana
            instantHeal.Caster.CurrentMana -= instantHeal.ManaCost;

            //Makes sure the HP doesnt exceed the maximum HP
            if (instantHeal.Caster.CurrentHp > instantHeal.Caster.TotalHp)
            {
                instantHeal.Caster.CurrentHp = instantHeal.Caster.TotalHp;
            }

            //Declares that the spell update is finished
            instantHeal.Duration = 0;
        }
Exemple #3
0
        internal void Update(float a_elapsedTime)
        {
            //Rensar listan från spells där..
            m_activeSpells.RemoveAll(Spell => (Spell.Duration == 0 && Spell.CoolDown <= 0) ||                  //Duration och Cooldown är noll
                                     (!Spell.Caster.IsAlive()) ||                                              //Kastaren är död
                                     (Spell.Caster.Target != null && (Spell.GetType() == FIRE_BALL && !Spell.Caster.Target.IsAlive())) ||
                                     (Spell.GetType() == FIRE_BALL && Spell.Caster.Target == null));           //Fireballens target är död eller null



            //Uppdaterar varje aktiv instantheal
            foreach (Spell spell in m_activeSpells)
            {
                #region InstanHeal
                if (spell.GetType() == SpellSystem.INSTANT_HEAL)
                {
                    InstantHeal instantHeal = spell as Model.InstantHeal;

                    //Om casttiden är klar och spellen inte är påbörjad
                    if (instantHeal.CastTime <= 0 && instantHeal.Duration != 0)
                    {
                        //kasta spell
                        instantHeal.Caster.IsCastingSpell = false;
                        CastInstantHeal(instantHeal);
                    }
                    //Annars om kast-tid finns: minska den
                    else if (spell.CastTime > 0)
                    {
                        if (spell.Caster.GetType() == GameModel.ENEMY_NPC)
                        {
                            spell.Caster.UnitState = Enemy.IS_CASTING_HEAL;
                        }
                        instantHeal.CastTime -= a_elapsedTime;
                    }
                    //Annars minska spellens cd
                    else
                    {
                        instantHeal.CoolDown -= a_elapsedTime;
                    }
                }
                #endregion

                #region FireBall
                else if (spell.GetType() == SpellSystem.FIRE_BALL)
                {
                    Fireball fireBall = spell as Model.Fireball;
                    //Uppdaterar fireballens target.
                    fireBall.Update(spell.Caster.Target);

                    //Om Casttime är nedräknad och spellen inte träffat sitt target.
                    if (fireBall.CastTime <= 0 && spell.Duration != 0)
                    {
                        //Gör så att fireballen fick status kastad om den inte hade det.
                        if (!fireBall.WasCasted)
                        {
                            CastFireBall(fireBall);
                            fireBall.WasCasted = true;
                        }

                        //Om spellen har träffat sitt target.
                        if (fireBall.Target.ThisUnit.Bounds.Intersects(fireBall.FireBallArea) && fireBall.Duration > 0)
                        {
                            //Gör skada
                            fireBall.Caster.Target.CurrentHp -= (int)fireBall.Damage + fireBall.Caster.SpellPower;

                            //Säger att spellen träffat.
                            spell.Duration = 0;
                        }

                        //Uppdaterar spellen.
                        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;
                    }
                    //Om kast-tid finns: minska den
                    if (spell.CastTime > 0)
                    {
                        //Medans spelares kastar så kollar han neråt.
                        spell.Caster.UnitState = Enemy.IS_CASTING_FIREBALL;

                        fireBall.CastTime -= a_elapsedTime;
                    }
                    //Annars minska spellens cd
                    else
                    {
                        fireBall.CoolDown -= a_elapsedTime;
                    }
                }
                #endregion

                #region Smite

                else if (spell.GetType() == SpellSystem.SMITE)
                {
                    Smite smite = spell as Model.Smite;

                    //Om Casttime är nedräknad och spellen inte träffat sitt target.
                    if (smite.CastTime <= 0 && spell.Duration != 0)
                    {
                        CastSmite(smite);
                    }
                    //Om kast-tid finns: minska den
                    if (spell.CastTime > 0)
                    {
                        if (spell.Caster.GetType() == GameModel.PLAYER)
                        {
                            spell.Caster.UnitState = Player.FACING_CAMERA;
                        }

                        smite.CastTime -= a_elapsedTime;
                    }
                    //Annars minska spellens cd
                    else
                    {
                        smite.CoolDown -= a_elapsedTime;
                    }
                }

                #endregion
            }
        }
        /// <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
            }
        }