Skip to content

Commit

Permalink
Rough sketch of ST behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooshua committed Mar 8, 2024
1 parent 0cb80de commit 72f5a16
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 2 deletions.
38 changes: 38 additions & 0 deletions lang/Jailbreak.English/Warden/SpecialTreatmentNotifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;

namespace Jailbreak.English.Warden;

public class SpecialTreatmentNotifications : ISpecialTreatmentNotifications, ILanguage<Formatting.Languages.English>
{
public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.Lime}[{ChatColors.Green}ST{ChatColors.Lime}]" )
{
// Hide in panorama and center text
Plain = false,
Panorama = false,
Chat = true,
};

public IView GRANTED =>
new SimpleView { PREFIX, "You now have special treatment!" };

public IView REVOKED =>
new SimpleView { PREFIX, "Your special treatment was removed" };

public IView GRANTED_TO(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "now has Special Treatment!" };
}

public IView REVOKED_FROM(CCSPlayerController player)
{
return new SimpleView { PREFIX, player, "no longer has Special Treatment." };
}

}
17 changes: 17 additions & 0 deletions mod/Jailbreak.Warden/Commands/SpecialTreatmentCommandsBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;

namespace Jailbreak.Warden.Commands;

public class SpecialTreatmentCommandsBehavior
{

[ConsoleCommand("css_treat", "Grant or revoke special treatment from a player")]
[ConsoleCommand("css_st", "Grant or revoke special treatment from a player")]
[CommandHelper(0, "css_st / css_treat <player>", CommandUsage.CLIENT_ONLY)]
public void Command_Toggle(CCSPlayerController? player, CommandInfo command)
{

}
}
90 changes: 90 additions & 0 deletions mod/Jailbreak.Warden/SpecialTreatment/SpecialTreatmentBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Drawing;

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;

using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Generic;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.Warden.SpecialTreatment;

public class SpecialTreatmentBehavior : IPluginBehavior, ISpecialTreatmentService
{
private IPlayerState<SpecialTreatmentState> _sts;
private IRebelService _rebel;
private ISpecialTreatmentNotifications _notifications;

public SpecialTreatmentBehavior(IPlayerStateFactory factory, IRebelService rebel, ISpecialTreatmentNotifications notifications)
{
_sts = factory.Round<SpecialTreatmentState>();

_rebel = rebel;
_notifications = notifications;
}

private class SpecialTreatmentState
{
public bool HasSpecialTreatment { get; set; } = false;
}

public bool IsSpecialTreatment(CCSPlayerController player)
{
return _sts.Get(player)
.HasSpecialTreatment;
}

public void Grant(CCSPlayerController player)
{
// Player is already granted ST
if (IsSpecialTreatment(player))
return;

_sts.Get(player).HasSpecialTreatment = true;

_rebel.UnmarkRebel(player);
this.SetPlayerColor(player, /* hasSt */ true);

_notifications.GRANTED
.ToPlayerChat(player)
.ToPlayerCenter(player);

_notifications.GRANTED_TO(player)
.ToAllChat();
}

public void Revoke(CCSPlayerController player)
{
// Player is already revoked
if (!IsSpecialTreatment(player))
return;

_sts.Get(player).HasSpecialTreatment = false;

this.SetPlayerColor(player, /* hasSt */ false);

_notifications.REVOKED
.ToPlayerChat(player)
.ToPlayerCenter(player);

_notifications.REVOKED_FROM(player)
.ToAllChat();
}

private void SetPlayerColor(CCSPlayerController player, bool hasSt)
{
if (!player.IsValid || player.Pawn.Value == null)
return;

var color = hasSt
? Color.FromArgb(254, 150, 255, 150)
: Color.FromArgb(254, 255, 255, 255);

player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor;
player.Pawn.Value.Render = color;
Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender");
}
}
5 changes: 4 additions & 1 deletion mod/Jailbreak.Warden/WardenServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Jailbreak.Warden.Markers;
using Jailbreak.Warden.Paint;
using Jailbreak.Warden.Selection;
using Jailbreak.Warden.SpecialTreatment;

using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.Warden;
Expand All @@ -15,9 +17,10 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection)
{
serviceCollection.AddPluginBehavior<IWardenService, WardenBehavior>();
serviceCollection.AddPluginBehavior<IWardenSelectionService, WardenSelectionBehavior>();
serviceCollection.AddPluginBehavior<ISpecialTreatmentService, SpecialTreatmentBehavior>();

serviceCollection.AddPluginBehavior<WardenCommandsBehavior>();
serviceCollection.AddPluginBehavior<WardenMarkerBehavior>();
serviceCollection.AddPluginBehavior<WardenPaintBehavior>();
}
}
}
6 changes: 5 additions & 1 deletion public/Jailbreak.Formatting/Logistics/LanguageConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public void WithRebel<TRebel>()
public void WithLogging<TLogging>()
where TLogging : class, ILanguage<TDialect>, ILogMessages
=> _collection.AddSingleton<ILogMessages, TLogging>();

public void WithLastRequest<TLastRequest>()
where TLastRequest : class, ILanguage<TDialect>, ILastRequestMessages
=> _collection.AddSingleton<ILastRequestMessages, TLastRequest>();

public void WithSpecialTreatment<TSpecialTreatment>()
where TSpecialTreatment : class, ILanguage<TDialect>, ISpecialTreatmentNotifications
=> _collection.AddSingleton<ISpecialTreatmentNotifications, TSpecialTreatment>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using CounterStrikeSharp.API.Core;

using Jailbreak.Formatting.Base;

namespace Jailbreak.Formatting.Views;

public interface ISpecialTreatmentNotifications
{
public IView GRANTED { get; }

public IView REVOKED { get; }

public IView GRANTED_TO(CCSPlayerController player);

public IView REVOKED_FROM(CCSPlayerController player);

}
21 changes: 21 additions & 0 deletions public/Jailbreak.Public/Mod/Warden/ISpecialTreatmentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CounterStrikeSharp.API.Core;

namespace Jailbreak.Public.Mod.Warden;

public interface ISpecialTreatmentService
{
public bool IsSpecialTreatment(CCSPlayerController player);

/// <summary>
/// Give this player ST for the rest of the round
/// </summary>
/// <param name="player"></param>
public void Grant(CCSPlayerController player);

/// <summary>
/// Revoke the player's special treatment for the current round
/// Does nothing if not ST.
/// </summary>
/// <param name="player"></param>
public void Revoke(CCSPlayerController player);
}
1 change: 1 addition & 0 deletions src/Jailbreak/JailbreakServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void ConfigureServices(IServiceCollection serviceCollection)
config.WithRebel<RebelNotifications>();
config.WithLogging<LogMessages>();
config.WithLastRequest<LastRequestMessages>();
config.WithSpecialTreatment<SpecialTreatmentNotifications>();
});
}
}

0 comments on commit 72f5a16

Please sign in to comment.