Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement player spawn system #69

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Implement player spawn system
MrDave1999 committed Sep 9, 2024
commit aabcd3efd1f2cc00eb20a72cf71c878ffa1f111a
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
@@ -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)
{