-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPI.cs
183 lines (129 loc) · 4.27 KB
/
API.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System.Collections.Generic;
using ModLibsCore.Libraries.Debug;
using Terraria;
using Terraria.ModLoader;
using TimeLimit.Logic;
using TimeLimit.NetProtocol;
namespace TimeLimit {
public delegate void CustomTimerAction();
public static partial class TimeLimitAPI {
public static void RunTimesUpAction( string actionName ) {
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
myworld.Logic.RunAction( actionName, false );
}
////////////////
public static void TimerStart( string actionName, int seconds, bool repeats ) {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName + " for "+seconds+", repeating? "+repeats );
}
ActionTimer timer = myworld.Logic.StartTimer( seconds * 60, seconds * 60, actionName, repeats, true );
if( Main.netMode == 2 ) {
SendPackets.SendStartTimerCommand( timer, myworld.Logic.Timers.Count, -1 );
}
}
public static void TimerStop( string actionName ) {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
myworld.Logic.StopTimers( actionName );
if( Main.netMode == 2 ) {
SendPackets.SendStopTimersCommand( actionName, -1 );
}
}
public static void TimerPause( string actionName ) {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
myworld.Logic.PauseTimers( actionName );
if( Main.netMode == 2 ) {
SendPackets.SendPauseTimersCommand( actionName, -1 );
}
}
public static void TimerResume( string actionName ) {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
myworld.Logic.ResumeTimers( actionName );
if( Main.netMode == 2 ) {
SendPackets.SendResumeTimersCommand( actionName, - 1 );
}
}
////////////////
public static void TimerAllStop() {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn(string.Empty);
}
myworld.Logic.StopAllTimers();
if( Main.netMode == 2 ) {
SendPackets.SendStopAllTimersCommand( -1 );
}
}
public static void TimerAllPause() {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( string.Empty );
}
myworld.Logic.PauseAllTimers();
if( Main.netMode == 2 ) {
SendPackets.SendPauseAllTimersCommand( -1 );
}
}
public static void TimerAllResume() {
if( Main.netMode == 1 ) { return; }
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( string.Empty );
}
myworld.Logic.ResumeAllTimers();
if( Main.netMode == 2 ) {
SendPackets.SendResumeAllTimersCommand( -1 );
}
}
////////////////
public static IList<ActionTimer> GetTimersOf( string actionName ) {
var mymod = TimeLimitMod.Instance;
var myworld = ModContent.GetInstance<TimeLimitSystem>();
IList<ActionTimer> timers = new List<ActionTimer>();
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
foreach( var timer in myworld.Logic.Timers ) {
if( timer.Action.Equals(timer) ) {
timers.Add( timer );
}
}
return timers;
}
////////////////
public static void AddCustomAction( string actionName, CustomTimerAction hook ) {
var mymod = TimeLimitMod.Instance;
var logic = mymod.Logic;
if( mymod.Config.DebugModeInfo ) {
LogLibraries.Warn( actionName );
}
logic.CustomActions[ actionName ] = hook;
}
}
}