-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeVariantObject.java
More file actions
188 lines (182 loc) · 4.59 KB
/
TimeVariantObject.java
File metadata and controls
188 lines (182 loc) · 4.59 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
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
184
185
186
187
188
package awpsoft.gamemodule;
public class TimeVariantObject
{
public long TimeRemain;
public boolean DisableTimeVariant;
public TimeVariantObject()
{
DisableTimeVariant = false;
TimeRemain = 0;
}
public void clearTimeRemain()
{
TimeRemain = 0;
}
public void reset()
{
DisableTimeVariant = false;
TimeRemain = 0;
}
public boolean giveTime(int timeGived)
{
if (DisableTimeVariant) return false;
if (timeGived < 0) return false;
TimeRemain += timeGived;
return true;
}
public static class TimerTrigger extends TimeVariantObject
{
public boolean Ready;
public int Cycle;
public TimerTrigger()
{
Cycle = 1;
Ready = false;
}
public TimerTrigger(int timerCycle)
{
if (timerCycle < 0) timerCycle = 0;
Cycle = timerCycle;
Ready = false;
}
public void clearStates()
{
TimeRemain = 0;
Ready = false;
}
public boolean tryTriggerOnce()
{
if (Ready)
{
Ready = false;
return true;
}
return false;
}
@Override public void reset() {clearStates();}
@Override public boolean giveTime(int timeGived)
{
if (super.giveTime(timeGived)) return false;
if (Cycle == 0)
{
TimeRemain = 0;
Ready = true;
return true;
}
if (TimeRemain >= Cycle)
{
TimeRemain = TVOSafeModInt64(TimeRemain, Cycle);
Ready = true;
return true;
}
return true;
}
};
public static class TimerClip extends TimeVariantObject
{
public int Charged;
public int MaxCharge;
public int Cycle;
public TimerClip()
{
Cycle = 1;
MaxCharge = 1;
Charged = 0;
}
public TimerClip(int maximumCharge)
{
if (maximumCharge < 0) maximumCharge = 0;
MaxCharge = maximumCharge;
Cycle = 1;
Charged = 0;
}
public TimerClip(int maximumCharge, int timerCycle)
{
if (timerCycle < 0) timerCycle = 0;
if (maximumCharge < 0) maximumCharge = 0;
Cycle = timerCycle;
MaxCharge = maximumCharge;
Charged = 0;
}
public void clearStates()
{
TimeRemain = 0;
Charged = 0;
}
public boolean tryConsume(int count)
{
if (count <= 0) return true;
if (Charged >= count)
{
Charged -= count;
return true;
}
return false;
}
public boolean tryConsume()
{
if (Charged >= 1)
{
Charged -= 1;
return true;
}
return false;
}
public int tryConsumePart(int count)
{
if (count <= 0) return 1;
int TempCharged = Charged;
count = Math.min(TempCharged, count);
Charged -= count;
return count;
}
public int tryConsumePart()
{
int TempCharged = Charged;
Charged -= Math.min(TempCharged, 1);
return 1;
}
@Override public void reset() {clearStates();}
@Override public boolean giveTime(int timeGived)
{
if (Charged >= MaxCharge)
{
TimeRemain = 0;
return false;
}
if (!super.giveTime(timeGived)) return false;
if (Cycle == 0 && Charged < MaxCharge)
{
Charged = MaxCharge;
TimeRemain = 0;
return true;
}
int ChargeInc = (int)TVOSafeDivInt64(TimeRemain, Cycle);
if (ChargeInc == 0) return false;
if (Charged + ChargeInc >= MaxCharge || Charged + ChargeInc < 0)
{
Charged = MaxCharge;
TimeRemain = 0;
return true;
}
Charged += ChargeInc;
TimeRemain = TVOSafeModInt64(TimeRemain, Cycle);
return true;
}
};
private static long TVOSafeModInt64(long a, long b)
{
if (b == 0L) return 0L;
return a % b;
}
private static long TVOSafeDivInt64(long a, long b)
{
if (b == 0L)
{
if (a > 0L) return Long.MAX_VALUE;
if (a == 0L) return 1;
if (a < 0L) return Long.MIN_VALUE;
}
return a / b;
}
}