-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
497 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / build
|
||
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => "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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
Oops, something went wrong.