source: binary-improvements2/CommandExtensions/src/Commands/ListLandProtection.cs@ 394

Last change on this file since 394 was 391, checked in by alloc, 2 years ago

Major refactoring/cleanup

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