-
Notifications
You must be signed in to change notification settings - Fork 4
/
Imperium.cs
12336 lines (10432 loc) · 447 KB
/
Imperium.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
/* LICENSE
* Copyright (C) 2022-2024 evict
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#region > Singleton
namespace Oxide.Plugins
{
using System;
using System.IO;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries.Covalence;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using Network;
[Info("Imperium", "chucklenugget/evict", "2.2.9")]
[Description("Land Claims for Rust")]
public partial class Imperium : RustPlugin
{
//Optional Dependencies
[PluginReference]
private Plugin BetterChat, Clans, RaidableBases, NPCSpawn;
private List<HookDeferral> HookDeferralRegistry = new List<HookDeferral>();
public class HookDeferral
{
public string hookName;
public Plugin plugin;
public HookDeferral(string HookName, Plugin Plugin)
{
hookName = HookName;
plugin = Plugin;
}
}
//Hook Deferrals
[PluginReference]
private Plugin NpcSpawn, AirEvent;
private void InitDeferList()
{
//RegisterHookDeferral("OnEntityTakeDamage", NpcSpawn);
//RegisterHookDeferral("OnEntityTakeDamage", AirEvent);
}
private static Imperium Instance;
private bool Ready;
public static string dataDirectory = $"file://{Interface.Oxide.DataDirectory}{Path.DirectorySeparatorChar}ImperiumImages{Path.DirectorySeparatorChar}";
private DynamicConfigFile AreasFile;
private DynamicConfigFile FactionsFile;
private DynamicConfigFile PinsFile;
private DynamicConfigFile WarsFile;
private GameObject GO;
private ImperiumOptions Options;
private Timer UpkeepCollectionTimer;
private AreaManager Areas;
private FactionManager Factions;
private HudManager Hud;
private PinManager Pins;
private UserManager Users;
private WarManager Wars;
private ZoneManager Zones;
private RecruitManager Recruits;
private void Init()
{
AreasFile = GetDataFile("areas");
FactionsFile = GetDataFile("factions");
PinsFile = GetDataFile("pins");
WarsFile = GetDataFile("wars");
}
private void RegisterHookDeferral(string hook, Plugin plugin)
{
if (plugin == null)
return;
HookDeferralRegistry.Add(new HookDeferral(hook, plugin));
}
private object GetExternalHookResult(string hook, params object[] args)
{
if (HookDeferralRegistry.Count == 0)
return null;
List<HookDeferral> filtered = HookDeferralRegistry.FindAll(r => r.hookName == hook && r.plugin != null);
if (filtered.Count == 0)
return null;
object result = null;
foreach (HookDeferral def in filtered)
{
if (def.plugin == null)
continue;
result = def.plugin.Call(hook, args);
if (result != null)
return result;
}
return null;
}
private void Loaded()
{
InitLang();
InitDeferList();
Permission.RegisterAll(this);
try
{
Options = Config.ReadObject<ImperiumOptions>();
}
catch (Exception ex)
{
PrintError($"Error while loading configuration: {ex.ToString()}");
}
Puts("Area claims are " + (Options.Claims.Enabled ? "enabled" : "disabled"));
Puts("Taxation is " + (Options.Taxes.Enabled ? "enabled" : "disabled"));
Puts("Badlands are " + (Options.Badlands.Enabled ? "enabled" : "disabled"));
Puts("Map pins are " + (Options.Map.PinsEnabled ? "enabled" : "disabled"));
Puts("War is " + (Options.War.Enabled ? "enabled" : "disabled"));
Puts("Decay reduction is " + (Options.Decay.Enabled ? "enabled" : "disabled"));
Puts("Claim upkeep is " + (Options.Upkeep.Enabled ? "enabled" : "disabled"));
Puts("Zones are " + (Options.Zones.Enabled ? "enabled" : "disabled"));
if (Options.Upgrading.Enabled)
{
PrintWarning("Land upgrading is not available in this Imperium version yet! Disabling it");
Options.Upgrading.Enabled = false;
}
if (Options.Recruiting.Enabled)
{
PrintWarning("Recruiting is not available in this Imperium version yet! Disabling it");
//Options.Recruiting.Enabled = false;
}
if (BetterChat != null)
{
Puts("Using " + BetterChat.Name + " by " + BetterChat.Author);
Interface.CallHook("API_RegisterThirdPartyTitle", this, new Func<IPlayer, string>(BetterChat_FormattedFactionTag));
}
Instance = this;
//Puts("Recruiting is " + (Options.Recruiting.Enabled ? "enabled" : "disabled"));
// If the map has already been initialized, we can set up now; otherwise,
// we need to wait until the savefile has been loaded.
if (TerrainMeta.Size.x > 0) Setup();
}
private void OnServerInitialized(bool initial)
{
if (initial)
Setup();
}
private void Setup()
{
GO = new GameObject();
Areas = new AreaManager();
Factions = new FactionManager();
Hud = new HudManager();
Pins = new PinManager();
Users = new UserManager();
Wars = new WarManager();
Zones = new ZoneManager();
Recruits = new RecruitManager();
Factions.Init(TryLoad<FactionInfo>(FactionsFile));
Areas.Init(TryLoad<AreaInfo>(AreasFile));
Pins.Init(TryLoad<PinInfo>(PinsFile));
Users.Init();
Wars.Init(TryLoad<WarInfo>(WarsFile));
Zones.Init();
Hud.Init();
Hud.GenerateMapOverlayImage();
if (Options.Factions.OverrideInGameTeamSystem)
{
RelationshipManager.maxTeamSize = 128;
RelationshipManager.maxTeamSize_Internal = 128;
}
if (Instance.Options.Factions.UseClansPlugin)
{
Factions.SyncAllWithClans();
}
if (Options.Upkeep.Enabled)
UpkeepCollectionTimer =
timer.Every(Options.Upkeep.CheckIntervalMinutes * 60, Upkeep.CollectForAllFactions);
PrintToChat($"{Title} v{Version} initialized.");
Ready = true;
}
private void Unload()
{
SaveData();
Hud.Destroy();
Zones.Destroy();
Users.Destroy();
Wars.Destroy();
Pins.Destroy();
Areas.Destroy();
Factions.Destroy();
if (UpkeepCollectionTimer != null && !UpkeepCollectionTimer.Destroyed)
UpkeepCollectionTimer.Destroy();
if (GO != null)
UnityEngine.Object.Destroy(GO);
Instance = null;
}
private void OnServerSave()
{
timer.Once(Core.Random.Range(10, 30), SaveData);
}
private void SaveData()
{
AreasFile.WriteObject(Areas.Serialize());
FactionsFile.WriteObject(Factions.Serialize());
PinsFile.WriteObject(Pins.Serialize());
WarsFile.WriteObject(Wars.Serialize());
}
private DynamicConfigFile GetDataFile(string name)
{
return Interface.Oxide.DataFileSystem.GetFile(Name + Path.DirectorySeparatorChar + name);
}
private IEnumerable<T> TryLoad<T>(DynamicConfigFile file)
{
List<T> items;
try
{
items = file.ReadObject<List<T>>();
}
catch (Exception ex)
{
PrintWarning($"Error reading data from {file.Filename}: ${ex.ToString()}");
items = new List<T>();
}
return items;
}
private void Log(string message, params object[] args)
{
LogToFile("log", String.Format(message, args), this, true);
}
private bool EnsureUserCanChangeFactionClaims(User user, Faction faction)
{
if (faction == null || !faction.HasLeader(user))
{
user.SendChatMessage(nameof(Messages.NotLeaderOfFaction));
return false;
}
if (faction.MemberCount < Options.Claims.MinFactionMembers)
{
user.SendChatMessage(nameof(Messages.FactionTooSmallToOwnLand), Options.Claims.MinFactionMembers);
return false;
}
return true;
}
private bool EnsureFactionCanClaimArea(User user, Faction faction, Area area)
{
if (area.Type == AreaType.Badlands)
{
user.SendChatMessage(nameof(Messages.AreaIsBadlands), area.Id);
return false;
}
if (faction.MemberCount < Instance.Options.Claims.MinFactionMembers)
{
user.SendChatMessage(nameof(Messages.FactionTooSmallToOwnLand), Instance.Options.Claims.MinFactionMembers);
return false;
}
Area[] claimedAreas = Areas.GetAllClaimedByFaction(faction);
if (Instance.Options.Claims.RequireContiguousClaims && !area.IsClaimed && claimedAreas.Length > 0)
{
int contiguousClaims = Areas.GetNumberOfContiguousClaimedAreas(area, faction);
if (contiguousClaims == 0)
{
user.SendChatMessage(nameof(Messages.AreaNotContiguous), area.Id, faction.Id);
return false;
}
}
int? maxClaims = Instance.Options.Claims.MaxClaims;
if (maxClaims != null && claimedAreas.Length >= maxClaims)
{
user.SendChatMessage(nameof(Messages.FactionOwnsTooMuchLand), faction.Id, maxClaims);
return false;
}
return true;
}
private bool EnsureCupboardCanBeUsedForClaim(User user, BuildingPrivlidge cupboard)
{
if (cupboard == null)
{
user.SendChatMessage(nameof(Messages.SelectingCupboardFailedInvalidTarget));
return false;
}
if (!cupboard.IsAuthed(user.Player))
{
user.SendChatMessage(nameof(Messages.SelectingCupboardFailedNotAuthorized));
return false;
}
return true;
}
private bool EnsureLockerCanBeUsedForArmory(User user, Locker locker, Area area)
{
if (area == null || area.FactionId != user.Faction.Id)
{
user.SendChatMessage(nameof(Messages.AreaNotOwnedByYourFaction));
return false;
}
return true;
}
private bool EnsureUserAndFactionCanEngageInDiplomacy(User user, Faction faction)
{
if (faction == null)
{
user.SendChatMessage(nameof(Messages.NotMemberOfFaction));
return false;
}
if (faction.MemberCount < Options.Claims.MinFactionMembers)
{
user.SendChatMessage(nameof(Messages.FactionTooSmallToOwnLand));
return false;
}
if (Areas.GetAllClaimedByFaction(faction).Length == 0)
{
user.SendChatMessage(nameof(Messages.FactionDoesNotOwnLand));
return false;
}
return true;
}
private bool EnforceCommandCooldown(User user, string command, int cooldownSeconds)
{
int secondsRemaining = user.GetSecondsLeftOnCooldown(command);
if (secondsRemaining > 0)
{
user.SendChatMessage(nameof(Messages.CommandIsOnCooldown), secondsRemaining);
return false;
}
user.SetCooldownExpiration(command, DateTime.UtcNow.AddSeconds(cooldownSeconds));
return true;
}
private bool TryCollectFromStacks(ItemDefinition itemDef, IEnumerable<Item> stacks, int amount)
{
if (stacks.Sum(item => item.amount) < amount)
return false;
int amountRemaining = amount;
var dirtyContainers = new HashSet<ItemContainer>();
foreach (Item stack in stacks)
{
var amountToTake = Math.Min(stack.amount, amountRemaining);
stack.amount -= amountToTake;
amountRemaining -= amountToTake;
dirtyContainers.Add(stack.GetRootContainer());
if (stack.amount == 0)
stack.RemoveFromContainer();
if (amountRemaining == 0)
break;
}
foreach (ItemContainer container in dirtyContainers)
container.MarkDirty();
return true;
}
}
}
namespace Oxide.Plugins
{
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
public partial class Imperium
{
private string BetterChat_FormattedFactionTag(IPlayer player)
{
if (Clans)
return null;
Faction faction = Factions.GetByMember(player.Id);
if (faction == null)
return string.Empty;
FactionColorPicker colorPicker = new FactionColorPicker();
return "[" + colorPicker.GetHexColorForFaction(faction.Id) + "][" + faction.Id + "][/#]";
}
}
}
#endregion
#region > Console To Chat
namespace Oxide.Plugins
{
public partial class Imperium
{
[ConsoleCommand("imperium.panel.close")]
private void ccmdImperiumPanelClose(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
User user = player.GetComponent<User>();
if (user == null)
return;
user.Panel.Close();
}
}
}
namespace Oxide.Plugins
{
using UnityEngine;
public partial class Imperium
{
[ConsoleCommand("imperium.panel.opentab")]
private void ccmdImperiumPanelOpenTab(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
User user = player.GetComponent<User>();
if (user == null)
return;
user.Panel.OpenTab(arg.Args[0]);
}
}
}
namespace Oxide.Plugins
{
using UnityEngine;
public partial class Imperium
{
[ConsoleCommand("imperium.panel.opencmd")]
private void ccmdImperiumPanelOpenCmd(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
User user = player.GetComponent<User>();
if (user == null)
return;
user.Panel.OpenCommand(arg.Args[0]);
}
}
}
namespace Oxide.Plugins
{
using UnityEngine;
using System;
using System.Text.RegularExpressions;
public partial class Imperium
{
[ConsoleCommand("imperium.panel.run")]
private void ccmdImperiumPanelRun(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
User user = player.GetComponent<User>();
if (user == null)
return;
string chatCommand = user.Panel.GetFullConsoleCommand();
Regex.Replace(chatCommand, @"[\""]", "\\\"", RegexOptions.None);
player.SendConsoleCommand("chat.say " + chatCommand);
if (Convert.ToBoolean(arg.Args[0]))
{
user.Panel.Close();
}
else
{
user.Panel.ClearCurrentCommand();
user.Panel.Refresh();
}
}
}
}
namespace Oxide.Plugins
{
using System;
using UnityEngine;
public partial class Imperium
{
[ConsoleCommand("imperium.panel.setarg")]
private void ccmdImperiumPanelSetArg(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (!player)
return;
User user = player.GetComponent<User>();
if (!user)
return;
if (arg.Args.Length < 3)
return;
string fullArg = "";
for (int i = 2; i < arg.Args.Length; i++)
{
fullArg = fullArg + arg.Args[i];
if (i != arg.Args.Length - 1)
fullArg = fullArg + " ";
}
user.Panel.SetArg(Convert.ToInt32(arg.Args[0]), fullArg, Convert.ToBoolean(arg.Args[1]));
}
}
}
#endregion
#region > Chat Commands
#region commons
namespace Oxide.Plugins
{
public partial class Imperium
{
[ChatCommand("cancel")]
private void OnCancelCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
if (user.CurrentInteraction == null)
{
user.SendChatMessage(nameof(Messages.NoInteractionInProgress));
return;
}
user.SendChatMessage(nameof(Messages.InteractionCanceled));
user.CancelInteraction();
}
}
}
namespace Oxide.Plugins
{
using System.Text;
public partial class Imperium
{
[ChatCommand("help")]
private void OnHelpCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
if (user == null) return;
var sb = new StringBuilder();
sb.AppendLine($"<size=18>Welcome to {ConVar.Server.hostname}!</size>");
sb.AppendLine($"Powered by {Name} v{Version} by <color=#ffd479>chucklenugget</color> and <color=#ffd479>evict</color>");
sb.AppendLine(
"Do <color=#ffd479>/i</color> to open Imperium UI. You can also do <color=#ffd479>bind i chat.say /i</color> in F1 console to easily toggle Imperium UI");
sb.AppendLine();
sb.Append(
"The following commands are available. To learn more about each command, do <color=#ffd479>/command help</color>. ");
sb.AppendLine("For example, to learn more about how to claim land, do <color=#ffd479>/claim help</color>.");
sb.AppendLine();
sb.AppendLine("<color=#ffd479>/faction</color> Create or join a faction");
sb.AppendLine("<color=#ffd479>/claim</color> Claim areas of land");
if (Options.Taxes.Enabled)
sb.AppendLine("<color=#ffd479>/tax</color> Manage taxation of your land");
if (Options.Map.PinsEnabled)
sb.AppendLine("<color=#ffd479>/pin</color> Add pins (points of interest) to the map");
if (Options.War.Enabled)
sb.AppendLine("<color=#ffd479>/war</color> See active wars, declare war, or offer peace");
if (Options.Badlands.Enabled)
{
if (user.HasPermission(Permission.AdminBadlands))
sb.AppendLine("<color=#ffd479>/badlands</color> Find or change badlands areas");
else
sb.AppendLine("<color=#ffd479>/badlands</color> Find badlands (PVP) areas");
}
user.SendChatMessage(sb);
}
}
}
#endregion
#region /imperium
namespace Oxide.Plugins
{
public partial class Imperium
{
[ChatCommand("i")]
private void OnImperiumCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
user.Panel.Toggle();
}
}
}
#endregion
#region /pvp
namespace Oxide.Plugins
{
public partial class Imperium
{
[ChatCommand("pvp")]
private void OnPvpCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
if (!Options.Pvp.EnablePvpCommand)
{
user.SendChatMessage(nameof(Messages.PvpModeDisabled));
return;
}
if (!EnforceCommandCooldown(user, "pvp", Options.Pvp.CommandCooldownSeconds))
return;
if (user.IsInPvpMode)
{
user.IsInPvpMode = false;
user.SendChatMessage(nameof(Messages.ExitedPvpMode));
Util.RunEffect(user.transform.position, "assets/prefabs/missions/effects/mission_objective_complete.prefab");
}
else
{
user.IsInPvpMode = true;
user.SendChatMessage(nameof(Messages.EnteredPvpMode));
Util.RunEffect(user.transform.position, "assets/prefabs/missions/effects/mission_objective_complete.prefab");
}
user.Hud.Refresh();
}
}
}
#endregion
#region /badlands
namespace Oxide.Plugins
{
using System.Linq;
public partial class Imperium
{
[ChatCommand("badlands")]
private void OnBadlandsCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
if (user == null) return;
if (!Options.Badlands.Enabled)
{
user.SendChatMessage(nameof(Messages.BadlandsDisabled));
return;
}
if (args.Length == 0)
{
var areas = Areas.GetAllByType(AreaType.Badlands).Select(a => a.Id);
user.SendChatMessage(nameof(Messages.BadlandsList), Util.Format(areas), Options.Taxes.BadlandsGatherBonus);
return;
}
if (!user.HasPermission(Permission.AdminBadlands))
{
user.SendChatMessage(nameof(Messages.NoPermission));
return;
}
var areaIds = args.Skip(1).Select(arg => Util.NormalizeAreaId(arg)).ToArray();
switch (args[0].ToLower())
{
case "add":
if (args.Length < 2)
user.SendChatMessage(nameof(Messages.Usage), "/badlands add [XY XY XY...]");
else
OnAddBadlandsCommand(user, areaIds);
break;
case "remove":
if (args.Length < 2)
user.SendChatMessage(nameof(Messages.Usage), "/badlands remove [XY XY XY...]");
else
OnRemoveBadlandsCommand(user, areaIds);
break;
case "set":
if (args.Length < 2)
user.SendChatMessage(nameof(Messages.Usage), "/badlands set [XY XY XY...]");
else
OnSetBadlandsCommand(user, areaIds);
break;
case "clear":
if (args.Length != 1)
user.SendChatMessage(nameof(Messages.Usage), "/badlands clear");
else
OnSetBadlandsCommand(user, new string[0]);
break;
default:
OnBadlandsHelpCommand(user);
break;
}
}
}
}
namespace Oxide.Plugins
{
using System.Collections.Generic;
using System.Linq;
public partial class Imperium
{
private void OnAddBadlandsCommand(User user, string[] args)
{
var areas = new List<Area>();
foreach (string arg in args)
{
Area area = Areas.Get(Util.NormalizeAreaId(arg));
if (area == null)
{
user.SendChatMessage(nameof(Messages.UnknownArea), arg);
return;
}
if (area.Type != AreaType.Wilderness)
{
user.SendChatMessage(nameof(Messages.AreaNotWilderness), area.Id);
return;
}
areas.Add(area);
}
Areas.AddBadlands(areas);
Util.RunEffect(user.transform.position, "assets/prefabs/missions/effects/mission_objective_complete.prefab");
user.SendChatMessage(nameof(Messages.BadlandsSet), Util.Format(Areas.GetAllByType(AreaType.Badlands)));
Log($"{Util.Format(user)} added {Util.Format(areas)} to badlands");
}
}
}
namespace Oxide.Plugins
{
using System.Text;
public partial class Imperium
{
private User user;
private void OnBadlandsHelpCommand(User user)
{
var sb = new StringBuilder();
sb.AppendLine("Available commands:");
sb.AppendLine(" <color=#ffd479>/badlands add XY [XY XY...]</color>: Add area(s) to the badlands");
sb.AppendLine(" <color=#ffd479>/badlands remove XY [XY XY...]</color>: Remove area(s) from the badlands");
sb.AppendLine(" <color=#ffd479>/badlands set XY [XY XY...]</color>: Set the badlands to a list of areas");
sb.AppendLine(" <color=#ffd479>/badlands clear</color>: Remove all areas from the badlands");
sb.AppendLine(" <color=#ffd479>/badlands help</color>: Prints this message");
user.SendChatMessage(sb);
}
}
}
namespace Oxide.Plugins
{
using System.Collections.Generic;
using System.Linq;
public partial class Imperium
{
private void OnRemoveBadlandsCommand(User user, string[] args)
{
var areas = new List<Area>();
foreach (string arg in args)
{
Area area = Areas.Get(Util.NormalizeAreaId(arg));
if (area == null)
{
user.SendChatMessage(nameof(Messages.UnknownArea), arg);
return;
}
if (area.Type != AreaType.Badlands)
{
user.SendChatMessage(nameof(Messages.AreaNotBadlands), area.Id);
return;
}
areas.Add(area);
}
Areas.Unclaim(areas);
Util.RunEffect(user.transform.position, "assets/prefabs/missions/effects/mission_objective_complete.prefab");
user.SendChatMessage(nameof(Messages.BadlandsSet), Util.Format(Areas.GetAllByType(AreaType.Badlands)));
Log($"{Util.Format(user)} removed {Util.Format(areas)} from badlands");
}
}
}
namespace Oxide.Plugins
{
using System.Collections.Generic;
using System.Linq;
public partial class Imperium
{
private void OnSetBadlandsCommand(User user, string[] args)
{
var areas = new List<Area>();
foreach (string arg in args)
{
Area area = Areas.Get(Util.NormalizeAreaId(arg));
if (area == null)
{
user.SendChatMessage(nameof(Messages.UnknownArea), arg);
return;
}
if (area.Type != AreaType.Wilderness)
{
user.SendChatMessage(nameof(Messages.AreaNotWilderness), area.Id);
return;
}
areas.Add(area);
}
Areas.Unclaim(Areas.GetAllByType(AreaType.Badlands));
Areas.AddBadlands(areas);
Util.RunEffect(user.transform.position, "assets/prefabs/missions/effects/mission_objective_complete.prefab");
user.SendChatMessage(nameof(Messages.BadlandsSet), Util.Format(Areas.GetAllByType(AreaType.Badlands)));
Log($"{Util.Format(user)} set badlands to {Util.Format(areas)}");
}
}
}
#endregion
#region /claim
namespace Oxide.Plugins
{
using System.Linq;
public partial class Imperium
{
[ChatCommand("claim")]
private void OnClaimCommand(BasePlayer player, string command, string[] args)
{
User user = Users.Get(player);
if (user == null) return;
if (!Options.Claims.Enabled)
{
user.SendChatMessage(nameof(Messages.AreaClaimsDisabled));
return;
}
if (args.Length == 0)
{
OnClaimAddCommand(user);
return;
}
var restArguments = args.Skip(1).ToArray();
switch (args[0].ToLower())
{
case "add":
OnClaimAddCommand(user);
break;
case "remove":
OnClaimRemoveCommand(user);
break;
case "hq":
OnClaimHeadquartersCommand(user);
break;
case "rename":
OnClaimRenameCommand(user, restArguments);
break;
case "give":
OnClaimGiveCommand(user, restArguments);
break;
case "cost":
OnClaimCostCommand(user, restArguments);
break;
case "upkeep":
OnClaimUpkeepCommand(user);
break;
case "show":
OnClaimShowCommand(user, restArguments);
break;
case "list":
OnClaimListCommand(user, restArguments);
break;
case "assign":
OnClaimAssignCommand(user, restArguments);
break;
case "delete":
OnClaimDeleteCommand(user, restArguments);
break;
case "info":
case "upgrade":
default:
OnClaimHelpCommand(user);
break;
}
}
}
}
namespace Oxide.Plugins
{
public partial class Imperium
{
private void OnClaimAddCommand(User user)
{
Faction faction = Factions.GetByMember(user);
if (!EnsureUserCanChangeFactionClaims(user, faction))
return;
user.SendChatMessage(nameof(Messages.SelectClaimCupboardToAdd));
user.BeginInteraction(new AddingClaimInteraction(faction));
}
}
}
namespace Oxide.Plugins