Esempio n. 1
0
    public void Run()
    {
        var pi = CommandManager.Instance.CurrentExecuter;

        if (pi == null || !pi.CurrentActor)
        {
            string msg = $"没有选中任何部队!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            return;
        }

        var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor;

        if (avMe == null)
        {
            return;
        }

        var   currentCell  = avMe.HexUnit.Location;
        var   resType      = currentCell.Res.ResType;
        int   resAmount    = currentCell.Res.GetAmount(resType);
        float durationTime = resAmount * 3.0f;

        if (resAmount <= 0)
        {
            string msg = $"本地没有任何资源,请去其他地方采集!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Warning);
            return;
        }

        // 看看行动点够不够
        if (!CmdAttack.IsActionPointGranted())
        {
            string msg = "行动点数不够, 本操作无法执行! ";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.Log("CmdHarvest Run Error - " + msg);
            return;
        }

        {
            HarvestStart output = new HarvestStart()
            {
                RoomId       = avMe.RoomId,
                OwnerId      = avMe.OwnerId,
                ActorId      = avMe.ActorId,
                CellIndex    = avMe.CellIndex,
                ResType      = (int)resType,
                ResRemain    = resAmount,
                DurationTime = durationTime,
            };
            GameRoomManager.Instance.SendMsg(ROOM.HarvestStart, output.ToByteArray());

            CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.HARVEST, 0, 0, durationTime, durationTime);
            // 消耗行动点
            CmdAttack.TryCommand();
        }
    }
Esempio n. 2
0
    public void Run()
    {
        var pi = CommandManager.Instance.CurrentExecuter;

        if (pi == null || !pi.CurrentActor)
        {
            string msg = $"没有选中任何部队!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            return;
        }

        var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor;

        if (!avMe)
        {
            return;
        }
        CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.IDLE);
    }
