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
            {
                //如果不符合移动条件,什么都不做
            }
        }
Exemplo n.º 2
0
            private NavigationData GetEmptyNavigationData(BattleMapBlock _thisBlock, NavigationData _preBlock, int _G, int _H)
            {
                //优先从池子里取出
                NavigationData nd = null;

                if (curUsedIdx < navigationDataPool.Count)
                {
                    nd = navigationDataPool[curUsedIdx];
                }
                else
                {
                    nd = new NavigationData();
                    navigationDataPool.Add(nd);
                }

                ++curUsedIdx;

                nd.thisBlock         = _thisBlock;
                nd.preBlock          = _preBlock;
                nd.G                 = _G;
                nd.H                 = _H;
                nd.F                 = _G + _H;
                nd.open              = true;
                nd.thisBlock.tempRef = nd;

                return(nd);
            }
Exemplo n.º 3
0
 /// <summary>
 /// 处理地图方块的鼠标移出
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 virtual public void OnPointerExit(BattleMapBlock mapBlock, PointerEventData eventData)
 {
     if (BattleMap.BattleMap.Instance().IsColor == true)
     {
         BattleMap.BattleMap.Instance().HideBattleZooe(mapBlock.GetSelfPosition());
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 处理地图方块的鼠标进入
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 public void OnPointerEnter(BattleMapBlock mapBlock, PointerEventData eventData)
 {
     if (BattleMap.BattleMap.Instance().IsColor == true)
     {
         BattleMap.BattleMap.Instance().ShowBattleZooe(mapBlock.GetSelfPosition());
     }
     //TODO显示技能伤害的范围
 }
Exemplo n.º 5
0
 /// <summary>
 /// 处理地图方块的鼠标进入
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 virtual public void OnPointerEnter(BattleMapBlock mapBlock, PointerEventData eventData)
 {
     Debug.Log(mapBlock.GetSelfPosition());
     if (BattleMap.BattleMap.Instance().IsColor == true)
     {
         BattleMap.BattleMap.Instance().ShowBattleZooe(mapBlock.GetSelfPosition());
     }
 }
Exemplo n.º 6
0
 public int state = -1; //-2(默认值)
 /// <summary>
 /// 初始化检测范围
 /// </summary>
 /// <param name="battleMapBlock"></param>
 public void init(BattleMapBlock battleMapBlock)
 {
     for (int i = 0; i < 2; i++)
     {
         float x = battleMapBlock.position.x + i;
         float y = battleMapBlock.position.y + i;
         colliderRange.Add(new Vector2(x, y));
     }
 }
Exemplo n.º 7
0
            public void Reset()
            {
                open = true;

                F = 0;
                G = 0;
                H = 0;

                //清空关联
                if (thisBlock != null)
                {
                    thisBlock.tempRef = null;
                    thisBlock         = null;
                }

                preBlock = null;
            }
        public override void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
        {
            base.OnPointerDownBlock(mapBlock, eventData);

            //如果点击地图块符合指令牌异能的对象约束
            if (FSM.ability.AbilityTargetList[FSM.TargetList.Count].TargetType == Ability.TargetType.Field ||
                FSM.ability.AbilityTargetList[FSM.TargetList.Count].TargetType == Ability.TargetType.All)
            {
                FSM.TargetList.Add(mapBlock.position);
            }
            //如果已经选够了目标就发动卡片
            //这里应该让Card那边写个发动卡片的函数,写在Input里不科学
            if (FSM.TargetList.Count == FSM.ability.AbilityTargetList.Count)
            {
                Gameplay.Info.CastingCard = FSM.ability.GetComponent <OrderCard>();
                CardManager.Instance().OnTriggerCurrentCard();
            }
        }
Exemplo n.º 9
0
        public override void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
        {
            base.OnPointerDownBlock(mapBlock, eventData);

            //在对应MapBlock生成单位
            UnitManager.InstantiationUnit(FSM.selectedCard.id, OwnerEnum.Player, mapBlock);
            //把这张手牌从手牌里删掉
            CardManager.Instance().RemoveCardToMapList(FSM.selectedCard.gameObject);
            // 扣除消耗的Ap值
            Player.Instance().ConsumeAp(FSM.selectedCard.GetComponent <BaseCard>().cost);
            //删掉对应手牌槽的引用
            FSM.selectedCard = null;
            //关闭鼠标所在战区的高光显示
            BattleMap.BattleMap.Instance().IsColor = false;
            BattleMap.BattleMap.Instance().HideBattleZooe(mapBlock.GetSelfPosition());
            //创建部署指令并执行
            BattleDispositionCommand unitDispose = new BattleDispositionCommand(mapBlock.units_on_me);

            unitDispose.Excute();
            //状态机压入静止状态
            this.FSM.PushState(new InputFSMIdleState(FSM));
        }
Exemplo n.º 10
0
        //角色初始化到地图上
        public static void InstantiationUnit(string cardID, OwnerEnum owner, BattleMapBlock battleMapBlock)
        {
            //根据卡牌id生成单位
            GameObject temp = GameUnitPool.Instance().GetInst(cardID, owner);
            //获取GameUnit对象
            GameUnit gameUnit = temp.GetComponent <GameUnit>();

            //添加当前实例单位到UnitList中
            BattleMap.BattleMap.Instance().UnitsList.Add(gameUnit);
            //添加当前实例单位的所在地图块儿
            gameUnit.mapBlockBelow = battleMapBlock;

            //添加gameUnit到units_on_me上,且修改单位的父级对象
            battleMapBlock.AddUnit(gameUnit);
            //修改单位的本地坐标系坐标
            temp.transform.localPosition = Vector3.zero;
            //修改单位卡图的射线拦截设置
            temp.GetComponent <Image>().raycastTarget = true;

            //TODO 暂时用Text标识血量,以后改为slider
            var hpTest = temp.transform.GetChild(0);

            hpTest.gameObject.SetActive(true);
            float hp         = (temp.GetComponent <GameUnit>().hp = temp.GetComponent <GameUnit>().hp);
            float hpDivMaxHp = hp / temp.GetComponent <GameUnit>().MaxHP * 100;

            //格式化血量的显示
            hpTest.GetComponent <Text>().text = string.Format("HP: {0}%", hpDivMaxHp);

            //单位部署相当于单位驻足地图块儿
            gameUnit.nextPos = gameUnit.CurPos;

            //挂载ShowRange脚本
            temp.AddComponent <GameGUI.ShowRange>();

            //部署成功
            Gameplay.Instance().bmbColliderManager.Fresh(gameUnit);
        }
    /// <summary>
    /// 单位坐标发生变化后,管理更新所有Collider
    /// </summary>
    public void Fresh(Unit unit, List <Unit> units = null)
    {
        //1. 单位发生移动,召唤,死亡后更新
        //2. 如何更新?
        //a. 遍历collider,获取当前collider的范围值
        //b. 上一次更新保存好的在自己范围内的单位的引用,再搜一遍自己的范围
        //c. 最后对比出哪个Exit,哪个Enter
        if (units == null)
        {
            units = new List <Unit>();
            units.Add(unit);
        }

        foreach (BMBCollider collider in bmbColliders)
        {
            //获取当前地图块儿 (collider.colliderRange[0] 地图块儿地址)
            BattleMapBlock battleMapBlock = BattleMap.BattleMap.Instance().GetSpecificMapBlock(collider.colliderRange[0]);
            //先确认上一次自己范围内是否保存得有单位的引用
            if (collider.enterUnits.Count != 0 || collider.disposeUnits.Count != 0)
            {
                if (battleMapBlock.units_on_me.Count == 0)
                {
                    //单位坐标发生变化
                    //MsgDispatcher.SendMsg((int)MessageType.UnitExit);
                    collider.OnUnitExit();
                }
            }
            else
            {
                if (battleMapBlock.units_on_me.Count != 0 && battleMapBlock.units_on_me[0].owner != GameUnit.OwnerEnum.Enemy)
                {
                    collider.OnUnitEnter(units);
                }
            }
        }
    }
        /// <summary>
        /// 自动选择目标
        /// </summary>
        /// <param name="battleUnitAction"></param>
        protected override void AutoSelectTarget()
        {
            int stopDistance = AtkStopDistance();
            //从仇恨列表中确定目标
            Unit hatredUnit = null;

            //地图导航
            BattleMap.MapNavigator mapNavigator = BattleMap.BattleMap.Instance().MapNavigator;

            for (int i = 0; i < hatredRecorder.HatredCount; i++)
            {
                hatredUnit = hatredRecorder.GetHatredByIndex(i, i == 0);
                if (hatredUnit.IsDead())
                {
                    //已经排序过,且无法找到还能够行动的单位,就表示场上没有存活的敌方单位了
                    hatredUnit = null;
                    continue;
                }

                //判断这个单位是否可以到达
                bool catched = false;

                //如果这个单位就在攻击范围内,即身边
                if (Distance(battleUnit, hatredUnit) <= stopDistance)
                {
                    toTargetPath.Clear();
                    targetBattleUnit = hatredUnit;
                    AutoUseAtk();
                    catched = true;
                }
                else
                {
                    //if (catched = mapNavigator.PathSearch(battleUnit.CurPos, new Vector2(hatredUnit.CurPos.x, hatredUnit.CurPos.y + 1)))
                    //    toTargetPath = mapNavigator.Paths;
                    //TODO 把被仇恨单位作为起点
                    //遍历4个相邻地图块儿,把对于当前单位最近的地图块儿作为终点
                    Node nodeStart = new Node(hatredUnit.CurPos, hatredUnit.CurPos);
                    //获得A的周边MapBlock
                    List <BattleMapBlock> neighbourBlock = BattleMap.BattleMap.Instance().GetNeighbourBlock(nodeStart);
                    int            prevPathCount         = int.MaxValue;
                    BattleMapBlock preBattleMapBlock     = null;
                    foreach (BattleMapBlock battleMapBlock in neighbourBlock)
                    {
                        if (mapNavigator.PathSearchForAI(battleUnit.CurPos, battleMapBlock.position, this is SingleAutoControllerAtker))
                        {
                            //找到对于ai单位的最短路径
                            if (prevPathCount > mapNavigator.Paths.Count)
                            {
                                //更新路径
                                toTargetPath  = mapNavigator.Paths;
                                prevPathCount = mapNavigator.Paths.Count;

                                if (preBattleMapBlock != null)
                                {
                                    preBattleMapBlock.RemoveUnit(battleUnit);
                                }
                                battleMapBlock.units_on_me.Add(battleUnit);
                                preBattleMapBlock = battleMapBlock;
                                catched           = true;
                            }
                        }
                    }
                }

                //寻路不可达
                if (!catched)
                {
                    hatredUnit = null;
                    continue;
                }
                else //找到了
                {
                    break;
                }
            }

            //没有目标
            if (hatredUnit == null)
            {
                targetBattleUnit = null;
                return;
            }

            if (battleUnit != null && !hatredUnit.Equals(targetBattleUnit))
            {
                targetBattleUnit = hatredUnit;
            }
        }
Exemplo n.º 13
0
            public bool Navigate(
                BattleMapBlock from,
                BattleMapBlock to,
                List <BattleMapBlock> path,
                List <BattleMapBlock> searched = null,
                int mobility     = -1,
                int stopDistance = 0)
            {
                if (BattleMapManager.BattleMapManager.getInstance() == null)
                {
                    return(false);
                }

                if (path != null)
                {
                    path.Clear();
                }

                if (searched != null)
                {
                    searched.Clear();
                }

                //这种情况基本上也就不用寻路了吧...
                if (stopDistance <= 1 && from.Distance(to) > 1)
                {
                    return(false);
                }

                //本来就在停止距离内
                if (from.Distance(to) <= stopDistance)
                {
                    return(true);
                }

                int tryTimes = BattleMapManager.BattleMapManager.getInstance().BlockCount;

                //添加一个openPath 到list中
                List <NavigationData> opening = new List <NavigationData>();

                opening.Add(GetEmptyNavigationData(from, null, 0, from.Distance(to)));

                int  retry   = 0;
                bool catched = false;

                //当前探索方向
                int curDir = 0;
                //上次探索方向
                int lastDir = 0;
                //每次检测方向的次数
                int checkTimes = 0;

                //判断是否需要遍历open列表
                NavigationData gift = null;

                //距离最近的格子(接下来要移动的)
                NavigationData next_0 = null;
                //距离次近的格子
                NavigationData next_1 = null;

                int minStep = /*Mathf.Infinity*/ 99999;

                while (retry <= tryTimes && !catched)
                {
                    ++retry;
                    //从open中查找最近的节点
                    if (gift != null)
                    {
                        next_0 = next_1;
                        gift   = null;
                    }
                    else if (next_1 != null)
                    {
                        next_0 = next_1;
                        next_1 = null;
                    }
                    else
                    {
                        minStep = 99999;
                        if (opening.Count == 0)
                        {
                            break;
                        }


                        for (int i = opening.Count - 1; i >= 0; --i)
                        {
                            if (!opening[i].open)
                            {
                                opening.RemoveAt(i);
                            }
                            else if (opening[i].F < minStep)
                            {
                                next_0  = opening[i];
                                minStep = next_0.F;
                            }
                            else if (next_1 == null && next_0 != null && opening[i].F == next_0.F)
                            {
                                next_1 = opening[i];
                            }
                        }
                    }

                    //标志为已关闭
                    next_0.open = false;

                    //放入已搜索中
                    if (searched != null)
                    {
                        searched.Add(next_0.thisBlock);
                    }

                    checkTimes = 4;  //此处因为是四边形所以会有4次检测
                    curDir     = lastDir;
                    //遍历最近节点的周围6个节点,依次放入close中
                    //TODO 实现NavigationPassable get set构造器
                    //int roads = next_0.thisBlock.NavigationPassable ? 63 : next_0.thisGrid.roadPasses;

                    while (checkTimes > 0)
                    {
                        //沿着当前探索方向继续探索
                    }
                }

                return(false);
            }
Exemplo n.º 14
0
 /// <summary>
 /// 处理地图方块的鼠标点击
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 public void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
 {
     StateStack.Peek().OnPointerDownBlock(mapBlock, eventData);
     Debug.Log(BattleMap.BattleMap.Instance().GetCoordinate(mapBlock));
 }
Exemplo n.º 15
0
 /// <summary>
 /// 处理地图方块的鼠标点击
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 virtual public void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// 处理地图方块的鼠标点击
 /// </summary>
 /// <param name="mapBlock"></param>
 /// <param name="eventData"></param>
 public void OnPointerDownBlock(BattleMapBlock mapBlock, PointerEventData eventData)
 {
     InputFSM.OnPointerDownBlock(mapBlock, eventData);
 }