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

Last change on this file since 295 was 273, checked in by alloc, 9 years ago

fixes 8_10_13_1

File size: 4.6 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
6 public class ListLandProtection : ConsoleCmdAbstract
7 {
8 public override string GetDescription ()
9 {
10 return "lists all land protection blocks and owners";
11 }
12
13 public override string GetHelp () {
14 return "Usage:\n" +
15 " 1. listlandprotection summary\n" +
16 " 2. listlandprotection <steam 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 SteamID / 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 public override string[] GetCommands ()
25 {
26 return new string[] { "listlandprotection", "llp" };
27 }
28
29 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
30 {
31 try {
32 if (_senderInfo.RemoteClientInfo != null) {
33 if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
34 _params.Add (_senderInfo.RemoteClientInfo.playerId);
35 }
36 }
37
38 World w = GameManager.Instance.World;
39 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
40
41 bool summaryOnly = false;
42 string steamIdFilter = string.Empty;
43 Vector3i closeTo = default(Vector3i);
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 long tempLong;
55
56 if (_params [0].ToLower ().Equals ("summary")) {
57 summaryOnly = true;
58 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
59 steamIdFilter = _params [0];
60 } else {
61 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
62 if (ci != null) {
63 steamIdFilter = ci.playerId;
64 } else {
65 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
66 return;
67 }
68 }
69 } else if (_params.Count >= 2) {
70 if (_params [0].ToLower ().Equals ("nearby")) {
71 try {
72 if (_params.Count == 3) {
73 if (!int.TryParse (_params[1], out closeToDistance)) {
74 SdtdConsole.Instance.Output ("Given length is not an integer!");
75 return;
76 }
77 closeToDistance /= 2;
78 }
79 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
80 EntityPlayer ep = w.Players.dict [ci.entityId];
81 closeTo = new Vector3i (ep.GetPosition ());
82 onlyCloseToPlayer = true;
83 } catch (Exception e) {
84 SdtdConsole.Instance.Output ("Error getting current player's position");
85 Log.Out ("Error in ListLandProtection.Run: " + e);
86 return;
87 }
88 } else {
89 SdtdConsole.Instance.Output ("Illegal parameter list");
90 return;
91 }
92 }
93
94
95 LandClaimList.OwnerFilter[] ownerFilters = null;
96 if (!string.IsNullOrEmpty (steamIdFilter)) {
97 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (steamIdFilter) };
98 }
99 LandClaimList.PositionFilter[] posFilters = null;
100 if (onlyCloseToPlayer) {
101 posFilters = new LandClaimList.PositionFilter[] { LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance) };
102 }
103
104 Dictionary<PersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
105
106 foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) {
107 SdtdConsole.Instance.Output (String.Format (
108 "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
109 kvp.Key.Name,
110 kvp.Key.SteamID,
111 kvp.Key.LandProtectionActive,
112 kvp.Key.LandProtectionMultiplier,
113 kvp.Value.Count));
114 if (!summaryOnly) {
115 foreach (Vector3i v in kvp.Value) {
116 if (parseableOutput) {
117 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.SteamID + ", playerName=" + kvp.Key.Name + ", location=" + v.ToString ());
118 } else {
119 SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
120 }
121 }
122 }
123 }
124
125 if (steamIdFilter.Length == 0)
126 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
127 } catch (Exception e) {
128 Log.Out ("Error in ListLandProtection.Run: " + e);
129 }
130 }
131 }
132}
Note: See TracBrowser for help on using the repository browser.