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 killing spree system #64

Merged
merged 6 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="AddPoints" xml:space="preserve">
<value>Points must be between 1 to 100</value>
</data>
<data name="ConsecutiveKills" xml:space="preserve">
<value>{PlayerName} has had {Kills} consecutive kills without dying</value>
</data>
<data name="CreatePlayerAccount" xml:space="preserve">
<value>You have successfully registered. Password: {Password}</value>
</data>
Expand Down
38 changes: 38 additions & 0 deletions src/Application/Players/Accounts/KillingSpreeUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace CTF.Application.Players.Accounts;

public class KillingSpreeUpdater(
IWorldService worldService,
IPlayerRepository playerRepository)
{
public void Update(Player player, PlayerInfo playerInfo)
{
playerInfo.StatsPerRound.AddKillingSpree();
int currentKillingSpree = playerInfo.StatsPerRound.KillingSpree;
if (currentKillingSpree >= 2)
{
player.GameText($"KILL X{currentKillingSpree}", 3000, 3);
const int earnedPoints = 20;
playerInfo.StatsPerRound.AddPoints(earnedPoints);
player.AddHealth(10);

if (playerInfo.HasSurpassedMaxKillingSpree())
{
playerInfo.SetMaxKillingSpree(currentKillingSpree);
playerRepository.UpdateMaxKillingSpree(playerInfo);
}

if (currentKillingSpree % 3 == 0)
{
var message = Smart.Format(Messages.ConsecutiveKills, new
{
PlayerName = player.Name,
Kills = currentKillingSpree
});
// Sample Message:
// Dave has had 3 consecutive kills without dying.
worldService.SendClientMessage(Color.Orange, message);
player.AddHealth(40);
}
}
}
}
26 changes: 24 additions & 2 deletions src/Application/Players/PlayerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace CTF.Application.Players;

public class PlayerSystem(
IWorldService worldService,
IPlayerRepository playerRepository,
RankUpgrade rankUpgrade) : ISystem
RankUpgrade rankUpgrade,
KillingSpreeUpdater killingSpreeUpdater) : ISystem
{
[Event]
public void OnPlayerConnect(Player player)
{
worldService.SendDeathMessage(killer: null, player, Weapon.Connect);
}

[Event]
public void OnPlayerDisconnect(Player player, DisconnectReason reason)
{
worldService.SendDeathMessage(killer: null, player, Weapon.Disconnect);
}

[Event]
public bool OnPlayerRequestSpawn(Player player)
{
Expand All @@ -19,15 +33,23 @@ public bool OnPlayerRequestSpawn(Player player)
}

[Event]
public void OnPlayerDeath(Player player, Player killer, Weapon reason)
public void OnPlayerDeath(Player deadPlayer, Player killer, Weapon reason)
{
worldService.SendDeathMessage(killer, deadPlayer, reason);
PlayerInfo deadPlayerInfo = deadPlayer.GetInfo();
deadPlayerInfo.StatsPerRound.AddDeaths();
deadPlayerInfo.StatsPerRound.ResetKillingSpree();
deadPlayerInfo.AddTotalDeaths();
playerRepository.UpdateTotalDeaths(deadPlayerInfo);

if (killer.IsInvalidPlayer())
return;

PlayerInfo killerInfo = killer.GetInfo();
killerInfo.StatsPerRound.AddKills();
killerInfo.AddTotalKills();
playerRepository.UpdateTotalKills(killerInfo);
killingSpreeUpdater.Update(killer, killerInfo);
rankUpgrade.RankUp(killer, killerInfo);
}
}
1 change: 1 addition & 0 deletions src/Application/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
.AddSingleton<ServerTimeService>()
.AddSingleton<MapInfoService>()
.AddSingleton<RankUpgrade>()
.AddSingleton<KillingSpreeUpdater>()
.AddComboServices();

return services;
Expand Down
Loading