Skip to content

Commit

Permalink
Dev (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS authored Jul 6, 2024
2 parents 7f01db4 + b8f0d55 commit 85c9b7c
Show file tree
Hide file tree
Showing 35 changed files with 337 additions and 748 deletions.
12 changes: 6 additions & 6 deletions Jailbreak.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.LastRequest", "mo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Mute", "mod\Jailbreak.Mute\Jailbreak.Mute.csproj", "{C9F050A5-5B08-4F48-98F5-B5792A217DB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.SpecialDay", "mod\Jailbreak.SpecialDay\Jailbreak.SpecialDay.csproj", "{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.LastGuard", "mod\Jailbreak.LastGuard\Jailbreak.LastGuard.csproj", "{B77E4011-E07F-4BDA-A34F-99DADF0BD276}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -82,10 +82,10 @@ Global
{C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9F050A5-5B08-4F48-98F5-B5792A217DB0}.Release|Any CPU.Build.0 = Release|Any CPU
{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF21BE72-5A51-4F5D-B65D-4936FEAA806C}.Release|Any CPU.Build.0 = Release|Any CPU
{B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B77E4011-E07F-4BDA-A34F-99DADF0BD276}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581}
Expand All @@ -99,6 +99,6 @@ Global
{4F10E2B5-E8BB-4253-9BE6-9187575ADB13} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{D8952626-7B8D-4ABB-A3AE-FC81C688787B} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{C9F050A5-5B08-4F48-98F5-B5792A217DB0} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{CF21BE72-5A51-4F5D-B65D-4936FEAA806C} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{B77E4011-E07F-4BDA-A34F-99DADF0BD276} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ The classic Jail gamemode, ported to Counter-Strike 2.
Our **Stable** builds run on EdgeGamers' own Jailbreak servers.
Our **Nightly** builds are used exclusively for development and staging, and are likely to have problems.

## Versioning
Our release tags starting from 'v1.2.0' follow the [Semantic Versioning 2.0.0](https://semver.org/) standard,
where `MAJOR.MINOR.PATCH` are incremented based on the following:
- `MAJOR` when we make incompatible API changes,
- `MINOR` when we add functionality in a backwards-compatible manner, **or** modify gameplay behavior
- `PATCH` when we make backwards-compatible bug fixes, **or** modify non-gameplay (cosmetic) behavior

## Status

- **⚙️ Server**
Expand Down
9 changes: 9 additions & 0 deletions lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public IView InvalidParameter(string parameter, string expected)
$"{ChatColors.Red}Invalid parameter '{ChatColors.LightBlue}{parameter}{ChatColors.Red}', expected a(n) {ChatColors.White}{expected}{ChatColors.Red}."
};
}

public IView NoPermissionMessage(string permission)
{
return new SimpleView
{
PREFIX,
$"{ChatColors.Red}You do not have permission to use this command. Required permission: {ChatColors.White}{permission}{ChatColors.Red}."
};
}
}
28 changes: 28 additions & 0 deletions lang/Jailbreak.English/LastGuard/LastGuardNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Objects;

namespace Jailbreak.English.LastGuard;

public class LastGuardNotifications : ILastGuardNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX =
new HiddenFormatObject($" {ChatColors.Blue}[{ChatColors.LightBlue}Last Guard{ChatColors.Blue}]")
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true
};

public IView LG_STARTED(int ctHealth, int tHealth)
{
return new SimpleView()
{
PREFIX,
$"{ChatColors.Red}Last Guard has been activated! Last guard has", ctHealth, $"{ChatColors.Red}health and T's have", tHealth, $"{ChatColors.Red}health." };
}
}
49 changes: 0 additions & 49 deletions lang/Jailbreak.English/SpecialDay/SpecialDayNotifications.cs

This file was deleted.

13 changes: 11 additions & 2 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.La
new SimpleView { PREFIX, $"{ChatColors.LightRed}You are not the warden." };

public IView FIRE_COMMAND_FAILED =>
new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." };
new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." };

public IView PASS_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "has resigned from being warden." };
}

public IView FIRE_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "was fired from being warden." };
}

public IView FIRE_WARDEN(CCSPlayerController player, CCSPlayerController admin)
{
return new SimpleView { PREFIX, admin, "has fired", player, "from being warden." };
}

public IView NEW_WARDEN(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "is now the warden!" };
Expand All @@ -76,5 +86,4 @@ public IView FIRE_COMMAND_SUCCESS(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "has been fired and is no longer the warden." };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
</ItemGroup>

</Project>
101 changes: 101 additions & 0 deletions mod/Jailbreak.LastGuard/LastGuard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.LastGuard;
using Jailbreak.Public.Mod.LastRequest;

namespace Jailbreak.LastGuard;

