Example #1
0
    private void OnCityAddReply(byte[] bytes)
    {
        CityAddReply input = CityAddReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = $"创建城市失败!";
            GameRoomManager.Instance.Log("MSG: CityAddReply Error - " + msg);
            return;
        }
        UrbanCity city = new UrbanCity()
        {
            RoomId    = input.RoomId,
            OwnerId   = input.OwnerId,
            CityId    = input.CityId,
            PosX      = input.PosX,
            PosZ      = input.PosZ,
            CellIndex = input.CellIndex,
            CityName  = input.CityName,
            CitySize  = input.CitySize,
            IsCapital = input.IsCapital,
        };
        bool isMyCity = input.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId;

        UrbanManager.AddCity(city, isMyCity);

        if (city.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId &&
            city.IsCapital)
        {
            GameRoomManager.Instance.HexmapHelper.SetCameraPosition(input.CellIndex);
        }
        GameRoomManager.Instance.Log($"RoomLogic OnCityAddReply OK - 创建城市,坐标:{city.PosX}, {city.PosZ} - Index:{city.CellIndex} - CitySize:{city.CitySize} - IsCapital:{city.IsCapital}");
    }
    public UrbanCity CreateCityHere(HexCell cell)
    {
        int  size     = 1;
        bool bSuccess = TryALargeCityHere(cell);

        if (!bSuccess)
        {
            bSuccess = TryASmallCityHere(cell);
            size     = 0;
        }

        if (bSuccess)
        {
            UrbanCity city = new UrbanCity()
            {
                RoomId    = GameRoomManager.Instance.RoomId,
                OwnerId   = GameRoomManager.Instance.CurrentPlayer.TokenId,
                CityId    = Utils.GuidToLongId(),
                PosX      = cell.coordinates.X,
                PosZ      = cell.coordinates.Z,
                CellIndex = cell.Index,
                CityName  = "N/A",
                CitySize  = size,
            };
            return(city);
        }

        return(null);
    }
    public bool LoadBuffer(byte[] bytes, int size)
    {
        MemoryStream ms        = new MemoryStream(bytes);
        BinaryReader br        = new BinaryReader(ms);
        int          version   = br.ReadInt32();
        int          cityCount = br.ReadInt32();

        if (cityCount < 0 || cityCount > 9999)
        {
            ServerRoomManager.Instance.Log($"UrbanManager - LoadBuffer Error - count of cities is invalid: {cityCount} - should between:{0}~{9999}");
            return(false);
        }

        AllCities.Clear();
        for (int i = 0; i < cityCount; ++i)
        {
            int index = br.ReadInt32();
            if (index != i)
            {
                ServerRoomManager.Instance.Log($"UrbanManager - LoadBuffer Error - city index is not valid:{index}- should between:{0}~{cityCount}");
                return(false);
            }

            UrbanCity city = new UrbanCity();
            city.LoadBuffer(br);
            AddCity(city);
        }
        ServerRoomManager.Instance.Log($"UrbanManager LoadBuffer OK - Count of Cities :{AllCities.Count}"); // 城市个数

        return(true);
    }
Example #4
0
 public void Clear()
 {
     CurrentCell = null;
     //CurrentUnit = null;
     CurrentCity  = null;
     CurrentActor = null;
 }
