private void OnHarvestStopReply(byte[] bytes)
        {
            HarvestStopReply input = HarvestStopReply.Parser.ParseFrom(bytes);

            if (input.ActorId != ActorId)
            {
                return; // 不是自己,略过
            }
            if (!input.Ret)
            {
                return;
            }

            HexResource.RESOURCE_TYPE resType = (HexResource.RESOURCE_TYPE)input.ResType;
            HexCell     currentCell           = HexUnit.Location;
            HexResource res   = currentCell.Res;
            int         level = res.GetLevel(resType);

            res.SetAmount(resType, input.ResRemain);
            int levelNew = res.GetLevel(resType);

            if (level != levelNew)
            {
                res.Refresh(currentCell);
            }

            string [] resTypes = { "木材", "粮食", "铁矿" };
            string    msg      = $"获取了 {input.ResHarvest} 的 {resTypes[input.ResType]} 资源";

            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Success);
            GameRoomManager.Instance.Log("MSG: HarvestStop OK - " + msg + $" - 剩余资源{input.ResRemain}");

            // 必要的时候, 刷新地面上的资源数字
            PanelRoomMain.Instance.UpdateResInCell(currentCell.Index);
        }
Exemplo n.º 2
0
    public void SetSelector(PickInfo pickInfo)
    {
        ClearCommands();

        GameRoomManager.Instance.CommandManager.CurrentExecuter = pickInfo;

        //从“command_set”表格中读取对应于该单位的指令菜单集
        CsvStreamReader CommandSet = CsvDataManager.Instance.GetTable("command_set");

        if (CommandSet == null)
        {
            return;
        }
        string strCmdSet      = "";
        string toggleRootName = "";

        if (pickInfo.CurrentCity != null)
        {
            if (pickInfo.CurrentCity.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId) // 只有是自己的城市,才会出现[命令菜单]
            {
                strCmdSet = CommandSet.GetValue(2001, "CommandSet");
            }
            toggleRootName = "城市";
        }
        else if (pickInfo.CurrentActor != null)
        {
            var av = pickInfo.CurrentActor;
            if (av.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId) // 只有是自己的部队,才会出现[命令菜单]
            {
                strCmdSet = CommandSet.GetValue(av.ActorInfoId, "CommandSet");
            }
            CsvStreamReader csv = CsvDataManager.Instance.GetTable("actor_info");
            toggleRootName = csv.GetValue(av.ActorInfoId, "Name");
        }
        else if (pickInfo.CurrentCell != null)
        {
            HexResource res = pickInfo.CurrentCell.Res;
            if (res.GetAmount(res.ResType) > 0)
            {
                string[] resNames = { "木材", "粮食", "铁矿" };
                toggleRootName = $"{resNames[(int) res.ResType]}:{res.GetLevel(res.ResType)}";
            }
            else if (pickInfo.CurrentCell.IsUnderwater)
            {
                toggleRootName = "水";
            }
            else
            {// Sand-0; Grass-1; Mud-2; Stone-3; Snow-4
                string[] terrainNames = { "沙漠", "草原", "沃土", "山区", "雪地" };
                toggleRootName = terrainNames[(int)pickInfo.CurrentCell.TerrainTypeIndex];
            }
        }
        int countCmd = LoadCommandMenu(strCmdSet);

        //gameObject.SetActive(countCmd > 0);
        _toggleText.text = toggleRootName;
        gameObject.SetActive(true);
    }
Exemplo n.º 3
0
    private static void DOWNLOAD_RESCELL_REPLY(byte[] bytes)
    {
        DownloadResCellReply input = DownloadResCellReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = "下载资源数据失败! - " + input.ErrMsg;
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY OK - " + msg);
            return;
        }
        List <HexGridChunk> chunkList = new List <HexGridChunk>();

        for (int i = 0; i < input.InfoCount; ++i)
        {
            HexCell     cell = GameRoomManager.Instance.HexmapHelper.GetCell(input.ResInfo[i].CellIndex);
            HexResource hr   = cell.Res;
            hr.ResType = (HexResource.RESOURCE_TYPE)input.ResInfo[i].ResType;
            hr.SetAmount(hr.ResType, input.ResInfo[i].ResAmount);
            cell.UpdateFeatureLevelFromRes();
            if (!chunkList.Contains(cell.chunk))
            {
                chunkList.Add(cell.chunk);
            }
        }
        // 刷新模型
        foreach (var chunk in chunkList)
        {
            chunk.Refresh();
        }

        if (input.PackageIndex == 0 && input.PackageIndex < input.PackageCount - 1)
        {
            resCount = input.InfoCount;
            string msg = "开始下载资源数据...";
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY - " + msg + $"PackageCount:{input.PackageCount}");
        }
        else if (input.PackageIndex == input.PackageCount - 1)
        {
            resCount += input.InfoCount;
            string msg = "下载资源数据成功!";
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY OK - " + msg + $"PackageCount:{input.PackageCount} - Res Count:{resCount}");
        }
    }
        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);
//                    }
//                }
//            }
        }
Exemplo n.º 5
0
 void AddResToCell(int i, HexResource res)
 {
     cells[i].Res = res;
 }
Exemplo n.º 6
0
    void CreateResource(int x, int y, int i)
    {
        HexResource res = resLayer[i] = new HexResource();

        AddResToCell(i, res);
    }