Skip to content

Commit

Permalink
Smol updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Aug 21, 2021
1 parent 529fe5c commit cba476b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 47 deletions.
30 changes: 15 additions & 15 deletions CustomItems/CustomItems.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,36 @@
<Reference Include="CommandSystem.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>$(EXILED_REFERENCES)\CommandSystem.Core.dll</HintPath>
</Reference>
<Reference Include="Exiled.API, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.API.dll</HintPath>
<Reference Include="Exiled.API, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.API.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.Bootstrap, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.Bootstrap.dll</HintPath>
<Reference Include="Exiled.Bootstrap, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.Bootstrap.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.CreditTags, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.CreditTags.dll</HintPath>
<Reference Include="Exiled.CreditTags, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.CreditTags.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.CustomItems, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.CustomItems.dll</HintPath>
<Reference Include="Exiled.CustomItems, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.CustomItems.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.Events, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.Events.dll</HintPath>
<Reference Include="Exiled.Events, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.Events.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.Loader, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.Loader.dll</HintPath>
<Reference Include="Exiled.Loader, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.Loader.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.Permissions, Version=2.12.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.Permissions.dll</HintPath>
<Reference Include="Exiled.Permissions, Version=2.13.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.Permissions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exiled.Updater, Version=3.1.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\EXILED.2.12.0-beta\lib\net472\Exiled.Updater.dll</HintPath>
<HintPath>..\packages\EXILED.2.13.0-beta\lib\net472\Exiled.Updater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
Expand Down
22 changes: 20 additions & 2 deletions CustomItems/Items/EmpGrenade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace CustomItems.Items
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -208,9 +209,26 @@ private void OnExplodingGrenade(ExplodingGrenadeEventArgs ev)

Timing.CallDelayed(Duration, () =>
{
LockedRooms079.Remove(room);
try
{
LockedRooms079.Remove(room);
}
catch (Exception e)
{
Log.Debug($"REMOVING LOCKED ROOM: {e}");
}

if (gate != null)
disabledTeslaGates.Remove(gate);
{
try
{
disabledTeslaGates.Remove(gate);
}
catch (Exception e)
{
Log.Debug($"REMOVING DISABLED TESLA: {e}");
}
}
});
}

