-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathCastleSiegeSync.cpp
More file actions
281 lines (199 loc) · 5.49 KB
/
CastleSiegeSync.cpp
File metadata and controls
281 lines (199 loc) · 5.49 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include "stdafx.h"
#include "CastleSiegeSync.h"
#include "TUnion.h"
#include "protocol.h"
#include "DSProtocol.h"
#include "MapServerManager.h"
#include "logproc.h"
// GS-N 0.99.60T 0x0051B7C0 - Completed
// GS-N 1.00.18 JPN 0x0054D150 - Completed
CCastleSiegeSync::CCastleSiegeSync()
{
this->Clear();
}
CCastleSiegeSync::~CCastleSiegeSync()
{
return;
}
void CCastleSiegeSync::Clear()
{
this->m_iCurCastleState = -1;
this->m_iCurTaxRateChaos = 0;
this->m_iCurTaxRateStore = 0;
this->m_lCastleTributeMoney = 0;
this->m_iCsTributeMoneyTimer = 0;
memset(this->m_szCastleOwnerGuild, 0, sizeof(this->m_szCastleOwnerGuild));
}
void CCastleSiegeSync::SetCastleOwnerGuild(char * lpszGuildName)
{
if ( lpszGuildName == NULL )
{
DebugLog("%s NULL",__FUNCTION__);
return;
}
memset(this->m_szCastleOwnerGuild, 0, sizeof(this->m_szCastleOwnerGuild));
memcpy(this->m_szCastleOwnerGuild, lpszGuildName, sizeof(this->m_szCastleOwnerGuild)/2);
DebugLog("%s Setting to %s vs %s",__FUNCTION__,lpszGuildName,this->m_szCastleOwnerGuild);
}
int CCastleSiegeSync::GetTaxRateChaos(int iIndex)
{
//DebugLog("%s START",__FUNCTION__);
int iCurTaxRateChaos = this->m_iCurTaxRateChaos;
if ( this->CheckCastleOwnerMember(iIndex) == TRUE || this->CheckCastleOwnerUnionMember(iIndex) == TRUE )
{
iCurTaxRateChaos = 0;
}
//DebugLog("%s END",__FUNCTION__);
return iCurTaxRateChaos;
}
int CCastleSiegeSync::GetTaxRateStore(int iIndex)
{
//DebugLog("%s START",__FUNCTION__);
int iCurTaxRateStore = this->m_iCurTaxRateStore;
if ( this->CheckCastleOwnerMember(iIndex) == TRUE || this->CheckCastleOwnerUnionMember(iIndex) == TRUE )
{
iCurTaxRateStore = 0;
}
//DebugLog("%s END",__FUNCTION__);
return iCurTaxRateStore;
}
int CCastleSiegeSync::GetTaxHuntZone(int iIndex, BOOL bCheckOwnerGuild)
{
//DebugLog("%s START",__FUNCTION__);
int iCurTaxHuntZone = this->m_iCurTaxHuntZone;
if ( bCheckOwnerGuild == TRUE )
{
if ( this->CheckCastleOwnerMember(iIndex) == TRUE || this->CheckCastleOwnerUnionMember(iIndex) == TRUE )
{
iCurTaxHuntZone = 0;
}
}
//DebugLog("%s END",__FUNCTION__);
return iCurTaxHuntZone;
}
void CCastleSiegeSync::AddTributeMoney(int iMoney)
{
if ( iMoney <= 0 )
{
//DebugLog("%s END",__FUNCTION__);
return;
}
if ( (this->m_lCastleTributeMoney + iMoney) > MAX_TRIBUTE_MONEY )
{
//DebugLog("%s END",__FUNCTION__);
return;
}
//DebugLog("%s START",__FUNCTION__);
if ( this->m_lCastleTributeMoney < 0 )
{
InterlockedExchange((LPLONG)&this->m_lCastleTributeMoney, 0);
}
InterlockedExchangeAdd((LPLONG)&this->m_lCastleTributeMoney, iMoney);
//DebugLog("%s END",__FUNCTION__);
}
void CCastleSiegeSync::ResetTributeMoney()
{
//DebugLog("%s START",__FUNCTION__);
InterlockedExchange((LPLONG)&this->m_lCastleTributeMoney, 0);
//DebugLog("%s END",__FUNCTION__);
}
void CCastleSiegeSync::AdjustTributeMoney()
{
//DebugLog("%s START",__FUNCTION__);
if ( this->m_lCastleTributeMoney < 0 )
{
InterlockedExchange((LPLONG)&this->m_lCastleTributeMoney, 0);
}
if ( this->m_lCastleTributeMoney > MAX_TRIBUTE_MONEY )
{
InterlockedExchange((LPLONG)&this->m_lCastleTributeMoney, MAX_TRIBUTE_MONEY);
}
if ( this->m_lCastleTributeMoney <= 0 )
{
//DebugLog("%s END",__FUNCTION__);
return;
}
if ( GetTickCount() - this->m_iCsTributeMoneyTimer > 180000 )
{
this->m_iCsTributeMoneyTimer = GetTickCount();
LogAddTD("[CastleSiegeSync] AdjustTributeMoney() SRV: %d SEND MONEY:%d",
g_MapServerManager.GetMapSvrGroup(), this->m_lCastleTributeMoney);
GS_GDReqCastleTributeMoney(g_MapServerManager.GetMapSvrGroup(), this->m_lCastleTributeMoney);
InterlockedExchange((LPLONG)&this->m_lCastleTributeMoney, 0);
}
//DebugLog("%s END",__FUNCTION__);
}
BOOL CCastleSiegeSync::CheckCastleOwnerMember(int iIndex)
{
if ( gObjIsConnected(iIndex) == FALSE )
{
//DebugLog("%s Not Connected",__FUNCTION__);
return FALSE;
}
if ( strcmp(this->m_szCastleOwnerGuild, "") == 0 )
{
//DebugLog("%s Empty Guild Name",__FUNCTION__);
return FALSE;
}
if ( strcmp(gObj[iIndex].GuildName, this->m_szCastleOwnerGuild) != 0 )
{
//DebugLog("%s Guild Name [%s] vs [%s]",__FUNCTION__,gObj[iIndex].GuildName,this->m_szCastleOwnerGuild);
return FALSE;
}
//DebugLog("%s OK",__FUNCTION__);
return TRUE;
}
BOOL CCastleSiegeSync::CheckCastleOwnerUnionMember(int iIndex)
{
//DebugLog("%s START",__FUNCTION__);
if ( gObjIsConnected(iIndex) == FALSE )
{
return FALSE;
}
if ( strcmp(this->m_szCastleOwnerGuild, "") == 0 )
{
//DebugLog("%s END",__FUNCTION__);
return FALSE;
}
_GUILD_INFO_STRUCT * lpGuildInfo = gObj[iIndex].lpGuild;
if ( lpGuildInfo == NULL )
{
//DebugLog("%s END",__FUNCTION__);
return FALSE;
}
TUnionInfo * pUnionInfo = UnionManager.SearchUnion(lpGuildInfo->iGuildUnion);
if ( pUnionInfo == NULL )
{
//DebugLog("%s END",__FUNCTION__);
return FALSE;
}
if ( strcmp( pUnionInfo->m_szMasterGuild, this->m_szCastleOwnerGuild) == 0 )
{
//DebugLog("%s END",__FUNCTION__);
return TRUE;
}
return FALSE;
//DebugLog("%s END",__FUNCTION__);
}
int CCastleSiegeSync::CheckOverlapCsMarks(int iIndex)
{
for ( int x=INVENTORY_BAG_START;x<ReadConfig.MAIN_INVENTORY_SIZE(iIndex,false);x++)
{
if ( gObj[iIndex].pInventory[x].IsItem() == TRUE )
{
if ( gObj[iIndex].pInventory[x].m_Type == ITEMGET(14,21) )
{
if ( gObj[iIndex].pInventory[x].m_Level == 3 )
{
int op = gObj[iIndex].pInventory[x].m_Durability;
if ( ITEM_DUR_RANGE(op) != FALSE)
{
return x;
}
}
}
}
}
return -1;
}
CCastleSiegeSync g_CastleSiegeSync;