Skip to content

Commit

Permalink
Merge pull request #270 from MrDave1999/dev
Browse files Browse the repository at this point in the history
9.4.0 Release
  • Loading branch information
MrDave1999 authored Dec 28, 2024
2 parents d8ec79e + 72eed1e commit 85c80a7
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ ServerInfo__WebUrl=https://github.com/MrDave1999/Capture-The-Flag
ServerInfo__IntroAudioUrl=https://od.lk/s/Nl8yMDg4MTc0NDBf/intro-cs.mp3
# Expressed in seconds.
ServerInfo__FlagAutoReturnTime=120

# Expressed in seconds.
ServerInfo__FlagCarrierPauseTime=30
FlagCarrier__PauseTime=30
FlagCarrier__ShowOnRadarMap=true

ServerOwner__Name=MrDave
# Specify the secret key to give me admin.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="SampSharp.Entities" Version="0.10.1" />
<PackageVersion Include="SampSharp.Streamer.Entities" Version="0.10.0" />
<PackageVersion Include="SampSharp.CTF.Entities" Version="0.10.9" />
<PackageVersion Include="SampSharp.CTF.Entities" Version="0.10.11" />
<PackageVersion Include="SampSharp.CTF.Streamer.Entities" Version="0.10.1" />
<PackageVersion Include="SmartFormat" Version="3.5.1" />
<PackageVersion Include="MySqlConnector" Version="2.3.7" />
Expand Down
18 changes: 18 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.

6 changes: 6 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<data name="CommandLockMapLoading" xml:space="preserve">
<value>You cannot execute commands while the map is loading</value>
</data>
<data name="CommandNotFound" xml:space="preserve">
<value>Command not found. To see all available commands, use /cmds</value>
</data>
<data name="ConsecutiveKills" xml:space="preserve">
<value>{PlayerName} has had {Kills} consecutive kills without dying</value>
</data>
Expand Down Expand Up @@ -198,6 +201,9 @@
<data name="HasCapturedFlag" xml:space="preserve">
<value>You cannot use this command because you are the flag carrier</value>
</data>
<data name="HeadshotToPlayer" xml:space="preserve">
<value>{PlayerName1} landed a headshot with a sniper at {PlayerName2}</value>
</data>
<data name="InsufficientCoins" xml:space="preserve">
<value>You do not have enough coins to obtain this combo</value>
</data>
Expand Down
1 change: 0 additions & 1 deletion src/Application/Common/Settings/ServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class ServerSettings
public string WebUrl { get; init; } = string.Empty;
public string IntroAudioUrl { get; init; } = string.Empty;
public int FlagAutoReturnTime { get; init; } = 120;
public int FlagCarrierPauseTime { get; init; } = 30;
}
12 changes: 9 additions & 3 deletions src/Application/Players/HeadShotSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace CTF.Application.Players;

public class HeadShotSystem(IPlayerRepository playerRepository) : ISystem
public class HeadShotSystem(
IPlayerRepository playerRepository,
IWorldService worldService) : ISystem
{
/// <summary>
/// This callback is called when a player takes damage.
Expand Down Expand Up @@ -37,9 +39,13 @@ public void OnPlayerTakeDamage(Player player, Player issuer, float amount, Weapo
issuerInfo.AddHeadShots();
issuerInfo.StatsPerRound.AddCoins(5);
playerRepository.UpdateHeadShots(issuerInfo);
issuer.GameText("Headshot +1", 3000, 3);
issuer.SendClientMessage(Color.Yellow, "Headshot +1");
player.Health = 0;
var message = Smart.Format(Messages.HeadshotToPlayer, new
{
PlayerName1 = issuer.Name,
PlayerName2 = player.Name
});
worldService.SendClientMessage(Color.Yellow, message);
}
}
}
30 changes: 30 additions & 0 deletions src/Application/Players/PlayerCommandTextSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CTF.Application.Players;

