Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Jul 15, 2023
1 parent 9516e68 commit a97de92
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 80 deletions.
34 changes: 0 additions & 34 deletions CustomItems/Items/C4Charge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,40 +300,6 @@ private void OnShooting(ShootingEventArgs ev)
}
}

private Pickup Throw(Player player, Throwable throwable, bool weakThrow)
{
ThrowableItem.ProjectileSettings settings =
weakThrow ? throwable.Base.WeakThrowSettings : throwable.Base.FullThrowSettings;
ThrownProjectile projectile = Object.Instantiate(
throwable.Projectile.Base,
throwable.Owner.ReferenceHub.PlayerCameraReference.position,
throwable.Owner.ReferenceHub.PlayerCameraReference.rotation);
Transform transform = projectile.transform;
PickupSyncInfo newInfo = new(Type, transform.position, transform.rotation, Weight, throwable.Serial)
{
Locked = true,
};

projectile.Info = PickupSyncInfo.None;
projectile.PreviousOwner = player.Footprint;
NetworkServer.Spawn(projectile.gameObject);
Vector3 limitedVelocity = ThrowableNetworkHandler.GetLimitedVelocity(player.Velocity);
try
{
projectile.Awake();
projectile.NetworkInfo = newInfo;
}
catch (Exception e)
{
Log.Error($"{e}\n\n{e.StackTrace}");
}

projectile.InfoReceived(new(), newInfo);
throwable.Base.PropelBody(projectile.RigidBody, settings.StartTorque, limitedVelocity, settings.StartVelocity, settings.UpwardsFactor);

return Pickup.Get(projectile);
}

