tdm done
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Photon.Realtime;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,7 +11,6 @@ public class LeaderboardTDM : MonoBehaviour
|
||||
|
||||
public Transform[] TeamParents;
|
||||
public void Populate(PlayerNetwork[] list){
|
||||
|
||||
//Teamify
|
||||
Teams = new Dictionary<string, List<PlayerNetwork>>();
|
||||
foreach(PlayerNetwork player in list){
|
||||
@@ -24,13 +24,12 @@ public class LeaderboardTDM : MonoBehaviour
|
||||
for(int i=0; i < TeamParents.Length; i++){
|
||||
bool withinRange = (Teams.Keys.Count > i);
|
||||
TeamParents[i].gameObject.SetActive(withinRange);
|
||||
|
||||
unsortedTeamScores = new Dictionary<string, int>();
|
||||
if(withinRange){
|
||||
TeamParents[i].GetChild(0).GetComponent<TMP_Text>().text = Teams.Keys.ElementAt(i);
|
||||
int score =0;
|
||||
|
||||
for(int ii = 0; ii < TeamParents[i].GetChild(2).childCount; ii++){
|
||||
|
||||
bool playerItemsWithinRange = Teams.Values.ElementAt(i).Count > ii;
|
||||
Transform playerItemTransform = TeamParents[i].GetChild(2).GetChild(ii);
|
||||
playerItemTransform.gameObject.SetActive(playerItemsWithinRange);
|
||||
@@ -44,11 +43,13 @@ public class LeaderboardTDM : MonoBehaviour
|
||||
|
||||
score+= player.kills;
|
||||
}
|
||||
|
||||
unsortedTeamScores.Add(Teams.Keys.ElementAt(i), score);
|
||||
|
||||
TeamParents[i].GetChild(1).GetComponent<TMP_Text>().text = (score * 10).ToString("n0");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, int> unsortedTeamScores;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
private double m_startTime;
|
||||
public int DeathmatchRoundLength = 600;
|
||||
public int DeathmtachRoundCountdown = 5;
|
||||
public int TDM_MinPlayers = 4;
|
||||
public double StartTime{
|
||||
get{
|
||||
return m_startTime;
|
||||
@@ -55,7 +56,7 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
public static string partyId;
|
||||
public static string RoomName;
|
||||
public static bool isInit =false;
|
||||
public static string desiredGameMode;
|
||||
public static string desiredGameMode = GameModes.Deathmatch.ToString();
|
||||
public static GameManager instance;
|
||||
public static PlayerController localPlayer;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
base.OnJoinedRoom();
|
||||
StartCoroutine(KickstartGame());
|
||||
//
|
||||
|
||||
UIManager.instance.loadingPanel.SetActive(false);
|
||||
}
|
||||
|
||||
void SpawnLoots(){
|
||||
@@ -166,11 +167,11 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
}
|
||||
|
||||
public void FinishRound(){
|
||||
int position =0;
|
||||
for(position=0; position < Leaderboard.list.Length; position++){
|
||||
if(Leaderboard.list[position] == localPlayer.playerNetwork){
|
||||
break;
|
||||
}
|
||||
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
FinishDeathmatch();
|
||||
}else if(desiredGameMode == GameModes.TeamDeathmatch.ToString()){
|
||||
FinishTeamdeathmatch();
|
||||
}
|
||||
|
||||
if(PhotonNetwork.IsMasterClient){
|
||||
@@ -179,16 +180,37 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
CameraFollow.Pause();
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
UIManager.ShowDeathmatchFinishScreen(position, Leaderboard.list[0].username);
|
||||
}
|
||||
|
||||
|
||||
PhotonNetwork.LeaveRoom();
|
||||
|
||||
StartCoroutine(PlayAgain());
|
||||
}
|
||||
|
||||
void FinishDeathmatch(){
|
||||
int position =0;
|
||||
for(position=0; position < Leaderboard.list.Length; position++){
|
||||
if(Leaderboard.list[position] == localPlayer.playerNetwork){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
UIManager.ShowDeathmatchFinishScreen(position, Leaderboard.list[0].username);
|
||||
}
|
||||
}
|
||||
|
||||
void FinishTeamdeathmatch(){
|
||||
KeyValuePair<string,int> winnerTeam = new KeyValuePair<string, int>("",0);
|
||||
foreach(KeyValuePair<string,int> team in LeaderboardTDM.unsortedTeamScores){
|
||||
if(team.Value > winnerTeam.Value){
|
||||
winnerTeam = team;
|
||||
}
|
||||
}
|
||||
|
||||
if(desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
UIManager.ShowTDMFinishScreen(winnerTeam.Key);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator PlayAgain(){
|
||||
yield return new WaitForSeconds(10f);
|
||||
ResetStatics();
|
||||
@@ -269,10 +291,10 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
localPlayer = PhotonNetwork.Instantiate("Player", GetRandomSpawnPoint().position, Quaternion.identity).GetComponentInChildren<PlayerController>();
|
||||
// localPlayer.GetComponent<PlayerNetwork>().SetPartyName(partyName,partyId);
|
||||
UIManager.instance.RoundLength = DeathmatchRoundLength;
|
||||
|
||||
localPlayer.GetComponent<PlayerNetwork>().AutoAssignParty();
|
||||
//Wait for Players
|
||||
if(PhotonNetwork.IsMasterClient){
|
||||
while(PhotonNetwork.CurrentRoom.PlayerCount < DeathmatchMinPlayerCount){
|
||||
while(PhotonNetwork.CurrentRoom.PlayerCount <(desiredGameMode == GameModes.TeamDeathmatch.ToString() ? TDM_MinPlayers : DeathmatchMinPlayerCount)){
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
UIManager.WaitingForPlayers();
|
||||
}
|
||||
@@ -329,6 +351,8 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
{
|
||||
StartCoroutine(BeginStartTimer());
|
||||
}else if(eventCode == BeginGameModeCode){
|
||||
isInit=true;
|
||||
|
||||
object[] customData = (object[])photonEvent.CustomData;
|
||||
|
||||
StartTime = (double)customData[0];
|
||||
@@ -347,7 +371,6 @@ public class GameManager : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
|
||||
localPlayer.transform.position = SpawnPositions[customPlayerId].position;
|
||||
|
||||
isInit=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,8 @@ public class MainMenu : MonoBehaviourPunCallbacks, IOnEventCallback
|
||||
if(val.ToLower() == "dm"){gameMode = GameModes.Deathmatch;}
|
||||
if(val.ToLower()== "tdm"){gameMode = GameModes.TeamDeathmatch;}
|
||||
if(val.ToLower() == "br"){gameMode = GameModes.BattleRoyale;}
|
||||
|
||||
btnPlay.interactable = gameMode != GameModes.BattleRoyale;
|
||||
|
||||
Debug.Log("Set game mode to : " + gameMode.ToString() + $" ({val})");
|
||||
GameManager.desiredGameMode = gameMode.ToString();
|
||||
|
||||
@@ -513,6 +513,7 @@ public class PlayerController : MonoBehaviourPunCallbacks
|
||||
collider.GetComponent<HitBox>().OnPunched(photonView.ViewID, meleeListener.transform.position, transform);
|
||||
}
|
||||
}
|
||||
public LayerMask shootingLayerMask;
|
||||
IEnumerator CoroutineFireShot()
|
||||
{
|
||||
bool aiming = anim.GetCurrentAnimatorClipInfo(1)[0].clip.name.Contains("Aiming");
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PlayerFX : MonoBehaviourPunCallbacks
|
||||
{
|
||||
HitBox hitbox = impact?.collider.GetComponent<HitBox>();
|
||||
if(hitbox == null){
|
||||
playerNetwork.OnHit(photonView.ViewID, PlayerControllerHelper.GetDamageForHitboxType(HitBoxType.Body), transform.position, 1);
|
||||
// playerNetwork.OnHit(photonView.ViewID, PlayerControllerHelper.GetDamageForHitboxType(HitBoxType.Body), transform.position, 1); //PHANTOM SHOTS
|
||||
}else{
|
||||
hitbox.OnHit(photonView.ViewID, impact?.point ?? transform.position, transform);
|
||||
}
|
||||
|
||||
@@ -60,37 +60,103 @@ public class PlayerNetwork : MonoBehaviourPunCallbacks, IPunObservable
|
||||
|
||||
|
||||
//
|
||||
partyId = GameManager.partyId;
|
||||
List<string> availablePartyNames = Helpers.battleTeamNames.ToList<string>();
|
||||
string partyName = Helpers.RandomTeamName;
|
||||
PlayerNetwork[] players = FindObjectsOfType<PlayerNetwork>();
|
||||
bool foundMyParty = false;
|
||||
foreach(PlayerNetwork player in players){
|
||||
if(player == this){continue;}
|
||||
if(player.partyId == partyId){
|
||||
//Found my party!
|
||||
partyName = player.partyname;
|
||||
foundMyParty = true;
|
||||
Debug.Log("Found my party! Its called " + player.partyname);
|
||||
break;
|
||||
}else{
|
||||
if(availablePartyNames.Contains(player.partyname)){
|
||||
availablePartyNames.Remove(player.partyname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMyParty){
|
||||
partyName = availablePartyNames[UnityEngine.Random.Range(0, availablePartyNames.Count)];
|
||||
Debug.Log("Got a new party name! : " + partyName);
|
||||
}
|
||||
|
||||
partyname = partyName;
|
||||
if(GameManager.desiredGameMode== GameModes.TeamDeathmatch.ToString()){ignoreFriendlyFire=true;}
|
||||
}
|
||||
|
||||
GetComponent<CharacterController>().detectCollisions=false;
|
||||
}
|
||||
|
||||
|
||||
public void AutoAssignParty(){
|
||||
StartCoroutine(AutoSwitchTeams());
|
||||
}
|
||||
|
||||
void autoAssignParty(){
|
||||
partyId = GameManager.partyId;
|
||||
List<string> availablePartyNames = Helpers.battleTeamNames.ToList<string>();
|
||||
|
||||
Dictionary<string, int> parties = new Dictionary<string, int>();
|
||||
PlayerNetwork[] players = FindObjectsOfType<PlayerNetwork>();
|
||||
|
||||
string myLobbyParty = "";
|
||||
foreach(PlayerNetwork player in players){
|
||||
if(player.partyname != ""){
|
||||
//has a party
|
||||
if(parties.ContainsKey(player.partyname)){
|
||||
parties[player.partyname]++;
|
||||
}else{
|
||||
parties.Add(player.partyname, 1);
|
||||
}
|
||||
|
||||
if(availablePartyNames.Contains(player.partyname)){availablePartyNames.Remove(player.partyname);}
|
||||
|
||||
if(partyId == player.partyId){
|
||||
myLobbyParty = player.partyname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"Found {parties.Count} Parties");
|
||||
|
||||
if(myLobbyParty == ""){
|
||||
//Didn't find a party of my own
|
||||
if(parties.Count > 1){
|
||||
foreach(KeyValuePair<string,int> party in parties){
|
||||
if(party.Value < 4){
|
||||
partyname = party.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
partyname = availablePartyNames[UnityEngine.Random.Range(0, availablePartyNames.Count)];
|
||||
}
|
||||
}else{
|
||||
if(parties[myLobbyParty] < 4){
|
||||
partyname = myLobbyParty;
|
||||
}else{
|
||||
foreach(KeyValuePair<string,int> party in parties){
|
||||
if(party.Value < 4){
|
||||
partyname = party.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(partyname == ""){
|
||||
partyname = availablePartyNames[UnityEngine.Random.Range(0, availablePartyNames.Count)];
|
||||
}
|
||||
}
|
||||
|
||||
int autoTeamSwitchCount = 0;
|
||||
IEnumerator AutoSwitchTeams(){
|
||||
while(autoTeamSwitchCount < 4){
|
||||
autoTeamSwitchCount++;
|
||||
yield return new WaitForSeconds(UnityEngine.Random.Range(0.5f,1f));
|
||||
|
||||
autoAssignParty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Dictionary<string, int> GetPartySizes(){
|
||||
Dictionary<string, int> parties = new Dictionary<string, int>();
|
||||
|
||||
foreach(PlayerNetwork player in FindObjectsOfType<PlayerNetwork>()){
|
||||
if(player.partyname != ""){
|
||||
//has a party
|
||||
if(parties.ContainsKey(player.partyname)){
|
||||
parties[player.partyname]++;
|
||||
}else{
|
||||
parties.Add(player.partyname, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parties;
|
||||
}
|
||||
|
||||
public void SetActiveWeapon(LootItemScriptableObject data)
|
||||
{
|
||||
int _selectedIndex = -1;
|
||||
@@ -247,7 +313,7 @@ public class PlayerNetwork : MonoBehaviourPunCallbacks, IPunObservable
|
||||
return DistanceDamageCurve.Evaluate(Mathf.Clamp01(dist/BulletEffectiveRange));
|
||||
}
|
||||
|
||||
|
||||
public bool ignoreFriendlyFire;
|
||||
[PunRPC]
|
||||
void RpcOnHit(int id, float damage, Vector3 point)
|
||||
{
|
||||
@@ -256,6 +322,17 @@ public class PlayerNetwork : MonoBehaviourPunCallbacks, IPunObservable
|
||||
float newShield = shield;
|
||||
float newHealth = health;
|
||||
|
||||
if(ignoreFriendlyFire){
|
||||
PlayerNetwork[] players = FindObjectsOfType<PlayerNetwork>();
|
||||
foreach(PlayerNetwork p in players){
|
||||
if(p.photonView.ViewID == id){
|
||||
//This is the shooter
|
||||
|
||||
if(partyname == p.partyname){return;} //Friendly fire
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(shield > 0){
|
||||
newShield = Mathf.Clamp(shield - damage,0,100);
|
||||
}else{
|
||||
@@ -383,7 +460,7 @@ public class PlayerNetwork : MonoBehaviourPunCallbacks, IPunObservable
|
||||
CameraFollow.Resume();
|
||||
playerController.isActive=true;
|
||||
UIManager.OnRespawn();
|
||||
if(GameManager.desiredGameMode == GameModes.Deathmatch.ToString()){
|
||||
if(GameManager.desiredGameMode == GameModes.Deathmatch.ToString() || GameManager.desiredGameMode == GameModes.TeamDeathmatch.ToString()){
|
||||
InventoryManager.instance.GiveDefaultLoots(GameManager.instance.DeathmatchDefaultInventory);
|
||||
}
|
||||
UIManager.UpdateInventory(InventoryManager.instance);
|
||||
|
||||
@@ -38,8 +38,8 @@ public class UIManager : MonoBehaviour
|
||||
public GameObject inventoryPanel;
|
||||
public Transform inventoryGridParent;
|
||||
public GameObject inventoryGridItemPrefab;
|
||||
|
||||
public Image weaponSlot1Inventory, weaponSlot2Inventory, pistolSlotInventory, throwableSlotInventory;
|
||||
|
||||
[Header("Deathmatch")]
|
||||
public TMP_Text TimerTxt;
|
||||
public TMP_Text LastChampTxt;
|
||||
@@ -134,6 +134,19 @@ public class UIManager : MonoBehaviour
|
||||
instance.m_ShowDeathmatchFinishScreen(position, winnerName);
|
||||
}
|
||||
|
||||
public static void ShowTDMFinishScreen(string winnerName){
|
||||
instance.m_ShowTDMFinishScreen(winnerName);
|
||||
}
|
||||
|
||||
void m_ShowTDMFinishScreen(string winnerName){
|
||||
DeathmatchPanel.SetActive(true);
|
||||
// DeathmatchPositionTxt.text = $"You finished {Helpers.numberToPosition(position+1)}";
|
||||
|
||||
DeathmatchWinnerTxt.text = $"The Winner is {winnerName}";
|
||||
|
||||
StartCoroutine(StartDeathmatchRestartCountdown());
|
||||
}
|
||||
|
||||
void m_ShowDeathmatchFinishScreen(int position, string winnerName){
|
||||
DeathmatchPanel.SetActive(true);
|
||||
DeathmatchPositionTxt.text = $"You finished {Helpers.numberToPosition(position+1)}";
|
||||
@@ -174,7 +187,6 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
public static void SetHealth(float health,float shield)
|
||||
{
|
||||
//instance.HealthSlider.value = health;
|
||||
instance.Healthbar.fillAmount = health / 100f;
|
||||
instance.ShieldBar.fillAmount = shield /100f;
|
||||
instance.HealthTxt.text = health.ToString("n0") + " / 100";
|
||||
|
||||
Reference in New Issue
Block a user