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

Last change on this file since 260 was 253, checked in by alloc, 9 years ago

Fixes 6_8_10

File size: 4.3 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" +
15 " 1. listlandprotection summary\n" +
16 " 2. listlandprotection <steam id>\n" +
17 " 3. listlandprotection <player name / entity id>\n" +
18 " 4. listlandprotection nearby\n" +
19 " 5. listlandprotection nearby <radius>\n" +
20 "1. Lists only players that own claimstones, the number they own and the protection status\n" +
21 "2. Lists only the claims of the player given by his SteamID including the individual claim positions\n" +
22 "3. Same as 2 but player given by his player name or entity id (as given by e.g. \"lpi\")\n" +
23 "4. Lists claims in a square with edge length of 64 around the executing player\n" +
24 "5. Same as 4 but square edge length can be specified";
25 }
26
[230]27 public override string[] GetCommands ()
[224]28 {
29 return new string[] { "listlandprotection", "llp" };
30 }
31
[230]32 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]33 {
34 try {
[230]35 if (_senderInfo.RemoteClientInfo != null) {
36 if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
37 _params.Add (_senderInfo.RemoteClientInfo.playerId);
38 }
[224]39 }
40
[230]41 World w = GameManager.Instance.World;
42 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]43
44 bool summaryOnly = false;
45 string steamIdFilter = string.Empty;
46 Vector3i closeTo = default(Vector3i);
47 bool onlyCloseToPlayer = false;
48 int closeToDistance = 32;
49
[230]50 if (_params.Count == 1) {
[224]51 long tempLong;
52
53 if (_params [0].ToLower ().Equals ("summary")) {
54 summaryOnly = true;
55 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
56 steamIdFilter = _params [0];
57 } else {
[230]58 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]59 if (ci != null) {
[230]60 steamIdFilter = ci.playerId;
[224]61 } else {
[230]62 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
[224]63 return;
64 }
65 }
[230]66 } else if (_params.Count >= 2) {
[224]67 if (_params [0].ToLower ().Equals ("nearby")) {
68 try {
[230]69 if (_params.Count == 3) {
[224]70 if (!int.TryParse (_params[1], out closeToDistance)) {
[230]71 SdtdConsole.Instance.Output ("Given radius is not an integer!");
[224]72 }
73 }
[230]74 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
75 EntityPlayer ep = w.Players.dict [ci.entityId];
[224]76 closeTo = new Vector3i (ep.GetPosition ());
77 onlyCloseToPlayer = true;
78 } catch (Exception e) {
[230]79 SdtdConsole.Instance.Output ("Error getting current player's position");
[224]80 Log.Out ("Error in ListLandProtection.Run: " + e);
81 }
82 } else {
[230]83 SdtdConsole.Instance.Output ("Illegal parameter list");
[224]84 return;
85 }
86 }
87
88
[253]89 LandClaimList.OwnerFilter[] ownerFilters = null;
90 if (!string.IsNullOrEmpty (steamIdFilter)) {
91 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (steamIdFilter) };
92 }
93 LandClaimList.PositionFilter[] posFilters = null;
94 if (onlyCloseToPlayer) {
95 posFilters = new LandClaimList.PositionFilter[] { LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance) };
96 }
[224]97
[253]98 Dictionary<PersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
99
100 foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) {
101 SdtdConsole.Instance.Output (String.Format (
102 "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
103 kvp.Key.Name,
104 kvp.Key.SteamID,
105 kvp.Key.LandProtectionActive,
106 kvp.Key.LandProtectionMultiplier,
107 kvp.Value.Count));
108 if (!summaryOnly) {
109 foreach (Vector3i v in kvp.Value) {
110 SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
[224]111 }
112 }
113 }
114
115 if (steamIdFilter.Length == 0)
[253]116 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
[224]117 } catch (Exception e) {
118 Log.Out ("Error in ListLandProtection.Run: " + e);
119 }
120 }
121 }
122}
Note: See TracBrowser for help on using the repository browser.