-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeVariantObject.cpp
More file actions
161 lines (146 loc) · 2.72 KB
/
Copy pathTimeVariantObject.cpp
File metadata and controls
161 lines (146 loc) · 2.72 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
#include "TimeVariantObject.h"
#include <Windows.h>
namespace AwpSoftGameModule
{
long long TVOSafeModInt64(long long a, long long b)
{
if (b == 0) return 0;
return a % b;
}
long long TVOSafeDivInt64(long long a, long long b)
{
if (b == 0)
{
if (a > 0) return MAXINT64;
if (a == 0) return 1;
if (a < 0) return MININT64;
}
return a / b;
}
TimeVariantObject::TimeVariantObject()
{
DisableTimeVariant = false;
TimeRemain = 0;
}
void TimeVariantObject::reset()
{
DisableTimeVariant = false;
TimeRemain = 0;
}
TimeVariantObject::~TimeVariantObject()
{
}
void TimeVariantObject::clearTimeRemain()
{
TimeRemain = 0;
}
bool TimeVariantObject::giveTime(int timeGived)
{
if (DisableTimeVariant) return false;
if (timeGived < 0) return false;
TimeRemain += timeGived;
return true;
}
bool TimerTrigger::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;
}
TimerTrigger::TimerTrigger(int timerCycle)
{
if (timerCycle < 0) timerCycle = 0;
Cycle = timerCycle;
Ready = false;
}
void TimerTrigger::clearStates()
{
TimeRemain = 0;
Ready = 0;
}
bool TimerTrigger::tryTriggerOnce()
{
if (Ready)
{
Ready = false;
return true;
}
return false;
}
void TimerTrigger::reset()
{
clearStates();
}
TimerClip::TimerClip(int maximumCharge, int timerCycle)
{
if (timerCycle < 0) timerCycle = 0;
if (maximumCharge < 0) maximumCharge = 0;
Cycle = timerCycle;
MaxCharge = maximumCharge;
Charged = 0;
}
void TimerClip::clearStates()
{
TimeRemain = 0;
Charged = 0;
}
bool TimerClip::tryConsume(int count)
{
if (count <= 0) return true;
if (Charged >= count)
{
Charged -= count;
return true;
}
return false;
}
int TimerClip::tryConsumePart(int count)
{
if (count <= 0) return 1;
int TempCharged = Charged;
count = min(TempCharged, count);
Charged -= count;
return count;
}
void TimerClip::reset()
{
clearStates();
}
bool TimerClip::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) return false;
if (Charged + ChargeInc >= MaxCharge || Charged + ChargeInc < 0)
{
Charged = MaxCharge;
TimeRemain = 0;
return true;
}
Charged += ChargeInc;
TimeRemain = TVOSafeModInt64(TimeRemain, Cycle);
return true;
}
};