/// <summary> /// [Serverside] Creates a <see cref="PlayerShell"/> with a random username /// </summary> /// <param name="sender"></param> private void CreateShellServerside(System.Net.IPEndPoint sender) { if (ConnectedClients.Keys.Where(x => x.Equals(sender)).Count() == 0) { RWConsole.LogInfo("Creating PlayerInfo..."); ConnectedClients[sender] = new PlayerInfo() { ID = GetNewID(), }; RWConsole.LogInfo("Creating abstract player..."); AbstractCreature abstractPlayer = null; try { abstractPlayer = new AbstractCreature (Game.world, StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Slugcat), null, new WorldCoordinate(), new EntityID()); } catch (Exception e) { if (Game == null) { RWConsole.LogError("Game is null!"); } RWConsole.LogError(e); } RWConsole.LogInfo("Created abstract player."); RWConsole.LogInfo("Creating PlayerState..."); PlayerState playerState = new PlayerState(abstractPlayer, 0, 1, false); abstractPlayer.state = playerState; RWConsole.LogInfo("Created PlayerState."); RWConsole.LogInfo("Realizing player..."); try { abstractPlayer?.Realize(); ConnectedClients[sender].Player = abstractPlayer?.realizedCreature as Player; if (ConnectedClients[sender].Player == null) { RWConsole.LogError("Player is null!"); } } catch (Exception e) { RWConsole.LogError(e); } RWConsole.LogInfo("Realized player."); PlayerShell playerShell = new PlayerShell(ConnectedClients[sender]); Game.Players[0].Room.realizedRoom.AddObject(playerShell); RWConsole.LogInfo("Created PlayerInfo"); } }
/// <summary> /// [Clientside] Creates a <see cref="PlayerShell"/> /// </summary> /// <param name="username"></param> private void CreateShellClientside(string username) { if (!RemotePlayers.ContainsKey(username)) { RWConsole.LogInfo($"Creating PlayerInfo for {username}..."); RemotePlayers[username] = new PlayerInfo(); RWConsole.LogInfo("Creating abstract player..."); AbstractCreature abstractPlayer = null; try { abstractPlayer = new AbstractCreature (Game.world, StaticWorld.GetCreatureTemplate(CreatureTemplate.Type.Slugcat), null, new WorldCoordinate(), new EntityID()); } catch (Exception e) { if (Game == null) { RWConsole.LogError("Game is null!"); } RWConsole.LogError(e); } RWConsole.LogInfo("Created abstract player."); RWConsole.LogInfo("Creating PlayerState..."); PlayerState playerState = new PlayerState(abstractPlayer, 0, 1, false); abstractPlayer.state = playerState; RWConsole.LogInfo("Created PlayerState."); RWConsole.LogInfo("Realizing player..."); try { abstractPlayer?.Realize(); RemotePlayers[username].Player = abstractPlayer?.realizedCreature as Player; if (RemotePlayers[username].Player == null) { RWConsole.LogError("Player is null!"); } } catch (Exception e) { RWConsole.LogError(e); } RWConsole.LogInfo("Realized player."); PlayerShell playerShell = new PlayerShell(RemotePlayers[username]); Game.Players[0].Room.realizedRoom.AddObject(playerShell); RWConsole.LogInfo($"Created PlayerInfo for {username}"); } }