public void GamestateApplyMultiplePlayerPacketsTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(8); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); playerEntry.Commit(); GamestatePacket packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); playerEntry = players.Get(i); GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet); generator.RandomisePlayerEntry(playerEntry); playerEntry.Commit(); packet = testHelper.commitedPackets[1]; testHelper.Apply(packet); playerEntry = players.Get(i); GamestateAssertionUnit.AssertPacketApplied(playerEntry, packet); playerEntry.Release(); testHelper.commitedPackets.Clear(); } }
// Start is called before the first frame update void Start() { maxPlayers = PhotonNetwork.CurrentRoom.MaxPlayers; playersInLobby = PhotonNetwork.CurrentRoom.PlayerCount; // add ourselves if (PhotonNetwork.IsMasterClient) { PlayerEntry playerEntry = gamestateTracker.players.Create((short)PhotonNetwork.LocalPlayer.ActorNumber); playerEntry.name = PhotonNetwork.LocalPlayer.NickName; playerEntry.Commit(); selectMapText.text = "Select a map:"; } foreach (LobbyButtonScript lobbyButton in lobbyButtons) { if (lobbyButton.gameObject.activeInHierarchy) { //gamestateTracker.schema.teamsList.Add(new GamestateTracker.TeamDetails(lobbyButton.teamId)); if (PhotonNetwork.IsMasterClient) { lobbyButton.CreateTeamEntry(); } //TeamEntry team = gamestateTracker.teams.Create((short)lobbyButton.teamId); //team.Commit(); } } }
void SetReady(bool state) { isReady = state; PlayerEntry playerEntry = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); if (playerEntry.role == (short)PlayerEntry.Role.None) { isReady = false; } lobbySlotMaster.GetComponent <PhotonView>().RPC(nameof(LobbySlotMaster.UpdateCountAndReady), RpcTarget.All); playerEntry.ready = isReady; playerEntry.Commit(); if (!isReady) { buttonFill.color = new Color32(0xFF, 0x61, 0x61, 0xFF); buttonText.text = "Ready Up"; } else { buttonFill.color = new Color32(0x65, 0xC5, 0x6B, 0xFF); buttonText.text = "Unready"; } }
public void GamestateApplyPlayerPacketErrorCallbackTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(9); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); GamestatePacket packet = GamestatePacketManager.GetPacket(); bool errorCallbackCalled = false; playerEntry.Commit((PlayerEntry entry, bool succeeded) => { Assert.That(succeeded, Is.EqualTo(true)); GamestateAssertionUnit.AssertPacketApplied(entry, packet); entry.Release(); errorCallbackCalled = true; }); packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); Assert.That(errorCallbackCalled, Is.EqualTo(true)); testHelper.commitedPackets.Clear(); } }
public void GamestateApplyPlayerPacketListenerDeletionTest() { short actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(12); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); GamestatePacket packet = GamestatePacketManager.GetPacket(); bool listenerACalled = false; bool listenerBCalled = false; bool listenerCCalled = false; bool listenerDCalled = false; int a = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerACalled = true; }); int b = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerBCalled = true; }); int c = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerCCalled = true; }); playerEntry.RemoveListener(b); int d = playerEntry.AddListener((PlayerEntry entry) => { entry.Release(); listenerDCalled = true; }); playerEntry.RemoveListener(c); playerEntry.Commit(); packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); Assert.That(listenerACalled, Is.EqualTo(true)); Assert.That(listenerBCalled, Is.EqualTo(false)); Assert.That(listenerCCalled, Is.EqualTo(false)); Assert.That(listenerDCalled, Is.EqualTo(true)); testHelper.commitedPackets.Clear(); } }
// gets incomplete teams in the gamestate tracker and puts in a bot // only to be called by master client public void FillIncompleteTeamsWithBots() { if (PhotonNetwork.IsMasterClient) { // foreach team in the gamestate tracker, check that valid ids exist for driver and gunner // if ids are 0 (ie not valid) then create a bot for (int i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry teamEntry = gamestateTracker.teams.GetAtIndex(i); // add driver bot if (teamEntry.driverId == 0) { PlayerEntry bot = gamestateTracker.players.Create(true, true); bot.ready = true; bot.role = (short)PlayerEntry.Role.Driver; bot.isBot = true; bot.name = "Bot " + -bot.id; bot.teamId = (short)teamEntry.id; bot.Commit(); // now add the entry to the team teamEntry.driverId = bot.id; teamEntry.Commit(); } else { teamEntry.Release(); } teamEntry = gamestateTracker.teams.GetAtIndex(i); // add gunner bot if (teamEntry.gunnerId == 0) { PlayerEntry bot = gamestateTracker.players.Create(true, true); bot.ready = true; bot.role = (short)PlayerEntry.Role.Gunner; bot.isBot = true; bot.name = "Bot " + -bot.id; bot.teamId = (short)teamEntry.id; bot.Commit(); // now add the entry to the team teamEntry.gunnerId = bot.id; teamEntry.Commit(); } else { teamEntry.Release(); } } } }
public override void OnPlayerEnteredRoom(Player newPlayer) { base.OnPlayerEnteredRoom(newPlayer); playersInLobby = PhotonNetwork.CurrentRoom.PlayerCount; // update the lobby stats on screen if (PhotonNetwork.IsMasterClient) { PlayerEntry playerEntry = gamestateTracker.players.Create((short)newPlayer.ActorNumber); playerEntry.name = newPlayer.NickName; playerEntry.Commit(); } }
public void GamestateCreatePlayerTest() { short id = 7; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(1); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); PlayerEntry playerEntry = players.Create(id); Assert.That(playerEntry, Is.Not.Null); Assert.That(playerEntry.id, Is.EqualTo(id)); playerEntry.Commit(); testHelper.Apply(testHelper.commitedPackets[0]); Assert.That(players.Get(id), Is.Not.Null); }
// USED // add the driver bot public void AddDriverBot() { if (CanSelectDriver()) { PlayerEntry bot = gamestateTracker.players.Create(true, true); bot.ready = true; bot.role = (short)PlayerEntry.Role.Driver; bot.isBot = true; bot.teamId = (short)teamId; bot.name = "Bot " + -bot.id; bot.Commit(); // now add the entry to the team TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); teamEntry.driverId = bot.id; teamEntry.Commit(); } }
public void GamestateCommitPlayerTest() { short actorNumber = 1; short entryId = 2; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); PlayerEntry playerEntry = players.Create(entryId); playerEntry.name = "AAA"; playerEntry.isBot = false; playerEntry.ready = true; playerEntry.actorNumber = actorNumber; playerEntry.role = 5; playerEntry.character = 2; playerEntry.teamId = 9; playerEntry.Commit(); Assert.That(testHelper.commitedPackets.Count, Is.EqualTo(1)); GamestatePacket packet = testHelper.commitedPackets[0]; Assert.That(packet.revisionNumber, Is.EqualTo(1)); Assert.That(packet.revisionActor, Is.EqualTo(actorNumber)); Assert.That(packet.id, Is.EqualTo(entryId)); Assert.That(packet.hasName, Is.EqualTo(true)); Assert.That(packet.name, Is.EqualTo("AAA")); bool[] hasShortValues = new bool[GamestatePacket.maxShorts]; hasShortValues[(int)PlayerEntry.ShortFields.ActorNumber] = true; hasShortValues[(int)PlayerEntry.ShortFields.Role] = true; hasShortValues[(int)PlayerEntry.ShortFields.Character] = true; hasShortValues[(int)PlayerEntry.ShortFields.TeamId] = true; Assert.That(packet.hasShortValues, Is.EquivalentTo(hasShortValues)); Assert.That(packet.shortValues, Is.EquivalentTo(new short[] { actorNumber, 5, 2, 9 })); bool[] boolValues = new bool[GamestatePacket.maxBools]; boolValues[0] = false; boolValues[1] = true; Assert.That(packet.boolValues, Is.EquivalentTo(boolValues)); }
// USED public void SelectGunner() { if (CanSelectGunner()) { // get my player id short myId = (short)PhotonNetwork.LocalPlayer.ActorNumber; PlayerEntry playerEntry = gamestateTracker.players.Get(myId); // search for myself in the teams // if I already am in a team, remove me if (playerEntry.teamId != 0) { TeamEntry oldTeamEntry = gamestateTracker.teams.Get(playerEntry.teamId); if (playerEntry.role == (short)PlayerEntry.Role.Driver) { oldTeamEntry.driverId = 0; } if (playerEntry.role == (short)PlayerEntry.Role.Gunner) { oldTeamEntry.gunnerId = 0; } oldTeamEntry.Commit(); } // set my roles playerEntry.role = (short)PlayerEntry.Role.Gunner; // set my team playerEntry.teamId = (short)teamId; playerEntry.Commit(); // set the driver team TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); teamEntry.gunnerId = myId; teamEntry.Commit(); } }
public void GamestateAttemptApplyPlayerPacketTest() { byte actorNumber = 1; GamestateCommitTestHelper <PlayerEntry> testHelper = new GamestateCommitTestHelper <PlayerEntry>(actorNumber); GamestateTable <PlayerEntry> players = testHelper.TestTable(GamestateTracker.Table.Players); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(902); for (short i = 0; i < 100; i++) { PlayerEntry playerEntry = players.Create(i); generator.RandomisePlayerEntry(playerEntry); playerEntry.Commit(); GamestatePacket packetA = testHelper.commitedPackets[0]; bool attemptA = testHelper.AttemptApply(packetA); GamestatePacket packetB = generator.GetRandomPacket(); packetB.id = i; packetB.packetType = GamestatePacket.PacketType.Update; packetB.revisionNumber = packetA.revisionNumber; bool attemptB = testHelper.AttemptApply(packetB); GamestatePacket packetC = generator.GetRandomPacket(); packetC.id = i; packetC.packetType = GamestatePacket.PacketType.Update; packetC.revisionNumber = packetA.revisionNumber; bool attemptC = testHelper.AttemptApply(packetC); Assert.That(attemptA, Is.EqualTo(true)); Assert.That(attemptB, Is.EqualTo(false)); Assert.That(attemptC, Is.EqualTo(false)); playerEntry = players.Get(i); GamestateAssertionUnit.AssertPacketApplied(playerEntry, packetA); playerEntry.Release(); testHelper.commitedPackets.Clear(); } }