Skip to content

Commit

Permalink
A few fixes for SCP-2818
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Mar 7, 2021
1 parent b51f206 commit 47f5ab8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
41 changes: 33 additions & 8 deletions CustomItems/Items/Scp2818.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 Exiled.API.Features;
Expand Down Expand Up @@ -41,13 +42,13 @@ public class Scp2818 : CustomWeapon
/// Gets or sets how often the <see cref="ShooterProjectile"/> coroutine will move the player.
/// </summary>
[Description("How frequently the shooter will be moved towards his target.\n# Note, a lower tick frequency, and lower MaxDistance will make the travel smoother, but be more stressful on your server.")]
public float TickFrequency { get; set; } = 0.0005f;
public float TickFrequency { get; set; } = 0.00025f;

/// <summary>
/// Gets or sets the max distance towards the target location the shooter can be moved each tick.
/// </summary>
[Description("The max distance towards the target location the shooter can be moved each tick.")]
public float MaxDistancePerTick { get; set; } = 0.25f;
public float MaxDistancePerTick { get; set; } = 0.50f;

/// <inheritdoc/>
public override SpawnProperties SpawnProperties { get; set; } = new SpawnProperties
Expand Down Expand Up @@ -79,27 +80,49 @@ public class Scp2818 : CustomWeapon
/// <inheritdoc/>
protected override void OnShooting(ShootingEventArgs ev)
{
Player target = null;
if (ev.Target != null)
target = Player.Get(ev.Target);
Timing.RunCoroutine(ShooterProjectile(ev.Shooter, ev.Position, target));
try
{
Player target = null;
if (ev.Target != null)
target = Player.Get(ev.Target);
if (ev.Position == Vector3.zero || Vector3.Distance(ev.Shooter.Position, ev.Position) > 100f)
{
ev.Shooter.Kill(DamageTypes.Nuke);
ev.IsAllowed = false;
return;
}

Timing.RunCoroutine(ShooterProjectile(ev.Shooter, ev.Position, target));
}
catch (Exception e)
{
Log.Error(e);
}
}

private IEnumerator<float> ShooterProjectile(Player player, Vector3 targetPos, Player target = null)
{
RoleType playerRole = player.Role;

// This is the camera transform used to make grenades appear like they are coming from the player's head instead of their stomach. We move them here so they aren't skidding across the floor.
player.Position = player.CameraTransform.TransformPoint(new Vector3(0.0715f, 0.0225f, 0.45f));
player.Scale = new Vector3(0.15f, 0.15f, 0.15f);
if (target != null)
while (Vector3.Distance(player.Position, target.Position) > (MaxDistancePerTick + 0.15f))
{
if (player.Role != playerRole)
break;

player.Position = Vector3.MoveTowards(player.Position, target.Position, MaxDistancePerTick);

yield return Timing.WaitForSeconds(TickFrequency);
}
else
while (Vector3.Distance(player.Position, targetPos) > 0.5f)
{
if (player.Role != playerRole)
break;

player.Position = Vector3.MoveTowards(player.Position, targetPos, MaxDistancePerTick);

yield return Timing.WaitForSeconds(TickFrequency);
Expand All @@ -110,8 +133,10 @@ private IEnumerator<float> ShooterProjectile(Player player, Vector3 targetPos, P
// Make sure the scale is reset properly *before* killing them. That's important.
yield return Timing.WaitForSeconds(0.01f);

player.Kill(DamageTypes.Nuke);
target?.Kill(DamageTypes.Nuke);
if (player.Role != RoleType.Spectator)
player.Kill(DamageTypes.Nuke);
if (target?.Role != RoleType.Spectator)
target?.Kill(DamageTypes.Nuke);
}
}
}
2 changes: 1 addition & 1 deletion CustomItems/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.1.0")]
[assembly: AssemblyVersion("2.2.2.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]

0 comments on commit 47f5ab8

Please sign in to comment.