-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement player spawn system (#69)
- Loading branch information
1 parent
53dbc39
commit f928ba8
Showing
2 changed files
with
45 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters