public void BattleStartHandler(NetConnection connection, object data) { PlayerInitDatas inits = GCli.Deserialize <PlayerInitDatas>((byte[])data); GCli.ClearPacketHandler(); room.SetActive(false); menu.SetActive(false); GCli.SetPacketHandler(MessageType.Snapshot, DataType.Bytes, SnapshotHandler); GCli.SetPacketHandler(MessageType.ReplyWon, DataType.Int32, ReplyWonHandler); GCli.SetPacketHandler(MessageType.BattleEnd, DataType.Null, BattleEndHandler); GCli.SetPacketHandler(MessageType.ReplySetBlock, DataType.Bytes, ReplySetBlockHandler); GCli.SetPacketHandler(MessageType.ReplyFire, DataType.Int32, ReplyFire); foreach (PlayerInitData init in inits.datas) { if (init.sync.userid == Players.userid) { World.SetCoreFaction(init.faction); Players.AddPlayer(init); } } foreach (PlayerInitData init in inits.datas) { if (init.sync.userid != Players.userid) { Players.AddOtherPlayer(init); } } }
public void CheckBattleStart() { if (players.Count == 0) { return; } Player not_ready_player = players.FirstOrDefault(x => x.Value.ready == false).Value; if (not_ready_player != null) { return; } PlayerInitDatas datas = new PlayerInitDatas(); foreach (Player player in players.Values) { if (player.faction == 0) { PlayerSyncData sync = new PlayerSyncData { userid = player.userid, xpos = 16.0f, ypos = 17.0f, zpos = 1.0f, xrot = 0.0f, yrot = 0.0f, animestate = 0, hp = 100 }; player.sync = sync; } else { PlayerSyncData sync = new PlayerSyncData { userid = player.userid, xpos = 16.0f, ypos = 17.0f, zpos = 63.0f, xrot = 0.0f, yrot = 180.0f, animestate = 0, hp = 100 }; player.sync = sync; } player.ResetRespawnTimer(); datas.datas.Add(new PlayerInitData { username = player.username, faction = player.faction, sync = player.sync }); } foreach (Player player in players.Values) { GSrv.Send(MessageType.BattleStart, GSrv.Serialize <PlayerInitDatas>(datas), player.connection, NetDeliveryMethod.ReliableOrdered); } roomstate = 1; }