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 | if (_senderInfo.RemoteClientInfo != null) {
|
---|
28 | if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {
|
---|
29 | _params.Add (_senderInfo.RemoteClientInfo.playerId);
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | World w = GameManager.Instance.World;
|
---|
34 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
35 |
|
---|
36 | bool summaryOnly = false;
|
---|
37 | string steamIdFilter = string.Empty;
|
---|
38 | Vector3i closeTo = default (Vector3i);
|
---|
39 | bool onlyCloseToPlayer = false;
|
---|
40 | int closeToDistance = 32;
|
---|
41 | bool parseableOutput = false;
|
---|
42 |
|
---|
43 | if (_params.Contains ("parseable")) {
|
---|
44 | parseableOutput = true;
|
---|
45 | _params.Remove ("parseable");
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (_params.Count == 1) {
|
---|
49 | long tempLong;
|
---|
50 |
|
---|
51 | if (_params [0].EqualsCaseInsensitive ("summary")) {
|
---|
52 | summaryOnly = true;
|
---|
53 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
|
---|
54 | steamIdFilter = _params [0];
|
---|
55 | } else {
|
---|
56 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
57 | if (ci != null) {
|
---|
58 | steamIdFilter = ci.playerId;
|
---|
59 | } else {
|
---|
60 | SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | } else if (_params.Count >= 2) {
|
---|
65 | if (_params [0].EqualsCaseInsensitive ("nearby")) {
|
---|
66 | try {
|
---|
67 | if (_params.Count == 3) {
|
---|
68 | if (!int.TryParse (_params [1], out closeToDistance)) {
|
---|
69 | SdtdConsole.Instance.Output ("Given length is not an integer!");
|
---|
70 | return;
|
---|
71 | }
|
---|
72 |
|
---|
73 | closeToDistance /= 2;
|
---|
74 | }
|
---|
75 |
|
---|
76 | ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
|
---|
77 | EntityPlayer ep = w.Players.dict [ci.entityId];
|
---|
78 | closeTo = new Vector3i (ep.GetPosition ());
|
---|
79 | onlyCloseToPlayer = true;
|
---|
80 | } catch (Exception e) {
|
---|
81 | SdtdConsole.Instance.Output ("Error getting current player's position");
|
---|
82 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
83 | return;
|
---|
84 | }
|
---|
85 | } else {
|
---|
86 | SdtdConsole.Instance.Output ("Illegal parameter list");
|
---|
87 | return;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | LandClaimList.OwnerFilter[] ownerFilters = null;
|
---|
93 | if (!string.IsNullOrEmpty (steamIdFilter)) {
|
---|
94 | ownerFilters = new[] {LandClaimList.SteamIdFilter (steamIdFilter)};
|
---|
95 | }
|
---|
96 |
|
---|
97 | LandClaimList.PositionFilter[] posFilters = null;
|
---|
98 | if (onlyCloseToPlayer) {
|
---|
99 | posFilters = new[] {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)};
|
---|
100 | }
|
---|
101 |
|
---|
102 | Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
|
---|
103 |
|
---|
104 | foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) {
|
---|
105 | SdtdConsole.Instance.Output (string.Format (
|
---|
106 | "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
|
---|
107 | kvp.Key.Name,
|
---|
108 | kvp.Key.SteamID,
|
---|
109 | kvp.Key.LandProtectionActive,
|
---|
110 | kvp.Key.LandProtectionMultiplier,
|
---|
111 | kvp.Value.Count));
|
---|
112 | if (!summaryOnly) {
|
---|
113 | foreach (Vector3i v in kvp.Value) {
|
---|
114 | if (parseableOutput) {
|
---|
115 | SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.SteamID +
|
---|
116 | ", playerName=" + kvp.Key.Name + ", location=" + v);
|
---|
117 | } else {
|
---|
118 | SdtdConsole.Instance.Output (" (" + v + ")");
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | if (string.IsNullOrEmpty (steamIdFilter)) {
|
---|
125 | SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|