-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUtils.cs
More file actions
79 lines (70 loc) · 3.08 KB
/
Utils.cs
File metadata and controls
79 lines (70 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.ComponentModel;
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.API.Features.Items;
using PlayerRoles;
using UnityEngine;
using EP = Exiled.API.Features.Player;
namespace ExtendedItems
{
public static class Utils
{
/// <summary>
/// Calculates the global coords of a point inside a room based on the room type and the location
/// </summary>
/// <param name="roomType"></param>
/// <param name="localPos"></param>
/// <returns>Vector3</returns>
public static Vector3 GetGlobalCords(RoomType roomType, Vector3 localPos)
{
var room = Room.Get(roomType);
var rotation = room.Rotation;
var roomPos = room.Position;
var offsetY = Math.Round(Math.Abs(rotation.eulerAngles.y / 90f));
return offsetY switch
{
0 => new Vector3(roomPos.x + localPos.x, roomPos.y + localPos.y, roomPos.z + localPos.z),
1 => new Vector3(roomPos.x + localPos.z, roomPos.y + localPos.y, roomPos.z - localPos.x),
2 => new Vector3(roomPos.x - localPos.x, roomPos.y + localPos.y, roomPos.z - localPos.z),
3 => new Vector3(roomPos.x - localPos.z, roomPos.y + localPos.y, roomPos.z + localPos.x),
_ => Vector3.zero,
};
}
/// <summary>
/// Removes 1 from an ushort (I hate this language sometimes)
/// </summary>
/// <param name="input"></param>
/// <param name="mask"></param>
/// <returns>input - 1</returns>
// I want someone to double-check this before it goes into full prod
public static ushort Subtract(ushort input, int mask = 1)
{
int temp = input;
while (!((temp & mask) > 0))
{
temp ^= mask;
mask <<= 1;
}
temp ^= mask;
return (ushort)temp;
}
// ReSharper disable once InconsistentNaming
public static bool PDWarning(EP player)
{
return (from actEffects in player.ActiveEffects
let Larry = EP.List.First(L => L.Role == RoleTypeId.Scp106).Position
select actEffects.name == "Corroding" && Plugin.Instance != null &&
Vector3.Distance(player.Position, Larry) < Plugin.Instance.Config.LarryDistance).FirstOrDefault();
}
public static void Exploding(EP player)
{
var grenade = (ExplosiveGrenade)Item.Create(ItemType.GrenadeHE);
grenade.FuseTime = 0.1f;
grenade.SpawnActive(player.Position + new Vector3(0, 1, 0), player);
}
public static bool HasEffect(EP player, EffectType effect)
{
return !Enum.IsDefined(typeof(EffectType), effect) ? throw new InvalidEnumArgumentException(nameof(effect), (int)effect, typeof(EffectType)) : player.ActiveEffects.Any(targetActiveEffect => targetActiveEffect.name == nameof(effect));
}
}
}