Beispiel #1
0
        public override void OnPointerDownEnemy(GameUnit.GameUnit unit, PointerEventData eventData)
        {
            base.OnPointerDownEnemy(unit, eventData);

            //获取攻击者和被攻击者

            GameUnit.GameUnit Attacker     = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(FSM.TargetList[FSM.TargetList.Count - 1]);
            GameUnit.GameUnit AttackedUnit = unit;
            //创建攻击指令
            UnitAttackCommand unitAtk = new UnitAttackCommand(Attacker, AttackedUnit);

            //如果攻击指令符合条件则执行
            if (unitAtk.Judge())
            {
                GameUtility.UtilityHelper.Log("触发攻击", GameUtility.LogColor.RED);
                FSM.HandleAtkCancel(BattleMap.BattleMap.Instance().GetUnitCoordinate(Attacker)); ////攻击完工攻击范围隐藏
                unitAtk.Excute();
                Attacker.disarm = true;                                                          //单位横置不能攻击
                FSM.TargetList.Clear();                                                          //清空对象列表
                FSM.PushState(new InputFSMIdleState(FSM));                                       //状态机压入静止状态
            }
            else
            {
                //如果攻击指令不符合条件就什么都不做
            }
        }
        /// <summary>
        /// 自动攻击
        /// </summary>
        protected override void AutoUseAtk()
        {
            //TODO 异能引入后进行修改

            //异能为引入前版本
            //获取攻击者和被攻击者
            GameUnit.GameUnit Attacker     = battleUnit;
            GameUnit.GameUnit AttackedUnit = targetBattleUnit;
            //创建攻击指令
            UnitAttackCommand unitAtk = new UnitAttackCommand(Attacker, AttackedUnit);

            unitAtk.Excute();//已经判断过距离,放心攻击
        }
    public void HandleConfirm(Vector2 target)
    {
        BattleMapManager.BattleMapManager mapManager = BattleMapManager.BattleMapManager.getInstance();
        if (TargetList.Count == 0)
        {
            if (mapManager.CheckIfHasUnits(target))
            {
                TargetList.Add(target);
                GameUnit.GameUnit unit = BattleMapManager.BattleMapManager.getInstance().GetUnitsOnMapBlock(TargetList[0]);
                unit.GetComponent <ShowRange>().MarkMoveRange();
                unit.GetComponent <ShowRange>().MarkAttackRange();
            }
        }
        else
        if (TargetList.Count == 1)
        {
            if (mapManager.CheckIfHasUnits(target))
            {
                //TargetList.Add(target);
                GameUnit.GameUnit unit1 = mapManager.GetUnitsOnMapBlock(TargetList[0]);
                //GameUnit.GameUnit unit2 = mapManager.GetUnitsOnMapBlock(TargetList[1])[0];
                GameUnit.GameUnit unit2         = mapManager.GetUnitsOnMapBlock(target);
                UnitAttackCommand attackCommand = new UnitAttackCommand(unit1, unit2);
                if (attackCommand.Judge())
                {
                    //关闭染色
                    unit1.GetComponent <ShowRange>().CancleAttackRangeMark();
                    unit1.GetComponent <ShowRange>().CancleMoveRangeMark();

                    attackCommand.Excute();
                    TargetList.Clear();
                }
            }
            else
            {
                //TargetList.Add(target);
                GameUnit.GameUnit unit1       = mapManager.GetUnitsOnMapBlock(TargetList[0]);
                Vector2           unit2       = target;
                UnitMoveCommand   moveCommand = new UnitMoveCommand(unit1, unit2);
                if (moveCommand.Judge())
                {
                    //关闭染色
                    unit1.GetComponent <ShowRange>().CancleAttackRangeMark();
                    unit1.GetComponent <ShowRange>().CancleMoveRangeMark();

                    moveCommand.Excute();
                    TargetList.Clear();
                }
            }
        }
    }