Expand Down
13 changes: 13 additions & 0 deletions CustomItems/Items/Scp2818.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ protected override void OnShooting(ShootingEventArgs ev)
{
try
{
foreach (var item in ev.Shooter.Inventory.items)
if (Check(item))
{
Log.Debug($"SCP-2818: Found a 2818 in inventory of shooter, removing.");
ev.Shooter.RemoveItem(item);
}

Player target = null;
if (ev.Target != null)
target = Player.Get(ev.Target);
Expand Down Expand Up @@ -141,9 +148,15 @@ private IEnumerator<float> ShooterProjectile(Player player, Vector3 targetPos, P
yield return Timing.WaitForSeconds(0.01f);

if (DespawnAfterUse)
{
Log.Debug($"inv count: {player.Items.Count}");
foreach (Inventory.SyncItemInfo item in player.Items.ToList())
if (Check(item))
{
Log.Debug("found 2818 in inventory, doing funni");
player.RemoveItem(item);
}
}

if (player.Role != RoleType.Spectator)
player.Kill(DamageTypes.Nuke);
Expand Down
100 changes: 71 additions & 29 deletions CustomItems/Items/TranquilizerGun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace CustomItems.Items
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -19,11 +20,13 @@ namespace CustomItems.Items
using MEC;
using Mirror;
using UnityEngine;
using Random = UnityEngine.Random;

/// <inheritdoc />
public class TranquilizerGun : CustomWeapon
{
private readonly Dictionary<Player, float> tranquilizedPlayers = new Dictionary<Player, float>();
private readonly List<Player> activeTranqs = new List<Player>();

/// <inheritdoc/>
public override uint Id { get; set; } = 11;
Expand Down Expand Up @@ -99,18 +102,20 @@ public class TranquilizerGun : CustomWeapon
public int ScpResistChance { get; set; } = 40;

/// <inheritdoc/>
public override void Destroy()
protected override void UnsubscribeEvents()
{
Exiled.Events.Handlers.Player.PickingUpItem -= OnTranqPickingUpItem;
activeTranqs.Clear();
tranquilizedPlayers.Clear();
Timing.KillCoroutines($"{nameof(TranquilizerGun)}-{Id}-reducer");

base.Destroy();
base.UnsubscribeEvents();
}

/// <inheritdoc/>
protected override void SubscribeEvents()
{
Timing.RunCoroutine(ReduceResistances(), $"{nameof(TranquilizerGun)}-{Id}-reducer");
Exiled.Events.Handlers.Player.PickingUpItem += OnTranqPickingUpItem;
base.SubscribeEvents();
}

Expand All @@ -119,27 +124,40 @@ protected override void OnHurting(HurtingEventArgs ev)
{
base.OnHurting(ev);

if (ev.Attacker == ev.Target || (ev.Target.Team == Team.SCP && ResistantScps && Random.Range(1, 101) <= ScpResistChance))
if (ev.Attacker == ev.Target)
return;

if (ev.Target.Team == Team.SCP)
{
int r = Random.Range(1, 101);
Log.Debug($"{Name}: SCP roll: {r} (must be greater than {ScpResistChance})", CustomItems.Instance.Config.IsDebugEnabled);
if (r <= ScpResistChance)
{
Log.Debug($"{Name}: {r} is too low, no tranq.", CustomItems.Instance.Config.IsDebugEnabled);
return;
}
}

float duration = Duration;

if (!tranquilizedPlayers.TryGetValue(ev.Target, out _))
tranquilizedPlayers.Add(ev.Target, 1);

tranquilizedPlayers[ev.Target] *= ResistanceModifier;
Log.Debug($"{Name}: Resistance Duration Mod: {tranquilizedPlayers[ev.Target]}", CustomItems.Instance.Config.IsDebugEnabled);

duration -= tranquilizedPlayers[ev.Target];
Log.Debug($"{Name}: Duration: {duration}", CustomItems.Instance.Config.IsDebugEnabled);

if (duration > 0f)
Timing.RunCoroutine(DoTranquilize(ev.Target, duration));
}

private IEnumerator<float> DoTranquilize(Player player, float duration)
{
activeTranqs.Add(player);
Vector3 oldPosition = player.Position;
Inventory.SyncItemInfo previousItem =
player.ReferenceHub.inventory.items[player.ReferenceHub.inventory.GetItemIndex()];
Inventory.SyncItemInfo previousItem = player.CurrentItem;
Vector3 previousScale = player.Scale;
float newHealth = player.Health - Damage;
List<PlayerEffect> activeEffects = NorthwoodLib.Pools.ListPool<PlayerEffect>.Shared.Rent();
Expand All @@ -151,21 +169,31 @@ private IEnumerator<float> DoTranquilize(Player player, float duration)
if (effect.Enabled)
activeEffects.Add(effect);

if (DropItems)
try
{
foreach (Inventory.SyncItemInfo item in player.Inventory.items.ToList())
if (DropItems)
{
if (TryGet(item, out CustomItem customItem))
if (player.Items.Count < 0)
{
customItem.Spawn(player.Position, item, out _);
player.Inventory.items.Remove(item);
foreach (Inventory.SyncItemInfo item in player.Inventory.items.ToList())
{
if (TryGet(item, out CustomItem customItem))
{
customItem.Spawn(player.Position, item, out _);
player.Inventory.items.Remove(item);
}
}

player.DropItems();
}
}

player.DropItems();
}
catch (Exception e)
{
Log.Error($"{nameof(DoTranquilize)}: {e}");
}

Ragdoll ragdoll = Map.SpawnRagdoll(player, DamageTypes.None, oldPosition, allowRecall: false);
Ragdoll ragdoll = Ragdoll.Spawn(player, DamageTypes.None, oldPosition, allowRecall: false);

player.Inventory.curItem = ItemType.None;
player.IsInvisible = true;
Expand All @@ -178,27 +206,35 @@ private IEnumerator<float> DoTranquilize(Player player, float duration)

yield return Timing.WaitForSeconds(duration);

if (ragdoll != null)
NetworkServer.Destroy(ragdoll.gameObject);
try
{
if (ragdoll != null)
NetworkServer.Destroy(ragdoll.GameObject);

if (player.GameObject == null)
yield break;
if (player.GameObject == null)
yield break;

newHealth = player.Health;
newHealth = player.Health;

player.IsGodModeEnabled = false;
player.Scale = previousScale;
player.Health = newHealth;
player.IsInvisible = false;
player.IsGodModeEnabled = false;
player.Scale = previousScale;
player.Health = newHealth;
player.IsInvisible = false;

if (!DropItems)
player.Inventory.CmdSetUnic(previousItem.uniq);
if (!DropItems)
player.Inventory.CmdSetUnic(previousItem.uniq);

foreach (PlayerEffect effect in activeEffects)
if ((effect.Duration - duration) > 0)
player.ReferenceHub.playerEffectsController.EnableEffect(effect, effect.Duration - duration);
foreach (PlayerEffect effect in activeEffects)
if ((effect.Duration - duration) > 0)
player.ReferenceHub.playerEffectsController.EnableEffect(effect, effect.Duration - duration);

NorthwoodLib.Pools.ListPool<PlayerEffect>.Shared.Return(activeEffects);
activeTranqs.Remove(player);
NorthwoodLib.Pools.ListPool<PlayerEffect>.Shared.Return(activeEffects);
}
catch (Exception e)
{
Log.Error($"{nameof(DoTranquilize)}: {e}");
}

if (Warhead.IsDetonated && player.Position.y < 900)
{
Expand All @@ -219,5 +255,11 @@ private IEnumerator<float> ReduceResistances()
yield return Timing.WaitForSeconds(ResistanceFalloffDelay);
}
}

private void OnTranqPickingUpItem(PickingUpItemEventArgs ev)
{
if (activeTranqs.Contains(ev.Player))
ev.IsAllowed = false;
}
}
}
2 changes: 1 addition & 1 deletion CustomItems/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EXILED" version="2.12.0-beta" targetFramework="net472" />
<package id="EXILED" version="2.13.0-beta" targetFramework="net472" />
<package id="Lib.Harmony" version="2.0.4" targetFramework="net472" />
<package id="StyleCop.Analyzers" version="1.1.118" targetFramework="net472" developmentDependency="true" />
</packages>

0 comments on commit cba476b

Please sign in to comment.