Example #5
0
    private void OnCityAdd(SocketAsyncEventArgs args, byte[] bytes)
    {
        CityAdd input = CityAdd.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        // 删除建造城市的开拓者
        {
            bool ret = ActorManager.RemoveActor(input.CreatorId);

            ActorRemoveReply output = new ActorRemoveReply()
            {
                RoomId  = input.RoomId,
                OwnerId = input.OwnerId,
                ActorId = input.CreatorId,
                Ret     = ret,
            };
            BroadcastMsg(ROOM_REPLY.ActorRemoveReply, output.ToByteArray());
        }

        if (input.CellIndex == 0)
        {
            Debug.LogError("OnCityAdd F**k!!! City position is lost!!!");
        }

        bool      isCapiirtal = UrbanManager.CountOfThePlayer(input.OwnerId) == 0; // 第一座城市是都城
        UrbanCity city        = new UrbanCity()
        {
            RoomId    = input.RoomId,
            OwnerId   = input.OwnerId,
            CityId    = input.CityId,
            PosX      = input.PosX,
            PosZ      = input.PosZ,
            CellIndex = input.CellIndex,
            CityName  = input.CityName,
            CitySize  = input.CitySize,
            IsCapital = isCapiirtal,
        };

        UrbanManager.AddCity(city);

        {
            CityAddReply output = new CityAddReply()
            {
                RoomId    = input.RoomId,
                OwnerId   = input.OwnerId,
                CityId    = input.CityId,
                PosX      = input.PosX,
                PosZ      = input.PosZ,
                CellIndex = input.CellIndex,
                CityName  = input.CityName,
                CitySize  = input.CitySize,
                IsCapital = isCapiirtal,
                Ret       = true,
            };
            BroadcastMsg(ROOM_REPLY.CityAddReply, output.ToByteArray());
        }
    }
    public void OnClickReturnCity()
    {
        Vector3 posCity = Vector3.zero;

        if (GameRoomManager.Instance.RoomLogic.UrbanManager.Cities.Count > 0)
        {
            UrbanCity city = null;
            foreach (var keyValue in GameRoomManager.Instance.RoomLogic.UrbanManager.Cities)
            {
                UrbanCity urban = keyValue.Value;
                if (urban != null)
                {
                    if (urban.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId && urban.IsCapital)
                    {
                        city = urban;
                    }
                }
            }
            if (city != null)
            {
                var cell = GameRoomManager.Instance.HexmapHelper.GetCell(city.CellIndex);
                if (cell != null)
                {
                    posCity = cell.Position;
                }
            }
        }

        if (posCity != Vector3.zero)
        {
            StartCoroutine(ReturningCity(posCity));
        }
    }
 private void ShowSelectorCity(UrbanCity city, bool bShow)
 {
     _selectObj.SetActive(bShow);
     if (city != null)
     {
         HexCell cell = hexmapHelper.GetCell(city.CellIndex);
         if (cell)
         {
             _selectObj.transform.parent        = cell.transform;
             _selectObj.transform.localPosition = Vector3.up * 0.2f;
             SelectCircle sc = _selectObj.GetComponent <SelectCircle>();
             if (sc)
             {
                 if (city.CitySize == 1)
                 {
                     sc.SetSize(20);
                 }
                 else
                 {
                     sc.SetSize(8);
                 }
             }
         }
     }
 }
 public void AddCity(UrbanCity city, bool isMyCity)
 {
     if (Cities.ContainsKey(city.CityId))
     {
         GameRoomManager.Instance.Log("MSG: Duplicated city!");
     }
     else
     {
         Cities.Add(city.CityId, city);
     }
     _HexmapHelper.AddCity(city.CellIndex, city.CitySize, isMyCity);
 }