public class LastGuard : ILastGuardService, IPluginBehavior
{

private readonly LastGuardConfig _config;
private readonly ILastGuardNotifications _notifications;
private readonly ILastRequestManager _lrManager;
private bool _canStart = false;

public LastGuard(LastGuardConfig config, ILastGuardNotifications notifications, ILastRequestManager lrManager)
{
_config = config;
_notifications = notifications;
_lrManager = lrManager;
}

public void Start(BasePlugin plugin)
{

}

[GameEventHandler]
public HookResult OnPlayerDeathEvent(EventPlayerDeath @event, GameEventInfo info)
{
var target = @event.Userid;
if (target == null) return HookResult.Continue;
if (target.Team != CsTeam.CounterTerrorist) return HookResult.Continue;
var aliveCts = Utilities.GetPlayers()
.Count(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist }) - 1;

if (aliveCts == 1 && !_lrManager.IsLREnabled)
{
var lastGuard = Utilities.GetPlayers().First(plr => plr.IsReal() && plr != target && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist });

StartLastGuard(lastGuard);
}
return HookResult.Continue;
}

[GameEventHandler]
public HookResult OnRoundStartEvent(EventRoundStart @event, GameEventInfo info)
{
_canStart = Utilities.GetPlayers().Count(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.CounterTerrorist}) >= _config.MinimumCTs;
return HookResult.Continue;
}

public int CalculateHealth()
{
var aliveTerrorists = Utilities.GetPlayers()
.Where(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.Terrorist });

foreach (var terrorist in aliveTerrorists)
{
if (terrorist.PlayerPawn.Value?.Health > 100) terrorist.PlayerPawn.Value.Health = 100;
}

return aliveTerrorists.Select(player => player.PlayerPawn.Value.Health).Select(playerHealth => (int)(playerHealth * 0.45)).Sum();

Check warning on line 69 in mod/Jailbreak.LastGuard/LastGuard.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

public void StartLastGuard(CCSPlayerController lastGuard)
{
if (!_canStart) return;

var ctPlayerPawn = lastGuard.PlayerPawn.Value;

if (!ctPlayerPawn.IsValid) return;

Check warning on line 78 in mod/Jailbreak.LastGuard/LastGuard.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

var ctHealth = ctPlayerPawn.Health;
var ctCalcHealth = CalculateHealth();

ctPlayerPawn.Health = ctHealth > ctCalcHealth ? 125 : ctCalcHealth;

Utilities.SetStateChanged(ctPlayerPawn, "CBaseEntity", "m_iHealth");

var aliveTerrorists = Utilities.GetPlayers()
.Where(plr => plr.IsReal() && plr is { PawnIsAlive: true, Team: CsTeam.Terrorist });


_notifications.LG_STARTED(lastGuard.PlayerPawn.Value.Health, aliveTerrorists.Select(plr => plr.PlayerPawn.Value.Health).Sum()).ToAllCenter().ToAllChat();

Check warning on line 91 in mod/Jailbreak.LastGuard/LastGuard.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 91 in mod/Jailbreak.LastGuard/LastGuard.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

if (string.IsNullOrEmpty(_config.LastGuardWeapon)) return;

foreach (var player in aliveTerrorists)
{
player.GiveNamedItem(_config.LastGuardWeapon);
}

}
}
7 changes: 7 additions & 0 deletions mod/Jailbreak.LastGuard/LastGuardConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Jailbreak.LastGuard;

public class LastGuardConfig
{
public string? LastGuardWeapon { get; } = "weapon_glock";
public int MinimumCTs { get; } = 4;
}
14 changes: 14 additions & 0 deletions mod/Jailbreak.LastGuard/LastGuardServiceExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.LastGuard;
using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.LastGuard;

public static class RebelServiceExtension
{
public static void AddJailbreakLastGuard(this IServiceCollection collection)
{
collection.AddConfig<LastGuardConfig>("lastguard");
collection.AddPluginBehavior<ILastGuardService, LastGuard>();
}
}
9 changes: 0 additions & 9 deletions mod/Jailbreak.LastRequest/LastRequestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,25 @@
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;
using Jailbreak.Public.Mod.SpecialDays;
using Microsoft.Extensions.DependencyModel;

namespace Jailbreak.LastRequest;

public class LastRequestCommand(

Check warning on line 17 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / publish

Non-nullable field '_menuSelector' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 17 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / publish

Non-nullable field '_playerSelector' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 17 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / publish

Non-nullable field '_plugin' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
ILastRequestManager manager,
ISpecialDayHandler sdHandler,
ILastRequestMessages messages,
IGenericCommandNotifications generic,
ILastRequestFactory factory)
: IPluginBehavior
{
private LastRequestMenuSelector _menuSelector;
private LastRequestPlayerSelector _playerSelector;
private ISpecialDayHandler _sdHandler;
private BasePlugin _plugin;

// css_lr <player> <LRType>
public void Start(BasePlugin plugin)
{
_plugin = plugin;
_sdHandler = sdHandler;
_playerSelector = new LastRequestPlayerSelector(manager);
_menuSelector = new LastRequestMenuSelector(factory);
}
Expand All @@ -49,11 +45,6 @@ public void Command_LastRequest(CCSPlayerController? executor, CommandInfo info)
return;
}

if (_sdHandler.IsSpecialDayActive())
{
info.ReplyToCommand("You cannot LR during a special day!");
}

if (!executor.PawnIsAlive)
{
info.ReplyToCommand("You must be alive to LR.");
Expand Down
Loading

0 comments on commit 85c9b7c

Please sign in to comment.