public void OnServerDisconnect(NetworkConnection conn) { PlayerDisconnectedHandler handler = PlayerDisconnected; if (oem.shouldTriggerEvent(handler)) { handler(PlayerIdentifier.CreateNew(conn)); } }
GetScoreList() { return(PlayerScore .Select( kvp => new KeyValuePair <PlayerIdentifier, int> (PlayerIdentifier.CreateNew(kvp.Key), kvp.Value) ) .ToList()); }
public void OnPlayerJoin(NetworkedPlayerController playerController) { MyContract.RequireArgumentNotNull(playerController, "playerController"); PlayerIdentifier NewPlayerId = PlayerIdentifier.CreateNew(playerController); playerController.ShipDestroyed += delegate(PlayerIdentifier hunter) { Scoreboard.OnKillEvent(hunter, NewPlayerId); }; Scoreboard.ScoreUpdate += playerController.OnScoreUpdate; Scoreboard.PlayerRemoved += playerController.OnPlayerRemovedFromScoreboardPassthrough; Scoreboard.RegisterNewPlayer(NewPlayerId); //Debug.Log("Game State Manager: Checking if we have a spaceship class manager"); MyContract.RequireFieldNotNull(SSClassManager, "Spaceship Class Manager"); //Debug.Log("Game State Manager: Initialising given NPC with our SSCManager"); playerController.initialiseShipClassManager(SSClassManager); }
private void SpawnSpaceShip(SpaceShipClass spaceShipType) { lock (SpaceshipSpawnLock) { if (ShipSpawned) { Debug.LogWarning(ShipAlreadySpawnedWarning); return; } MyContract.RequireArgument( spaceShipType != SpaceShipClass.NONE, "is not NONE", "spaceShipType" ); MyContract.RequireFieldNotNull( SpaceshipClassManager, "Spaceship Class Manager" ); GameObject SpaceshipPrefab = SpaceshipClassManager.getSpaceShipPrefab(spaceShipType); MyContract.RequireFieldNotNull(SpaceshipPrefab, "Spaceship Prefab"); // Should not remain null unless Unity.Instantiate can return null GameObject ServerSpaceship = null; if (CurrentSpaceship != null && ShipController.getSpaceshipClass() == spaceShipType) { // current_spaceship was just despawned, not destroyed, // so it simply needs to be respawned ServerSpaceship = CurrentSpaceship; ServerSpaceship.SetActive(true); MyContract.RequireFieldNotNull( ShipController, "ShipController" ); ShipController.Respawn(); } else { // Create the ship locally (local to the server) // NB: the ship will be moved to an appropriate NetworkStartPosition // by the server so the location specified here is irrelevant ServerSpaceship = (GameObject)Instantiate( SpaceshipPrefab, transform.TransformPoint(chooseSpawnLocation()), transform.rotation); ShipController = ServerSpaceship.GetComponent<PlayerShipController>(); ShipController.SetSpaceshipClass(spaceShipType); ShipController.owner = PlayerIdentifier.CreateNew(this); ShipController.EventDeath += ShipDestroyedServerAction; } MyContract.RequireFieldNotNull( ServerSpaceship, "Server Spaceship" ); CanRespawn = false; ShipSpawned = true; // Spawn the ship on the clients NetworkServer.SpawnWithClientAuthority( ServerSpaceship, connectionToClient ); CurrentSpaceship = ServerSpaceship; // Update [SyncVar] RpcPlayerShipSpawned(CurrentSpaceship); } }