Skip to content

Commit

Permalink
feat: Implement player spawn system (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 authored Sep 9, 2024
1 parent 53dbc39 commit f928ba8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
45 changes: 45 additions & 0 deletions src/Application/Players/PlayerSpawnSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace CTF.Application.Players;

public class PlayerSpawnSystem(MapInfoService mapInfoService) : ISystem
{
private readonly CurrentMap _currentMap = mapInfoService.Read();

[Event]
public bool OnPlayerRequestSpawn(Player player)
{
var accountComponent = player.GetComponent<AccountComponent>();
bool isNotLoggedInOrRegistered = accountComponent is null;
if (isNotLoggedInOrRegistered)
{
player.SendClientMessage(Color.Red, Messages.LoginOrRegisterToContinue);
return false;
}
Team selectedTeam = player.Team == (int)TeamId.Alpha ? Team.Alpha : Team.Beta;
if (selectedTeam.IsFull())
{
string gameText = selectedTeam.GetAvailabilityMessage();
player.GameText(gameText, 999999999, 3);
return false;
}
player.GetComponent<ClassSelectionComponent>().IsInClassSelection = false;
player.GameText("_", 1000, 4);
PlayerInfo playerInfo = accountComponent.PlayerInfo;
playerInfo.SetTeam((TeamId)player.Team);
return true;
}

[Event]
public void OnPlayerSpawn(Player player)
{
PlayerInfo playerInfo = player.GetInfo();
SpawnLocation spawnLocation = _currentMap.GetRandomSpawnLocation(playerInfo.Team.Id);
player.Position = spawnLocation.Position;
player.Angle = spawnLocation.Angle;
player.Interior = _currentMap.Interior;
player.Color = playerInfo.Team.ColorHex;
if (playerInfo.HasSkin())
{
player.Skin = playerInfo.SkinId;
}
}
}
14 changes: 0 additions & 14 deletions src/Application/Players/PlayerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ public void OnPlayerDisconnect(Player player, DisconnectReason reason)
worldService.SendDeathMessage(killer: null, player, Weapon.Disconnect);
}

[Event]
public bool OnPlayerRequestSpawn(Player player)
{
var accountComponent = player.GetComponent<AccountComponent>();
bool isNotLoggedInOrRegistered = accountComponent is null;
if (isNotLoggedInOrRegistered)
{
player.SendClientMessage(Color.Red, Messages.LoginOrRegisterToContinue);
return false;
}

return true;
}

[Event]
public void OnPlayerDeath(Player deadPlayer, Player killer, Weapon reason)
{
Expand Down

0 comments on commit f928ba8

Please sign in to comment.