Example #9
0
    public void Run()
    {
        PickInfo pi = CommandManager.Instance.CurrentExecuter;

        if (pi.CurrentCity == null)
        {
            return;
        }
        UrbanCity city = pi.CurrentCity;

        PanelRoomMain.Instance.AskCreateUnit(city, 10013);
    }
    private static void DOWNLOAD_CITIES_REPLY(byte[] bytes)
    {
        DownloadCitiesReply input = DownloadCitiesReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = $"查询城市信息失败!";
            GameRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES_REPLY Error - " + msg);
            return;
        }
        GameRoomManager.Instance.Log($"MSG: DOWNLOAD_CITIES_REPLY OK - 城市个数:{input.MyCount}/{input.TotalCount}");

        // 如果我一个城市都没有,则主动创建一个城市
        if (input.MyCount == 0)
        {
            UrbanCity city = GameRoomManager.Instance.RoomLogic.UrbanManager.CreateRandomCity();
            if (city == null)
            {
                string msg = "自动创建城市失败!";
                UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
                GameRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES_REPLY - " + msg);
            }
            else
            {
                CityAdd output = new CityAdd()
                {
                    RoomId    = city.RoomId,
                    OwnerId   = city.OwnerId,
                    CityId    = city.CityId,
                    PosX      = city.PosX,
                    PosZ      = city.PosZ,
                    CellIndex = city.CellIndex,
                    CityName  = city.CityName,
                    CitySize  = city.CitySize,
                };
                GameRoomManager.Instance.SendMsg(ROOM.CityAdd, output.ToByteArray());
                GameRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES_REPLY OK - 申请创建城市...");
            }
        }

        {
            string msg = $"查询城市信息成功!";
            GameRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES_REPLY OK - " + msg + $"City Count:{input.MyCount}/{input.TotalCount}");
        }
        // 进入房间整体流程完成
        UIManager.Instance.EndLoading();
    }
    public UrbanCity CreateRandomCity()
    {
        int       size;
        HexCell   cityCenter = SearchAnUrbanArea(out size);
        UrbanCity city       = new UrbanCity()
        {
            RoomId    = GameRoomManager.Instance.RoomId,
            OwnerId   = GameRoomManager.Instance.CurrentPlayer.TokenId,
            CityId    = Utils.GuidToLongId(),
            PosX      = cityCenter.coordinates.X,
            PosZ      = cityCenter.coordinates.Z,
            CellIndex = cityCenter.Index,
            CityName  = "N/A",
            CitySize  = size,
        };

        return(city);
    }
    bool AskBuildCity()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && cell.Unit)
        {
            string msg = $"这里有部队存在,不能创建城市!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            GameRoomManager.Instance.Log("AskBuildCity - " + msg);
            return(false);
        }
        UrbanCity city = GameRoomManager.Instance.RoomLogic.UrbanManager.CreateCityHere(cell);

        if (city == null)
        {
            string msg = "无法创建城市!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            GameRoomManager.Instance.Log("AskBuildCity - " + msg);
            return(false);
        }
        else
        {
            CityAdd output = new CityAdd()
            {
                RoomId    = city.RoomId,
                OwnerId   = city.OwnerId,
                CityId    = city.CityId,
                PosX      = city.PosX,
                PosZ      = city.PosZ,
                CellIndex = city.CellIndex,
                CityName  = city.CityName,
                CitySize  = city.CitySize,
            };
            GameRoomManager.Instance.SendMsg(ROOM.CityAdd, output.ToByteArray());
            GameRoomManager.Instance.Log("AskBuildCity - 申请创建城市...");
        }
        return(true);
    }
    private static void DOWNLOAD_CITIES(byte [] bytes)
    {
        DownloadCities input     = DownloadCities.Parser.ParseFrom(bytes);
        RoomLogic      roomLogic = ServerRoomManager.Instance.GetRoomLogic(input.RoomId);

        if (roomLogic == null)
        {
            string msg = $"Battlefield is not found!"; // 战场没有找到
            ServerRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES Error - " + msg + $" - {input.RoomId}");
            DownloadCitiesReply output = new DownloadCitiesReply()
            {
                RoomId = input.RoomId,
                Ret    = false,
                ErrMsg = msg,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadCitiesReply, output.ToByteArray());
            return;
        }
        PlayerInfo pi = ServerRoomManager.Instance.GetPlayer(_args);

        if (pi == null)
        {
            string msg = $"Current Player is not found!"; // 当前玩家没有找到
            ServerRoomManager.Instance.Log("MSG: DOWNLOAD_CITIES Error - " + msg);
            DownloadCitiesReply output = new DownloadCitiesReply()
            {
                RoomId = input.RoomId,
                Ret    = false,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadCitiesReply, output.ToByteArray());
            return;
        }

        long OwnerId = pi.Enter.TokenId;

        long capitalCityId = 0;

        foreach (var keyValue in roomLogic.UrbanManager.AllCities)
        {
            UrbanCity city = keyValue.Value;
            if (city.IsCapital && city.OwnerId == OwnerId)
            {
                capitalCityId = city.CityId;
            }
            CityAddReply output = new CityAddReply()
            {
                RoomId    = city.RoomId,
                OwnerId   = city.OwnerId,
                CityId    = city.CityId,
                PosX      = city.PosX,
                PosZ      = city.PosZ,
                CellIndex = city.CellIndex,
                CityName  = city.CityName,
                CitySize  = city.CitySize,
                IsCapital = city.IsCapital,
                Ret       = true,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.CityAddReply, output.ToByteArray());
        }

        {
            DownloadCitiesReply output = new DownloadCitiesReply()
            {
                RoomId        = input.RoomId,
                TotalCount    = roomLogic.UrbanManager.AllCities.Count,
                MyCount       = roomLogic.UrbanManager.CountOfThePlayer(OwnerId),
                CapitalCityId = capitalCityId,
                Ret           = true,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadCitiesReply, output.ToByteArray());
            ServerRoomManager.Instance.Log($"MSG: DOWNLOAD_CITIES OK - Player:{pi.Enter.Account} - City Count:{output.MyCount}/{output.TotalCount}");
        }
    }
 public void AddCity(UrbanCity city)
 {
     AllCities[city.CityId] = city;
 }
Example #15
0
    public void Run()
    {
        var pi = CommandManager.Instance.CurrentExecuter;

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

        long creatorId = 0;
        var  av        = pi.CurrentActor;

        if (av != null)
        {
            creatorId = av.ActorId;
        }
        else
        {
            string msg = "没有找到开拓者,无法创建城市!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            GameRoomManager.Instance.Log("CmdBuildCity Error - " + msg);
            return;
        }

        UrbanCity city = GameRoomManager.Instance.RoomLogic.UrbanManager.CreateCityHere(av.HexUnit.Location);

        if (city == null)
        {
            string msg = "这个位置无法创建城市!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            GameRoomManager.Instance.Log("CmdBuildCity Error - " + msg);
            return;
        }
        // 看看行动点够不够
        if (!CmdAttack.IsActionPointGranted())
        {
            string msg = "行动点数不够, 本操作无法执行! ";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.Log("CmdBuildCity Run Error - " + msg);
            return;
        }

        {
            CityAdd output = new CityAdd()
            {
                RoomId    = city.RoomId,
                OwnerId   = city.OwnerId,
                CityId    = city.CityId,
                PosX      = city.PosX,
                PosZ      = city.PosZ,
                CellIndex = city.CellIndex,
                CityName  = city.CityName,
                CitySize  = city.CitySize,
                CreatorId = creatorId,
            };
            GameRoomManager.Instance.SendMsg(ROOM.CityAdd, output.ToByteArray());
            GameRoomManager.Instance.Log("AskBuildCity - 申请创建城市...");
            // 消耗行动点
            CmdAttack.TryCommand();
        }
    }
    public bool AskCreateUnit(UrbanCity city, int actorInfoId)
    {
        HexCell cellCenter = GameRoomManager.Instance.HexmapHelper.GetCell(city.CellIndex);// 城市中心地块

        return(AskCreateUnit(cellCenter, actorInfoId));
    }