Skip to content

Commit

Permalink
Add soccer and chicken cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 28, 2024
1 parent c76daad commit ae68386
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lang/Jailbreak.English/Warden/WardenCmdChickenLocale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.English.Warden;

public class WardenCmdChickenLocale : IWardenCmdChickenLocale,
ILanguage<Formatting.Languages.English> {
public IView ChickenSpawned
=> new SimpleView {
WardenLocale.PREFIX,
ChatColors.Blue + "The warden" + ChatColors.Grey + " spawned a chicken."
};

public IView SpawnFailed
=> new SimpleView {
WardenLocale.PREFIX, ChatColors.Red + "Failed to spawn a chicken."
};

public IView TooManyChickens
=> new SimpleView { WardenLocale.PREFIX, "Too many chickens." };
}
26 changes: 26 additions & 0 deletions lang/Jailbreak.English/Warden/WardenCmdSoccerLocale.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.English.Warden;

public class WardenCmdSoccerLocale : IWardenCmdSoccerLocale,
ILanguage<Formatting.Languages.English> {
public IView SoccerSpawned
=> new SimpleView {
WardenLocale.PREFIX,
ChatColors.Blue + "The warden" + ChatColors.Grey
+ " spawned a soccer ball."
};

public IView SpawnFailed
=> new SimpleView {
WardenLocale.PREFIX, ChatColors.Red + "Failed to spawn a soccer ball."
};

public IView TooManySoccers
=> new SimpleView { WardenLocale.PREFIX, "Too many soccer balls." };
}
51 changes: 51 additions & 0 deletions mod/Jailbreak.Warden/Commands/ChickenCommandBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.Warden.Commands;

public class ChickenCommandBehavior(IWardenService warden,
IWardenLocale wardenLocale, IWardenCmdChickenLocale locale)
: IPluginBehavior {
public static readonly FakeConVar<int> CV_MAX_CHICKENS =
new("css_jb_max_chickens",
"The maximum number of chickens that the warden can spawn", 5);

private int chickens = 0;

[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) {
chickens = 0;
return HookResult.Continue;
}

[ConsoleCommand("css_chicken", "Spawn a chicken as the warden")]
public void Command_Toggle(CCSPlayerController? player, CommandInfo command) {
if (player == null) return;

if (!warden.IsWarden(player)) {
wardenLocale.NotWarden.ToChat(player);
return;
}

if (chickens >= CV_MAX_CHICKENS.Value) {
locale.TooManyChickens.ToChat(player);
return;
}

var chicken = Utilities.CreateEntityByName<CChicken>("chicken");
if (chicken == null || !chicken.IsValid) {
locale.SpawnFailed.ToChat(player);
return;
}
chicken.Teleport(player.AbsOrigin);
locale.ChickenSpawned.ToAllChat();
chicken.DispatchSpawn();
}
}
56 changes: 56 additions & 0 deletions mod/Jailbreak.Warden/Commands/SoccerCommandBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.Warden.Commands;

public class SoccerCommandBehavior(IWardenService warden,
IWardenLocale wardenLocale, IWardenCmdSoccerLocale locale) : IPluginBehavior {
public static readonly FakeConVar<int> CV_MAX_SOCCERS =
new("css_jb_max_soccers",
"The maximum number of soccer balls that the warden can spawn", 3);

private int soccers = 0;

[GameEventHandler]
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) {
soccers = 0;
return HookResult.Continue;
}

[ConsoleCommand("css_soccer", "Spawn a soccer ball as the warden")]
[ConsoleCommand("css_spawnball", "Spawn a soccer ball as the warden")]
public void Command_Toggle(CCSPlayerController? player, CommandInfo command) {
if (player == null) return;

if (!warden.IsWarden(player)) {
wardenLocale.NotWarden.ToChat(player);
return;
}

if (soccers >= CV_MAX_SOCCERS.Value) {
locale.TooManySoccers.ToChat(player);
return;
}

var chicken =
Utilities.CreateEntityByName<CPhysicsPropMultiplayer>(
"prop_physics_multiplayer");
if (chicken == null || !chicken.IsValid) {
locale.SpawnFailed.ToChat(player);
return;
}

chicken.SetModel(
"models/props/de_dust/hr_dust/dust_soccerball/dust_soccer_ball001.vmdl");
chicken.Teleport(player.AbsOrigin);
locale.SoccerSpawned.ToAllChat();
chicken.DispatchSpawn();
}
}
2 changes: 2 additions & 0 deletions mod/Jailbreak.Warden/WardenServiceExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static void AddJailbreakWarden(
serviceCollection.AddPluginBehavior<PeaceCommandsBehavior>();
serviceCollection.AddPluginBehavior<WardenCommandsBehavior>();
serviceCollection.AddPluginBehavior<RollCommandBehavior>();
serviceCollection.AddPluginBehavior<ChickenCommandBehavior>();
serviceCollection.AddPluginBehavior<SoccerCommandBehavior>();

serviceCollection.AddPluginBehavior<WardenMarkerBehavior>();
serviceCollection.AddPluginBehavior<WardenPaintBehavior>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Jailbreak.Formatting.Base;

namespace Jailbreak.Formatting.Views.Warden;

public interface IWardenCmdChickenLocale {
public IView ChickenSpawned { get; }
public IView SpawnFailed { get; }
public IView TooManyChickens { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Jailbreak.Formatting.Base;

namespace Jailbreak.Formatting.Views.Warden;

public interface IWardenCmdSoccerLocale {
public IView SoccerSpawned { get; }
public IView SpawnFailed { get; }
public IView TooManySoccers { get; }
}
5 changes: 5 additions & 0 deletions src/Jailbreak/JailbreakServiceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Jailbreak.LastRequest;
using Jailbreak.Logs;
using Jailbreak.Mute;
using Jailbreak.Public.Mod.Warden;
using Jailbreak.Rebel;
using Jailbreak.RTD;
using Jailbreak.SpecialDay;
Expand Down Expand Up @@ -50,6 +51,10 @@ public void ConfigureServices(IServiceCollection serviceCollection) {
serviceCollection.AddSingleton<IWardenPeaceLocale, WardenPeaceLocale>();
serviceCollection.AddSingleton<IWardenSTLocale, WardenSTLocale>();
serviceCollection.AddSingleton<IRTDLocale, RTDLocale>();
serviceCollection
.AddSingleton<IWardenCmdChickenLocale, WardenCmdChickenLocale>();
serviceCollection
.AddSingleton<IWardenCmdSoccerLocale, WardenCmdSoccerLocale>();

// Do we want to make this scoped?
// Not sure how this will behave with multiple rounds and whatnot.
Expand Down

0 comments on commit ae68386

Please sign in to comment.