-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeconOnDemand.cs
157 lines (142 loc) · 4.4 KB
/
DeconOnDemand.cs
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using Smod2;
using Smod2.Attributes;
using Smod2.EventHandlers;
using Smod2.Events;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace ArithFeather.DeconOnDemand
{
[PluginDetails(
author = "Arith",
name = "Decon On Demand",
description = "",
id = "ArithFeather.DeconOnDemand",
configPrefix = "afdod",
version = "1.1",
SmodMajor = 3,
SmodMinor = 4,
SmodRevision = 0
)]
public class DeconOnDemand : Plugin, IEventHandlerCallCommand, IEventHandlerWaitingForPlayers
{
private const string InfoMessage = "'.decon disable' - Disables decontamination)\n" +
"'.decon #' Starts decontamination with minute value\n" +
"Announcements in:\n" +
"15 Minutes.\n" +
"10 Minutes.\n" +
"5 Minutes.\n" +
"1 Minute.\n" +
"0.5 Minutes. (30 seconds)\n";
public override void OnDisable() => Info("DeconOnDemand disabled.");
public override void OnEnable() => Info("DeconOnDemand enabled.");
public override void Register()
{
instance = this;
AddEventHandlers(this);
}
private static DeconOnDemand instance;
private DecontaminationLCZ decontamination;
public static void StartDecontamination(float timeInMinutes) => instance.InitializeDecontamination(timeInMinutes);
public static void StartDecontamination(int announcement) => instance.InitializeDecontamination(announcement);
public static void DisableDecontamination() => instance.disableDeconInfo.SetValue(instance.decontamination, true);
private readonly FieldInfo curAnmInfo = typeof(DecontaminationLCZ).GetField("curAnm", BindingFlags.NonPublic | BindingFlags.Instance);
private readonly FieldInfo disableDeconInfo = typeof(DecontaminationLCZ).GetField("smDisableDecontamination", BindingFlags.NonPublic | BindingFlags.Instance);
public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
{
decontamination = GameObject.Find("Host").GetComponent<DecontaminationLCZ>() as DecontaminationLCZ;
}
private void InitializeDecontamination(float minutes)
{
if (minutes >= 0f)
{
switch (minutes)
{
case 15f:
decontamination.time = 41f;
break;
case 10f:
decontamination.time = 239f;
break;
case 5f:
decontamination.time = 437f;
break;
case 1f:
decontamination.time = 635f;
break;
case 0.5f:
decontamination.time = 665f;
break;
case 0f:
decontamination.time = 703.4f;
break;
default:
decontamination.time = (11.74f - minutes) * 60;
break;
}
disableDeconInfo.SetValue(decontamination, false);
for (int i = 0; i < decontamination.announcements.Count; i++)
{
var annStartTime = decontamination.announcements[i].startTime;
if (decontamination.time / 60f < annStartTime)
{
curAnmInfo.SetValue(decontamination, i);
return;
}
}
}
}
/// <summary>
/// 0 - 15 Minutes - 0.7
/// 1 - 10 Minutes - 4
/// 2 - 5 Minutes - 7.3
/// 3 - 1 Minute - 10.6
/// 4 - 30 Seconds - 11.1
/// 5 - Decontaminate - 11.74
/// </summary>
private void InitializeDecontamination(int announcement)
{
var anns = decontamination.announcements;
if (announcement >= 0 && announcement <= 5)
{
disableDeconInfo.SetValue(decontamination, false);
curAnmInfo.SetValue(decontamination, announcement);
decontamination.time = anns[announcement].startTime * 60f;
}
}
public void OnCallCommand(PlayerCallCommandEvent ev)
{
var rank = ev.Player.GetRankName().ToUpper();
if (rank == "OWNER" || rank == "MOD" || rank == "ADMIN")
{
string[] inputs = ev.Command.Split(' ');
if (inputs.Count() > 1 && inputs[0].ToUpper() == "DECON")
{
var input = inputs[1].ToUpper();
if (input == "HELP")
{
ev.ReturnMessage = InfoMessage;
}
else if (input == "DISABLE")
{
disableDeconInfo.SetValue(decontamination, true);
ev.ReturnMessage = "Decontamination Disabled. Note you can not disable decontamination after decontaminate starts.";
}
else if (float.TryParse(inputs[1], out float minutes) && minutes >= 0)
{
InitializeDecontamination((float)minutes);
ev.ReturnMessage = $"Initializing Decontamination.";
}
else
{
ev.ReturnMessage = $"Wrong Input..\n{InfoMessage}";
}
}
else if (inputs.Count() == 1 && inputs[0].ToUpper() == "DECON")
{
ev.ReturnMessage = $"Wrong Input..\n{InfoMessage}";
}
}
}
}
}