-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerManager.GameRoom.cs
724 lines (656 loc) · 38.5 KB
/
ServerManager.GameRoom.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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Newtonsoft.Json.Linq;
namespace MSB_SERVER
{
public partial class ServerManager
{
public class GameRoom
{
public enum GAME_TYPE
{
TYPE_SOLO, TYPE_TEAM
}
public enum GAME_STATE
{
STATE_READY, STATE_INGAME, STATE_END, STATE_CLEAR
}
public int gameNumber;
public int gameDatabaseIndex = 0;
public readonly GAME_TYPE gameType;
public GAME_STATE gameState;
public List<NetworkData.ClientData> clientList;
public List<NetworkData.ClientData> clientBlueList;
public List<NetworkData.ClientData> clientRedList;
Thread gameThread;
Thread readyCheckThread;
public static int gameTime = 60;
public static int gameHealPackValue = 30;
public static int gameHealPackSpawn = 5;
public static int gameUserSpawn = 5;
public static int gameObjectHealth = 10;
public static int gamePointValue = 1;
public static int gamePointSpawn = 15;
public static int gameMatchValue = 40;
public int gameBlueKill;
public int gameBlueDeath;
public int gameBluePoint;
public int gameBlueTotal;
public int gameRedKill;
public int gameRedDeath;
public int gameRedPoint;
public int gameRedTotal;
int[] gameObjects = { gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth, gameObjectHealth };
int[] gameHealPacks = { 1, 1, 1 };
int[] gamePointPacks = { 1, 1, 1 };
public GameRoom(int number, GAME_TYPE type, GAME_STATE state)
{
gameNumber = number;
gameType = type;
gameState = state;
clientList = new List<NetworkData.ClientData>();
clientBlueList = new List<NetworkData.ClientData>();
clientRedList = new List<NetworkData.ClientData>();
}
public void OnGameUserReady(NetworkData.ClientData userClient)
{
userClient.currentReady = true;
bool isEveryPlayerReady = true;
if (readyCheckThread == null)
{
readyCheckThread = new Thread(DoReadyCheck);
readyCheckThread.Start();
}
try
{
JArray readyData = new JArray();
foreach (NetworkData.ClientData clientData in clientList)
{
JObject clientReadyData = new JObject
{
{ clientData.clientUser.userNumber.ToString(), clientData.currentReady }
};
readyData.Add(clientReadyData);
if (!clientData.currentReady)
{
isEveryPlayerReady = false;
}
}
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameStatusReady(clientData.clientHID, readyData.ToString());
}
} catch (Exception e)
{
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", "G]OnGameUserReady ERROR");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", e.ToString());
}
if (isEveryPlayerReady && gameThread == null)
{
foreach (NetworkData.ClientData clientData in clientList)
{
clientData.currentReady = true;
clientData.character = -1;
clientData.gameRespawn = 0;
clientData.gameHealth = 100;
clientData.gameKill = 0;
clientData.gameDeath = 0;
clientData.gameAssist = 0;
clientData.gameBonus = 0;
clientData.enduredDamage = 0;
clientData.lastKillTime = 0;
clientData.assistClient = null;
clientData.totalGivenDamage = 0;
clientData.totalTakenDamage = 0;
clientData.gameWin = false;
clientData.gameLose = false;
clientData.killHistory?.Clear();
clientData.killStreakHistory?.Clear();
clientData.assistHistory?.Clear();
clientData.medalHistory?.Clear();
}
gameDatabaseIndex = DatabaseManager.GetInstance().saveGameStart(this);
gameThread = new Thread(DoGameStart);
gameThread.Start();
}
}
public void OnGameUserDamage(NetworkData.ClientData userClient, int dataTarget, int dataAmount, string dataOption)
{
try
{
if (gameState != GAME_STATE.STATE_INGAME) return;
long currentTimeStamp = (long) (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
NetworkData.ClientData targetClient = null;
foreach (NetworkData.ClientData clientData in clientList)
{
if (clientData.clientUser.userNumber == dataTarget)
{
targetClient = clientData;
break;
}
}
if (targetClient == null || targetClient.gameRespawn > 0) return;
if (targetClient.gameHealth < dataAmount)
{
dataAmount = targetClient.gameHealth;
}
targetClient.gameHealth -= dataAmount;
targetClient.enduredDamage += dataAmount;
userClient.totalGivenDamage += dataAmount;
targetClient.totalTakenDamage += dataAmount;
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventDamage(clientData.clientHID, userClient.clientUser.userNumber, targetClient.clientUser.userNumber, dataAmount, dataOption);
NetworkGate.OnGameEventHealth(clientData.clientHID, targetClient.clientUser.userNumber, targetClient.gameHealth);
}
if (targetClient.gameHealth <= 0)
{
if (userClient != targetClient)
{
userClient.gameKill++;
userClient.killHistory.Add(targetClient);
userClient.killStreakHistory.Add(targetClient);
userClient.gameBonus++;
}
targetClient.gameDeath++;
targetClient.lastKillTime = 0;
targetClient.enduredDamage = 0;
targetClient.killStreakHistory = new List<NetworkData.ClientData>();
targetClient.assistClient = null;
targetClient.gameBonus--;
targetClient.gameRespawn = gameUserSpawn;
gameBlueKill = 0;
gameBlueDeath = 0;
gameRedKill = 0;
gameRedDeath = 0;
foreach (NetworkData.ClientData clientData in clientBlueList)
{
gameBlueKill += clientData.gameKill;
gameBlueDeath += clientData.gameDeath;
}
foreach (NetworkData.ClientData clientData in clientRedList)
{
gameRedKill += clientData.gameKill;
gameRedDeath += clientData.gameDeath;
}
gameBlueTotal = gameBlueKill + gameBluePoint;
gameRedTotal = gameRedKill + gameRedPoint;
// User Client Killed Target Client Count
int UCKTC = userClient.killHistory.Count(client => client!=null && client == targetClient);
// Target Client Killed User Client Count
int TCKUC = targetClient.killHistory.Count(client => client!=null && client == userClient);
JObject killObject = new JObject();
killObject.Add("killMaker", userClient.clientUser.userNumber);
killObject.Add("killTarget", targetClient.clientUser.userNumber);
killObject.Add("killCount", UCKTC);
killObject.Add("deathCount", TCKUC);
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventKill(clientData.clientHID, userClient.clientUser.userNumber, targetClient.clientUser.userNumber, dataOption);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 0, userClient.clientUser.userNick + "KILLED " + targetClient.clientUser.userNick);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 1, killObject.ToString());
}
// CHECK MEDAL - FIRST KILL
int gameTotalKill = 0;
if (userClient != targetClient)
{
foreach (NetworkData.ClientData clientData in clientList)
{
gameTotalKill += clientData.gameKill;
}
if (gameTotalKill == 0)
{
// ACHIEVE userClient FIRST KILL MEDAL
userClient.gameBonus++;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, userClient.clientUser.userNumber, 1);
userClient.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(userClient.clientHID, 2, "1");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] FIRST KILL : " + userClient.clientUser.userID);
}
}
// CHECK MEDAL - TIT FOR TAT
if (userClient != targetClient && targetClient.gameKill > 0)
{
if (targetClient.killStreakHistory != null && targetClient.killStreakHistory.Count > 0 &&
targetClient.killStreakHistory.Contains(userClient))
{
// ACHIEVE userClient TIT FOR TAT
userClient.gameBonus++;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, userClient.clientUser.userNumber, 3);
userClient.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(userClient.clientHID, 2, "3");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] TIT FOR TAT : " + userClient.clientUser.userID);
}
}
// CHECK MEDAL - KILL STREAK
if (userClient != targetClient && userClient.killStreakHistory != null && userClient.killStreakHistory.Count > 0)
{
if (userClient.lastKillTime + 5 > currentTimeStamp)
{
// ACHIEVE userClient KILL STREAK
userClient.gameBonus++;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, userClient.clientUser.userNumber, 2);
userClient.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(userClient.clientHID, 2, "2");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] KILL STREAK : " + userClient.clientUser.userID);
}
}
if (userClient != targetClient)
{
userClient.lastKillTime = currentTimeStamp;
}
// CHECK MEDAL - ASSIST
if (userClient != targetClient && targetClient.assistClient != null && targetClient.assistClient != userClient)
{
foreach (NetworkData.ClientData clientData in clientList)
{
if (clientData.Equals(targetClient.assistClient))
{
// ACHIEVE clientData ASSIST
userClient.gameBonus++;
clientData.gameAssist++;
clientData.assistHistory.Add(targetClient);
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 6);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "6");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ASSIST : " + clientData.clientUser.userID);
}
}
}
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameStatusScore(clientData.clientHID, gameBlueKill, gameBlueDeath, gameBlueTotal, gameRedKill, gameRedDeath, gameRedTotal);
}
}
else
{
if (targetClient.gameHealth <= 50)
{
targetClient.assistClient = userClient;
}
// CHECK MEDAL - ADAMANT
if (targetClient.enduredDamage >= 200)
{
// ACHIEVE targetClient ADAMANT
targetClient.gameBonus++;
targetClient.enduredDamage -= 200;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, targetClient.clientUser.userNumber, 4);
targetClient.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(targetClient.clientHID, 2, "4");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ADAMANT : " + targetClient.clientUser.userID);
}
}
} catch (Exception e)
{
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", "G]OnGameUserDamage ERROR");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", e.ToString());
}
}
public void OnGameUserObject(NetworkData.ClientData userClient, int dataTarget, int dataAmount)
{
try
{
if (gameState != GAME_STATE.STATE_INGAME) return;
if (dataTarget >= gameObjects.Length) return;
if (gameObjects[dataTarget] < dataAmount)
{
dataAmount = gameObjects[dataTarget];
}
gameObjects[dataTarget] -= dataAmount;
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventObject(clientData.clientHID, dataTarget, gameObjects[dataTarget]);
}
} catch (Exception e)
{
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", "G]OnGameUserObject ERROR");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", e.ToString());
}
}
public void OnGameUserItem(NetworkData.ClientData userClient, int type, int dataTarget)
{
try
{
if (gameState != GAME_STATE.STATE_INGAME) return;
if (type == 0) // SCORE POINT ITEM
{
if (dataTarget >= gamePointPacks.Length) return;
if (gamePointPacks[dataTarget] > 0) return;
userClient.gameBonus++;
foreach (NetworkData.ClientData clientData in clientBlueList)
{
if (userClient.clientUser.userNumber == clientData.clientUser.userNumber)
{
gameBluePoint += gamePointValue;
break;
}
}
foreach (NetworkData.ClientData clientData in clientRedList)
{
if (userClient.clientUser.userNumber == clientData.clientUser.userNumber)
{
gameRedPoint += gamePointValue;
break;
}
}
gameBlueTotal = gameBlueKill + gameBluePoint;
gameRedTotal = gameRedKill + gameRedPoint;
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventItem(clientData.clientHID, type, dataTarget, userClient.clientUser.userNumber);
NetworkGate.OnGameStatusScore(clientData.clientHID, gameBlueKill, gameBlueDeath, gameBlueTotal, gameRedKill, gameRedDeath, gameRedTotal);
}
gamePointPacks[dataTarget] = gamePointSpawn;
}
if (type == 1) // HEALPACK ITEM
{
if (dataTarget >= gameHealPacks.Length) return;
if (gameHealPacks[dataTarget] > 0) return;
userClient.gameHealth += gameHealPackValue;
if (userClient.gameHealth > 100) userClient.gameHealth = 100;
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventItem(clientData.clientHID, type, dataTarget, userClient.clientUser.userNumber);
NetworkGate.OnGameEventHealth(clientData.clientHID, userClient.clientUser.userNumber, userClient.gameHealth);
}
gameHealPacks[dataTarget] = gameHealPackSpawn;
}
} catch (Exception e)
{
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", "G]OnGameUserItem ERROR");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_CRITICAL, LogManager.LOG_TARGET.LOG_NETWORK, "ServerManager", e.ToString());
}
}
private void DoReadyCheck()
{
Thread.Sleep(1000);
if (gameState != GAME_STATE.STATE_READY) return;
if (GetInstance().MODULE_ROOM_STOP_FLAG) return;
Thread.Sleep(1000);
if (gameState != GAME_STATE.STATE_READY) return;
if (GetInstance().MODULE_ROOM_STOP_FLAG) return;
Thread.Sleep(1000);
if (gameState != GAME_STATE.STATE_READY) return;
if (GetInstance().MODULE_ROOM_STOP_FLAG) return;
Thread.Sleep(1000);
if (gameState != GAME_STATE.STATE_READY) return;
if (GetInstance().MODULE_ROOM_STOP_FLAG) return;
Thread.Sleep(1000);
if (gameState != GAME_STATE.STATE_READY) return;
if (GetInstance().MODULE_ROOM_STOP_FLAG) return;
gameThread = new Thread(DoGameStart);
gameThread.Start();
}
private void DoGameStart()
{
gameState = GAME_STATE.STATE_INGAME;
foreach (NetworkData.ClientData clientData in clientList)
{
clientData.gameDeath = 0;
clientData.gameKill = 0;
clientData.gameRespawn = 0;
clientData.gameHealth = 100;
}
for (int countDown = 3; countDown >= 0; countDown --)
{
if (GetInstance().MODULE_ROOM_STOP_FLAG)
{
return;
}
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameStatusCountdown(clientData.clientHID, countDown);
}
if (countDown > 0)
{
Thread.Sleep(1000);
}
}
for (int remainGameTime = gameTime; remainGameTime >= 0; remainGameTime--)
{
if (GetInstance().MODULE_ROOM_STOP_FLAG)
{
return;
}
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameStatusTime(clientData.clientHID, remainGameTime);
if (clientData.gameRespawn > 0)
{
clientData.gameRespawn--;
clientData.gameHealth = 100;
foreach (NetworkData.ClientData cData in clientList)
{
NetworkGate.OnGameEventRespawn(cData.clientHID, clientData.clientUser.userNumber, clientData.gameRespawn);
}
}
}
for (int index = 0; index < gameHealPacks.Length; index ++)
{
if (gameHealPacks[index] > 0)
{
gameHealPacks[index] --;
if (gameHealPacks[index] == 0)
{
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventItem(clientData.clientHID, 1, index, 0);
}
}
}
}
for (int index = 0; index < gamePointPacks.Length; index++)
{
if (gamePointPacks[index] > 0)
{
gamePointPacks[index]--;
if (gamePointPacks[index] == 0)
{
foreach (NetworkData.ClientData clientData in clientList)
{
NetworkGate.OnGameEventItem(clientData.clientHID, 0, index, 0);
}
}
}
}
if (remainGameTime > 0)
{
Thread.Sleep(1000);
}
}
DoGameEnd();
}
private void DoGameEnd()
{
gameState = GAME_STATE.STATE_END;
int gameTotalDamage = 0;
foreach (NetworkData.ClientData clientData in clientList)
{
gameTotalDamage += clientData.totalGivenDamage;
}
// CHECK MEDAL - IM NOT MAD
foreach (NetworkData.ClientData clientData in clientList)
{
if (clientData.gameKill == 0)
{
// ACHIEVE clientData IM NOT MAD
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 5);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "5");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] IM NOT MAD : " + clientData.clientUser.userID);
}
}
// CHECK MEDAL - ATTACK MEDAL
foreach (NetworkData.ClientData clientData in clientList)
{
if (gameType == GAME_TYPE.TYPE_SOLO)
{
if (clientData.totalGivenDamage >= gameTotalDamage/10 * 8)
{
// ACHIEVE clientData ATTACK GOLD
clientData.gameBonus += 6;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 9);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "9");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK GOLD : " + clientData.clientUser.userID);
} else if (clientData.totalGivenDamage >= gameTotalDamage/10 * 7)
{
// ACHIEVE clientData ATTACK SILVER
clientData.gameBonus += 4;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 8);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "8");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK SILVER : " + clientData.clientUser.userID);
} else if (clientData.totalGivenDamage >= gameTotalDamage/10 * 6)
{
// ACHIEVE clientData ATTACK BRONZE
clientData.gameBonus += 2;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 7);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "7");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK BRONZE : " + clientData.clientUser.userID);
}
}
if (gameType == GAME_TYPE.TYPE_TEAM)
{
if (clientData.totalGivenDamage >= gameTotalDamage/10 * 7)
{
// ACHIEVE clientData ATTACK GOLD
clientData.gameBonus += 6;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 9);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "9");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK GOLD : " + clientData.clientUser.userID);
} else if (clientData.totalGivenDamage >= gameTotalDamage/10 * 5)
{
// ACHIEVE clientData ATTACK SILVER
clientData.gameBonus += 4;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 8);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "8");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK SILVER : " + clientData.clientUser.userID);
} else if (clientData.totalGivenDamage >= gameTotalDamage/10 * 3)
{
// ACHIEVE clientData ATTACK BRONZE
clientData.gameBonus += 2;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 7);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "7");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] ATTACK BRONZE : " + clientData.clientUser.userID);
}
}
}
// CHECK MEDAL - DEFENSE MEDAL
foreach (NetworkData.ClientData clientData in clientList)
{
if (gameType == GAME_TYPE.TYPE_SOLO)
{
if (clientData.totalTakenDamage >= gameTotalDamage/10 * 8)
{
// ACHIEVE clientData DEFENSE GOLD
clientData.gameBonus += 6;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 12);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "12");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE GOLD : " + clientData.clientUser.userID);
} else if (clientData.totalTakenDamage >= gameTotalDamage/10 * 7)
{
// ACHIEVE clientData DEFENSE SILVER
clientData.gameBonus += 4;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 11);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "11");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE SILVER : " + clientData.clientUser.userID);
} else if (clientData.totalTakenDamage >= gameTotalDamage/10 * 6)
{
// ACHIEVE clientData DEFENSE BRONZE
clientData.gameBonus += 2;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 10);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "10");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE BRONZE : " + clientData.clientUser.userID);
}
}
if (gameType == GAME_TYPE.TYPE_TEAM)
{
if (clientData.totalTakenDamage >= gameTotalDamage/10 * 7)
{
// ACHIEVE clientData DEFENSE GOLD
clientData.gameBonus += 6;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 12);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "12");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE GOLD : " + clientData.clientUser.userID);
} else if (clientData.totalTakenDamage >= gameTotalDamage/10 * 5)
{
// ACHIEVE clientData DEFENSE SILVER
clientData.gameBonus += 4;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 11);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "11");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE SILVER : " + clientData.clientUser.userID);
} else if (clientData.totalTakenDamage >= gameTotalDamage/10 * 3)
{
// ACHIEVE clientData DEFENSE BRONZE
clientData.gameBonus += 2;
int medalIndex = DatabaseManager.GetInstance().saveUserMedal(this, clientData.clientUser.userNumber, 10);
clientData.medalHistory.Add(medalIndex);
NetworkGate.OnGameStatusMessage(clientData.clientHID, 2, "10");
serverApplication.logManager.NewLog(LogManager.LOG_LEVEL.LOG_DEBUG, LogManager.LOG_TARGET.LOG_SYSTEM, "ServerManager", "G]MEDAL] DEFENSE BRONZE : " + clientData.clientUser.userID);
}
}
}
DatabaseManager.GetInstance().saveGameResult(this);
// MM MODIFICATION
if (gameBlueTotal == gameRedTotal)
{
foreach (NetworkData.ClientData clientData in clientList)
{
DatabaseManager.GetInstance().saveUserGameResult(this, clientData.clientUser.userNumber, clientData);
}
}
if (gameBlueTotal > gameRedTotal)
{
foreach (NetworkData.ClientData clientData in clientBlueList)
{
clientData.gameWin = true;
clientData.gameBonus += gameMatchValue;
DatabaseManager.GetInstance().saveUserGameResult(this, clientData.clientUser.userNumber, clientData);
}
foreach (NetworkData.ClientData clientData in clientRedList)
{
clientData.gameLose = true;
clientData.gameBonus -= gameMatchValue;
DatabaseManager.GetInstance().saveUserGameResult(this, clientData.clientUser.userNumber, clientData);
}
}
if (gameBlueTotal < gameRedTotal)
{
foreach (NetworkData.ClientData clientData in clientRedList)
{
clientData.gameWin = true;
clientData.gameBonus += gameMatchValue;
DatabaseManager.GetInstance().saveUserGameResult(this, clientData.clientUser.userNumber, clientData);
}
foreach (NetworkData.ClientData clientData in clientBlueList)
{
clientData.gameLose = true;
clientData.gameBonus -= gameMatchValue;
DatabaseManager.GetInstance().saveUserGameResult(this, clientData.clientUser.userNumber, clientData);
}
}
Thread.Sleep(3000);
foreach (NetworkData.ClientData clientData in clientList)
{
clientData.currentReady = false;
clientData.currentGame = null;
NetworkGate.OnGameResult(clientData.clientHID, string.Empty);
}
gameState = GAME_STATE.STATE_CLEAR;
serverApplication.serverManager.serverGameList.Remove(this);
}
}
}
}