private void FindPlayerSpawnPositionsInScene() { PlayersSpawnPositions.Clear(); // Try to find already placed player spawn positions in the scene AbstractPlayerSpawnPosition[] spawnPositions = FindObjectsOfType <AbstractPlayerSpawnPosition>(); foreach (AbstractPlayerSpawnPosition spawnPosition in spawnPositions) { PlayersSpawnPositions.Add(spawnPosition.PayerID, spawnPosition); } // Determine spawn positions relative to this transform if no PlayerSpawnPosition found in scene if (MotherOfManagers.Instance.IsSpawnGhostPlayerPositionsIfNotFound == true) { int angle; for (int i = 1; i < 5; i++) { angle = 90 * i; EPlayerID playerID = BUtils.GetPlayerIDFrom(i); if (PlayersSpawnPositions.ContainsKey(playerID) == false) { AbstractPlayerSpawnPosition spawnGhost = Instantiate(playerSpawnPositionPrefab); spawnGhost.PayerID = playerID; spawnGhost.Position = transform.position + Vector3.forward * 3.0f + Vector3.left * 3.0f; spawnGhost.transform.RotateAround(transform.position, Vector3.up, angle); spawnGhost.Rotation = transform.rotation; PlayersSpawnPositions.Add(playerID, spawnGhost); } } } }
public void LeavePlayer(EPlayerID playerID) { if ((IS_KEY_CONTAINED(partyStatusMap, playerID)) && (IS_TRUE(partyStatusMap[playerID].HasJoined))) { // Destroy Player if (ActivePlayers.ContainsKey(playerID)) { DestroyPlayer(playerID); } // Reset controller to Spectator EControllerID controllerID = partyStatusMap[playerID].ControllerID; if (IS_KEY_CONTAINED(ControllersMap, controllerID)) { ControllersMap[controllerID] = EPlayerID.SPECTATOR; } // Reset entry of playerID in party status partyStatusMap[playerID] = new PlayerJoinStatus(EControllerID.NONE); // Trigger global event BEventsCollection.PLAYERS_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); // Are the rest of the joined players ready? CheckIfAllPlayersAreReady(); } }
private void On_INPUT_ControllerDisconnected(BEHandle <EControllerID> eventHandle) { EControllerID controllerID = eventHandle.Arg1; if (IS_KEY_CONTAINED(ControllersMap, controllerID)) { EPlayerID playerID = ControllersMap[controllerID]; // Was a joined controller? if (playerID != EPlayerID.SPECTATOR && IS_KEY_CONTAINED(partyStatusMap, playerID)) { partyStatusMap[playerID].Flush(); } // Destroy Player if (ActivePlayers.ContainsKey(playerID)) { DestroyPlayer(playerID); } ControllersMap.Remove(controllerID); BEventsCollection.PLAYERS_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); } }
/// <summary> Converts a controllerID (AI or Network) to a PlayerID </summary> public static EPlayerID GetPlayerIDFrom(EControllerID controllerID) { EPlayerID result = EPlayerID.NONE; switch (controllerID) { /* AI */ case EControllerID.AI_1: result = EPlayerID.PLAYER_1; break; case EControllerID.AI_2: result = EPlayerID.PLAYER_2; break; case EControllerID.AI_3: result = EPlayerID.PLAYER_3; break; case EControllerID.AI_4: result = EPlayerID.PLAYER_4; break; } return(result); }
public TestPlayerStats(EPlayerID playerStatID, int maximumNumberOfLives) { PlayerID = playerStatID; RemainingLives = maximumNumberOfLives; NumberOfKilledPlayers = 0; LastHitBy = EPlayerID.NONE; }
public EControllerID GetAssignedControllerID(EPlayerID playerID) { if (IS_KEY_CONTAINED(partyStatusMap, playerID)) { return(partyStatusMap[playerID].ControllerID); } return(EControllerID.NONE); }
//protected override void InitializeObjecsInScene() //{ // base.InitializeObjecsInScene(); // arena = FindObjectOfType<Arena>(); // IS_NOT_NULL(arena); //} protected override void Start() { base.Start(); playerID = myPlayer.PlayerID; controllerID = PlayerManager.Instance.GetAssignedControllerID(playerID); IS_NOT_NONE(playerID); IS_NOT_NONE(controllerID); //StartNewCoroutine(ref StartSpammingAllSpellButtonsEnumerator, StartSpammingAllSpellButtonsCoroutine()); }
public void CancelPlayerReady(EPlayerID playerID) { if ((IS_KEY_CONTAINED(partyStatusMap, playerID)) && (IS_TRUE(partyStatusMap[playerID].HasJoined)) && (IS_TRUE(partyStatusMap[playerID].IsReady))) { partyStatusMap[playerID].IsReady = false; BEventsCollection.PLAYERS_PlayerCanceledReady.Invoke(new BEHandle <EPlayerID>(playerID)); } }
private void On_InputSource_ButtonReleased(EControllerID controllerID, EInputButton inputButton) { if (IS_VALUE_CONTAINED(connectedControllers, controllerID)) { EPlayerID playerID = PlayerManager.Instance.GetAssignedPlayerID(controllerID); if (inputButton != EInputButton.NONE) { BEventsCollection.INPUT_ButtonReleased.Invoke(new BEHandle <EControllerID, EInputButton>(controllerID, inputButton), BEventReplicationType.LOCAL, MotherOfManagers.Instance.DebugButtonEvents); } } }
public void CreateCharacter(EPlayerID playerID, CharacterType type, Vector3 spawnPosition) { GameObject character; string charName; Color charColor; if(playerID == EPlayerID.PlayerOne) { character = playerOne; charName = "PLAYER_ONE"; charColor = Color.red; } else { character = playerTwo; charName = "PLAYER_TWO"; charColor = Color.blue; } if(character) Destroy(character); character = (GameObject) Instantiate(Resources.Load(type == CharacterType.Sausage ? "SAUSAGE" : "NINJA")); character.transform.parent = transform; character.GetComponent<PlayerController>().Init(playerID); character.name = charName; character.tag = charName; character.layer = LayerMask.NameToLayer(charName); foreach (Transform child in character.transform) { Renderer rndr = child.gameObject.GetComponent<Renderer>(); if(rndr) { rndr.material.color = charColor; } } Character charaterScript = character.GetComponent<Character>(); charaterScript.Spawn(spawnPosition); charaterScript.SetPlayerID(playerID); charaterScript.game = this; charaterScript.gameManager = gameManager; if(playerID == EPlayerID.PlayerOne) { playerOne = character; } else { playerTwo = character; } }
private void On_InputSource_JoystickMoved(EControllerID controllerID, EInputAxis inputAxis, float x, float y) { if (IS_VALUE_CONTAINED(connectedControllers, controllerID)) { EPlayerID playerID = PlayerManager.Instance.GetAssignedPlayerID(controllerID); if (inputAxis != EInputAxis.NONE) { BEventsCollection.INPUT_AxisUpdated.Invoke(new BEHandle <EControllerID, EInputAxis, float, float>(controllerID, inputAxis, x, y), BEventReplicationType.LOCAL, MotherOfManagers.Instance.DebugJoystickEvents); } } }
public bool HasPlayerJoined(EPlayerID playerID) { foreach (KeyValuePair <EPlayerID, PlayerJoinStatus> pair in partyStatusMap) { PlayerJoinStatus playerJoinStatus = pair.Value; if ((playerID == pair.Key) && (playerJoinStatus.HasJoined == true)) { return(true); } } return(false); }
private void AssignPlayerToTeam(EPlayerID playerID, ETeamID teamID) { // First remove from old team ETeamID oldTeamID = PlayersTeam[playerID]; if (oldTeamID != ETeamID.NONE) { Teams[oldTeamID].Remove(playerID); } Teams[teamID].Add(playerID); PlayersTeam[playerID] = teamID; }
public void SetPlayerReady(EPlayerID playerID) { LogConsole(playerID + " ready"); if ((IS_KEY_CONTAINED(partyStatusMap, playerID)) && (IS_TRUE(partyStatusMap[playerID].HasJoined)) && (IS_NOT_TRUE(partyStatusMap[playerID].IsReady))) { partyStatusMap[playerID].IsReady = true; BEventsCollection.PLAYERS_PlayerReady.Invoke(new BEHandle <EPlayerID>(playerID)); CheckIfAllPlayersAreReady(); } }
protected override void OnValidate() { base.OnValidate(); if (CanValidate()) { if (dZPlayer == null) { dZPlayer = GetComponentInHierarchy <DropZonePlayer>(); playerID = dZPlayer.PlayerID; owner = dZPlayer.GetOwner(); } } }
private EPlayerID GetNextNotJoinedPlayerID() { foreach (var pair in partyStatusMap) { EPlayerID playerID = pair.Key; PlayerJoinStatus playerJoinStatus = pair.Value; if (playerJoinStatus.HasJoined == false) { return(playerID); } } return(EPlayerID.NONE); }
public bool OnCatch(EPlayerID playerID) { if (ARE_EQUAL(currentState, EBallDroneState.FREE)) { lastCatchingPlayerID = playerID; UpdateState(EBallDroneState.CAUGHT); gameObject.SetActive(false); return(true); } return(false); }
private EPlayerID JoinNextAIPlayer(EControllerID controllerID) { foreach (var pair in partyStatusMap) { EPlayerID playerID = pair.Key; PlayerJoinStatus playerJoinStatus = pair.Value; if (playerJoinStatus.HasJoined == false) { JoinPlayer(playerID, controllerID); return(playerID); } } return(EPlayerID.NONE); }
//public void RespawnPlayer(EPlayerID playerID) //{ // if ((IS_KEY_NOT_CONTAINED(ActivePlayers, playerID)) // && (IS_KEY_CONTAINED(PlayersDeathPositions, playerID)) // && (IS_KEY_CONTAINED(PlayersDeathRotations, playerID)) // && (IS_KEY_CONTAINED(PlayersSpawnPositions, playerID))) // { // Vector3 startPostion = PlayersDeathPositions[playerID]; // Quaternion startRotation = PlayersDeathRotations[playerID]; // Vector3 endPosition = PlayersSpawnPositions[playerID].Position; // Quaternion endRotation = PlayersSpawnPositions[playerID].Rotation; // PlayerRespawnGhost playerRespawnGhost = Instantiate(playerRespawnGhostPrefab, startPostion, startRotation); // playerRespawnGhost.PlayerID = playerID; // playerRespawnGhost.RespawnAnimationDone += On_RespawnAnimationDone; // playerRespawnGhost.StartRespawnAnimation(startPostion, startRotation, endPosition, endRotation); // } //} //private void On_RespawnAnimationDone(PlayerRespawnGhost playerRespawnGhost) //{ // playerRespawnGhost.RespawnAnimationDone -= On_RespawnAnimationDone; // LogConsole(playerRespawnGhost.PlayerID + " completed respawn animation"); // SpawnPlayer(playerRespawnGhost.PlayerID); // playerRespawnGhost.DestroyGhost(); //} public void DestroyPlayer(EPlayerID playerID) { if (IS_KEY_CONTAINED(ActivePlayers, playerID)) { AbstractPlayer player = ActivePlayers[playerID]; if ((IS_KEY_CONTAINED(PlayersDeathPositions, playerID)) && (IS_KEY_CONTAINED(PlayersDeathRotations, playerID))) { PlayersDeathPositions[playerID] = player.Position; PlayersDeathRotations[playerID] = player.Rotation; } ActivePlayers.Remove(playerID); BEventsCollection.PLAYERS_PlayerDied.Invoke(new BEHandle <EPlayerID, IPlayer>(playerID, player)); player.DestroyPawn(); } }
public bool JoinPlayer(EPlayerID playerID, EControllerID controllerID) { if (IS_KEY_CONTAINED(partyStatusMap, playerID) && IS_KEY_CONTAINED(ControllersMap, controllerID) && IS_NOT_TRUE(partyStatusMap[playerID].HasJoined)) { partyStatusMap[playerID].ControllerID = controllerID; partyStatusMap[playerID].HasJoined = true; // Update assigned PlayerID in the controller map (instead of Spectator) ControllersMap[controllerID] = playerID; BEventsCollection.PLAYERS_PlayerJoined.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID)); return(true); } return(false); }
/* Player Management */ public AbstractPlayer SpawnPlayer(EPlayerID playerID) { AbstractPlayer spawnedPlayer = null; if (IS_TRUE(HasPlayerJoined(playerID)) && IS_KEY_NOT_CONTAINED(ActivePlayers, playerID) && IS_KEY_CONTAINED(playersPrefabsMap, playerID)) { AbstractPlayer playerPrefab = playersPrefabsMap[playerID]; Vector3 playerPosition = Vector3.zero; Quaternion playerRotation = Quaternion.identity; AbstractPlayerSpawnPosition playerSpawnPosition = null; if (PlayersSpawnPositions.ContainsKey(playerID)) { playerSpawnPosition = PlayersSpawnPositions[playerID]; playerPosition = playerSpawnPosition.Position; playerRotation = playerSpawnPosition.Rotation; } else { LogConsoleWarning("No spawn position defined for : " + playerID + ". Spawning at root"); } spawnedPlayer = Instantiate(playerPrefab, playerPosition, playerRotation); spawnedPlayer.PlayerID = playerID; spawnedPlayer.TeamID = PlayersTeam[playerID]; ActivePlayers.Add(playerID, spawnedPlayer); // Place player under parent of SpawnPosition if (playerSpawnPosition && MotherOfManagers.Instance.SpawnPlayersUnderSameTransformAsSpawnPositions == true && playerSpawnPosition.transform.parent != null) { spawnedPlayer.transform.parent = playerSpawnPosition.transform.parent; } BEventsCollection.PLAYERS_PlayerSpawned.Invoke(new BEHandle <EPlayerID, IPlayer>(playerID, spawnedPlayer)); } return(spawnedPlayer); }
private void On_PLAYERS_PlayerSpawned(BEHandle <EPlayerID, IPlayer> bHandle) { // Add an AIPlayerController on the spawned player if he's an AI EPlayerID playerID = bHandle.Arg1; EControllerID controllerID = PlayerManager.Instance.GetAssignedControllerID(playerID); if ((controllerID.ContainedIn(BConsts.AI_CONTROLLERS)) && (IS_KEY_CONTAINED(PlayerManager.Instance.ActivePlayers, playerID)) && (IS_NOT_NULL(PlayerManager.Instance.ActivePlayers[playerID]))) { AbstractPlayer player = PlayerManager.Instance.ActivePlayers[playerID]; AbstractAIPlayerController aIPlayerController = player.gameObject.AddComponent <AbstractAIPlayerController>(); aIPlayerController.AxisUpdated += On_AIPlayerController_JoystickMoved; aIPlayerController.ButtonPressed += On_AIPlayerController_ButtonPressed; aIPlayerController.ButtonReleased += On_AIPlayerController_ButtonReleased; aIPlayerController.WillGetDestroyed += On_AIPlayerController_WillGetDestroyed; aIPlayerController.InitializeAIController(this); activeAIControllers.Add(aIPlayerController); } }
protected override void Start() { base.Start(); if (dZPlayer == null) { dZPlayer = GetComponentInHierarchy <DropZonePlayer>(); } if (IS_NOT_NULL(dZPlayer)) { playerID = dZPlayer.PlayerID; owner = dZPlayer.GetOwner(); } // Disable collision if not locally owned if (IS_NOT_NULL(myCollider) && owner != BEventManager.Instance.LocalNetworkID) { myCollider.enabled = false; } }
private void On_NETWORK_NetworkIDDisconnected(BEHandle <ENetworkID> handle) { if (BEventManager.Instance.LocalNetworkID == ENetworkID.HOST) { EControllerID controllerID = BUtils.GetControllerIDFrom(handle.Arg1); if (IS_NOT_NONE(controllerID) && IS_TRUE(InputManager.Instance.IsControllerConnected(controllerID)) && IS_KEY_CONTAINED(partyMap, controllerID)) { EPlayerID playerID = partyMap[controllerID]; if (IS_NOT_NONE(playerID)) { partyMap.Remove(controllerID); // Disconnect Controller (-> Remove from party) InputManager.Instance.DisconnectController(controllerID); BEventsCollection.NETWORK_PlayerLeft.Invoke(new BEHandle <EPlayerID, EControllerID>(playerID, controllerID), BEventReplicationType.TO_ALL_OTHERS, true); } } } }
private IEnumerator JoinConnectedPlayerCoroutine(BEHandle <ENetworkID> handle, EControllerID newControllerID) { // Wait a delay yield return(new WaitForSeconds(1.0f)); // Connect Controller InputManager.Instance.ConnectController(newControllerID); // Join Player EPlayerID newPlayerID = PlayerManager.Instance.JoinPlayer(newControllerID); // TODO : Move to OnButtonPressed if (IS_NOT_NONE(newPlayerID)) { // Spawn Player AbstractNetPlayer newPlayer = (AbstractNetPlayer)PlayerManager.Instance.SpawnPlayer(newPlayerID); if (IS_NOT_NULL(newPlayer)) { newPlayer.SetOwner(handle.Arg1); } // Update map partyMap.Add(newControllerID, newPlayerID); // Replicate all connected net controllers to all other clients (Refresh) foreach (ENetworkID networkIDitr in BEventManager.Instance.GetConnectedNetworkIDs()) { if (networkIDitr != localNetworkID) // != Host { foreach (KeyValuePair <EControllerID, EPlayerID> pair in partyMap) { BEventsCollection.NETWORK_PlayerJoined.Invoke(new BEHandle <EPlayerID, EControllerID>(pair.Value, pair.Key), BEventReplicationType.TO_TARGET, true, networkIDitr); } } } } }
/// <summary> Convert a PlayerID enum to an int </summary> public static int GetIntFrom(EPlayerID playerID) { int result = 0; switch (playerID) { case EPlayerID.PLAYER_1: result = 1; break; case EPlayerID.PLAYER_2: result = 2; break; case EPlayerID.PLAYER_3: result = 3; break; case EPlayerID.PLAYER_4: result = 4; break; } return(result); }
///// <summary> Convert an int (index of spell) to an InputButton enum (1 -> CAST_SPELL_1)</summary> //public static EInputButton GetInputButtonFrom(int spellID) //{ // EInputButton result = EInputButton.NONE; // switch (spellID) // { // case 1: // result = EInputButton.SOUTH; // break; // case 2: // result = EInputButton.WEST; // break; // case 3: // result = EInputButton.EAST; // break; // } // return result; //} /// <summary> Returns the same team ID as the player ID (e.g. Player 2 -> Team 2)</summary> public static ETeamID GetIdenticPlayerTeam(EPlayerID playerID) { ETeamID result = ETeamID.NONE; switch (playerID) { case EPlayerID.PLAYER_1: result = ETeamID.TEAM_1; break; case EPlayerID.PLAYER_2: result = ETeamID.TEAM_2; break; case EPlayerID.PLAYER_3: result = ETeamID.TEAM_3; break; case EPlayerID.PLAYER_4: result = ETeamID.TEAM_4; break; } return(result); }
/// <summary> Convert an int to a PlayerID enum </summary> public static EPlayerID GetPlayerIDFrom(int playerID) { EPlayerID result = EPlayerID.NONE; switch (playerID) { case 1: result = EPlayerID.PLAYER_1; break; case 2: result = EPlayerID.PLAYER_2; break; case 3: result = EPlayerID.PLAYER_3; break; case 4: result = EPlayerID.PLAYER_4; break; } return(result); }
private void On_PLAYERS_PlayerDied(EPlayerID diedPlayerID) { if (IsRunning == false) { return; } // Update Killed Player stats TestPlayerStats killedPlayerStats = PlayerStats[diedPlayerID]; killedPlayerStats.DecrementPlayerLives(); //EventManager.Instance.Invoke_GAME_PlayerStatsUpdated(killedPlayerStats, GameModeType); // Update Killer stats if (killedPlayerStats.LastHitBy != EPlayerID.NONE) { TestPlayerStats killingPlayer = PlayerStats[killedPlayerStats.LastHitBy]; killingPlayer.IncrementNumberOfKilledPlayers(); //EventManager.Instance.Invoke_GAME_PlayerStatsUpdated(killingPlayer, GameModeType); } // Respawn Killed Player if (killedPlayerStats.RemainingLives > 0) { //PlayerManager.Instance.RespawnPlayer(diedPlayerID); } else { killedPlayerStats.SetTimeOfDeath(RemainingTime); } // Check if game over (only one player still alive) int gameOverPlayerCounter = 0; EPlayerID winnerPlayerID = EPlayerID.NONE; foreach (EPlayerID playerID in PlayerStats.Keys) { if (PlayerStats[playerID].IsGameOver == true) { gameOverPlayerCounter++; } else { winnerPlayerID = playerID; } } if (gameOverPlayerCounter == PlayerStats.Count - 1) { ETeamID winnerTeamID = PlayerManager.Instance.PlayersTeam[winnerPlayerID]; //Itirate through the the players time of death and set the ranking foreach (TestPlayerStats playerStats in PlayerStats.Values) { int counter = 0; foreach (TestPlayerStats otherPlayerStats in PlayerStats.Values) { if (playerStats != otherPlayerStats && playerStats.TimeOfDeath > otherPlayerStats.TimeOfDeath) { counter++; // Debug.Log(" Player " + Maleficus.Utils.GetIntFrom(playerStats.PlayerID) + " Time of Death = " + playerStats.TimeOfDeath + " died before Player " + Maleficus.Utils.GetIntFrom(otherPlayerStats.PlayerID) + " with a Time of Death = " + otherPlayerStats.TimeOfDeath); } } playerStats.SetRank(counter + 1); } //if ((NetworkManager.Instance.HasAuthority == true) // || (MotherOfManagers.Instance.ConnectionMode == EConnectionMode.PLAY_OFFLINE)) //{ // NetEvent_GameOver gameOverEventHandle = new NetEvent_GameOver(EClientID.SERVER, teamID); // EventManager.Instance.GAME_GameOver.Invoke(gameOverEventHandle, EEventInvocationType.TO_ALL); //} } }
public void SetPlayerID(EPlayerID id) { playerID = id; }
public AbstractPlayerStats(EPlayerID playerID) { PlayerID = playerID; }
public void Init(EPlayerID player) { playerID = player; }
/// <summary> /// Sets the Player ID of the last player that hit this player. /// Used to determine who finally killed this player. /// </summary> public void SetLastHitBy(EPlayerID hitByPlayerID) { LastHitBy = hitByPlayerID; }