Exemplo n.º 1
0
        /// <summary>
        /// 响应伤害类命令
        /// </summary>
        /// <param name="command">收到的命令</param>
        protected void DoDamageCommand(BattleCommand command)
        {
            if (IsDead)
            {
                return;
            }

            BattleObjects sender = command.Sender as BattleObjects;

            if (sender == null)
            {
                return;
            }

            int finalDamage = sender.Attack + command.Value - Defend;

            finalDamage = finalDamage < 1 ? 1 : finalDamage;

            Console.WriteLine(Name + " 受到 " + finalDamage + " 点伤害");
            Hp = Hp - finalDamage;
            Hp = Hp < 0 ? 0 : Hp;

            if (IsDead)
            {
                Console.WriteLine(Name + " 死亡 ");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取生命值最低的对象
        /// </summary>
        /// <returns></returns>
        protected BattleObjects GetHpMinTarget(BattleObjects[] datas)
        {
            if (datas == null)
            {
                return(null);
            }

            BattleObjects battleObjects = null;

            for (int i = 0; i < datas.Length; ++i)
            {
                if (datas[i] != null && !datas[i].IsDead)
                {
                    if (battleObjects == null)
                    {
                        battleObjects = datas[i];
                    }

                    if (battleObjects.Hp > datas[i].Hp)
                    {
                        battleObjects = datas[i];
                    }
                }
            }

            return(battleObjects);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="teamMate">队友对象</param>
 /// <param name="enemy">敌人对象</param>
 /// <param name="commander">命令下达者</param>
 /// <param name="reciver">命令接收者</param>
 protected AiStrategy(BattleObjects[] teamMate, BattleObjects[] enemy,
                      BattleObjects commander, IReciver reciver)
 {
     TeamMate  = teamMate;
     Enemy     = enemy;
     Commander = commander;
     Reciver   = reciver;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 设置怪物对象
        /// </summary>
        /// <param name="monster">怪物对象</param>
        /// <param name="index">索引</param>
        public void SetMonster(BattleObjects monster, int index)
        {
            if (monster == null || index < 0 || index > 2)
            {
                return;
            }

            MonsterObjectses[index] = monster;
            monster.Index           = index;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 设置英雄对象
        /// </summary>
        /// <param name="hero">英雄对象</param>
        /// <param name="index">索引</param>
        public void SetHero(BattleObjects hero, int index)
        {
            if (hero == null || index < 0 || index > 2)
            {
                return;
            }

            HeroObjectses[index] = hero;
            hero.Index           = index;
        }
Exemplo n.º 6
0
        /// <summary>
        /// 响应治疗类命令
        /// </summary>
        /// <param name="command">收到的命令</param>
        protected void DoCureCommand(BattleCommand command)
        {
            if (IsDead)
            {
                return;
            }

            BattleObjects sender = command.Sender as BattleObjects;

            if (sender == null)
            {
                return;
            }

            int finalHpAdd = sender.Attack / 2 + command.Value;

            Console.WriteLine(Name + " 获得 " + finalHpAdd + " 点治疗");
            Hp = Hp + finalHpAdd;
            Hp = Hp > MaxHp ? MaxHp : Hp;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 收到战斗类消息
        /// </summary>
        /// <param name="command">执行的命令</param>
        private void OnReciveBattleCommand(BattleCommand command)
        {
            if (command == null || command.Index < 0 || command.Index >= 3)
            {
                return;
            }

            BattleObjects sender = command.Sender as BattleObjects;

            if (sender == null || sender.IsDead)
            {
                return;
            }

            for (int i = 0; i < 6; ++i)
            {
                _temp[i] = null;
            }

            int index     = 0;
            int effectNum = command.ValueEffectNum;

            BattleObjects[] group = null;

            switch (command.EffectGroup)
            {
            case EffectGroup.Self:
                group = sender.Group == GroupTag.Monster ? MonsterObjectses : HeroObjectses;
                break;

            case EffectGroup.Enemy:
                group = sender.Group == GroupTag.Monster ? HeroObjectses : MonsterObjectses;
                break;
            }

            if (group == null)
            {
                return;
            }

            //优先处理选定对象
            if (IsLegalBattleTarget(command, group[command.Index]))
            {
                _temp[index++] = group[command.Index];
                effectNum--;
                Console.WriteLine(sender.Name + " 向 " + group[command.Index].Name + " 使用了 " +
                                  command.Name);
            }

            //处理附加对象
            for (int i = 0; i < 3 && effectNum > 0; ++i)
            {
                if (i != command.Index && IsLegalBattleTarget(command, group[i]))
                {
                    _temp[index++] = group[i];
                    effectNum--;
                    Console.WriteLine(sender.Name + " 向 " + group[command.Index].Name + " 使用了 " +
                                      command.Name);
                }
            }

            for (int i = 0; i < index; ++i)
            {
                _temp[i].OnReciveCommand(command);
            }
        }
Exemplo n.º 8
0
 public bool IsLegalBattleTarget(BattleCommand command, BattleObjects battleObjects)
 {
     return(command != null && battleObjects != null &&
            ((!battleObjects.IsDead && command.BuffType != BuffType.Revive) ||
             (battleObjects.IsDead && command.BuffType == BuffType.Revive)));
 }
Exemplo n.º 9
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="teamMate">队友对象</param>
 /// <param name="enemy">敌人对象</param>
 /// <param name="commander">命令下达者</param>
 /// <param name="reciver">命令接收者</param>
 public GoblinSoldierAi(BattleObjects[] teamMate, BattleObjects[] enemy,
                        BattleObjects commander, IReciver reciver)
     : base(teamMate, enemy, commander, reciver)
 {
 }