public override void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
        {
            base.OnPointerDownBlock(mapBlock, eventData);

            //获取第一个选择的对象
            GameUnit.GameUnit unit = BattleMap.BattleMap.Instance().GetUnitsOnMapBlock(FSM.TargetList[0]);
            //创建移动指令
            Vector2         startPos = FSM.TargetList[0];
            Vector2         endPos   = mapBlock.position;
            UnitMoveCommand unitMove = new UnitMoveCommand(unit, startPos, endPos, mapBlock.GetSelfPosition());

            //如果移动指令合法
            if (unitMove.Judge())
            {
                //移动完毕关闭移动范围染色
                Vector2 pos = BattleMap.BattleMap.Instance().GetUnitCoordinate(unit);
                FSM.HandleMovCancel(pos);
                GameUtility.UtilityHelper.Log("移动完成,进入攻击状态,点击敌人进行攻击,右键点击角色取消攻击", GameUtility.LogColor.RED);
                unitMove.Excute();

                //清空对象列表
                //FSM.TargetList.Clear();
                FSM.TargetList.Add(endPos);
                //unit.restrain = true;

                FSM.PushState(new InputFSMAttackState(FSM));//状态机压入新的攻击状态
            }
            else
            {
                //如果不符合移动条件,什么都不做
            }
        }
Esempio n. 2
0
    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();
                }
            }
        }
    }