-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdatableAndDeletable.cs
More file actions
100 lines (89 loc) · 3.64 KB
/
Copy pathUpdatableAndDeletable.cs
File metadata and controls
100 lines (89 loc) · 3.64 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using MoreSlugcats;
namespace TimeStopDependency
{
public partial class TimeStopDependency
{
}
internal static class UpdatableAndDeletableCWT
{
static ConditionalWeakTable<UpdatableAndDeletable, Data> table = new ConditionalWeakTable<UpdatableAndDeletable, Data>();
public static Data GetCustomData(this UpdatableAndDeletable self)
{
// Пытаемся получить существующие данные
if (table.TryGetValue(self, out Data data))
return data;
// Создаем новые данные с передачей self в конструктор
data = new Data(self);
table.Add(self, data);
return data;
}
public class Data
{
public UpdatableAndDeletable Target { get; }
internal bool isImmuneToTimeStop;
internal bool checkedTimeStopImmunity = false;
public Data(UpdatableAndDeletable target)
{
Target = target;
}
}
}
public static class UpdatableAndDeletableExtensions
{
/// <summary>
/// Switches Time Stop Immunity State for selected UpdatableAndDeletable object.
/// Grants immunity if object doesn't have it, and revokes immunity if object already has it.
/// </summary>
public static void SwitchTimeStopImmunityState(this UpdatableAndDeletable uAD)
{
uAD.GetCustomData().isImmuneToTimeStop = !uAD.GetCustomData().isImmuneToTimeStop;
}
/// <summary>
/// Makes selected UpdatableAndDeletable object immune to Time Stop
/// </summary>
public static void GrantTimeStopImmunity(this UpdatableAndDeletable uAD)
{
uAD.GetCustomData().isImmuneToTimeStop = true;
}
/// <summary>
/// Makes selected UpdatableAndDeletable object vulnerable to Time Stop
/// </summary>
public static void RevokeTimeStopImmunity(this UpdatableAndDeletable uAD)
{
uAD.GetCustomData().isImmuneToTimeStop = false;
}
/// <summary>
/// Returns whenever or not selected UpdatableAndDeletable object has immunity to Time Stop
/// </summary>
public static bool IsTimeStopImmune(this UpdatableAndDeletable uAD)
{
return uAD.GetCustomData().isImmuneToTimeStop;
}
/// <summary>
/// Returns whenever or not entity is allowed to update during Time Stop.
/// </summary>
public static bool IsEligableForUpdate(this UpdatableAndDeletable uAD)
{
if (uAD.GetCustomData().isImmuneToTimeStop || uAD is IAmImmuneToTimeStop) return true;
if (uAD is Player && TimeStopDependency.TimeStopImmuneTypes.Contains(typeof(Player)) && (uAD as Player).isNPC && !(uAD as Player).abstractCreature.world.game.CanSlugNPCUpdate()) return false;
if (TimeStopDependency.TimeStopImmuneTypes.Contains(uAD.GetType())) return true;
return false;
}
/// <summary>
/// Returns whenever or not type of selected UpdatableAndDeletable object contains in TimeStopImmuneTypes list
/// </summary>
public static bool IsThisTypeImmune(this UpdatableAndDeletable uAD)
{
Type type = uAD.GetType();
if (type == null) return false;
return TimeStopDependency.TimeStopImmuneTypes.Contains(type);
}
}
}