Esempio n. 3
0
    private void DoMove(PickInfo piTarget)
    {
        // 看看行动点够不够
        if (!CmdAttack.IsActionPointGranted())
        {
            string msg = "行动点数不够, 本操作无法执行! ";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.Log("CmdMarch DoMove Error - " + msg);
            return;
        }

        var pi = CommandManager.Instance.CurrentExecuter;

        if (pi == null || !pi.CurrentActor)
        {
            string msg = $"没有选中任何部队!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.Log("CmdMarch DoMove Error - " + msg);
            return;
        }

        var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor;

        if (avMe == null)
        {
            return;
        }

        HexCell cellTarget = piTarget.CurrentCell;

        if (!cellTarget)
        {
            return;
        }

        {
            var currentCell = avMe.HexUnit.Location;
            GameRoomManager.Instance.HexmapHelper.hexGrid.FindPath(currentCell, cellTarget, avMe.HexUnit);
            var hexmapHelper = GameRoomManager.Instance.HexmapHelper;
            if (!hexmapHelper.hexGrid.HasPath)
            {
                return;
            }

//            TroopMove output = new TroopMove()
//            {
//                RoomId = GameRoomManager.Instance.RoomId,
//                OwnerId = GameRoomManager.Instance.CurrentPlayer.TokenId,
//                ActorId = av.ActorId,
//                PosFromX = av.PosX,
//                PosFromZ = av.PosZ,
//                PosToX = cellTarget.coordinates.X,
//                PosToZ = cellTarget.coordinates.Z,
//            };
//            GameRoomManager.Instance.SendMsg(ROOM.TroopMove, output.ToByteArray());

            HexCell newCell  = hexmapHelper.hexGrid.GetCell(currentCell.coordinates.X, currentCell.coordinates.Z);
            HexCell newCell2 = hexmapHelper.hexGrid.GetCell(currentCell.Position);
            if (newCell.Position != currentCell.Position)
            {
                Debug.LogWarning($"OhNo Hexmap!!! - Orgin<{currentCell.coordinates.X},{currentCell.coordinates.Z}> - New<{newCell.coordinates.X},{newCell.coordinates.Z}>");
            }
            if (newCell2.Position != currentCell.Position)
            {
                Debug.LogWarning($"OhNo Hexmap 2!!! - Orgin<{currentCell.coordinates.X},{currentCell.coordinates.Z}> - New2<{newCell2.coordinates.X},{newCell2.coordinates.Z}>");
            }

            Debug.Log($"CmdMarch DoMove - From<{avMe.PosX},{avMe.PosZ}> - Dest<{cellTarget.coordinates.X},{cellTarget.coordinates.Z}>");
            CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.WALK, cellTarget.Index);
        }
    }
        private void AI_Running()
        {
            if (!GameRoomManager.Instance.IsAiOn)
            {
                return;
            }

            // 如果本地AI可以控制本单位, 或者是当前玩家自己, 则继续, 否则这里返回
            if (!HasAiRights && OwnerId != GameRoomManager.Instance.CurrentPlayer.TokenId)
            {
                return;
            }

            if (StateMachine.CurrentAiState == StateEnum.IDLE)
            {
                float lastedTime = StateMachine.GetLastedTime();
                if (lastedTime > _REST_TIME || _first)
                { // 进入休闲状态超过_REST_TIME秒, 也就是说闲置超过_REST_TIME秒的情况下
                    _first = false;
                    switch (HighAiState)
                    {
                    case StateEnum.GUARD:
                        StateMachine.TriggerTransition(StateEnum.GUARD);
                        break;

                    case StateEnum.WALKFIGHT:
                        // 敌人死了, 或者我没有弹药了, 而且我已经走到目的地了
                        var ab = GameRoomManager.Instance.RoomLogic.ActorManager.GetActor(HighAiTargetId);
                        if ((ab == null || ab.IsDead || AmmoBase <= 0) && CellIndex == HighAiTargetCell)
                        {
                            // 结束这个高级AI
                            CmdAttack.SendAiStateHigh(OwnerId, ActorId, StateEnum.IDLE);
                            GameRoomManager.Instance.Log($"ActorBehaviour AI_Running - 结束高级AI:{HighAiState}");
                            break;
                        }
                        if (AmmoBase <= 0)
                        {     // 如果没有弹药了, 则仅仅是走过去
                            StateMachine.TriggerTransition(StateEnum.WALK, HighAiTargetCell);
                            break;
                        }
                        // 如果可以直接攻击, 则直接攻击, 否则走过去再攻击
                        if (!ActorWalkFightState.AttackEnemyInRange(this, HighAiTargetId))
                        {
                            StateMachine.TriggerTransition(StateEnum.WALKFIGHT, HighAiTargetCell,
                                                           HighAiTargetId);
                        }
                        break;

                    case StateEnum.WALK: // 解决拥堵问题,
                        if (HighAiTargetCell == CellIndex)
                        {                // 走到了, 跳出本逻辑
                            CmdAttack.SendAiStateHigh(OwnerId, ActorId, StateEnum.IDLE);
                            GameRoomManager.Instance.Log($"ActorBehaviour AI_Running - 到达目的地! 结束高级AI:{HighAiState}");
                        }
                        else
                        {
                            StateMachine.TriggerTransition(StateEnum.WALK, HighAiTargetCell);
                        }
                        break;

                    case StateEnum.HARVEST:
                        HexCell     currentCell = HexUnit.Location;
                        HexResource res         = currentCell.Res;
                        int         amount      = res.GetAmount(res.ResType);
                        if (amount == 0)
                        {     // 没资源了, 跳出
                            CmdAttack.SendAiStateHigh(OwnerId, ActorId, StateEnum.IDLE);
                        }
                        else
                        {
                            StateMachine.TriggerTransition(HighAiState, HighAiTargetCell, HighAiTargetId,
                                                           HighAiDurationTime, HighAiTotalTime);
                        }

                        break;
                    }
                }
            }



//            float range = 100f;
//            if (StateMachine.CurrentAiState == FSMStateActor.StateEnum.IDLE)
//            {
//                float offsetX = Random.Range(-range, range);
//                float offsetZ = Random.Range(-range, range);
//                Vector3 newTargetPosition = new Vector3(CurrentPosition.x + offsetX, CurrentPosition.y, CurrentPosition.z + offsetZ);
//                HexCell newCell = HexUnit.Grid.GetCell(newTargetPosition);
//                if (newCell != null)
//                {
//                    if (HexUnit.IsValidDestination(newCell))
//                    {
//                        SetTarget(newCell.Position);
//                        StateMachine.TriggerTransition(FSMStateActor.StateEnum.WALK);
//                    }
//                }
//            }
        }