Example #1
0
        private void HandleBuffer(Army allies, int unitIndex)
        {
            var buffer = allies[unitIndex] as IBufferUnit;

            if (Random.Next(100) > buffer.BuffChance)
            {
                return;
            }
            var buff   = BuffTypes[Random.Next(BuffTypes.Length)];
            var target = Strategy.FindRandomUnitInRange(allies, unitIndex, buffer.BuffRange,
                                                        unit => unit.CurrentHealth > 0 && unit is IBuffableUnit buffable && buffable.CanBeBuffed(buff));

            if (!target.HasValue)
            {
                return;
            }
            CommandsInvoker.Execute(new BuffCommand(allies, unitIndex, allies, target.Value, buff));
        }
Example #2
0
        private void HandleHealer(Army allies, int unitIndex)
        {
            var healer = allies[unitIndex] as IHealerUnit;

            if (Random.Next(100) > healer.HealChance)
            {
                return;
            }
            var target = Strategy.FindRandomUnitInRange(allies, unitIndex, healer.HealRange,
                                                        unit => unit.CurrentHealth > 0 && unit is IHealableUnit);

            if (!target.HasValue)
            {
                return;
            }
            var targetUnit = allies[target.Value];
            var endHealth  = Math.Min(targetUnit.MaxHealth, targetUnit.CurrentHealth + healer.Heal);
            int heal       = endHealth - targetUnit.CurrentHealth;

            if (heal > 0)
            {
                CommandsInvoker.Execute(new HealCommand(allies, unitIndex, allies, target.Value, heal));
            }
        }