Skip to content

Commit

Permalink
Add gangs integration (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS authored Sep 17, 2024
2 parents b90d8b9 + dec7d93 commit 1d1ea68
Show file tree
Hide file tree
Showing 41 changed files with 474 additions and 70 deletions.
24 changes: 24 additions & 0 deletions Jailbreak.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Trail", "mod\Jail
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.RTD", "mod\Jailbreak.RTD\Jailbreak.RTD.csproj", "{C68D4760-7E1E-4633-995A-5EC1EF40E63B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gangs.BombIconPerk", "mod\Gangs.BombIconPerk\Gangs.BombIconPerk.csproj", "{80F8E8F7-6976-414D-AFC0-17E1E3ABD746}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gangs.BaseImpl", "mod\Gangs.BaseImpl\Gangs.BaseImpl.csproj", "{4035945A-80FA-49E7-A9BF-069FEA3213E5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gangs.Boostrap", "mod\Gangs.Boostrap\Gangs.Boostrap.csproj", "{214E54DB-DD70-4B61-BFFC-596C2717E333}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gangs", "Gangs", "{069A4F54-AE2A-4FDF-A5A8-F550B254C2A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -122,6 +130,18 @@ Global
{C68D4760-7E1E-4633-995A-5EC1EF40E63B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C68D4760-7E1E-4633-995A-5EC1EF40E63B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C68D4760-7E1E-4633-995A-5EC1EF40E63B}.Release|Any CPU.Build.0 = Release|Any CPU
{80F8E8F7-6976-414D-AFC0-17E1E3ABD746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80F8E8F7-6976-414D-AFC0-17E1E3ABD746}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80F8E8F7-6976-414D-AFC0-17E1E3ABD746}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80F8E8F7-6976-414D-AFC0-17E1E3ABD746}.Release|Any CPU.Build.0 = Release|Any CPU
{4035945A-80FA-49E7-A9BF-069FEA3213E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4035945A-80FA-49E7-A9BF-069FEA3213E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4035945A-80FA-49E7-A9BF-069FEA3213E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4035945A-80FA-49E7-A9BF-069FEA3213E5}.Release|Any CPU.Build.0 = Release|Any CPU
{214E54DB-DD70-4B61-BFFC-596C2717E333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{214E54DB-DD70-4B61-BFFC-596C2717E333}.Debug|Any CPU.Build.0 = Debug|Any CPU
{214E54DB-DD70-4B61-BFFC-596C2717E333}.Release|Any CPU.ActiveCfg = Release|Any CPU
{214E54DB-DD70-4B61-BFFC-596C2717E333}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581}
Expand All @@ -142,5 +162,9 @@ Global
{C93A626A-BB44-4309-8DAD-4B28B2941870} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{91F4EC7A-993A-4CA0-84C3-9F1100124A9C} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{C68D4760-7E1E-4633-995A-5EC1EF40E63B} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{069A4F54-AE2A-4FDF-A5A8-F550B254C2A9} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7}
{4035945A-80FA-49E7-A9BF-069FEA3213E5} = {069A4F54-AE2A-4FDF-A5A8-F550B254C2A9}
{80F8E8F7-6976-414D-AFC0-17E1E3ABD746} = {069A4F54-AE2A-4FDF-A5A8-F550B254C2A9}
{214E54DB-DD70-4B61-BFFC-596C2717E333} = {069A4F54-AE2A-4FDF-A5A8-F550B254C2A9}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions lang/Jailbreak.English/RTD/RTDLocale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.RTD;
using Jailbreak.Public.Mod.RTD;

namespace Jailbreak.English.RTD;
Expand Down
4 changes: 1 addition & 3 deletions lang/Jailbreak.English/Warden/WardenCmdChickenLocale.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
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;

Expand Down
4 changes: 1 addition & 3 deletions lang/Jailbreak.English/Warden/WardenCmdSoccerLocale.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
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;

Expand Down
44 changes: 44 additions & 0 deletions mod/Gangs.BaseImpl/BasePerk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using GangsAPI.Data.Gang;
using GangsAPI.Data.Stat;
using GangsAPI.Perks;
using GangsAPI.Services.Menu;

namespace Gangs.BaseImpl;

public abstract class BasePerk(IServiceProvider provider) : BaseStat, IPerk {

Check warning on line 8 in mod/Gangs.BaseImpl/BasePerk.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'provider' is unread.

Check warning on line 8 in mod/Gangs.BaseImpl/BasePerk.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'provider' is unread.
public abstract Task<int?> GetCost(IGangPlayer player);
public abstract Task OnPurchase(IGangPlayer player);
public abstract Task<IMenu?> GetMenu(IGangPlayer player);
}

public abstract class BasePerk<TV>(IServiceProvider provider)
: BasePerk(provider), IPerk, IStat<TV> {
protected IServiceProvider Provider { get; } = provider;
public override Type ValueType => typeof(TV);
public abstract TV Value { get; set; }

public bool Equals(IStat<TV>? other) {
return other is not null && StatId == other.StatId;
}
}

public abstract class BaseStat : IStat {
public bool Equals(IStat? other) {
return other is not null && StatId == other.StatId;
}

public abstract string StatId { get; }
public abstract string Name { get; }
public abstract string? Description { get; }
public abstract Type ValueType { get; }
}

public abstract class BaseStat<V> : BaseStat, IStat<V?> {
public override Type ValueType => typeof(V);

public bool Equals(IStat<V?>? other) {
return other is not null && StatId == other.StatId;
}

public abstract V? Value { get; set; }
}
23 changes: 23 additions & 0 deletions mod/Gangs.BaseImpl/Gangs.BaseImpl.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
</ItemGroup>

</Project>
55 changes: 55 additions & 0 deletions mod/Gangs.BombIconPerk/BombIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Gangs.BombIconPerk;

[Flags]
public enum BombIcon {
ANYASMUG = 1 << 0,
C4_RED = 1 << 1,
CACHINGA = 1 << 2,
CLOWN_EMOJI = 1 << 3,
CSGO = 1 << 4,
DOGE = 1 << 5,
DOLLAR = 1 << 6,
EGO = 1 << 7,
GOAT = 1 << 8,
IM = 1 << 9,
IMBAD = 1 << 10,
KZ = 1 << 11,
OMEGALUL = 1 << 12,
PEPEGA = 1 << 13,
POOP = 1 << 14,
STEAM = 1 << 15,
THINKING = 1 << 16,
UWUNUKE = 1 << 17,
ZZZ = 1 << 18
}

public static class BombIconExtensions {
public static int GetCost(this BombIcon icon) {
return icon switch {
BombIcon.ANYASMUG => 750,
BombIcon.C4_RED => 500,
BombIcon.CACHINGA => 1000,
BombIcon.CLOWN_EMOJI => 2000,
BombIcon.CSGO => 750,
BombIcon.DOGE => 1500,
BombIcon.DOLLAR => 10000,
BombIcon.EGO => 1000,
BombIcon.GOAT => 5000,
BombIcon.IM => 500,
BombIcon.IMBAD => 1000,
BombIcon.KZ => 1000,
BombIcon.OMEGALUL => 3500,
BombIcon.PEPEGA => 2500,
BombIcon.POOP => 650,
BombIcon.STEAM => 750,
BombIcon.THINKING => 800,
BombIcon.UWUNUKE => 2500,
BombIcon.ZZZ => 2000,
_ => 0
};
}

public static string GetEquipment(this BombIcon icon) {
return icon.ToString().ToLower();
}
}
125 changes: 125 additions & 0 deletions mod/Gangs.BombIconPerk/BombIconCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using GangsAPI;
using GangsAPI.Data;
using GangsAPI.Data.Command;
using GangsAPI.Exceptions;
using GangsAPI.Extensions;
using GangsAPI.Perks;
using GangsAPI.Permissions;
using GangsAPI.Services;
using GangsAPI.Services.Commands;
using GangsAPI.Services.Gang;
using GangsAPI.Services.Menu;
using GangsAPI.Services.Player;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;

namespace Gangs.BombIconPerk;

public class BombIconCommand(IServiceProvider provider) : ICommand {
private readonly IEcoManager eco = provider.GetRequiredService<IEcoManager>();

private readonly IGangChatPerk? gangChat =
provider.GetService<IGangChatPerk>();

private readonly IGangManager gangs =
provider.GetRequiredService<IGangManager>();

private readonly IGangStatManager gangStats =
provider.GetRequiredService<IGangStatManager>();

private readonly IStringLocalizer localizer =
provider.GetRequiredService<IStringLocalizer>();

private readonly IMenuManager menus =
provider.GetRequiredService<IMenuManager>();

private readonly IPlayerManager players =
provider.GetRequiredService<IPlayerManager>();

private readonly IRankManager ranks =
provider.GetRequiredService<IRankManager>();

public string Name => "css_bombicon";
public string[] Usage => ["<icon>"];

public void Start() {
provider.GetRequiredService<ICommandManager>().RegisterCommand(this);
}

public async Task<CommandResult> Execute(PlayerWrapper? executor,
CommandInfoWrapper info) {
if (executor == null) return CommandResult.PLAYER_ONLY;
var player = await players.GetPlayer(executor.Steam)
?? throw new PlayerNotFoundException(executor.Steam);
if (player.GangId == null) {
info.ReplySync(localizer.Get(MSG.NOT_IN_GANG));
return CommandResult.SUCCESS;
}

var gang = await gangs.GetGang(player.GangId.Value)
?? throw new GangNotFoundException(player.GangId.Value);

var (success, data) =
await gangStats.GetForGang<BombPerkData>(gang, BombPerk.STAT_ID);

if (!success || data == null) data = new BombPerkData();

if (info.ArgCount == 1) {
var menu = new BombIconMenu();
await menus.OpenMenu(executor, menu);
return CommandResult.SUCCESS;
}

BombIcon icon;
if (!int.TryParse(info[1], out var iconInt) || iconInt < 0) {
if (!Enum.TryParse(info[1], out icon)) {
info.ReplySync(localizer.Get(MSG.COMMAND_INVALID_PARAM, info[1],
"an icon"));
return CommandResult.SUCCESS;
}
} else { icon = (BombIcon)iconInt; }

if (!data.Unlocked.HasFlag(icon)) {
var (canPurchase, minRank) = await ranks.CheckRank(player,
Perm.PURCHASE_PERKS);

if (!canPurchase) {
info.ReplySync(localizer.Get(MSG.GENERIC_NOPERM_RANK, minRank.Name));
return CommandResult.SUCCESS;
}

var cost = icon.GetCost();
if (await eco.TryPurchase(executor, cost,
item: "Bomb Icon: " + icon.ToString().ToTitleCase()) < 0)
return CommandResult.SUCCESS;

data.Unlocked |= icon;

await gangStats.SetForGang(gang, BombPerk.STAT_ID, data);

if (gangChat == null) return CommandResult.SUCCESS;

await gangChat.SendGangChat(player, gang,
localizer.Get(MSG.PERK_PURCHASED, icon.ToString()));
return CommandResult.SUCCESS;
}


var (canManage, required) =
await ranks.CheckRank(player, Perm.MANAGE_PERKS);
if (!canManage) {
info.ReplySync(localizer.Get(MSG.GENERIC_NOPERM_RANK, required.Name));
return CommandResult.SUCCESS;
}

data.Equipped = icon;
await gangStats.SetForGang(gang, BombPerk.STAT_ID, data);

if (gangChat == null) return CommandResult.SUCCESS;

await gangChat.SendGangChat(player, gang,
localizer.Get(MSG.GANG_THING_SET, "Bomb Icon",
icon.ToString().ToTitleCase()));
return CommandResult.SUCCESS;
}
}
12 changes: 12 additions & 0 deletions mod/Gangs.BombIconPerk/BombIconExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using GangsAPI.Services;
using Microsoft.Extensions.DependencyInjection;

namespace Gangs.BombIconPerk;

public class BombIconBootstrap {
public BombIconBootstrap(IServiceProvider collection) {
new BombIconCommand(collection).Start();
collection.GetRequiredService<IPerkManager>()
.Perks.Add(new BombPerk(collection));
}
}
17 changes: 17 additions & 0 deletions mod/Gangs.BombIconPerk/BombIconMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using GangsAPI.Data;
using GangsAPI.Services.Menu;

namespace Gangs.BombIconPerk;

public class BombIconMenu : IMenu {
public Task Open(PlayerWrapper player) {
player.PrintToChat("Bomb Icon Menu");
return Task.CompletedTask;
}

public Task Close(PlayerWrapper player) { return Task.CompletedTask; }

public Task AcceptInput(PlayerWrapper player, int input) {
return Task.CompletedTask;
}
}
34 changes: 34 additions & 0 deletions mod/Gangs.BombIconPerk/BombPerk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Gangs.BaseImpl;
using GangsAPI.Data.Gang;
using GangsAPI.Services.Menu;

namespace Gangs.BombIconPerk;

public class BombPerk(IServiceProvider provider)
: BasePerk<BombPerkData>(provider) {
public const string STAT_ID = "jb_bomb_icon";
public override string StatId => STAT_ID;
public override string Name => "Bomb Icon";

public override string? Description
=> "Customize the icon that is shown when you bomb a CT";

public override BombPerkData Value { get; set; } = new();

public override Task<int?> GetCost(IGangPlayer player) {
return Task.FromResult<int?>(null);
}

public override Task OnPurchase(IGangPlayer player) {
throw new NotImplementedException();
}

public override Task<IMenu?> GetMenu(IGangPlayer player) {
return Task.FromResult<IMenu?>(new BombIconMenu());
}
}

public class BombPerkData {
public BombIcon Unlocked { get; set; }
public BombIcon Equipped { get; set; }
}
Loading

0 comments on commit 1d1ea68

Please sign in to comment.