private void OnRoundEnded(RoundEndedEventArgs ev)
{
PlacedCharges.Clear();
Expand Down
165 changes: 119 additions & 46 deletions CustomItems/Items/Scp714.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,48 @@ namespace CustomItems.Items;
using System;
using System.Collections.Generic;
using System.ComponentModel;

using CustomPlayerEffects;

using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features;
using Exiled.API.Features.Attributes;
using Exiled.API.Features.Pools;
using Exiled.API.Features.Roles;
using Exiled.API.Features.Spawn;
using Exiled.CustomItems.API.Features;
using Exiled.Events.EventArgs.Map;
using Exiled.Events.EventArgs.Player;
using Exiled.Events.EventArgs.Scp049;

using InventorySystem.Items.Usables.Scp330;

using MEC;

using PlayerRoles;
using PlayerRoles.FirstPersonControl;

using PlayerStatsSystem;

using UnityEngine;

/// <inheritdoc/>
[CustomItem(ItemType.Coin)]
public class Scp714 : CustomItem
{
private HashSet<Player> equippedPlayers = new();
private Dictionary<Player, CoroutineHandle> stamLimiters = new();
private Dictionary<Player, List<(EffectType, float)>> existingEffects = new();

/// <inheritdoc/>
public override uint Id { get; set; } = 12;

/// <inheritdoc/>
public override string Name { get; set; } = "SCP-714";

/// <inheritdoc/>
public override string Description { get; set; } = "The green ring that protects you from SCP-049.";
public override string Description { get; set; } = "The jade ring that protects you from hazards.";

/// <inheritdoc/>
public override float Weight { get; set; } = 1.15f;
Expand Down Expand Up @@ -62,9 +84,19 @@ public class Scp714 : CustomItem
/// Gets or sets which effects should be given to the player, when he will put on SCP-714.
/// </summary>
[Description("Which effects should be given to the player, when he will put on SCP-714.")]
public List<string> Scp714Effects { get; set; } = new()
public List<EffectType> Scp714Effects { get; set; } = new()
{
EffectType.Asphyxiated,
};

public List<EffectType> PreventedEffects { get; set; } = new()
{
"Asphyxiated",
EffectType.AmnesiaItems,
EffectType.AmnesiaVision,
EffectType.Hypothermia,
EffectType.Burned,
EffectType.Concussed,
EffectType.Blinded,
};

/// <summary>
Expand All @@ -73,87 +105,128 @@ public class Scp714 : CustomItem
[Description("Message shown to player, when he takes off the SCP-714.")]
public string TakeOffMessage { get; set; } = "You've taken off the ring.";

public string PutOnMessage { get; set; } = "You have put on the ring.";

public float Scp049Damage { get; set; } = 40f;

public float PocketDimensionModifier { get; set; } = 0.75f;

public float StamLimitModifier { get; set; } = 0.5f;

public override bool Check(Player? player) => player is not null ? equippedPlayers.Contains(player) : base.Check(player);

/// <inheritdoc/>
protected override void SubscribeEvents()
{
Exiled.Events.Handlers.Player.ChangingItem += OnChangingItem;
Exiled.Events.Handlers.Player.Hurting += OnHurting;

Exiled.Events.Handlers.Scp049.Attacking += OnAttacking;
Exiled.Events.Handlers.Player.FlippingCoin += OnFlippingCoin;
Exiled.Events.Handlers.Player.ReceivingEffect += OnReceivingEffect;
base.SubscribeEvents();
}

/// <inheritdoc/>
protected override void UnsubscribeEvents()
{
Exiled.Events.Handlers.Player.ChangingItem -= OnChangingItem;
Exiled.Events.Handlers.Player.Hurting -= OnHurting;
Exiled.Events.Handlers.Scp049.Attacking -= OnAttacking;
Exiled.Events.Handlers.Player.FlippingCoin -= OnFlippingCoin;
Exiled.Events.Handlers.Player.ReceivingEffect -= OnReceivingEffect;

base.UnsubscribeEvents();
}

/// <inheritdoc/>
protected override void OnDropping(DroppingItemEventArgs ev)
{
ev.Player.ShowHint(TakeOffMessage);

foreach (string effect in Scp714Effects)
{
try
{
ev.Player.DisableEffect((EffectType)Enum.Parse(typeof(EffectType), effect, true));
}
catch (Exception)
{
Log.Error($"\"{effect}\" is not a valid effect name.");
continue;
}
}
if (Check(ev.Player))
SetRingState(ev.Player, false);

base.OnDropping(ev);
}

private void OnChangingItem(ChangingItemEventArgs ev)
private void OnFlippingCoin(FlippingCoinEventArgs ev)
{
if (Check(ev.NewItem))
if (!Check(ev.Player.CurrentItem))
return;

SetRingState(ev.Player, !Check(ev.Player));
}

private void OnAttacking(AttackingEventArgs ev)
{
if (Check(ev.Player) && (Scp714Roles?.Contains(ev.Player.Role.Type) ?? false))
{
foreach (string effect in Scp714Effects)
if (ev.Target is not null)
{
if (!ev.Player.EnableEffect(effect, 999f, false))
{
Log.Error($"\"{effect}\" is not a valid effect name.");
}
ev.IsAllowed = false;
ev.Target.Hurt(Scp049Damage);
}
}
else
}

private void OnHurting(HurtingEventArgs ev)
{
if (Check(ev.Player.CurrentItem))
{
if (!string.IsNullOrEmpty(TakeOffMessage))
ev.Player.ShowHint(TakeOffMessage);
if (ev.Attacker is not null && Scp714Roles is not null && Scp714Roles.Contains(ev.Attacker.Role))
ev.IsAllowed = false;

foreach (string effect in Scp714Effects)
{
try
{
ev.Player.DisableEffect((EffectType)Enum.Parse(typeof(EffectType), effect, true));
}
catch (Exception)
if (ev.DamageHandler.Type is DamageType.PocketDimension)
ev.Amount *= PocketDimensionModifier;
}
}

private void OnReceivingEffect(ReceivingEffectEventArgs ev)
{
if (Check(ev.Player) && PreventedEffects.Contains(ev.Effect.GetEffectType()))
ev.IsAllowed = false;
}

private void SetRingState(Player player, bool equipped)
{
switch (equipped)
{
case true:
List<(EffectType, float)> activeEffects = ListPool<(EffectType, float)>.Pool.Get();
foreach (StatusEffectBase? active in player.ActiveEffects)
activeEffects.Add(new(active.GetEffectType(), active.TimeLeft));

existingEffects[player] = activeEffects;
ListPool<(EffectType, float)>.Pool.Return(activeEffects);
foreach (EffectType effect in Scp714Effects)
player.EnableEffect(effect);
stamLimiters[player] = Timing.RunCoroutine(LimitStamina(player));
equippedPlayers.Add(player);
player.ShowHint(PutOnMessage);

break;
case false:
foreach (EffectType effect in Scp714Effects)
player.DisableEffect(effect);
equippedPlayers.Remove(player);
player.ShowHint(TakeOffMessage);
Timing.KillCoroutines(stamLimiters[player]);
stamLimiters.Remove(player);
if (existingEffects.TryGetValue(player, out List<(EffectType, float)>? existingEffect))
{
Log.Error($"\"{effect}\" is not a valid effect name.");
continue;
foreach ((EffectType type, float dur) in existingEffect)
player.EnableEffect(type, dur);
existingEffects.Remove(player);
}
}

break;
}
}

private void OnHurting(HurtingEventArgs ev)
private IEnumerator<float> LimitStamina(Player player)
{
if (Check(ev.Player.CurrentItem) && ev.Attacker is not null)
while (Check(player))
{
if (Scp714Roles is not null && Scp714Roles.Contains(ev.Attacker.Role))
{
ev.IsAllowed = false;
}
if (player.Stamina > player.StaminaStat.MaxValue * StamLimitModifier)
player.Stamina = player.StaminaStat.MaxValue * StamLimitModifier;

yield return Timing.WaitForSeconds(0.15f);
}
}
}

0 comments on commit a97de92

Please sign in to comment.