source: binary-improvements/AllocsCommands/Commands/ListLandProtection.cs@ 457

Last change on this file since 457 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 4.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using AllocsFixes.PersistentData;
4using JetBrains.Annotations;
5
6namespace AllocsFixes.CustomCommands {
7 [UsedImplicitly]
8 public class ListLandProtection : ConsoleCmdAbstract {
9 protected override string getDescription () {
10 return "lists all land protection blocks and owners";
11 }
12
13 protected override string getHelp () {
14 return "Usage:\n" +
15 " 1. listlandprotection summary\n" +
16 " 2. listlandprotection <user id / player name / entity id> [parseable]\n" +
17 " 3. listlandprotection nearby [length]\n" +
18 "1. Lists only players that own claimstones, the number they own and the protection status\n" +
19 "2. Lists only the claims of the player given by his UserID / entity id / playername, including the individual claim positions.\n" +
20 " If \"parseable\" is specified the output of the individual claims will be in a format better suited for programmatical readout.\n" +
21 "3. Lists claims in a square with edge length of 64 (or the optionally specified size) around the executing player\n";
22 }
23
24 protected override string[] getCommands () {
25 return new[] {"listlandprotection", "llp"};
26 }
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
29 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {
30 if (_senderInfo.RemoteClientInfo != null) {
31 _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ());
32 } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) {
33 _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ());
34 }
35 }
36
37 World w = GameManager.Instance.World;
38 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
39
40 bool summaryOnly = false;
41 PlatformUserIdentifierAbs userIdFilter = null;
42 Vector3i closeTo = default (Vector3i);
43 bool onlyCloseToPlayer = false;
44 int closeToDistance = 32;
45 bool parseableOutput = false;
46
47 if (_params.Contains ("parseable")) {
48 parseableOutput = true;
49 _params.Remove ("parseable");
50 }
51
52 if (_params.Count == 1) {
53 if (_params [0].EqualsCaseInsensitive ("summary")) {
54 summaryOnly = true;
55 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params[0], out userIdFilter)) {
56 } else {
57 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
58 if (ci != null) {
59 userIdFilter = ci.InternalId;
60 } else {
61 SdtdConsole.Instance.Output ($"Player name or entity id \"{_params[0]}\" not found.");
62 return;
63 }
64 }
65 } else if (_params.Count >= 2) {
66 if (_params [0].EqualsCaseInsensitive ("nearby")) {
67 try {
68 if (_params.Count == 3) {
69 if (!int.TryParse (_params [1], out closeToDistance)) {
70 SdtdConsole.Instance.Output ("Given length is not an integer!");
71 return;
72 }
73
74 closeToDistance /= 2;
75 }
76
77 int entityId = int.Parse (_params [_params.Count - 1]);
78 EntityPlayer ep = w.Players.dict [entityId];
79 closeTo = new Vector3i (ep.GetPosition ());
80 onlyCloseToPlayer = true;
81 } catch (Exception e) {
82 SdtdConsole.Instance.Output ("Error getting current player's position");
83 Log.Out ($"Error in ListLandProtection.Run: {e}");
84 return;
85 }
86 } else {
87 SdtdConsole.Instance.Output ("Illegal parameter list");
88 return;
89 }
90 }
91
92
93 LandClaimList.OwnerFilter[] ownerFilters = null;
94 if (userIdFilter != null) {
95 ownerFilters = new[] {LandClaimList.UserIdFilter (userIdFilter)};
96 }
97
98 LandClaimList.PositionFilter[] posFilters = null;
99 if (onlyCloseToPlayer) {
100 posFilters = new[] {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)};
101 }
102
103 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
104
105 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) {
106 SdtdConsole.Instance.Output (
107 $"Player \"{kvp.Key.Name} ({kvp.Key.InternalId})\" owns {kvp.Value.Count} keystones (protected: {kvp.Key.LandProtectionActive}, current hardness multiplier: {kvp.Key.LandProtectionMultiplier})");
108 if (summaryOnly) {
109 continue;
110 }
111
112 foreach (Vector3i v in kvp.Value) {
113 if (parseableOutput) {
114 SdtdConsole.Instance.Output ($"LandProtectionOf: id={kvp.Key.InternalId}, playerName={kvp.Key.Name}, location={v}");
115 } else {
116 SdtdConsole.Instance.Output ($" ({v})");
117 }
118 }
119 }
120
121 if (userIdFilter == null) {
122 SdtdConsole.Instance.Output ($"Total of {ppl.m_lpBlockMap.Count} keystones in the game");
123 }
124 }
125 }
126}
Note: See TracBrowser for help on using the repository browser.