1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using AllocsFixes.PersistentData;
|
---|
4 |
|
---|
5 | namespace AllocsFixes.CustomCommands {
|
---|
6 | public class ListLandProtection : ConsoleCmdAbstract {
|
---|
7 | public override string GetDescription () {
|
---|
8 | return "lists all land protection blocks and owners";
|
---|
9 | }
|
---|
10 |
|
---|
11 | public override string GetHelp () {
|
---|
12 | return "Usage:\n" +
|
---|
13 | " 1. listlandprotection summary\n" +
|
---|
14 | " 2. listlandprotection <steam id / player name / entity id> [parseable]\n" +
|
---|
15 | " 3. listlandprotection nearby [length]\n" +
|
---|
16 | "1. Lists only players that own claimstones, the number they own and the protection status\n" +
|
---|
17 | "2. Lists only the claims of the player given by his SteamID / entity id / playername, including the individual claim positions.\n" +
|
---|
18 | " If \"parseable\" is specified the output of the individual claims will be in a format better suited for programmatical readout.\n" +
|
---|
19 | "3. Lists claims in a square with edge length of 64 (or the optionally specified size) around the executing player\n";
|
---|
20 | }
|
---|
21 |
|
---|
22 | public override string[] GetCommands () {
|
---|
23 | return new[] {"listlandprotection", "llp"};
|
---|
24 | }
|
---|
25 |
|
---|
26 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
27 | try {
|
---|
28 | if (_senderInfo.RemoteClientInfo != null) {
|
---|
29 | if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {
|
---|
30 | _params.Add (_senderInfo.RemoteClientInfo.playerId);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | World w = GameManager.Instance.World;
|
---|
35 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
36 |
|
---|
37 | bool summaryOnly = false;
|
---|
38 | string steamIdFilter = string.Empty;
|
---|
39 | Vector3i closeTo = default (Vector3i);
|
---|
40 | bool onlyCloseToPlayer = false;
|
---|
41 | int closeToDistance = 32;
|
---|
42 | bool parseableOutput = false;
|
---|
43 |
|
---|
44 | if (_params.Contains ("parseable")) {
|
---|
45 | parseableOutput = true;
|
---|
46 | _params.Remove ("parseable");
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (_params.Count == 1) {
|
---|
50 | long tempLong;
|
---|
51 |
|
---|
52 | if (_params [0].EqualsCaseInsensitive ("summary")) {
|
---|
53 | summaryOnly = true;
|
---|
54 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
|
---|
55 | steamIdFilter = _params [0];
|
---|
56 | } else {
|
---|
57 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
58 | if (ci != null) {
|
---|
59 | steamIdFilter = ci.playerId;
|
---|
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 | ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
|
---|
78 | EntityPlayer ep = w.Players.dict [ci.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 (!string.IsNullOrEmpty (steamIdFilter)) {
|
---|
95 | ownerFilters = new[] {LandClaimList.SteamIdFilter (steamIdFilter)};
|
---|
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 (string.Format (
|
---|
107 | "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
|
---|
108 | kvp.Key.Name,
|
---|
109 | kvp.Key.SteamID,
|
---|
110 | kvp.Key.LandProtectionActive,
|
---|
111 | kvp.Key.LandProtectionMultiplier,
|
---|
112 | kvp.Value.Count));
|
---|
113 | if (!summaryOnly) {
|
---|
114 | foreach (Vector3i v in kvp.Value) {
|
---|
115 | if (parseableOutput) {
|
---|
116 | SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.SteamID +
|
---|
117 | ", playerName=" + kvp.Key.Name + ", location=" + v);
|
---|
118 | } else {
|
---|
119 | SdtdConsole.Instance.Output (" (" + v + ")");
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (string.IsNullOrEmpty (steamIdFilter)) {
|
---|
126 | SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
|
---|
127 | }
|
---|
128 | } catch (Exception e) {
|
---|
129 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|