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

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

fixes 8_10_13_1

File size: 4.6 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
[230]6 public class ListLandProtection : ConsoleCmdAbstract
[224]7 {
[230]8 public override string GetDescription ()
[224]9 {
10 return "lists all land protection blocks and owners";
11 }
12
[238]13 public override string GetHelp () {
14 return "Usage:\n" +
[273]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";
[238]22 }
23
[230]24 public override string[] GetCommands ()
[224]25 {
26 return new string[] { "listlandprotection", "llp" };
27 }
28
[230]29 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]30 {
31 try {
[230]32 if (_senderInfo.RemoteClientInfo != null) {
33 if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
34 _params.Add (_senderInfo.RemoteClientInfo.playerId);
35 }
[224]36 }
37
[230]38 World w = GameManager.Instance.World;
39 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]40
41 bool summaryOnly = false;
42 string steamIdFilter = string.Empty;
43 Vector3i closeTo = default(Vector3i);
44 bool onlyCloseToPlayer = false;
45 int closeToDistance = 32;
[273]46 bool parseableOutput = false;
[224]47
[273]48 if (_params.Contains ("parseable")) {
49 parseableOutput = true;
50 _params.Remove ("parseable");
51 }
52
[230]53 if (_params.Count == 1) {
[224]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 {
[230]61 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]62 if (ci != null) {
[230]63 steamIdFilter = ci.playerId;
[224]64 } else {
[230]65 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
[224]66 return;
67 }
68 }
[230]69 } else if (_params.Count >= 2) {
[224]70 if (_params [0].ToLower ().Equals ("nearby")) {
71 try {
[230]72 if (_params.Count == 3) {
[224]73 if (!int.TryParse (_params[1], out closeToDistance)) {
[273]74 SdtdConsole.Instance.Output ("Given length is not an integer!");
75 return;
[224]76 }
[273]77 closeToDistance /= 2;
[224]78 }
[230]79 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
80 EntityPlayer ep = w.Players.dict [ci.entityId];
[224]81 closeTo = new Vector3i (ep.GetPosition ());
82 onlyCloseToPlayer = true;
83 } catch (Exception e) {
[230]84 SdtdConsole.Instance.Output ("Error getting current player's position");
[224]85 Log.Out ("Error in ListLandProtection.Run: " + e);
[273]86 return;
[224]87 }
88 } else {
[230]89 SdtdConsole.Instance.Output ("Illegal parameter list");
[224]90 return;
91 }
92 }
93
94
[253]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 }
[224]103
[253]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) {
[273]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 }
[224]121 }
122 }
123 }
124
125 if (steamIdFilter.Length == 0)
[253]126 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
[224]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.