private static void DOWNLOAD_ACTORS_REPLY(byte[] bytes) { DownloadActorsReply input = DownloadActorsReply.Parser.ParseFrom(bytes); if (!input.Ret) { string msg = $"查询单元信息失败!"; GameRoomManager.Instance.Log("MSG: DOWNLOAD_ACTORS_REPLY Error - " + msg); return; } { string msg = $"查询单元信息成功!"; GameRoomManager.Instance.Log("MSG: DOWNLOAD_ACTORS_REPLY OK - " + msg + $"City Count:{input.MyCount}/{input.TotalCount}"); } }
private static void DOWNLOAD_ACTORS(byte[] bytes) { DownloadActors input = DownloadActors.Parser.ParseFrom(bytes); RoomLogic roomLogic = ServerRoomManager.Instance.GetRoomLogic(input.RoomId); if (roomLogic == null) { string msg = $"Battlefield is not found!"; // 战场没有找到 ServerRoomManager.Instance.Log("MSG: DOWNLOAD_ACTORS Error - " + msg + $" - {input.RoomId}"); DownloadCitiesReply output = new DownloadCitiesReply() { RoomId = input.RoomId, Ret = false, ErrMsg = msg, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadActorsReply, output.ToByteArray()); return; } // 把房间内已有的所有actor都发给本人 foreach (var keyValue in roomLogic.ActorManager.AllActors) { ActorBehaviour ab = keyValue.Value; if (ab.CellIndex == 0) { Debug.LogError("DOWNLOAD_ACTORS Erro - Actor position is lost!!!"); continue; } ActorAddReply output = new ActorAddReply() { RoomId = ab.RoomId, OwnerId = ab.OwnerId, ActorId = ab.ActorId, PosX = ab.PosX, PosZ = ab.PosZ, CellIndex = ab.CellIndex, Orientation = ab.Orientation, Species = ab.Species, ActorInfoId = ab.ActorInfoId, Name = ab.Name, Hp = ab.Hp, HpMax = ab.HpMax, AttackPower = ab.AttackPower, DefencePower = ab.DefencePower, Speed = ab.Speed, FieldOfVision = ab.FieldOfVision, ShootingRange = ab.ShootingRange, AttackDuration = ab.AttackDuration, AttackInterval = ab.AttackInterval, AmmoBase = ab.AmmoBase, AmmoBaseMax = ab.AmmoBaseMax, // High AI params HighAiState = ab.HighAiState, HighAiTargetId = ab.HighAiTargetId, HighAiCellIndexTo = ab.HighAiCellIndexTo, HighAiDurationTime = ab.HighAiDurationTime, HighAiTotalTime = ab.HighAiTotalTime, Ret = true, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.ActorAddReply, output.ToByteArray()); // 更新AI状态, 注: 尽管参数与ActorAiStateReply一样, 但是这里是高级AI状态 if (ab.HighAiDurationTime > 0) { ab.HighAiDurationTime -= (float)(DateTime.Now - ab.HighAiStartTime).TotalSeconds; if (ab.HighAiDurationTime < 0f) { ServerRoomManager.Instance.Log($"RoomMsgReply DOWNLOAD_ACTORS Error - HighAiDurationTime is less than 0 - Name:{ab.Name} - Time:{ab.HighAiDurationTime}"); ab.HighAiDurationTime = 0f; } } } { PlayerInfo pi = ServerRoomManager.Instance.GetPlayer(_args); if (pi == null) { string msg = $"当前玩家没有找到!"; ServerRoomManager.Instance.Log("MSG: DOWNLOAD_ACTORS Error - " + msg); DownloadCitiesReply output = new DownloadCitiesReply() { RoomId = input.RoomId, Ret = false, ErrMsg = msg, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadActorsReply, output.ToByteArray()); return; } pi.IsReady = true; // 客户端准备好了,可以检测心跳了 long OwnerId = pi.Enter.TokenId; { DownloadActorsReply output = new DownloadActorsReply() { RoomId = input.RoomId, TotalCount = roomLogic.UrbanManager.AllCities.Count, MyCount = roomLogic.UrbanManager.CountOfThePlayer(OwnerId), Ret = true, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadActorsReply, output.ToByteArray()); ServerRoomManager.Instance.Log($"MSG: DOWNLOAD_ACTORS OK - Player:{pi.Enter.Account} - City Count:{output.MyCount}/{output.TotalCount}"); } } }