Esempio n. 1
0
        /// <summary>
        /// Reduces the user's current health by at most the amount specified by the input.
        /// </summary>
        /// <param name="amount"></param>
        /// <param name="magicType"></param>
        /// <returns>The amount of Damage the fighter took (e.g. if amount if 5 but current health is 3, fighter only took 3 damage)</returns>
        public virtual int MagicalDamage(int amount, MagicType magicType)
        {
            if (amount < 0)
            {
                throw new ArgumentException("MagicalDamage cannot be given a negative amount of damage!", nameof(amount));
            }

            int ret;

            if (BattleShield != null)
            {
                ret = BattleShield.DecrementHealth(amount, magicType);

                if (BattleShield.CurrentHealth == 0)
                {
                    RemoveBattleShield();
                }
            }
            else
            {
                var prevHealth = CurrentHealth;

                var damage = CalculateMagicalDamageAfterMultiplier(amount, magicType);

                CurrentHealth -= damage;

                if (CurrentHealth < 0)
                {
                    CurrentHealth = 0;
                }

                ret = (prevHealth - CurrentHealth);
                OnMagicalDamageTaken(new MagicalDamageTakenEventArgs(ret, magicType));

                if (CurrentHealth == 0)
                {
                    OnKilled(new KilledEventArgs());
                }
            }


            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Reduces the user's current health by at most the amount specified by the input.
        /// If the fighter's <see cref="BattleShield"/> is not null, it will take the damage instead of the fighter
        /// </summary>
        /// <param name="amount"></param>
        /// <returns>The amount of Damage the fighter took (e.g. if amount if 5 but current health is 3, fighter only took 3 damage)</returns>
        public virtual int PhysicalDamage(int amount)
        {
            if (amount < 0)
            {
                throw new ArgumentException("PhysicalDamage cannot be given a negative amount of damage!", nameof(amount));
            }

            int ret;

            if (BattleShield != null)
            {
                ret = BattleShield.DecrementHealth(amount);

                //TODO: move into an event handler?
                if (BattleShield.CurrentHealth == 0)
                {
                    RemoveBattleShield();
                }
            }
            else
            {
                var prevHealth = CurrentHealth;

                CurrentHealth -= amount;
                OnDamageTaken(new PhysicalDamageTakenEventArgs(amount));

                if (CurrentHealth < 0)
                {
                    CurrentHealth = 0;
                }

                if (CurrentHealth == 0)
                {
                    OnKilled(new KilledEventArgs());
                }
                ret = (prevHealth - CurrentHealth);
            }

            return(ret);
        }