mirror of
https://github.com/edgegamers/Jailbreak.git
synced 2025-12-05 20:40:29 -08:00
Add warden paint perk
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<ProjectReference Include="..\Gangs.SpecialDayColorPerk\Gangs.SpecialDayColorPerk.csproj"/>
|
||||
<ProjectReference Include="..\Gangs.SpecialIconPerk\Gangs.SpecialIconPerk.csproj"/>
|
||||
<ProjectReference Include="..\Gangs.WardenIconPerk\Gangs.WardenIconPerk.csproj"/>
|
||||
<ProjectReference Include="..\WardenPaintColorPerk\WardenPaintColorPerk.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -9,6 +9,7 @@ using Jailbreak.Public;
|
||||
using Jailbreak.Public.Behaviors;
|
||||
using Jailbreak.Public.Extensions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WardenPaintColorPerk;
|
||||
|
||||
namespace Gangs.Boostrap;
|
||||
|
||||
@@ -29,5 +30,6 @@ public class GangsInit : IPluginBehavior {
|
||||
_ = new LRColorBootstrap(services);
|
||||
_ = new WardenIconBootstrap(services);
|
||||
_ = new SpecialIconBootstrap(services);
|
||||
_ = new WardenColorBootstrap(services);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,10 @@ public class Rainbowizer : IRainbowColorizer {
|
||||
colorTimer = null;
|
||||
}
|
||||
|
||||
public Color GetRainbow() {
|
||||
return calculateColor(DateTime.Now - DateTime.UnixEpoch);
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
foreach (var (slot, start) in rainbowTimers) {
|
||||
var player = Utilities.GetPlayerFromSlot(slot);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<ProjectReference Include="..\Gangs.SpecialIconPerk\Gangs.SpecialIconPerk.csproj"/>
|
||||
<ProjectReference Include="..\Gangs.WardenIconPerk\Gangs.WardenIconPerk.csproj"/>
|
||||
<ProjectReference Include="..\Jailbreak.Zones\Jailbreak.Zones.csproj"/>
|
||||
<ProjectReference Include="..\WardenPaintColorPerk\WardenPaintColorPerk.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,23 +1,43 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using GangsAPI.Data;
|
||||
using GangsAPI.Services.Gang;
|
||||
using GangsAPI.Services.Player;
|
||||
using Jailbreak.Public;
|
||||
using Jailbreak.Public.Behaviors;
|
||||
using Jailbreak.Public.Extensions;
|
||||
using Jailbreak.Public.Mod.Draw;
|
||||
using Jailbreak.Public.Mod.Rainbow;
|
||||
using Jailbreak.Public.Mod.Warden;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WardenPaintColorPerk;
|
||||
|
||||
namespace Jailbreak.Warden.Paint;
|
||||
|
||||
public class WardenPaintBehavior(IWardenService wardenService)
|
||||
: IPluginBehavior {
|
||||
public class WardenPaintBehavior(IWardenService wardenService,
|
||||
IServiceProvider provider) : IPluginBehavior {
|
||||
private Vector? lastPosition;
|
||||
private BasePlugin? parent;
|
||||
|
||||
private IRainbowColorizer? colorizer =
|
||||
provider.GetService<IRainbowColorizer>();
|
||||
|
||||
private WardenPaintColor?[] colors = new WardenPaintColor?[65];
|
||||
|
||||
public void Start(BasePlugin basePlugin) {
|
||||
parent = basePlugin;
|
||||
basePlugin.RegisterListener<Listeners.OnTick>(paint);
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info) {
|
||||
colors = new WardenPaintColor?[65];
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void paint() {
|
||||
if (!wardenService.HasWarden) return;
|
||||
|
||||
@@ -42,7 +62,63 @@ public class WardenPaintBehavior(IWardenService wardenService)
|
||||
if (parent == null)
|
||||
throw new NullReferenceException("Parent plugin is null");
|
||||
|
||||
new BeamLine(parent, start.Clone(), position.Clone()).Draw(30f);
|
||||
var color = getColor(warden);
|
||||
var line = new BeamLine(parent, start.Clone(), position.Clone());
|
||||
line.SetColor(color);
|
||||
line.Draw(30);
|
||||
}
|
||||
|
||||
private Color getColor(CCSPlayerController player) {
|
||||
if (player.Pawn.Value == null || player.PlayerPawn.Value == null)
|
||||
return Color.White;
|
||||
var pawn = player.Pawn.Value;
|
||||
if (pawn == null || !pawn.IsValid) return Color.White;
|
||||
|
||||
var color = colors[player.Index];
|
||||
if (color != null) {
|
||||
if (color == WardenPaintColor.RAINBOW)
|
||||
return colorizer?.GetRainbow() ?? Color.White;
|
||||
if ((color & WardenPaintColor.RANDOM) != 0)
|
||||
return color.Value.PickRandom() ?? Color.White;
|
||||
return color.Value.GetColor() ?? Color.White;
|
||||
}
|
||||
|
||||
var wrapper = new PlayerWrapper(player);
|
||||
Task.Run(async () => {
|
||||
color = await fetchColor(wrapper);
|
||||
colors[player.Index] = color;
|
||||
});
|
||||
|
||||
return Color.White;
|
||||
}
|
||||
|
||||
private async Task<WardenPaintColor> fetchColor(PlayerWrapper player) {
|
||||
var gangs = API.Gangs?.Services.GetService<IGangManager>();
|
||||
var playerStats = API.Gangs?.Services.GetService<IPlayerStatManager>();
|
||||
var players = API.Gangs?.Services.GetService<IPlayerManager>();
|
||||
var gangStats = API.Gangs?.Services.GetService<IGangStatManager>();
|
||||
|
||||
if (gangs == null || playerStats == null || players == null
|
||||
|| gangStats == null)
|
||||
return WardenPaintColor.DEFAULT;
|
||||
|
||||
var (success, playerColors) =
|
||||
await playerStats.GetForPlayer<WardenPaintColor>(player.Steam,
|
||||
WardenPaintColorPerk.WardenPaintColorPerk.STAT_ID);
|
||||
|
||||
if (!success) return WardenPaintColor.DEFAULT;
|
||||
|
||||
var gangPlayer = await players.GetPlayer(player.Steam);
|
||||
|
||||
if (gangPlayer?.GangId == null) return WardenPaintColor.DEFAULT;
|
||||
|
||||
var gang = await gangs.GetGang(gangPlayer.GangId.Value);
|
||||
if (gang == null) return WardenPaintColor.DEFAULT;
|
||||
|
||||
var (_, available) = await gangStats.GetForGang<WardenPaintColor>(gang,
|
||||
WardenPaintColorPerk.WardenPaintColorPerk.STAT_ID);
|
||||
|
||||
return playerColors & available;
|
||||
}
|
||||
|
||||
private Vector? findFloorIntersection(CCSPlayerController player) {
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
namespace WardenPaintColorPerk;
|
||||
using GangsAPI.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace WardenPaintColorPerk;
|
||||
|
||||
public class WardenColorBootstrap {
|
||||
|
||||
public WardenColorBootstrap(IServiceProvider collection) {
|
||||
new WardenColorCommand(collection).Start();
|
||||
collection.GetRequiredService<IPerkManager>()
|
||||
.Perks.Add(new WardenPaintColorPerk(collection));
|
||||
}
|
||||
}
|
||||
55
mod/WardenPaintColorPerk/WardenPaintColor.cs
Normal file
55
mod/WardenPaintColorPerk/WardenPaintColor.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Drawing;
|
||||
using Gangs.BaseImpl.Extensions;
|
||||
|
||||
namespace WardenPaintColorPerk;
|
||||
|
||||
[Flags]
|
||||
public enum WardenPaintColor {
|
||||
DEFAULT = 1 << 0,
|
||||
RED = 1 << 1,
|
||||
ORANGE = 1 << 2,
|
||||
YELLOW = 1 << 3,
|
||||
GREEN = 1 << 4,
|
||||
CYAN = 1 << 5,
|
||||
BLUE = 1 << 6,
|
||||
PURPLE = 1 << 7,
|
||||
RANDOM = 1 << 8,
|
||||
RAINBOW = 1 << 9
|
||||
}
|
||||
|
||||
public static class WardenColorExtensions {
|
||||
private static readonly Random rng = new();
|
||||
|
||||
public static Color? GetColor(this WardenPaintColor paintColor) {
|
||||
return paintColor switch {
|
||||
WardenPaintColor.RED => Color.Red,
|
||||
WardenPaintColor.ORANGE => Color.Orange,
|
||||
WardenPaintColor.YELLOW => Color.Yellow,
|
||||
WardenPaintColor.GREEN => Color.Green,
|
||||
WardenPaintColor.CYAN => Color.Cyan,
|
||||
WardenPaintColor.BLUE => Color.Blue,
|
||||
WardenPaintColor.PURPLE => Color.Purple,
|
||||
WardenPaintColor.DEFAULT => null,
|
||||
WardenPaintColor.RANDOM => null,
|
||||
_ => Color.White
|
||||
};
|
||||
}
|
||||
|
||||
public static int GetCost(this WardenPaintColor paintColor) {
|
||||
if (paintColor == WardenPaintColor.RAINBOW) return 10 * 7500;
|
||||
if (paintColor == WardenPaintColor.DEFAULT) return 0;
|
||||
return (int)Math.Round(paintColor.GetColor().GetColorMultiplier() * 7500);
|
||||
}
|
||||
|
||||
public static Color? PickRandom(this WardenPaintColor paintColor) {
|
||||
var n = rng.Next(Enum.GetValues<WardenPaintColor>().Length);
|
||||
var available = Enum.GetValues<WardenPaintColor>()
|
||||
.Where(c => paintColor.HasFlag(c) && c.GetColor() != null)
|
||||
.ToList();
|
||||
|
||||
// Gang bought the random perk, but no colors, sillies!
|
||||
if (available.Count == 0) return null;
|
||||
|
||||
return available[n % available.Count].GetColor();
|
||||
}
|
||||
}
|
||||
19
mod/WardenPaintColorPerk/WardenPaintColorPerk.csproj
Normal file
19
mod/WardenPaintColorPerk/WardenPaintColorPerk.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Gangs.BaseImpl\Gangs.BaseImpl.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="GangsAPI">
|
||||
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using Jailbreak.Public.Behaviors;
|
||||
|
||||
@@ -16,4 +17,6 @@ public interface IRainbowColorizer : IPluginBehavior {
|
||||
}
|
||||
|
||||
void StopRainbow(int slot);
|
||||
|
||||
Color GetRainbow();
|
||||
}
|
||||
Reference in New Issue
Block a user