// 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(); } } } }
// spawn each player pair at a respective spawnpoint // to do this, loop through each player in the gamestate tracker and get a list of the unique teams // once we have this, get the driver and gunner from both. // instantiate the driver's vehicle for each of them (driver character) // instantiate the gunner attached to the vehicle for each of them (gunner character) // only to be called by the master client when we can be sure that everyone has loaded into the game IEnumerator SpawnPlayers() { spawningPlayersScreenInstance = Instantiate(spawningPlayersScreenPrefab, transform.position, Quaternion.identity); // yield return new WaitForSecondsRealtime(0.5f); // if(FindObjectOfType<MakeTheMap>() != null) FindObjectOfType<MakeTheMap>().MakeMap(); yield return(new WaitForSecondsRealtime(1f)); if (PhotonNetwork.IsMasterClient) { GamestateTracker gamestateTracker = FindObjectOfType <GamestateTracker>(); // players should have already had their teams validated through the lobby screen // If we end up with bugs, get Jordan to add extra checks to fill slots with bots at this point. for (short i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry entry = gamestateTracker.teams.GetAtIndex(i); int teamId = entry.id; entry.Release(); // instantiate the vehicle from the vehiclePrefabName in the schema, if null, instantiate the testing truck Spawn(teamId); yield return(new WaitForSeconds(0.5f)); } GameFullySetupMaster(); } }
// called whenever the team stuff changes // update the graphics of the button void TeamListenerCallback(TeamEntry teamEntry) { // display the player details of the driver and gunner in the buttons // driver stuff short driverId = teamEntry.driverId; if (driverId != 0) { PlayerEntry driverEntry = gamestateTracker.players.Get((short)driverId); driverPlayerText.text = driverEntry.name; driverEntry.Release(); if (driverId == PhotonNetwork.LocalPlayer.ActorNumber) { driverFillImage.color = new Color32(0x65, 0xC5, 0x6B, 0xFF); } else { driverFillImage.color = new Color32(0x44, 0x91, 0xCA, 0xFF); } driverButton.interactable = false; } else { driverPlayerText.text = "Empty"; driverFillImage.color = new Color32(0xB0, 0xB0, 0xB0, 0xFF); driverButton.interactable = true; } // gunner stuff short gunnerId = teamEntry.gunnerId; if (gunnerId != 0) { PlayerEntry gunnerEntry = gamestateTracker.players.Get((short)gunnerId); gunnerPlayerText.text = gunnerEntry.name; gunnerEntry.Release(); if (gunnerId == PhotonNetwork.LocalPlayer.ActorNumber) { gunnerFillImage.color = new Color32(0x65, 0xC5, 0x6B, 0xFF); } else { gunnerFillImage.color = new Color32(0x44, 0x91, 0xCA, 0xFF); } gunnerButton.interactable = false; } else { gunnerPlayerText.text = "Empty"; gunnerFillImage.color = new Color32(0xB0, 0xB0, 0xB0, 0xFF); gunnerButton.interactable = true; } teamEntry.Release(); }
void Start() { gamestateTracker = FindObjectOfType <GamestateTracker>(); gamestateVehicleLookup = FindObjectOfType <GamestateVehicleLookup>(); vehicleNames = gamestateVehicleLookup.sortedVehicleNames; PlayerEntry playerEntry = gamestateTracker.players.Get((short)PhotonNetwork.LocalPlayer.ActorNumber); PlayerEntry.Role ourRole = (PlayerEntry.Role)playerEntry.role; ourTeamId = playerEntry.teamId; playerEntry.Release(); // get the team we are in TeamEntry teamEntry = gamestateTracker.teams.Get(ourTeamId); short driverId = teamEntry.driverId; short gunnerId = teamEntry.gunnerId; teamEntry.Release(); // if we are a gunner, check if the driver is a bot. // if so, get priority if (ourRole == PlayerEntry.Role.Gunner) { PlayerEntry driverEntry = gamestateTracker.players.Get(driverId); if (driverEntry.isBot) { priority = true; } driverEntry.Release(); } // if we are a driver, get priority if (ourRole == PlayerEntry.Role.Driver) { priority = true; } // assign other player id, only needed if the other player is human // hence we only check for if we are a driver if (priority && ourRole == PlayerEntry.Role.Driver) { // get gunner id PlayerEntry gunnerEntry = gamestateTracker.players.Get(gunnerId); otherId = gunnerEntry.id; gunnerEntry.Release(); } SetButtonsInteractable(priority); SetupButtons(); }
void SetUpScoreboard() { for (int i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry team = gamestateTracker.teams.GetAtIndex(i); team.AddListener(TeamListener); team.Release(); teamPanels[i].gameObject.SetActive(true); teamPanels[i].Setup(); } UpdateScores(); }
// Die is a LOCAL function that is only called by the driver when they get dead. protected void Die(bool updateDeath, bool updateKill) { // Update gamestate networkManager.CallRespawnVehicle(5f, teamId); TeamEntry team = gamestateTracker.teams.Get((short)teamId); myPhotonView.RPC(nameof(SetGunnerHealth_RPC), RpcTarget.All, 0f); bool hadPotato = hpm.removePotato(); if (!hadPotato) { announcerManager.PlayAnnouncerLine(announcerManager.announcerShouts.onKilled, npv.GetDriverID(), npv.GetGunnerID()); } team.Release(); // update my deaths if (updateDeath) { /*GamestateTracker.TeamDetails myRecord = gamestateTracker.getTeamDetails(teamId); * myRecord.deaths += 1; * myRecord.isDead = true; * gamestateTrackerPhotonView.RPC(nameof(GamestateTracker.UpdateTeamWithNewRecord), RpcTarget.All, teamId, * JsonUtility.ToJson(myRecord));*/ TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); teamEntry.deaths += 1; teamEntry.isDead = true; teamEntry.Increment(); } if (updateKill) { // update their kills /*GamestateTracker.TeamDetails theirRecord = gamestateTracker.getTeamDetails(lastHitDetails.sourceTeamId); * theirRecord.kills += 1; * gamestateTrackerPhotonView.RPC(nameof(GamestateTracker.UpdateTeamWithNewRecord), RpcTarget.All, * lastHitDetails.sourceTeamId, JsonUtility.ToJson(theirRecord));*/ TeamEntry teamEntry = gamestateTracker.teams.Get((short)lastHitDetails.sourceTeamId); teamEntry.kills += 1; teamEntry.Increment(); } }
public void RespawnErrorHandler(TeamEntry teamEntry, bool succeeded) { if (teamEntry != null) { if (!succeeded && teamEntry.isDead) { teamEntry.isDead = false; teamEntry.Commit(RespawnErrorHandler); } else { teamEntry.Release(); } } }
bool CanSelectGunner() { bool canSelect = true; // check if there is a player occupying the current slot TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); // if there is a valid player id in the driver slot, return false if (teamEntry.gunnerId != 0) { canSelect = false; } teamEntry.Release(); return(canSelect); }
// Return the teams from the gamestate tracker, sorted by score. public List <TeamEntry> SortTeams(GamestateTracker gamestateTracker) { List <TeamEntry> unsortedTeams = new List <TeamEntry>(); for (int i = 0; i < gamestateTracker.teams.count; i++) { TeamEntry team = gamestateTracker.teams.GetAtIndex(i); unsortedTeams.Add(team); team.Release(); } List <TeamEntry> sortedTeams = unsortedTeams; sortedTeams.Sort((t1, t2) => CalcScore(t1).CompareTo(CalcScore(t2))); sortedTeams.Reverse(); return(sortedTeams); }
private void OnTriggerEnter(Collider other) { if (this.enabled) { short teamId = (short)GetComponent <VehicleHealthManager>().teamId; TeamEntry team = gamestateTracker.teams.Get(teamId); if (other.CompareTag("Checkpoint") && team.driverId == PhotonNetwork.LocalPlayer.ActorNumber) { checkpoints++; checkpointPos = bc.NextCheckpoint(checkpointPos); bc.gameObject.transform.position = checkpointPos; bc.photonView.RPC(nameof(BasicCheckpoint.UpdatePosition_RPC), RpcTarget.All, checkpointPos.x, checkpointPos.y, checkpointPos.z, team.gunnerId); team.checkpoint = (short)checkpoints; team.Increment(); } else { team.Release(); } } }
public void ResetProperties() { // Debug.Log("reset properties"); TeamEntry team = gamestateTracker.teams.Get((short)teamId); myPhotonView.RPC(nameof(SetGunnerHealth_RPC), RpcTarget.All, maxHealth); team.Release(); GunnerWeaponManager gunnerWeaponManager = GetComponentInChildren <GunnerWeaponManager>(); gunnerWeaponManager.Reset(); DriverAbilityManager driverAbilityManager = GetComponent <DriverAbilityManager>(); driverAbilityManager.Reset(); hpm.canPickupPotato = true; smokeL.Stop(); smokeM.Stop(); smokeH.Stop(); // Debug.Log("Called"); rb.linearDamping = defaultDrag; rb.angularDamping = defaultAngularDrag; rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; icd4.isDead = false; rb.centreOfMass = Vector3.zero; TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); teamEntry.isDead = false; teamEntry.Increment(); myPhotonView.RPC(nameof(ResetMesh_RPC), RpcTarget.AllBuffered); myPhotonView.RPC(nameof(SetIsDead_RPC), RpcTarget.All, false); GetComponentInChildren <DriverCinematicCam>().ResetCam(); }
public void GamestateApplyTeamPacketTest() { short actorNumber = 17; GamestateCommitTestHelper <TeamEntry> testHelper = new GamestateCommitTestHelper <TeamEntry>(actorNumber); GamestateTable <TeamEntry> teams = testHelper.TestTable(GamestateTracker.Table.Teams); GamestateRandomTestingUnit generator = new GamestateRandomTestingUnit(82); for (short i = 0; i < 100; i++) { TeamEntry teamEntry = teams.Create(i); generator.RandomiseTeamEntry(teamEntry); teamEntry.Commit(); GamestatePacket packet = testHelper.commitedPackets[0]; testHelper.Apply(packet); teamEntry = teams.Get(i); GamestateAssertionUnit.AssertPacketApplied(teamEntry, packet); teamEntry.Release(); testHelper.commitedPackets.Clear(); } }
// called by the lobby button master when we create a team public bool TeamRemoveEntry() { lobbySlotMaster = FindObjectOfType <LobbySlotMaster>(); gamestateTracker = FindObjectOfType <GamestateTracker>(); TeamEntry teamEntry = gamestateTracker.teams.Get((short)teamId); bool canRemove = true; // look for the corresponding players in the team // get driver player (if they exist) short driverId = teamEntry.driverId; if (driverId != 0) { PlayerEntry driverEntry = gamestateTracker.players.Get((short)driverId); // if they are bots, then kick them if (driverEntry.isBot) { driverEntry.Delete(); } // unready and unselect them else { canRemove = false; driverEntry.Release(); } } // get gunner player (if they exist) short gunnerId = teamEntry.gunnerId; if (gunnerId != 0) { PlayerEntry gunnerEntry = gamestateTracker.players.Get((short)gunnerId); if (gunnerEntry.isBot) { gunnerEntry.Delete(); } // unready and unselect them else { canRemove = false; gunnerEntry.Release(); } } if (canRemove) { Debug.Log("Deleting team entry"); teamEntry.Delete(); } else { teamEntry.Release(); } return(canRemove); }
void TeamListener(TeamEntry team) { team.Release(); UpdateScores(); }