mirror of
https://github.com/edgegamers/Jailbreak.git
synced 2025-12-05 20:40:29 -08:00
Add more weapon prevention
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
@@ -26,6 +25,7 @@ using Jailbreak.Public.Mod.LastRequest;
|
||||
using Jailbreak.Public.Mod.LastRequest.Enums;
|
||||
using Jailbreak.Public.Mod.Rainbow;
|
||||
using Jailbreak.Public.Mod.Rebel;
|
||||
using Jailbreak.Public.Mod.Weapon;
|
||||
using Jailbreak.Public.Utils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Localization;
|
||||
@@ -59,7 +59,10 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
|
||||
|
||||
private ILastRequestFactory? factory;
|
||||
public bool IsLREnabledForRound { get; set; } = true;
|
||||
private List<int> droppedWeaponSlots = new();
|
||||
public bool IsLREnabled { get; set; }
|
||||
|
||||
public IList<AbstractLastRequest> ActiveLRs { get; } =
|
||||
new List<AbstractLastRequest>();
|
||||
|
||||
public bool ShouldBlockDamage(CCSPlayerController player,
|
||||
CCSPlayerController? attacker, EventPlayerHurt @event) {
|
||||
@@ -100,68 +103,29 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
|
||||
stats?.Stats.Add(new LRStat());
|
||||
|
||||
basePlugin.RegisterListener<Listeners.OnEntityParentChanged>(OnDrop);
|
||||
VirtualFunctions.CCSPlayer_WeaponServices_CanUseFunc.Hook(OnCanUse,
|
||||
HookMode.Pre);
|
||||
VirtualFunctions.CCSPlayer_ItemServices_CanAcquireFunc.Hook(OnCanAcquire,
|
||||
HookMode.Pre);
|
||||
}
|
||||
|
||||
private void OnDrop(CEntityInstance entity, CEntityInstance newparent) {
|
||||
if (!entity.IsValid || !IsLREnabled) return;
|
||||
|
||||
if (!Tag.WEAPONS.Contains(entity.DesignerName)) return;
|
||||
|
||||
var weaponEntity =
|
||||
Utilities.GetEntityFromIndex<CCSWeaponBase>((int)entity.Index);
|
||||
if (weaponEntity == null || !weaponEntity.IsValid) return;
|
||||
|
||||
var owner = weaponEntity.PrevOwner.Get()?.OriginalController.Get();
|
||||
if (owner == null || !owner.IsValid) return;
|
||||
|
||||
if (newparent.IsValid) {
|
||||
// Player picked up a weapon
|
||||
if (!entity.IsValid) return;
|
||||
if (!Tag.WEAPONS.Contains(entity.DesignerName)
|
||||
&& !Tag.UTILITY.Contains(entity.DesignerName))
|
||||
return;
|
||||
}
|
||||
|
||||
var color = owner.Team == CsTeam.CounterTerrorist ? Color.Blue : Color.Red;
|
||||
weaponEntity.SetColor(color);
|
||||
var weapon = Utilities.GetEntityFromIndex<CCSWeaponBase>((int)entity.Index);
|
||||
var owner = weapon?.PrevOwner.Get()?.OriginalController.Get();
|
||||
|
||||
droppedWeaponSlots.Add((int)weaponEntity.Index);
|
||||
if (owner == null || weapon == null || !weapon.IsValid) return;
|
||||
if (newparent.IsValid) return;
|
||||
|
||||
var lr = ((ILastRequestManager)this).GetActiveLR(owner);
|
||||
if (lr is not IDropListener listener) return;
|
||||
listener.OnWeaponDrop(owner, weapon);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose() {
|
||||
VirtualFunctions.CCSPlayer_ItemServices_CanAcquireFunc.Unhook(OnCanAcquire,
|
||||
HookMode.Pre);
|
||||
}
|
||||
|
||||
private HookResult OnCanAcquire(DynamicHook hook) {
|
||||
if (!IsLREnabled) return HookResult.Continue;
|
||||
var data = VirtualFunctions.GetCSWeaponDataFromKey.Invoke(-1,
|
||||
hook.GetParam<CEconItemView>(1).ItemDefinitionIndex.ToString());
|
||||
var player = hook.GetParam<CCSPlayer_ItemServices>(0)
|
||||
.Pawn.Value.Controller.Value?.As<CCSPlayerController>();
|
||||
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
var method = hook.GetParam<AcquireMethod>(2);
|
||||
if (method != AcquireMethod.PickUp) return HookResult.Continue;
|
||||
var weapon = Utilities.GetEntityFromIndex<CCSWeaponBase>(data.Slot);
|
||||
|
||||
if (weapon == null || !weapon.IsValid) return HookResult.Continue;
|
||||
|
||||
if (droppedWeaponSlots.Contains((int)weapon.Index))
|
||||
return HookResult.Handled;
|
||||
|
||||
var lr = ((ILastRequestManager)this).GetActiveLR(player);
|
||||
if (lr == null) return HookResult.Continue;
|
||||
|
||||
if (lr.State == LRState.PENDING) return HookResult.Continue;
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
public bool IsLREnabled { get; set; }
|
||||
|
||||
public IList<AbstractLastRequest> ActiveLRs { get; } =
|
||||
new List<AbstractLastRequest>();
|
||||
|
||||
public void DisableLR() { IsLREnabled = false; }
|
||||
|
||||
public void DisableLRForRound() {
|
||||
@@ -289,6 +253,44 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
|
||||
return true;
|
||||
}
|
||||
|
||||
private HookResult OnCanUse(DynamicHook hook) {
|
||||
if (ActiveLRs.Count == 0) return HookResult.Continue;
|
||||
var player = hook.GetParam<CCSPlayer_WeaponServices>(0)
|
||||
.Pawn.Value.Controller.Value?.As<CCSPlayerController>();
|
||||
var weapon = hook.GetParam<CBasePlayerWeapon>(1);
|
||||
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
var lr = ((ILastRequestManager)this).GetActiveLR(player);
|
||||
if (lr is not IUseBlocker blocker) return HookResult.Continue;
|
||||
|
||||
return blocker.PreventUse(player, weapon) ?
|
||||
HookResult.Handled :
|
||||
HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnCanAcquire(DynamicHook hook) {
|
||||
if (ActiveLRs.Count == 0) return HookResult.Continue;
|
||||
var player = hook.GetParam<CCSPlayer_ItemServices>(0)
|
||||
.Pawn.Value.Controller.Value?.As<CCSPlayerController>();
|
||||
var data = VirtualFunctions.GetCSWeaponDataFromKey.Invoke(-1,
|
||||
hook.GetParam<CEconItemView>(1).ItemDefinitionIndex.ToString());
|
||||
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
var method = hook.GetParam<AcquireMethod>(2);
|
||||
if (method != AcquireMethod.PickUp) return HookResult.Continue;
|
||||
var weapon = Utilities.GetEntityFromIndex<CCSWeaponBase>(data.Slot);
|
||||
|
||||
if (weapon == null || !weapon.IsValid) return HookResult.Continue;
|
||||
|
||||
if (ActiveLRs.Where(s => s is IEquipBlocker)
|
||||
.Cast<IEquipBlocker>()
|
||||
.Any(lr => lr.PreventEquip(player, weapon)))
|
||||
return HookResult.Handled;
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private async Task colorForLR(PlayerWrapper a, PlayerWrapper b) {
|
||||
var playerStats = API.Gangs?.Services.GetService<IPlayerStatManager>();
|
||||
var gangStats = API.Gangs?.Services.GetService<IGangStatManager>();
|
||||
@@ -465,8 +467,6 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
|
||||
foreach (var lr in ActiveLRs.ToList())
|
||||
EndLastRequest(lr, LRResult.TIMED_OUT);
|
||||
|
||||
droppedWeaponSlots.Clear();
|
||||
|
||||
IsLREnabled = false;
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ using CounterStrikeSharp.API.Core;
|
||||
using Jailbreak.Public.Extensions;
|
||||
using Jailbreak.Public.Mod.LastRequest;
|
||||
using Jailbreak.Public.Mod.LastRequest.Enums;
|
||||
using Jailbreak.Public.Mod.Weapon;
|
||||
|
||||
namespace Jailbreak.LastRequest.LastRequests;
|
||||
|
||||
public class GunToss(BasePlugin plugin, ILastRequestManager manager,
|
||||
CCSPlayerController prisoner, CCSPlayerController guard)
|
||||
: TeleportingRequest(plugin, manager, prisoner, guard) {
|
||||
: TeleportingRequest(plugin, manager, prisoner, guard), IDropListener,
|
||||
IUseBlocker {
|
||||
public override LRType Type => LRType.GUN_TOSS;
|
||||
private bool guardThrew, prisonerThrew;
|
||||
|
||||
public override void Setup() {
|
||||
base.Setup();
|
||||
@@ -33,10 +36,22 @@ public class GunToss(BasePlugin plugin, ILastRequestManager manager,
|
||||
Guard.SetHealth(250);
|
||||
Guard.SetArmor(500);
|
||||
|
||||
Prisoner.GetWeaponBase("weapon_deagle").SetAmmo(2, 7);
|
||||
Prisoner.GetWeaponBase("weapon_deagle").SetAmmo(2, 0);
|
||||
|
||||
State = LRState.ACTIVE;
|
||||
}
|
||||
|
||||
public override void OnEnd(LRResult result) { State = LRState.COMPLETED; }
|
||||
|
||||
public void OnWeaponDrop(CCSPlayerController player, CCSWeaponBase weapon) {
|
||||
if (State != LRState.ACTIVE) return;
|
||||
|
||||
if (player == Guard) guardThrew = true;
|
||||
if (player == Prisoner) prisonerThrew = true;
|
||||
}
|
||||
|
||||
public bool PreventUse(CCSPlayerController player, CBasePlayerWeapon weapon) {
|
||||
if (State != LRState.ACTIVE) return false;
|
||||
return player.Slot == Prisoner.Slot && !guardThrew;
|
||||
}
|
||||
}
|
||||
@@ -26,20 +26,9 @@ public class Race(BasePlugin plugin, ILastRequestManager manager,
|
||||
base.Setup();
|
||||
|
||||
Prisoner.RemoveWeapons();
|
||||
|
||||
Guard.RemoveWeapons();
|
||||
Plugin.AddTimer(1, () => {
|
||||
if (State != LRState.PENDING) return;
|
||||
Guard.GiveNamedItem("weapon_knife");
|
||||
});
|
||||
|
||||
Plugin.AddTimer(3, () => {
|
||||
if (State != LRState.PENDING) return;
|
||||
Prisoner.GiveNamedItem("weapon_knife");
|
||||
});
|
||||
|
||||
messages.EndRaceInstruction.ToChat(Prisoner);
|
||||
|
||||
messages.RaceStartingMessage(Prisoner).ToChat(Guard);
|
||||
|
||||
startLocation = Prisoner.Pawn.Value?.AbsOrigin?.Clone();
|
||||
@@ -48,12 +37,11 @@ public class Race(BasePlugin plugin, ILastRequestManager manager,
|
||||
start = new BeamCircle(Plugin, startLocation, 20, 16);
|
||||
start.SetColor(Color.Aqua);
|
||||
start.Draw();
|
||||
State = LRState.ACTIVE;
|
||||
}
|
||||
|
||||
// Called when the prisoner types !endrace
|
||||
public override void Execute() {
|
||||
State = LRState.ACTIVE;
|
||||
|
||||
endLocation = Prisoner.Pawn.Value?.AbsOrigin?.Clone();
|
||||
|
||||
if (endLocation == null) return;
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
using Jailbreak.Public.Extensions;
|
||||
using Jailbreak.Public.Mod.LastRequest;
|
||||
using Jailbreak.Public.Mod.LastRequest.Enums;
|
||||
using Jailbreak.Public.Mod.Weapon;
|
||||
|
||||
namespace Jailbreak.LastRequest.LastRequests;
|
||||
|
||||
public abstract class TeleportingRequest(BasePlugin plugin,
|
||||
ILastRequestManager manager, CCSPlayerController prisoner,
|
||||
CCSPlayerController guard)
|
||||
: AbstractLastRequest(plugin, manager, prisoner, guard) {
|
||||
: AbstractLastRequest(plugin, manager, prisoner, guard), IEquipBlocker {
|
||||
public override void Setup() {
|
||||
State = LRState.PENDING;
|
||||
|
||||
@@ -19,4 +20,9 @@ public abstract class TeleportingRequest(BasePlugin plugin,
|
||||
Plugin.AddTimer(1, () => { Guard.UnFreeze(); });
|
||||
Plugin.AddTimer(2, () => { Prisoner.UnFreeze(); });
|
||||
}
|
||||
|
||||
public virtual bool PreventEquip(CCSPlayerController player, CCSWeaponBase weapon) {
|
||||
if (State == LRState.PENDING) return false;
|
||||
return player == Prisoner || player == Guard;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,6 @@ public class RandomZoneGenerator(IZoneManager zoneManager, IZoneFactory factory,
|
||||
|
||||
var map = Server.MapName;
|
||||
zone.Id = nearestPoint.Id;
|
||||
// Server.NextFrameAsync(async () => {
|
||||
Task.Run(async () => {
|
||||
await zoneManager.DeleteZone(zone.Id, map);
|
||||
await zoneManager.PushZoneWithID(zone, ZoneType.SPAWN_AUTO, map);
|
||||
@@ -113,7 +112,6 @@ public class RandomZoneGenerator(IZoneManager zoneManager, IZoneFactory factory,
|
||||
|
||||
var spawn = factory.CreateZone([pos]);
|
||||
autoSpawnPoints.Add(spawn);
|
||||
// Server.NextFrameAsync(async () => {
|
||||
Task.Run(async () => {
|
||||
await zoneManager.PushZone(spawn, ZoneType.SPAWN_AUTO, currentMap!);
|
||||
});
|
||||
|
||||
@@ -22,4 +22,12 @@ public abstract class AbstractLastRequest(BasePlugin plugin,
|
||||
public abstract void Setup();
|
||||
public abstract void Execute();
|
||||
public abstract void OnEnd(LRResult result);
|
||||
|
||||
// public bool PreventShoot(CCSPlayerController player, CBasePlayerWeapon weapon) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public bool PreventPickup(CCSPlayerController player, CCSWeaponBase weapon) {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
7
public/Jailbreak.Public/Mod/Weapon/IDropListener.cs
Normal file
7
public/Jailbreak.Public/Mod/Weapon/IDropListener.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace Jailbreak.Public.Mod.Weapon;
|
||||
|
||||
public interface IDropListener {
|
||||
void OnWeaponDrop(CCSPlayerController player, CCSWeaponBase weapon);
|
||||
}
|
||||
7
public/Jailbreak.Public/Mod/Weapon/IEquipBlocker.cs
Normal file
7
public/Jailbreak.Public/Mod/Weapon/IEquipBlocker.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace Jailbreak.Public.Mod.Weapon;
|
||||
|
||||
public interface IEquipBlocker {
|
||||
bool PreventEquip(CCSPlayerController player, CCSWeaponBase weapon);
|
||||
}
|
||||
7
public/Jailbreak.Public/Mod/Weapon/IUseBlocker.cs
Normal file
7
public/Jailbreak.Public/Mod/Weapon/IUseBlocker.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace Jailbreak.Public.Mod.Weapon;
|
||||
|
||||
public interface IUseBlocker {
|
||||
public bool PreventUse(CCSPlayerController player, CBasePlayerWeapon weapon);
|
||||
}
|
||||
Reference in New Issue
Block a user