public void Subscribe(EventType type, IBattleShield shield)
        {
            switch (type)
            {
            case EventType.ShieldDestroyed:
                shield.ShieldDestroyed += _logShieldDestroyed;
                break;

            case EventType.ShieldHealed:
                shield.ShieldHealed += _logShieldHealed;
                break;

            case EventType.ShieldFortified:
                shield.ShieldFortified += _logShieldFortified;
                break;

            case EventType.DamageTaken:
                BattleShield battleShield = shield as BattleShield;
                if (battleShield != null)
                {
                    battleShield.DamageTaken += _logDamageTaken;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, "a valid EventType must be specified compatible with IBattleShield's implemented events");
            }
        }
        public void BattleManager_CorrectlyPrintsDamageOutput()
        {
            int damage = (_shield.MaxHealth + _shield.Defense) - 1;

            _enemyPlayer1.SetMove(_basicAttackMove);
            _enemyPlayer1.SetStrength(damage);
            _enemyPlayer1.SetMoveTarget(_humanPlayer1);
            _chanceService.PushEventsOccur(true, false); //attack hits, not crit

            _humanPlayer1.SetBattleShield(_shield as BattleShield);
            BattleShield fighterShield = _humanPlayer1.BattleShield;

            _humanPlayer1.SetMove(_doNothingMove, 1);
            _humanPlayer1.SetMove(_runawayMove);
            _humanPlayer1.SetMoveTarget(_humanPlayer1);

            _humanTeam = new Team(_menuManager, _humanPlayer1);
            _enemyTeam = new Team(_menuManager, _enemyPlayer1);

            BattleManagerBattleConfiguration config = new BattleManagerBattleConfiguration
            {
                ShowIntroAndOutroMessages = false
            };

            _battleManager.Battle(_humanTeam, _enemyTeam, config: config);

            MockOutputMessage[] outputs = _output.GetOutputs();

            Assert.AreEqual(2, outputs.Length); //enemy attacks and shield took damage message

            MockOutputMessage output = outputs[1];

            Assert.AreEqual($"{fighterShield.Owner.DisplayName}'s {fighterShield.GetDisplayText(false)} took {damage} damage!\n", output.Message);
        }
Exemple #3
0
        public void SetBattleShield(BattleShield battleShield)
        {
            BattleShield = battleShield.Copy() as BattleShield;
            BattleShield.SetOwner(this);

            ShieldAddedEventArgs e = new ShieldAddedEventArgs(BattleShield);

            OnShieldAdded(e);
        }
        protected void PrintShieldDestroyedMessage(object sender, ShieldDestroyedEventArgs e)
        {
            BattleShield senderAsShield = sender as BattleShield;

            if (senderAsShield == null)
            {
                throw new InvalidOperationException($"Something other than a BattleShield fired an ShieldDestroyed event. sender: {sender}, typeof sender: {sender.GetType()}");
            }

            _output.WriteLine($"{senderAsShield.Owner.DisplayName}'s shield was destroyed!");
        }
        public void SubscribeAll(IBattleShield shield)
        {
            shield.ShieldHealed    += _logShieldHealed;
            shield.ShieldDestroyed += _logShieldDestroyed;
            shield.ShieldFortified += _logShieldFortified;

            BattleShield battleShield = shield as BattleShield;

            if (battleShield != null)
            {
                battleShield.DamageTaken        += _logDamageTaken;
                battleShield.MagicalDamageTaken += _logMagicalDamageTaken;
            }
        }
        private static BattleShield GetShieldFromType(Type t)
        {
            BattleShield ret = null;

            if (t == typeof(IronBattleShield))
            {
                ret = new IronBattleShield(1, 0, 0);
            }
            else if (t == typeof(ElementalBattleShield))
            {
                ret = new ElementalBattleShield(1, 0, 0, MagicType.Fire);
            }
            else
            {
                throw new NotImplementedException($"GetShieldFromType() does not yet know how to handle type '{t}'");
            }

            return(ret);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
        public void BattleManager_CorrectlyUnsubscribes_OnceShieldRemovedFromPlayer()
        {
            BattleShield shield     = new IronBattleShield(1, 0, 0);
            ShieldMove   shieldMove = new ShieldMove("foo", TargetType.Self, null, shield);

            _humanPlayer1.SetMove(shieldMove, 1);
            _humanPlayer1.SetMove(_doNothingMove);
            _humanPlayer1.SetMoveTarget(_humanPlayer1);
            _humanPlayer1.SetSpeed(1);

            _enemyPlayer1.SetMove(_basicAttackMove);
            _enemyPlayer1.SetStrength(1000);
            _enemyPlayer1.SetMoveTarget(_humanPlayer1);
            _chanceService.PushEventsOccur(true, false, true, false); //two attacks to end the battle, both hit, neither are crits

            _logger.Subscribe(EventType.ShieldAdded, _humanPlayer1);

            _humanTeam = new Team(_menuManager, _humanPlayer1);
            _enemyTeam = new Team(_menuManager, _enemyPlayer1);

            _battleManager.Battle(_humanTeam, _enemyTeam);

            int outputCountBefore = _output.GetOutputs().Length;

            ShieldAddedEventArgs e = _logger.Logs[0].E as ShieldAddedEventArgs;

            Assert.NotNull(e);

            BattleShield shieldCopy = e.BattleShield;

            shieldCopy.OnDamageTaken(new PhysicalDamageTakenEventArgs(7));

            int outputCountAfter = _output.GetOutputs().Length;

            Assert.AreEqual(outputCountBefore, outputCountAfter);
        }
 public ShieldAddedEventArgs(BattleShield shield)
 {
     BattleShield = shield;
 }
Exemple #11
0
 public IronBattleShield(BattleShield copy) : base(copy)
 {
 }