-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompetitiveRust.cs
More file actions
1111 lines (1035 loc) · 43.7 KB
/
CompetitiveRust.cs
File metadata and controls
1111 lines (1035 loc) · 43.7 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
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;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.Libraries.Covalence;
namespace Oxide.Plugins {
[Info("CompetitiveRust", "br0wnard", "0.5.1")]
[Description("Setup configuration and rules for competitive play in Rust.")]
public class CompetitiveRust : RustPlugin {
#region Configuration Data
private bool configChanged;
// Plugin settings
private const string DefaultChatPrefix = "[CompetitiveRust]";
private const string DefaultChatPrefixColor = "#ff8d00ff";
public string ChatPrefix { get; private set; }
public string ChatPrefixColor { get; private set; }
// Plugin options
private const int DefaultTeamSize = 2;
private const int DefaultPreparationTime = 600;
private const int DefaultDecayTickRate = 1;
private const int DefaultConsumeRate = 5;
private const int DefaultGatherRate = 6;
private const int DefaultPickupRate = 6;
private const int DefaultCraftRate = 6;
private const int DefaultScrapRate = 6;
private const int DefaultBlueHoodie = 887162672;
private const int DefaultRedHoodie = 887173152;
private const bool DefaultOnlyDay = true;
private const bool DefaultUnlockedBP = true;
private const bool DefaultNoItemWear = true;
public int TeamSize { get; private set; }
public int PreparationTime { get; private set; }
public int DecayTickRate { get; private set; }
public int ConsumeRate { get; private set; }
public int GatherRate { get; private set; }
public int PickupRate { get; private set; }
public int CraftRate { get; private set; }
public int ScrapRate { get; private set; }
public int BlueHoodie { get; private set; }
public int RedHoodie { get; private set; }
public bool OnlyDay { get; private set; }
public bool UnlockedBP { get; private set; }
public bool NoItemWear { get; private set; }
// Plugin messages
private const string DefaultTimeLeft = "{0} seconds left for the preparation phase.";
private const string DefaultTimeUp = "The preparation is finished.";
private const string DefaultNoPermission = "You don't have permission to use this command.";
private const string DefaultEmptyTeam = "Can't start the game, one team is empty.";
private const string DefaultStarted = "The game is already started.";
private const string DefaultNoTeam = "Please enter a team name between '{0}' and '{1}'";
private const string DefaultCantChangeTeam = "You can't change your team when the game is started.";
private const string DefaultNow = "{0} is now in the {1} team.";
private const string DefaultCantStop = "You can't stop the game, because it's not started yet.";
private const string DefaultStop = "The game is now stopped. Teams have been cleared.";
private const string DefaultStartCup = "You can't place a cupboard until the start of the game.";
private const string DefaultCupLimit = "Your team already has a cupboard placed.";
private const string DefaultCupPlaced = "You placed your team cupboard.";
private const string DefaultGameStart = "Game is started. You have {0} seconds left for the preparation phase, good luck.";
private const string DefaultWin = "{0} team cupboard has been destroyed. {1} team won the game !";
private const string DefaultReady = "{0} is now ready.";
private const string DefaultUnready = "{0} is now unready.";
private const string DefaultChoose = "Please choose a team before you get ready.";
private const string DefaultRemaining = "{0} seconds remaining before the end of the preparation phase.";
private const string DefaultRedLower = "<color=#ed3434ff>red</color>";
private const string DefaultBlueLower = "<color=#1340d6ff>blue</color>";
private const string DefaultRedUpper = "<color=#ed3434ff>Red</color>";
private const string DefaultBlueUpper = "<color=#1340d6ff>Blue</color>";
private const string DefaultBlue = "<color=#1340d6ff>{0}</color>";
private const string DefaultRed = "<color=#ed3434ff>{0}</color>";
private const string DefaultGrey = "<color=#9a9ca0ff>{0}</color>";
private const string DefaultKill = "{0} killed {1}";
private const string DefaultNoTC = "{0} team didn't place a cupboard. {1} team win the game.";
private const string DefaultDraw = "No cupboard has been placed, draw.";
private const string DefaultSurrend = "{0} team gave up. {1} team win.";
private const string DefaultTeamFull = "This team is full.";
private const string DefaultNotEnough = "Not enough player to do this.";
private const string DefaultVoteKick = "{0} voted to kick {1} ({2}/{3}).";
private const string DefaultVoteDone = "Vote successeful, player kicked.";
private const string DefaultPlayerLeft = "{0} players remaining.";
private const string DefaultGameProgress = "Game in progress.";
private const string DefaultConnected = "{0} joined the game.";
private const string DefaultDisconnected = "{0} left the game.";
public string CurrentTimeLeft { get; private set; }
public string CurrentTimeUp { get; private set; }
public string CurrentNoPermission { get; private set; }
public string CurrentEmptyTeam { get; private set; }
public string CurrentStarted { get; private set; }
public string CurrentNoTeam { get; private set; }
public string CurrentCantChangeTeam { get; private set; }
public string CurrentNow { get; private set; }
public string CurrentCantStop { get; private set; }
public string CurrentStop { get; private set; }
public string CurrentStartCup { get; private set; }
public string CurrentCupLimit { get; private set; }
public string CurrentCupPlaced { get; private set; }
public string CurrentGameStart { get; private set; }
public string CurrentWin { get; private set; }
public string CurrentReady { get; private set; }
public string CurrentUnready { get; private set; }
public string CurrentChoose { get; private set; }
public string CurrentRemaining { get; private set; }
public string CurrentRedLower { get; private set; }
public string CurrentBlueLower { get; private set; }
public string CurrentRedUpper { get; private set; }
public string CurrentBlueUpper { get; private set; }
public string CurrentBlue { get; private set; }
public string CurrentRed { get; private set; }
public string CurrentGrey { get; private set; }
public string CurrentKill { get; private set; }
public string CurrentNoTC { get; private set; }
public string CurrentDraw { get; private set; }
public string CurrentSurrend { get; private set; }
public string CurrentTeamFull { get; private set; }
public string CurrentNotEnough { get; private set; }
public string CurrentVoteKick { get; private set; }
public string CurrentVoteDone { get; private set; }
public string CurrentPlayerLeft { get; private set; }
public string CurrentGameProgress { get; private set; }
public string CurrentConnected { get; private set; }
public string CurrentDisconnected { get; private set; }
#endregion
#region Variables
private bool DefaultPreparationUp = false;
private bool DefaultGameStarted = false;
private bool DefaultCupBoardRed = false;
private bool DefaultCupBoardBlue = false;
private string DefaultCupBoardRedString = "";
private string DefaultCupBoardBlueString = "";
public bool PreparationUp { get; private set; }
public bool GameStarted { get; private set; }
public bool CupBoardRed { get; private set; }
public bool CupBoardBlue { get; private set; }
public string CupBoardRedString { get; private set; }
public string CupBoardBlueString { get; private set; }
public List<string> UnreadyList { get; private set; }
public List<ulong> RedTeam { get; private set; }
public List<ulong> BlueTeam { get; private set; }
public List<ulong> RedReady { get; private set; }
public List<ulong> BlueReady { get; private set; }
public RelationshipManager.PlayerTeam RedParty { get; private set; }
public RelationshipManager.PlayerTeam BlueParty { get; private set; }
public Dictionary<string, List<string>> VoteKickDcty { get; private set; }
private Timer TimeLeft;
private Timer message;
private Timer TimeCheck;
private int AlternativeMessage;
private bool INIT = false;
private Random rnd;
private Covalence coval = new Covalence();
private string DefaultHostName;
#endregion
#region Server Loading
private void Loaded() => LoadConfigValues();
private void Unload() => UnloadCraftTime();
protected override void LoadDefaultConfig() => PrintWarning("Configuration file has been created.");
private void LoadConfigValues()
{
// Plugin settings
ChatPrefix = GetConfigValue("Settings", "ChatPrefix", DefaultChatPrefix);
ChatPrefixColor = GetConfigValue("Settings", "ChatPrefixColor", DefaultChatPrefixColor);
// Plugin options
TeamSize = GetConfigValue("Options", "TeamSize", DefaultTeamSize);
PreparationTime = GetConfigValue("Options", "PreparationTime", DefaultPreparationTime);
DecayTickRate = GetConfigValue("Options", "DecayTickRate", DefaultDecayTickRate);
ConsumeRate = GetConfigValue("Options", "ConsumeRate", DefaultConsumeRate);
GatherRate = GetConfigValue("Options", "GatherRate", DefaultGatherRate);
PickupRate = GetConfigValue("Options", "PickupRate", DefaultPickupRate);
CraftRate = GetConfigValue("Options", "CraftRate", DefaultCraftRate);
ScrapRate = GetConfigValue("Options", "ScrapRate", DefaultScrapRate);
BlueHoodie = GetConfigValue("Options", "BlueHoodie", DefaultBlueHoodie);
RedHoodie = GetConfigValue("Options", "RedHoodie", DefaultRedHoodie);
OnlyDay = GetConfigValue("Options", "OnlyDay", DefaultOnlyDay);
UnlockedBP = GetConfigValue("Options", "CurrentUnlockedBP", DefaultUnlockedBP);
NoItemWear = GetConfigValue("Options", "CurrentNoItemWear", DefaultNoItemWear);
// Plugin messages
CurrentTimeLeft = GetConfigValue("Messages", "CurrentTimeLeft", DefaultTimeLeft);
CurrentTimeUp = GetConfigValue("Messages", "CurrentTimeUp", DefaultTimeUp);
CurrentNoPermission = GetConfigValue("Messages", "CurrentNoPermission", DefaultNoPermission);
CurrentEmptyTeam = GetConfigValue("Messages", "CurrentEmptyTeam", DefaultEmptyTeam);
CurrentStarted = GetConfigValue("Messages", "CurrentStarted", DefaultStarted);
CurrentNoTeam = GetConfigValue("Messages", "CurrentNoTeam", DefaultNoTeam);
CurrentCantChangeTeam = GetConfigValue("Messages", "CurrentCantChangeTeam", DefaultCantChangeTeam);
CurrentNow = GetConfigValue("Messages", "CurrentNow", DefaultNow);
CurrentCantStop = GetConfigValue("Messages", "CurrentCantStop", DefaultCantStop);
CurrentStop = GetConfigValue("Messages", "CurrentStop", DefaultStop);
CurrentStartCup = GetConfigValue("Messages", "CurrentStartCup", DefaultStartCup);
CurrentCupLimit = GetConfigValue("Messages", "CurrentCupLimit", DefaultCupLimit);
CurrentCupPlaced = GetConfigValue("Messages", "CurrentCupPlaced", DefaultCupPlaced);
CurrentGameStart = GetConfigValue("Messages", "CurrentGameStart", DefaultGameStart);
CurrentWin = GetConfigValue("Messages", "CurrentWin", DefaultWin);
CurrentReady = GetConfigValue("Messages", "CurrentReady", DefaultReady);
CurrentUnready = GetConfigValue("Messages", "CurrentUnready", DefaultUnready);
CurrentChoose = GetConfigValue("Messages", "CurrentChoose", DefaultChoose);
CurrentRemaining = GetConfigValue("Messages", "CurrentRemaining", DefaultRemaining);
CurrentRedLower = GetConfigValue("Messages", "CurrentRedLower", DefaultRedLower);
CurrentBlueLower = GetConfigValue("Messages", "CurrentBlueLower", DefaultBlueLower);
CurrentRedUpper = GetConfigValue("Messages", "CurrentRedUpper", DefaultRedUpper);
CurrentBlueUpper = GetConfigValue("Messages", "CurrentBlueUpper", DefaultBlueUpper);
CurrentBlue = GetConfigValue("Messages", "CurrentBlue", DefaultBlue);
CurrentRed = GetConfigValue("Messages", "CurrentRed", DefaultRed);
CurrentGrey = GetConfigValue("Messages", "CurrentGrey", DefaultGrey);
CurrentKill = GetConfigValue("Messages", "CurrentKill", DefaultKill);
CurrentNoTC = GetConfigValue("Messages", "CurrentNoTC", DefaultNoTC);
CurrentDraw = GetConfigValue("Messages", "CurrentDraw", DefaultDraw);
CurrentSurrend = GetConfigValue("Messages", "CurrentSurrend", DefaultSurrend);
CurrentTeamFull = GetConfigValue("Messages", "CurrentTeamFull", DefaultTeamFull);
CurrentNotEnough = GetConfigValue("Messages", "CurrentNotEnough", DefaultNotEnough);
CurrentVoteKick = GetConfigValue("Messages", "CurrentVoteKick", DefaultVoteKick);
CurrentVoteDone = GetConfigValue("Messages", "CurrentVoteDone", DefaultVoteDone);
CurrentPlayerLeft = GetConfigValue("Messages", "CurrentPlayerLeft", DefaultPlayerLeft);
CurrentGameProgress = GetConfigValue("Messages", "CurrentGameProgress", DefaultGameProgress);
CurrentConnected = GetConfigValue("Messages", "CurrentConnected", DefaultConnected);
CurrentDisconnected = GetConfigValue("Messages", "CurrentDisconnected", DefaultDisconnected);
if (!configChanged){ return;}
Puts("Configuration file updated.");
SaveConfig();
}
#endregion
#region Chat/Console command
[ChatCommand("votekick")]
private void VoteKickCommandChat(BasePlayer player, string command, string[] args)
{
int playerCount = BasePlayer.activePlayerList.Count;
if (playerCount < 3)
{
SendChatMessage(player, CurrentNotEnough);
return;
}
if (args.Length == 0)
{
SendChatMessage(player, "No target.");
return;
}
IPlayer target = coval.Players.FindPlayer(args[0]);
if (target == null || !target.IsConnected)
{
SendChatMessage(player, "Target not found.");
return;
}
if (player.Equals(target))
{
SendChatMessage(player, "Can't vote for yourself.");
return;
}
if (target.IsAdmin)
{
SendChatMessage(player, "You can't votekick an admin.");
return;
}
// si deja votekick
List<string> voteList;
if (VoteKickDcty.ContainsKey(target.Id))
{
if (VoteKickDcty.TryGetValue(target.Id, out voteList))
{
// si on a pas déja voter pour lui
if (!voteList.Contains(player.userID.ToString()))
{
voteList.Add(player.userID.ToString());
}
}
}
else
{
voteList = new List<string>();
voteList.Add(player.userID.ToString());
VoteKickDcty.Add(target.Id, voteList);
}
if (voteList.Count >= playerCount * 0.6f)
{
target.Kick("Vote kicked.");
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentVoteDone);
}
}
else
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentVoteKick, player.displayName, target.Id, voteList.Count, playerCount * 0.6f);
}
}
}
[ChatCommand("gg")]
private void SurrendCommandChat(BasePlayer player, string command, string[] args)
{
if (!GameStarted)
{
if (RedTeam.Contains(player.userID))
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentSurrend, CurrentRedUpper, CurrentBlueUpper);
}
ClearGame();
}
else if (BlueTeam.Contains(player.userID))
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentSurrend, CurrentBlueUpper, CurrentRedUpper);
}
ClearGame();
}
}
}
[ChatCommand("start")]
private void StartCommandChat(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin)
{
SendChatMessage(player, CurrentNoPermission);
return;
}
if (GameStarted)
{
SendChatMessage(player, CurrentStarted);
return;
}
if (!RedTeam.Any() && !BlueTeam.Any())
{
SendChatMessage(player, CurrentEmptyTeam);
return;
}
BeginGame();
}
[ChatCommand("join")]
private void JoinCommandChat(BasePlayer player, string command, string[] args)
{
if (GameStarted)
{
SendChatMessage(player, CurrentCantChangeTeam);
return;
}
if (args.Length != 1)
{
SendChatMessage(player, CurrentNoTeam, CurrentRedLower, CurrentBlueLower);
return;
}
if (args[0] == "red")
{
JoinRed(player);
return;
}
if (args[0] == "blue")
{
JoinBlue(player);
return;
}
SendChatMessage(player, CurrentNoTeam, CurrentRedLower, CurrentBlueLower);
return;
}
[ChatCommand("stop")]
private void StopCommandChat(BasePlayer player, string command, string[] args)
{
if (!player.IsAdmin)
{
SendChatMessage(player, CurrentNoPermission);
return;
}
if (!GameStarted) {
SendChatMessage(player, CurrentCantStop);
return;
}
GameStarted = false;
ClearGame();
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentStop);
}
return;
}
[ChatCommand("ready")]
private void ReadyCommandChat(BasePlayer player, string command, string[] args)
{
if (GameStarted) { return; }
if (RedTeam.Contains(player.userID) && !RedReady.Contains(player.userID))
{
RedReady.Add(player.userID);
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentReady, player.displayName);
}
}
else if (BlueTeam.Contains(player.userID) && !BlueReady.Contains(player.userID))
{
BlueReady.Add(player.userID);
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentReady, player.displayName);
}
}
else if (!RedTeam.Contains(player.userID) && !BlueReady.Contains(player.userID))
{
SendChatMessage(player, CurrentChoose);
}
if (RedReady.Count == TeamSize && BlueReady.Count == TeamSize)
{
BeginGame();
}
}
[ChatCommand("unready")]
private void UnreadyCommandChat(BasePlayer player, string command, string[] args)
{
if (GameStarted) { return; }
if (RedReady.Contains(player.userID))
{
RedReady.Remove(player.userID);
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentUnready, player.displayName);
}
}
else if (BlueReady.Contains(player.userID))
{
BlueReady.Remove(player.userID);
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentUnready, player.displayName);
}
}
}
[ChatCommand("random")]
private void RandomCommandChat(BasePlayer player, string command, string[] args)
{
if (GameStarted) { return; }
if (!player.IsAdmin)
{
SendChatMessage(player, CurrentNoPermission);
return;
}
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
JoinRand(x);
}
}
[ChatCommand("help")]
private void HelpCommandChat(BasePlayer player, string command, string[] args)
{
SendChatMessage(player, "Rules:");
SendChatMessage(player, "Two teams, red or blue, you need to destroy the ennemy TC.");
SendChatMessage(player, "A preparation phase of " + PreparationTime + "seconds without PvP.");
SendChatMessage(player, "During this phase you need to place your team cupboard.");
SendChatMessage(player, "Commands: \n");
SendChatMessage(player, "/votekick <player name> for votekick a player.");
SendChatMessage(player, "/gg to surrend.");
SendChatMessage(player, "/join to join a team before the game start.");
SendChatMessage(player, "/ready to get ready before the game start.");
SendChatMessage(player, "/unready to get unready before the game start.");
}
#endregion
#region ServerHook
private void OnServerInitialized()
{
// List initialization
UnreadyList = new List<string>();
RedTeam = new List<ulong>();
BlueTeam = new List<ulong>();
RedReady = new List<ulong>();
BlueReady = new List<ulong>();
RedParty = RelationshipManager.Instance.CreateTeam();
BlueParty = RelationshipManager.Instance.CreateTeam();
VoteKickDcty = new Dictionary<string, List<string>>();
rnd = new Random();
AlternativeMessage = 0;
message = timer.Repeat(15, -1, () =>
{
if (!GameStarted)
{
++AlternativeMessage;
if (AlternativeMessage % 2 == 0)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, "Please pick a team with /join and get ready with /ready.");
}
}
else
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
if (!RedReady.Contains(x.userID) && !BlueReady.Contains(x.userID))
{
UnreadyList.Add(x.displayName);
}
}
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, "Players unready : {0}", string.Join(",", UnreadyList));
}
UnreadyList.Clear();
}
}
});
if (OnlyDay)
{
TimeCheck = timer.Repeat(60, -1, () =>
{
TOD_Sky.Instance.Cycle.Hour = 12;
});
}
LoadCraftTime();
DefaultHostName = ConVar.Server.hostname;
int Consume = 1440 / ConsumeRate;
covalence.Server.Command("decay.upkeep_period_minutes " + Consume);
covalence.Server.Command("decay.scale " + ConsumeRate);
covalence.Server.Command("decay.tick " + DecayTickRate);
RefreshServerName();
INIT = true;
}
private void OnPlayerDisconnected(BasePlayer player, string reason)
{
timer.Once(5, () => {
RefreshServerName();
});
NotifyPlayerConnection(false, player.displayName);
}
private object OnLootSpawn(LootContainer container)
{
if (INIT)
{
if (container?.inventory?.itemList == null) return null;
while (container.inventory.itemList.Count > 0)
{
var item = container.inventory.itemList[0];
item.RemoveFromContainer();
item.Remove(0f);
}
container.PopulateLoot();
foreach (Item i in container.inventory.itemList)
{
if (i.IsBlueprint())
{
i.amount = 0;
} else if (!i.hasCondition)
{
i.amount *= ScrapRate;
}
}
return container;
}
return null;
}
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
if (!entity.ToPlayer()) { return; }
var amount = item.amount;
item.amount = item.amount * GatherRate;
try
{
dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount += amount - item.amount / GatherRate;
if (dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount < 0)
{
item.amount += (int)dispenser.containedItems.Single(x => x.itemid == item.info.itemid).amount;
}
}
catch { }
}
private void OnDispenserBonus(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
OnDispenserGather(dispenser, entity, item);
}
private void OnGrowableGather(GrowableEntity plant, Item item)
{
item.amount = (int)(item.amount * GatherRate);
}
private void OnQuarryGather(MiningQuarry quarry, Item item)
{
item.amount = (int)(item.amount * GatherRate);
}
private void OnCollectiblePickup(Item item, BasePlayer player)
{
item.amount = (int)(item.amount * PickupRate);
}
private void OnSurveyGather(SurveyCharge surveyCharge, Item item)
{
item.amount = (int)(item.amount * GatherRate);
}
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
if (GameStarted)
{
if (info == null || entity == null) { return; }
if (entity is BaseNpc) { return; }
BasePlayer victim = entity.ToPlayer();
if (info?.Initiator?.ToPlayer() == null) { return; }
BasePlayer killer = info.Initiator.ToPlayer();
if (victim == null || killer == null) { return; }
if (BlueTeam.Contains(killer.userID))
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentKill, String.Format(CurrentBlue, killer.displayName), String.Format(CurrentRed, victim.displayName));
}
}
else if (RedTeam.Contains(killer.userID))
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentKill, String.Format(CurrentRed, killer.displayName), String.Format(CurrentBlue, victim.displayName));
}
}
}
}
private void OnLoseCondition(Item item, ref float amount)
{
if (item != null && NoItemWear)
{
BasePlayer player;
if (item.GetOwnerPlayer() == null)
{
if (item?.info == null) return;
if (!item.info.shortname.Contains("mod")) return;
player = item?.GetRootContainer()?.GetOwnerPlayer();
if (player == null)
return;
}
else player = item.GetOwnerPlayer();
if (player != null)
{
var def = ItemManager.FindItemDefinition(item.info.itemid);
if (item.hasCondition) { item.RepairCondition(amount); }
}
}
}
private void OnEntityTakeDamage(BaseEntity entity, HitInfo info)
{
if (!GameStarted) { return; }
if (PreparationUp && GameStarted) { return; }
if (entity == null || info == null) { return; }
BasePlayer target = entity as BasePlayer;
if (info.Initiator == null) { return; }
BasePlayer from = info.Initiator as BasePlayer;
if (target == null || from == null) { return; }
if (target.UserIDString == from.UserIDString || target.IsNpc) { return; }
info.damageTypes.ScaleAll(0);
}
private void OnEntityKill(BaseNetworkable entity)
{
if (entity.ShortPrefabName.Contains("cupboard.tool"))
{
if (entity.ToString() == CupBoardRedString)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentWin, CurrentRedUpper, CurrentBlueUpper);
}
ClearGame();
return;
}
if (entity.ToString() == CupBoardBlueString)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentWin, CurrentBlueUpper, CurrentRedUpper);
}
ClearGame();
return;
}
}
}
private void OnEntitySpawned(BaseEntity entity, UnityEngine.GameObject gameObject)
{
if (entity.ShortPrefabName.Contains("cupboard.tool"))
{
BasePlayer player = BasePlayer.FindByID(entity.OwnerID);
if (player == null) { return; }
if (!GameStarted)
{
entity.KillMessage();
var itemtogive = ItemManager.CreateByItemID(-97956382, 1);
if (itemtogive != null) player.inventory.GiveItem(itemtogive);
SendChatMessage(player, CurrentStartCup);
return;
}
if (RedTeam.Contains(player.userID) && CupBoardRed)
{
entity.KillMessage();
var itemtogive = ItemManager.CreateByItemID(-97956382, 1);
if (itemtogive != null) player.inventory.GiveItem(itemtogive);
SendChatMessage(player, CurrentCupLimit);
return;
}
if (BlueTeam.Contains(player.userID) && CupBoardBlue)
{
entity.KillMessage();
var itemtogive = ItemManager.CreateByItemID(-97956382, 1);
if (itemtogive != null) player.inventory.GiveItem(itemtogive);
SendChatMessage(player, CurrentCupLimit);
return;
}
if (RedTeam.Contains(player.userID))
{
CupBoardRed = true;
CupBoardRedString = entity.ToString();
SendChatMessage(player, CurrentCupPlaced);
return;
}
if (BlueTeam.Contains(player.userID))
{
CupBoardBlue = true;
CupBoardBlueString = entity.ToString();
SendChatMessage(player, CurrentCupPlaced);
return;
}
}
}
private void OnPlayerRespawned(BasePlayer player)
{
if (RedTeam.Contains(player.userID))
{
var i = ItemManager.CreateByItemID(1751045826, 1, (ulong)RedHoodie);
if (i != null) { player.inventory.GiveItem(i, player.inventory.containerWear); }
return;
}
if (BlueTeam.Contains(player.userID))
{
var i = ItemManager.CreateByItemID(1751045826, 1, (ulong)BlueHoodie);
if (i != null) { player.inventory.GiveItem(i, player.inventory.containerWear); }
return;
}
return;
}
private void OnPlayerInit(BasePlayer player)
{
if (GameStarted && !player.IsAdmin)
{
if (!BlueTeam.Contains(player.userID) || !RedTeam.Contains(player.userID))
{
player.Kick("Game started. Please connect when the servername is updated.");
}
}
NotifyPlayerConnection(true, player.displayName);
RefreshServerName();
if (UnlockedBP) {
UnlockBP(player);
}
}
#endregion
#region Helper methods
private void NotifyPlayerConnection(bool type, string playerName)
{
if (type)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentConnected, playerName);
}
} else
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentDisconnected, playerName);
}
}
}
private void RefreshServerName()
{
if (GameStarted)
{
covalence.Server.Command("server.hostname "
+ '"' + DefaultHostName
+ ' '
+ CurrentGameProgress + '"');
return;
}
int slotRemaining = (TeamSize * 2) - BasePlayer.activePlayerList.Count;
if (slotRemaining < 0) { slotRemaining = 0; }
covalence.Server.Command("server.hostname "
+ '"' + DefaultHostName
+ ' '
+ String.Format(CurrentPlayerLeft, slotRemaining) + '"');
}
private void LoadCraftTime()
{
foreach (var bp in ItemManager.bpList)
{
if (CraftRate != 0f)
{
bp.time = bp.time / CraftRate;
}
else
{
bp.time = 0f;
}
}
}
private void UnloadCraftTime()
{
foreach (var bp in ItemManager.bpList)
{
if (CraftRate != 0f)
{
bp.time = bp.time * CraftRate;
}
else
{
bp.time = 0f;
}
}
}
private void ClearGame()
{
PreparationUp = DefaultPreparationUp;
GameStarted = DefaultGameStarted;
CupBoardRed = DefaultCupBoardRed;
CupBoardBlue = DefaultCupBoardBlue;
CupBoardRedString = DefaultCupBoardRedString;
CupBoardBlueString = DefaultCupBoardBlueString;
RedTeam.Clear();
BlueTeam.Clear();
RedReady.Clear();
BlueReady.Clear();
RefreshServerName();
}
private void SendChatMessage(BasePlayer player, string message, params object[] args)
=> player?.SendConsoleCommand("chat.add", -1, null, string.Format($"<color={ChatPrefixColor}>{ChatPrefix}</color>: {message}", args), 1.0);
T GetConfigValue<T>(string category, string setting, T defaultValue)
{
var data = Config[category] as Dictionary<string, object>;
if (data == null)
{
data = new Dictionary<string, object>();
Config[category] = data;
configChanged = true;
}
object value;
if (!data.TryGetValue(setting, out value))
{
value = defaultValue;
data[setting] = value;
configChanged = true;
}
return (T)Convert.ChangeType(value, typeof(T));
}
void SetConfigValue<T>(string category, string setting, T newValue)
{
var data = Config[category] as Dictionary<string, object>;
object value;
if (data != null && data.TryGetValue(setting, out value))
{
value = newValue;
data[setting] = value;
configChanged = true;
}
SaveConfig();
}
private void RemoveAll()
{
var allVehicules = UnityEngine.GameObject.FindObjectsOfType<BaseVehicle>();
for (int i = 0; i < allVehicules.Count(); i++)
{
var vehicules = allVehicules[i];
if (vehicules == null) continue;
vehicules.Kill(BaseNetworkable.DestroyMode.None);
}
var allDropped = UnityEngine.GameObject.FindObjectsOfType<DroppedItem>();
for (int i = 0; i < allDropped.Count(); i++)
{
var droppedItem = allDropped[i];
if (droppedItem == null) continue;
droppedItem.Kill(BaseNetworkable.DestroyMode.None);
}
var allCorpse = UnityEngine.GameObject.FindObjectsOfType<LootableCorpse>();
for (int i = 0; i < allCorpse.Count(); i++)
{
var corpseItem = allCorpse[i];
if (corpseItem == null) continue;
corpseItem.Kill(BaseNetworkable.DestroyMode.None);
}
var allBag = UnityEngine.GameObject.FindObjectsOfType<DroppedItemContainer>();
for (int i = 0; i < allBag.Count(); i++)
{
var bagItem = allBag[i];
if (bagItem == null) continue;
bagItem.Kill(BaseNetworkable.DestroyMode.None);
}
var allEntity = UnityEngine.GameObject.FindObjectsOfType<BaseEntity>();
for (int i = 0; i < allEntity.Count(); i++)
{
var entity = allEntity[i];
if (entity == null || entity.OwnerID == 0) continue;
entity.Kill(BaseNetworkable.DestroyMode.None);
}
}
private void BeginGame()
{
GameStarted = true;
timer.Destroy(ref message);
Timer killCountdown = timer.Once(2, () =>
{
if (GameStarted) {
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
x.Hurt(1000);
}
// debug plz BasePlayer.sleepingPlayerList.ForEach(x => x.Kill(BaseNetworkable.DestroyMode.None));
}
RemoveAll();
}
);
TimeLeft = timer.Once(PreparationTime, () =>
{
if (!GameStarted) { return; }
PreparationUp = true;
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentTimeUp);
}
if (!CupBoardBlue && !CupBoardRed)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentDraw);
}
ClearGame();
}
else if (!CupBoardBlue)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{
SendChatMessage(x, CurrentNoTC, CurrentBlueUpper, CurrentRedLower);
}
ClearGame();
}
else if (!CupBoardRed)
{
foreach (BasePlayer x in BasePlayer.activePlayerList)
{