public class PlayerCommandTextSystem(
IPlayerCommandService playerCommandService,
IServiceProvider serviceProvider) : ISystem
{
/// <summary>
/// This callback is called when a player enters a command into the client chat window.
/// Commands are anything that start with a forward slash, e.g. /help.
/// </summary>
/// <param name="player">
/// The player that entered a command.
/// </param>
/// <param name="text">
/// The command that was entered (including the forward slash).
/// </param>
/// <returns>
/// <c>true</c> if the command was processed, otherwise <c>false</c>; If the command was not found both in
/// filterscripts and in gamemode, the player will be received a message: 'SERVER: Unknown command'.
/// </returns>
[Event]
public bool OnPlayerCommandText(Player player, string text)
{
bool invokeResult = playerCommandService.Invoke(serviceProvider, player, text);
if (!invokeResult)
player.SendClientMessage(Color.Red, Messages.CommandNotFound);

return true;
}
}
8 changes: 6 additions & 2 deletions src/Application/Teams/Flags/Events/OnFlagCaptured.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class OnFlagCaptured(
IWorldService worldService,
TeamPickupService teamPickupService,
TeamSoundsService teamSoundsService,
PlayerStatsRenderer playerStatsRenderer) : IFlagEvent
PlayerStatsRenderer playerStatsRenderer,
FlagCarrierSettings flagCarrierSettings) : IFlagEvent
{
public FlagStatus FlagStatus => FlagStatus.Captured;

Expand All @@ -30,7 +31,10 @@ public void Handle(Team team, Player player)
playerInfo.StatsPerRound.AddCoins(5);
playerInfo.AddCapturedFlags();
player.AddScore(2);
player.ShowOnRadarMap();
if (flagCarrierSettings.ShowOnRadarMap)
{
player.ShowOnRadarMap();
}
playerRepository.UpdateCapturedFlags(playerInfo);
playerStatsRenderer.UpdateTextDraw(player);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Application/Teams/Flags/Events/OnFlagTaken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class OnFlagTaken(
IWorldService worldService,
TeamPickupService teamPickupService,
TeamSoundsService teamSoundsService,
FlagAutoReturnTimer flagAutoReturnTimer) : IFlagEvent
FlagAutoReturnTimer flagAutoReturnTimer,
FlagCarrierSettings flagCarrierSettings) : IFlagEvent
{
public FlagStatus FlagStatus => FlagStatus.Taken;

Expand All @@ -24,6 +25,9 @@ public void Handle(Team team, Player player)
});
worldService.SendClientMessage(team.ColorHex, message);
worldService.GameText($"~n~~n~~n~{team.GameText}{team.ColorName} flag taken!", 5000, 3);
player.ShowOnRadarMap();
if (flagCarrierSettings.ShowOnRadarMap)
{
player.ShowOnRadarMap();
}
}
}
6 changes: 3 additions & 3 deletions src/Application/Teams/Flags/FlagCarrierPauseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class FlagCarrierPauseHandler(
ITimerService timerService,
TeamPickupService teamPickupService,
TeamSoundsService teamSoundsService,
ServerSettings serverSettings) : ISystem
FlagCarrierSettings flagCarrierSettings) : ISystem
{
[Event]
public void OnPlayerDisconnect(Player player, DisconnectReason reason)
Expand All @@ -29,7 +29,7 @@ public void OnPlayerPauseStateChange(Player player, bool pauseState)
PlayerInfo playerInfo = player.GetInfo();
if (pauseState && playerInfo.HasCapturedFlag())
{
var interval = TimeSpan.FromSeconds(serverSettings.FlagCarrierPauseTime);
var interval = TimeSpan.FromSeconds(flagCarrierSettings.PauseTime);
var timerReference = timerService.Start(OnComplete, interval);
player.AddComponent<PauseTimerReference>(timerReference);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ void OnComplete(IServiceProvider serviceProvider)
{
rivalTeam.ColorName,
PlayerName = player.Name,
Seconds = serverSettings.FlagCarrierPauseTime
Seconds = flagCarrierSettings.PauseTime
});
worldService.SendClientMessage(rivalTeam.ColorHex, message);
worldService.GameText($"~n~~n~~n~{rivalTeam.GameText}{rivalTeam.ColorName} flag returned!", 5000, 3);
Expand Down
17 changes: 17 additions & 0 deletions src/Application/Teams/Flags/FlagCarrierSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace CTF.Application.Teams.Flags;

/// <summary>
/// Represents the settings for the flag carrier.
/// </summary>
public class FlagCarrierSettings
{
/// <summary>
/// Gets the maximum duration (in seconds) that the flag carrier can be idle (AFK) while holding the flag.
/// </summary>
public int PauseTime { get; init; } = 30;

/// <summary>
/// Gets a value indicating whether the flag carrier should be shown on the radar map.
/// </summary>
public bool ShowOnRadarMap { get; init; } = true;
}
7 changes: 6 additions & 1 deletion src/Host/Extensions/AppSettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ public static IServiceCollection AddSettings(
.GetRequiredSection("ServerOwner")
.Get<ServerOwnerSettings>();

var flagCarrierSettings = configuration
.GetRequiredSection("FlagCarrier")
.Get<FlagCarrierSettings>();

services
.AddSingleton(serverSettings)
.AddSingleton(commandCooldowns)
.AddSingleton(topPlayersSettings)
.AddSingleton(serverOwnerSettings);
.AddSingleton(serverOwnerSettings)
.AddSingleton(flagCarrierSettings);

return services;
}
Expand Down

0 comments on commit 85c80a7

Please sign in to comment.