-
Notifications
You must be signed in to change notification settings - Fork 0
/
OilRigGamemode.cs
1970 lines (1785 loc) · 55.3 KB
/
OilRigGamemode.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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Oxide.Core.Plugins;
using Random = UnityEngine.Random;
using Oxide.Core;
using System;
using System.Configuration;
using Newtonsoft.Json;
namespace Oxide.Plugins
{
[Info ("OilRigGamemode", "Blood", "0.0.1")]
[Description ("Give them the damn gamemode")]
public class OilRigGamemode : RustPlugin
{
private const string minicopterAssetPrefab = "assets/content/vehicles/minicopter/minicopter.entity.prefab";
private const string crateAssetPrefab = "assets/prefabs/deployable/chinooklockedcrate/codelockedhackablecrate.prefab";
public class Team
{
public List<BasePlayer> teamMembers;
public List<BasePlayer> connectedMembers;
public bool color;
public string gamemodeQueuedFor;
public BasePlayer identifier;
public bool inGame;
public ulong matchID;
public int roundsWon;
public int points;
public int crateHackWins;
public bool canForfeit;
public bool forfeited;
};
public class Match
{
public Team a;
public Team b;
public int onRound;
public int rounds;
public bool started;
public bool ended;
public List<BasePlayer> teamsCombined;
public List<BasePlayer> deathsTeamA;
public List<BasePlayer> deathsTeamB;
public List<BasePlayer> spectators;
public List<BasePlayer> PenalizePlayers;
public List<PlayerHelicopter> minicopters;
public ulong ID;
public string winner;
public float timeLeft;
public HackableLockedCrate crateKek;
public bool increaseRoundFlag;
public bool isRanked;
public bool [] VehicleQueuedFor;
public bool unloading;
public Dictionary<BasePlayer, float> Damages;
};
private class PlayerElo
{
public float elo
{
get; set;
}
public int matchesPlayed
{
get; set;
}
}
public class Ref<T> where T : struct
{
public T Value
{
get; set;
}
}
private class Configuration
{
[JsonProperty ("Format")]
public string Format { get; set; } = "{Title}: {Message}";
[JsonProperty ("Title")]
public string Title { get; set; } = "RustRetakes: ";
[JsonProperty ("Title Color")]
public string TitleColor { get; set; } = "white";
[JsonProperty ("Message Color")]
public string MessageColor { get; set; } = "white";
[JsonProperty ("Chat Icon (SteamID64)")]
public ulong ChatIcon { get; set; } = 0;
}
//Facepunch.Database
private Configuration _config;
private static Dictionary<ulong, PlayerElo> playerElo;
List<Match> Matches = new List<Match> ();
List<Team> teamsToRemove = new List<Team> ();
Dictionary<Team, int> Teams = new Dictionary<Team, int> ();
Dictionary<BasePlayer, float> DisconnectedPlayersAlert = new Dictionary<BasePlayer, float> ();
Timer displayMessageTimer = null;
Timer newTimer = null;
[PluginReference]
private Plugin ScraponomicsLite;
#region ChatCommands
[ChatCommand ("forfeit")]
private void ForfeitCMD(BasePlayer caller){
if (IsInMatch(caller)){
Match match = GetMatch(caller);
if (match.ID == 0)
return;
if (match.a.canForfeit && match.a.teamMembers.Contains(caller)){
End(match);
match.a.canForfeit = false;
}
else if (match.b.canForfeit){
End(match);
match.a.canForfeit = false;
}
else{
SendReply(caller, "You don't have permission to do this.");
}
}
else{
SendReply(caller, "You don't have permission to do this.");
}
}
[ChatCommand ("elo")]
private void CmdElo (BasePlayer caller)
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{GetElo (caller.userID) + " <color=#ed2323><size=10>ELO</size></color>"}");
SendReply (caller, chatOutput);
//SendReply (caller, chatOutput);
}
[ChatCommand ("qleave")]
private void LeaveQueue (BasePlayer caller)
{
KeyValuePair<Team, int> removeTeam = new KeyValuePair<Team, int> ();
bool foundTeamInQueue = false;
if (caller == null)
return;
if (caller == caller.Team.GetLeader ())
{
foreach (KeyValuePair<Team, int> entry in Teams)
{
if (entry.Key.identifier == caller)
{
removeTeam = entry;
foundTeamInQueue = true;
break;
}
}
if (foundTeamInQueue)
{
Teams.Remove (removeTeam.Key);
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Successfully removed your team from the queue."}");
SendReply (caller, chatOutput);
}
else
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Your team is not in the queue, try queuing first."}");
SendReply (caller, chatOutput);
}
}
else
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Only the Leader of your team can cancel a queue."}");
SendReply (caller, chatOutput);
}
}
[ChatCommand ("rig")]
private void CmdRig (BasePlayer initiator)
{
if (initiator == null)
return;
if (initiator.Team == null)// || initiator.currentTeam < 1) I honestly don't know how this was working before but it should be initiator.Team.members.Count < 1 but even then we allow solos
{
/*
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Not a large enough group for this event. Please ensure that you are on a team."}");
SendReply (initiator, chatOutput);
*/
//return;
try
{
RelationshipManager.PlayerTeam PlayerTeam = RelationshipManager.ServerInstance.CreateTeam ();
PlayerTeam.teamLeader = initiator.userID;
PlayerTeam.AddPlayer (initiator);
}
catch { }
}
if (Matches.Count > 0)
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Sorry, there is already an ongoing game, please try again when the other ends."}");
SendReply (initiator, chatOutput);
return;
}
if (initiator != initiator.Team.GetLeader ())
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Only the team leader is allowed to initiate queuing."}");
SendReply (initiator, chatOutput);
return;
}
foreach (KeyValuePair<Team, int> check in Teams)
{
if (check.Key.identifier == initiator)
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Your team is already in the Queue for " + check.Key.gamemodeQueuedFor}");
SendReply (initiator, chatOutput);
return;
}
}
// Check if the person queuing is already in the queue
if (IsInMatch (initiator))
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"You are already in a match, you cannot queue at this time."}");
SendReply (initiator, chatOutput);
return;
}
else
{
//int teamcount = 0;
Team newTeam = new Team
{
teamMembers = new List<BasePlayer> (),
connectedMembers = new List<BasePlayer> (),
identifier = initiator,
gamemodeQueuedFor = "",
inGame = false
};
foreach (ulong teamMemberSteamID64 in initiator.Team.members)
{
BasePlayer teammate = BasePlayer.FindByID (teamMemberSteamID64);
if (teammate != null && teammate.IsConnected)
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Member connected: " + teammate.displayName.ToString ()}");
SendReply (initiator, chatOutput);
newTeam.teamMembers.Add (teammate);
newTeam.connectedMembers.Add (teammate);
//teamcount++;
}
else if (teammate != null && !teammate.IsConnected)
{
initiator.Team.RemovePlayer (teammate.userID);
}
}
switch (newTeam.teamMembers.Count)
{
case 1:
newTeam.gamemodeQueuedFor = "Solos.";
break;
case 2:
newTeam.gamemodeQueuedFor = "Duos.";
break;
case 3:
newTeam.gamemodeQueuedFor = "Trios.";
break;
case 4:
newTeam.gamemodeQueuedFor = "Quads.";
break;
default:
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"Team size invalid for this gamemode (Small Oil Rig). Err: 1 < Team size < 5."}");
SendReply (initiator, chatOutput);
return;
}
Teams.Add (newTeam, newTeam.teamMembers.Count);
SendMessage (newTeam, "Now queuing for " + newTeam.gamemodeQueuedFor);
if (newTimer == null)
{
newTimer = timer.Every (3f, () =>
{
if (Teams.Count > 1) // there are two teams in the queue
{
KeyValuePair<Team, int> team = Teams.First ();
KeyValuePair<Team, int> entry = new KeyValuePair<Team, int> ();
foreach (KeyValuePair<Team, int> check in Teams)
{
if (check.Key.identifier != team.Key.identifier && team.Value == check.Value)
{
teamsToRemove.Add (team.Key);
teamsToRemove.Add (check.Key);
entry = check;
StartGame (ref team, ref entry);
if (newTimer != null)
{
newTimer.Destroy ();
newTimer = null;
}
break;
}
}
foreach (Team remove in teamsToRemove)
{
Teams.Remove (remove);
}
teamsToRemove.Clear ();
}
});
displayMessageTimer = timer.Every (20f, () =>
{
if (Teams.ContainsKey (newTeam))
{
string chatOutput = _config.Format
.Replace ("{Title}", $"<color={_config.TitleColor}>{_config.Title}</color>")
.Replace ("{Message}", $"{"You are in the Queue for " + newTeam.gamemodeQueuedFor}");
SendReply (initiator, chatOutput);
}
else
{
displayMessageTimer.Destroy ();
displayMessageTimer = null;
}
});
}
}
}
#endregion
private void StartGame (ref KeyValuePair<Team, int> teamA, ref KeyValuePair<Team, int> teamB)
{
bool selectedTeamColor = Random.Range (0, 2) == 1;
bool selectedEntryColor = !selectedTeamColor;
Team teamANew = new Team
{
color = selectedTeamColor,
gamemodeQueuedFor = teamA.Key.gamemodeQueuedFor,
matchID = teamA.Key.matchID,
identifier = teamA.Key.identifier,
inGame = teamA.Key.inGame,
teamMembers = teamA.Key.teamMembers,
connectedMembers = teamA.Key.connectedMembers,
roundsWon = 0
};
Team teamBNew = new Team
{
color = selectedEntryColor,
gamemodeQueuedFor = teamB.Key.gamemodeQueuedFor,
matchID = teamB.Key.matchID,
identifier = teamB.Key.identifier,
inGame = teamB.Key.inGame,
teamMembers = teamB.Key.teamMembers,
connectedMembers = teamB.Key.connectedMembers,
roundsWon = 0
};
KeyValuePair<Team, int> teamAKVP = new KeyValuePair<Team, int> (teamANew, teamANew.teamMembers.Count);
KeyValuePair<Team, int> teamBKVP = new KeyValuePair<Team, int> (teamBNew, teamBNew.teamMembers.Count);
teamANew.inGame = true;
teamBNew.inGame = true;
Match newMatch = new Match
{
a = teamANew,
b = teamBNew,
started = false,
onRound = 1,
rounds = 6,
ended = false,
ID = teamANew.identifier.userID + teamBNew.identifier.userID, // Unique key based on the leaders of both teams' game IDs
deathsTeamA = new List<BasePlayer> (),
deathsTeamB = new List<BasePlayer> (),
spectators = new List<BasePlayer> (),
teamsCombined = new List<BasePlayer> (),
PenalizePlayers = new List<BasePlayer> (),
minicopters = new List<PlayerHelicopter> (),
VehicleQueuedFor = new bool [4]
};
if (!newMatch.started)
{
if (newMatch.a.color)
{
SendMessage (newMatch.a, "You are on the <color=#316bf5>BLUE</color> team.");
SendMessage (newMatch.a, "You must wait 7.5 seconds before <color=#ed2323>DEFENDING</color> the OilRig from your opponent.");
}
else
{
SendMessage (newMatch.a, "You are on the <color=#ed2323>RED</color> team.");
SendMessage (newMatch.a, "Get to the Oil Rig and successfully <color=#ed2323>ELIMINATE</color> all enemies before the 5 minute timer runs out.");
}
if (!newMatch.b.color)
{
SendMessage (newMatch.b, "You are on the <color=#ed2323>RED</color> team.");
SendMessage (newMatch.b, "Get to the Oil Rig and successfully <color=#ed2323>ELIMINATE</color> all enemies before the 5 minute timer runs out.");
}
else
{
SendMessage (newMatch.b, "You are on the <color=#316bf5>BLUE</color> team.");
SendMessage (newMatch.b, "You must wait 7.5 seconds before <color=#ed2323>DEFENDING</color> the OilRig from your opponent.");
}
newMatch.started = true;
}
var objec = newMatch;
objec.crateKek = StartTimedCrate (newMatch);
//PlayLockedCrate (newMatch.crateKek.transform.position);
newMatch = objec;
newMatch.teamsCombined = CombineTeams (newMatch.a, newMatch.b);
string team1 = "";
string team2 = "";
for (int i = 0; i < teamA.Key.teamMembers.Count - 1; i++)
{
team1 = team1 + teamA.Key.teamMembers [i].displayName.ToString () + ", ";
}
for (int j = 0; j < teamB.Key.teamMembers.Count - 1; j++)
{
team2 = team2 + teamB.Key.teamMembers [j].displayName.ToString () + ", ";
}
if (teamA.Key.teamMembers.Count == 1)
{
team1 += teamA.Key.teamMembers [teamA.Key.teamMembers.Count - 1].displayName.ToString ();
}
else
{
team1 += teamA.Key.teamMembers [teamA.Key.teamMembers.Count - 1].displayName.ToString () + ".";
}
if (teamB.Key.teamMembers.Count == 1)
{
team2 += teamB.Key.teamMembers [teamB.Key.teamMembers.Count - 1].displayName.ToString ();
}
else
{
team2 += teamB.Key.teamMembers [teamB.Key.teamMembers.Count - 1].displayName.ToString () + ".";
}
if (teamAKVP.Key.teamMembers.Count == 1)
{
SendToGame (teamAKVP, teamANew.color, newMatch);
SendMessage (teamAKVP.Key, "You are facing, " + team2 + " at " + GetElo(teamBKVP.Key.identifier.userID) + " <color=#ed2323><size=10>ELO</size></color>");
SendToGame (teamBKVP, teamBNew.color, newMatch);
SendMessage (teamBKVP.Key, "You are facing, " + team1 + " at " + GetElo (teamBKVP.Key.identifier.userID) + " <color=#ed2323><size=10>ELO</size></color>");
}
else
{
float combinedEloA = 0;
float combinedEloB = 0;
foreach (BasePlayer teammate in teamAKVP.Key.teamMembers)
{
combinedEloA += GetElo (teammate.userID);
}
foreach (BasePlayer teammate2 in teamBKVP.Key.teamMembers)
{
combinedEloB += GetElo (teammate2.userID);
}
combinedEloA /= teamAKVP.Key.teamMembers.Count;
combinedEloB /= teamBKVP.Key.teamMembers.Count;
SendToGame (teamAKVP, teamANew.color, newMatch);
SendMessage (teamAKVP.Key, "You are facing, " + team2 + " with an average of " + combinedEloB + " <color=#ed2323><size=10>ELO</size></color>");
SendToGame (teamBKVP, teamBNew.color, newMatch);
SendMessage (teamBKVP.Key, "You are facing, " + team1 + " with an average of " + combinedEloA + " <color=#ed2323><size=10>ELO</size></color>");
}
Matches.Add (newMatch);
//var match = new Ref<Match> { Value = newMatch};
//matchRefList.Add (match);
CheckGame (newMatch);
}
/*
private void RoundIncrease (Match match)
{
Server.Broadcast ("In round increase");
if (match.ID == 0)
{
return;
}
Team teamANew = new Team
{
color = match.a.color,
gamemodeQueuedFor = match.a.gamemodeQueuedFor,
matchID = match.a.matchID,
identifier = match.a.identifier,
inGame = match.a.inGame,
teamMembers = match.a.teamMembers,
connectedMembers = match.a.connectedMembers,
roundsWon = match.a.roundsWon
};
if (match.a.color) // if the A team is blue
{
Server.Broadcast ("Increasing roundwon of team blue " + teamANew.roundsWon);
var objec = teamANew;
objec.roundsWon++;
teamANew = objec;
Server.Broadcast ("after increasing roundwon of team blue " + teamANew.roundsWon);
}
Team teamBNew = new Team
{
color = match.b.color,
gamemodeQueuedFor = match.b.gamemodeQueuedFor,
matchID = match.b.matchID,
identifier = match.b.identifier,
inGame = match.b.inGame,
teamMembers = match.b.teamMembers,
connectedMembers = match.b.connectedMembers,
roundsWon = match.b.roundsWon
};
if (match.b.color)
{
Server.Broadcast ("Increasing roundwon of team blue " + teamBNew.roundsWon);
var objec = teamBNew;
objec.roundsWon++;
teamBNew = objec;
Server.Broadcast ("after increasing roundwon of team blue " + teamBNew.roundsWon);
}
//KeyValuePair<Team, int> teamAKVP = new KeyValuePair<Team, int> (teamANew, teamANew.teamMembers.Count);
//KeyValuePair<Team, int> teamBKVP = new KeyValuePair<Team, int> (teamBNew, teamBNew.teamMembers.Count);
Match match2 = new Match {
a = teamANew,
b = teamBNew,
deathsTeamA = match.deathsTeamA,
deathsTeamB = match.deathsTeamB,
crateKek = match.crateKek,
teamsCombined = match.teamsCombined,
ended = match.ended,
ID = match.ID,
minicopters = match.minicopters,
onRound = match.onRound,
PenalizePlayers = match.PenalizePlayers,
rounds = match.rounds,
spectators = match.spectators,
started = match.started,
timeLeft = match.timeLeft,
winner = match.winner,
increaseRoundFlag = true
};
if (teamANew.color)
{
SendMessage (teamANew, "Your team successfully won the round by letting the crate time expire. ");
SendMessage (teamBNew, "Your team did not successfully eliminate all players before the time expired. ");
}
else
{
SendMessage (teamBNew, "Your team successfully won the round by letting the crate time expire. ");
SendMessage (teamANew, "Your team did not successfully eliminate all players before the time expired. ");
}
Server.Broadcast ("Checking match in roundincrease with flag of " + match2.increaseRoundFlag);
CheckGame (match2);
}
*/
private void SendToGame (KeyValuePair<Team, int> team, bool color, Match match)
{
Vector3 [] rigSpawns = new Vector3 [4];
Vector3 outsideSpawn;
rigSpawns [0].x = -323.398f;
rigSpawns [0].y = 22.4263f;
rigSpawns [0].z = -364.819f;
rigSpawns [1].x = -334.93f;
rigSpawns [1].y = 22.72f;
rigSpawns [1].z = -363.82f;
rigSpawns [2].x = -326.21f;
rigSpawns [2].y = 17.93f;
rigSpawns [2].z = -360.49f;
rigSpawns [3].x = -348.74f;
rigSpawns [3].y = 30.79f;
rigSpawns [3].z = -368.81f;
outsideSpawn.x = -426.597f;
outsideSpawn.y = 20.0818f;
outsideSpawn.z = -238.781f;
int [] itemIDsWear = { -194953424, 1110385766, 1850456855, -1549739227, 1366282552 };
List<int> index = new List<int> ();
foreach (BasePlayer teamMember in team.Key.teamMembers)
{
if (teamMember == null)
continue;
PlayerInventory Inventory = teamMember.inventory;
if (teamMember.isMounted)
{
teamMember.EnsureDismounted ();
}
if (!Inventory.containerWear.IsLocked ())
{
Inventory.containerWear.SetLocked (true);
}
Inventory.Strip ();
if (color)
{
int indicie = Random.Range (0, 4);
while (!index.Contains(indicie))
{
indicie = Random.Range (0, 4);
index.Add (indicie);
}
Teleport (teamMember, rigSpawns [indicie]);
timer.Repeat (0.125f, 56, () =>
{
bool move = (teamMember.transform.position.x >= rigSpawns [indicie].x + 3.0f ||
teamMember.transform.position.z >= rigSpawns [indicie].z + 3.0f) ||
(teamMember.transform.position.x <= rigSpawns [indicie].x - 3.0f ||
teamMember.transform.position.z <= rigSpawns [indicie].z - 3.0f) ||
(teamMember.transform.position.x >= rigSpawns [indicie].x + 3.0f ||
teamMember.transform.position.z <= rigSpawns [indicie].z - 3.0f) ||
(teamMember.transform.position.x <= rigSpawns [indicie].x - 3.0f ||
teamMember.transform.position.z >= rigSpawns [indicie].z + 3.0f);
if (teamMember != null && move)
teamMember.MovePosition (rigSpawns [indicie]);
});
}
else
{
Vector3 newSpawn;
newSpawn.x = outsideSpawn.x;
newSpawn.y = outsideSpawn.y + 25.0f;
newSpawn.z = outsideSpawn.z;
Teleport (teamMember, newSpawn);
teamMember.UpdateNetworkGroup ();
teamMember.UpdateSurroundings ();
}
GiveKit (teamMember, color);
Metabolize (teamMember);
}
if (!color)
{
OnEntitySpawned (team.Key, match);
}
index.Clear ();
}
private HackableLockedCrate StartTimedCrate (Match match)
{
Vector3 cratePos;
cratePos.x = -322.63f;
cratePos.y = 27.18f;
cratePos.z = -342.04f;
const float REQUIREDHACKSECONDS = 30f;
HackableLockedCrate lockedCrate;
lockedCrate = (HackableLockedCrate) GameManager.server.CreateEntity (crateAssetPrefab, cratePos, match.a.identifier.ServerRotation);
if (lockedCrate != null)
{
lockedCrate.SpawnAsMapEntity ();
lockedCrate.StartHacking ();
lockedCrate.shouldDecay = false;
lockedCrate.enableSaving = false;
lockedCrate.hackSeconds = HackableLockedCrate.requiredHackSeconds - REQUIREDHACKSECONDS;
return lockedCrate;
}
return lockedCrate;
}
private void CheckGame (Match match)
{
match.Damages = new Dictionary<BasePlayer, float> ();
Timer myTimer = null;
List<BasePlayer> removeFromTeamA = new List<BasePlayer> ();
List<BasePlayer> removeFromTeamB = new List<BasePlayer> ();
myTimer = timer.Every (1f, () =>
{
if (match.unloading)
{
if (myTimer != null)
{
myTimer.Destroy ();
myTimer = null;
}
}
match.timeLeft++;
foreach (BasePlayer teammate in match.a.teamMembers)
{
if (teammate != null && teammate.IsConnected && teammate.IsValid())
{
match.a.connectedMembers.Add (teammate);
}
else if (teammate != null && !teammate.IsConnected && teammate.IsValid () && match.a.teamMembers.Count != 1)
{
SwapLeadership(teammate);
removeFromTeamA.Add (teammate);
match.a.connectedMembers.Remove (teammate);
if (match.isRanked)
{
match.PenalizePlayers.Add (teammate);
SendMessage (match.a, "Your teammate, " + teammate.displayName.ToString () + " has abandoned the match. Your team is now available to /forfeit and will be punished accordingly.");
match.a.canForfeit = true;
}
else
{
SendMessage (match.a, teammate + " has abandoned the match.");
}
}
}
foreach (BasePlayer teammate2 in match.b.teamMembers)
{
if (teammate2 != null && teammate2.IsConnected && teammate2.IsValid () && !match.b.connectedMembers.Contains (teammate2))
{
match.b.connectedMembers.Add (teammate2);
}
else if (teammate2 != null && !teammate2.IsConnected && teammate2.IsValid () && match.a.teamMembers.Count != 1)
{
SwapLeadership(teammate2);
removeFromTeamB.Add (teammate2);
match.b.connectedMembers.Remove (teammate2);
if (match.isRanked)
{
match.PenalizePlayers.Add (teammate2);
SendMessage (match.b, "Your teammate, " + teammate2.displayName.ToString () + " has abandoned the match. Your team is now available to /forfeit and will be punished accordingly.");
match.PenalizePlayers.Add (teammate2);
match.b.canForfeit = true;
}
else if (teammate2 != null && !teammate2.IsConnected && teammate2.IsValid ())
{
SendMessage (match.b, teammate2 + " has abandoned the match.");
}
}
}
foreach (BasePlayer leaver in removeFromTeamA)
{
match.a.teamMembers.Remove (leaver);
}
removeFromTeamA.Clear ();
foreach (BasePlayer leaver2 in removeFromTeamB)
{
match.b.teamMembers.Remove (leaver2);
}
removeFromTeamB.Clear ();
//match.a.identifier.Team.
if (match.timeLeft >= 30f && match.rounds == match.onRound)
{
SendMessage (match.b, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
SendMessage (match.a, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
match.b.roundsWon += 1;
End (match);
if (myTimer != null)
{
myTimer.Destroy ();
myTimer = null;
}
}
else if (match.timeLeft >= 30f && match.onRound < match.rounds)
{
if (match.b.color)
{
Team teamBlue = new Team
{
color = match.b.color,
matchID = match.b.matchID,
gamemodeQueuedFor = match.b.gamemodeQueuedFor,
identifier = match.b.identifier,
inGame = match.b.inGame,
teamMembers = match.b.teamMembers,
connectedMembers = match.b.connectedMembers,
roundsWon = match.b.roundsWon + 1
};
SendMessage (teamBlue, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
SendMessage (match.a, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
match.b = teamBlue;
}
else
{
Team teamRED = new Team
{
color = match.a.color,
matchID = match.a.matchID,
gamemodeQueuedFor = match.a.gamemodeQueuedFor,
identifier = match.a.identifier,
inGame = match.a.inGame,
teamMembers = match.a.teamMembers,
connectedMembers = match.a.connectedMembers,
roundsWon = match.a.roundsWon + 1
};
SendMessage (teamRED, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
SendMessage (match.b, "<color=#316bf5>BLUE</color> won the round by expiring the crate time.");
match.a = teamRED;
}
match.onRound++;
if (match.b.roundsWon == 3 || match.a.roundsWon == 3)
{
End (match);
if (myTimer != null)
{
myTimer.Destroy ();
myTimer = null;
}
}
else
{
Reset (match);
match.timeLeft = 0;
match.ended = false;
}
}
else
{
if (match.rounds == match.onRound && (match.deathsTeamA.Count >= match.a.teamMembers.Count || match.deathsTeamB.Count >= match.b.teamMembers.Count))
{
if (match.deathsTeamA.Count >= match.a.teamMembers.Count)
{
match.b.roundsWon += 1;
}
else if (match.deathsTeamB.Count >= match.b.teamMembers.Count)
{
match.a.roundsWon += 1;
}
End (match);
if (myTimer != null)
{
myTimer.Destroy ();
myTimer = null;
}
}
else if (match.deathsTeamB.Count >= match.b.teamMembers.Count || match.deathsTeamA.Count >= match.a.teamMembers.Count)
{
if (match.deathsTeamA.Count >= match.a.teamMembers.Count)
{
Team teamB = new Team
{
color = match.b.color,
matchID = match.b.matchID,
gamemodeQueuedFor = match.b.gamemodeQueuedFor,
identifier = match.b.identifier,
inGame = match.b.inGame,
teamMembers = match.b.teamMembers,
connectedMembers = match.b.connectedMembers,
roundsWon = match.b.roundsWon + 1
};
if (match.b.color)
{
SendMessage (teamB, "<color=#316bf5>BLUE</color> won the round.");
SendMessage (match.a, "<color=#316bf5>BLUE</color> won the round.");
}
else
{
SendMessage (teamB, "<color=#ed2323>RED</color> won the round.");
SendMessage (match.a, "<color=#ed2323>RED</color> won the round.");
}
match.b = teamB;
}
else
{
Team teamA = new Team
{
color = match.a.color,
matchID = match.a.matchID,
gamemodeQueuedFor = match.a.gamemodeQueuedFor,
identifier = match.a.identifier,
inGame = match.a.inGame,
teamMembers = match.a.teamMembers,
connectedMembers = match.a.connectedMembers,
roundsWon = match.a.roundsWon + 1
};
if (match.a.color)
{
SendMessage (match.b, "<color=#316bf5>BLUE</color> won the round.");
SendMessage (teamA, "<color=#316bf5>BLUE</color> won the round.");
}
else
{
SendMessage (match.b, "<color=#ed2323>RED</color> won the round.");
SendMessage (teamA, "<color=#ed2323>RED</color> won the round.");
}
match.a = teamA;
}
match.onRound++;
match.timeLeft = 0;
match.ended = false;
if (match.b.roundsWon == 3 || match.a.roundsWon == 3)
{
End (match);
if (myTimer != null)
{
myTimer.Destroy ();
myTimer = null;
}
}
else
{
Reset (match);
}
}
match.ended = false;
//if (onlineConnectionsTeamA.Count != match.a.identifier.Team.members.Count)
//{
//passengers = teamList.Except (drivers).ToList ();
// removePlayersTeamA = match.a.identifier.Team.members.Except (onlineConnectionsTeamA.Values).ToList ();
//}
//if (onlineConnectionsTeamB.Count != match.b.identifier.Team.members.Count)
//{
//passengers = teamList.Except (drivers).ToList ();
// removePlayersTeamB = match.b.identifier.Team.members.Except (onlineConnectionsTeamB.Values).ToList ();
//}
}
});
}
private void Reset (Match match)
{
foreach (KeyValuePair<BasePlayer, float> KVP in match.Damages)
{
SendMessage (match.a, KVP.Value.ToString() + " dealt by " + KVP.Key.displayName.ToString());
SendMessage (match.b, KVP.Value.ToString () + " dealt by " + KVP.Key.displayName.ToString ());
}
if (match.ID == 0)
{
return;
}
var obj = match;
//match.crateKek = StartTimedCrate (match);
obj.increaseRoundFlag = false;
//AwardPoints (match);
List<PlayerHelicopter> MinicoptersToRemove = new List<PlayerHelicopter> ();
match.increaseRoundFlag = false;
match.deathsTeamB.Clear ();
match.deathsTeamA.Clear ();
match.spectators.Clear ();
if (match.crateKek != null)
{
match.crateKek.Kill ();
match.crateKek = StartTimedCrate (match);
}
if (match.minicopters != null)
{
foreach (PlayerHelicopter mini in match.minicopters)
{
if (mini != null && !mini.IsDestroyed)
{
mini.Kill ();