feat: add BasePower abstraction
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using Cs2SuperPowers.Players;
|
||||
using Cs2SuperPowers.Players.PlayerValidations;
|
||||
|
||||
namespace Cs2SuperPowers.Powers;
|
||||
|
||||
public class BulletStorm(IPlayerHud playerHud) : BasePower(playerHud)
|
||||
{
|
||||
public override int Id => 13;
|
||||
public override string Name => "Bullet Storm";
|
||||
|
||||
public override string Description => $"Gain effectively unlimited reserve ammo so you can keep reloading without ever running dry.";
|
||||
|
||||
public override char ChatColor => ChatColors.Olive;
|
||||
|
||||
public override string HtmlColor => "#0000FF";
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
RegisterEventHandler<EventWeaponFire>(OnWeaponFire);
|
||||
RegisterEventHandler<EventWeaponReload>(OnWeaponReload);
|
||||
}
|
||||
|
||||
private HookResult OnWeaponFire(EventWeaponFire @event, GameEventInfo info)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!Ensure.Player(player).IsValid().Check() || !IsAssignedTo(player!))
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
RefillReserveAmmo(player!);
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnWeaponReload(EventWeaponReload @event, GameEventInfo info)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (!Ensure.Player(player).IsValid().Check() || !IsAssignedTo(player!))
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
RefillReserveAmmo(player!);
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private static void RefillReserveAmmo(CCSPlayerController player)
|
||||
{
|
||||
var activeWeaponHandle = player.PlayerPawn.Value?.WeaponServices?.ActiveWeapon;
|
||||
if (activeWeaponHandle?.Value != null)
|
||||
{
|
||||
activeWeaponHandle.Value.ReserveAmmo[0] = 999;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user