1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using AllocsFixes.PersistentData;
|
---|
4 |
|
---|
5 | namespace AllocsFixes.CustomCommands {
|
---|
6 | public class ListLandProtection : ConsoleCmdAbstract {
|
---|
7 | protected override string getDescription () {
|
---|
8 | return "lists all land protection blocks and owners";
|
---|
9 | }
|
---|
10 |
|
---|
11 | protected override string getHelp () {
|
---|
12 | return "Usage:\n" +
|
---|
13 | " 1. listlandprotection summary\n" +
|
---|
14 | " 2. listlandprotection <user 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 UserID / 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 | protected override string[] getCommands () {
|
---|
23 | return new[] {"listlandprotection", "llp"};
|
---|
24 | }
|
---|
25 |
|
---|
26 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
27 | if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {
|
---|
28 | if (_senderInfo.RemoteClientInfo != null) {
|
---|
29 | _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ());
|
---|
30 | } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) {
|
---|
31 | _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ());
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | World w = GameManager.Instance.World;
|
---|
36 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
37 |
|
---|
38 | bool summaryOnly = false;
|
---|
39 | PlatformUserIdentifierAbs userIdFilter = null;
|
---|
40 | Vector3i closeTo = default (Vector3i);
|
---|
41 | bool onlyCloseToPlayer = false;
|
---|
42 | int closeToDistance = 32;
|
---|
43 | bool parseableOutput = false;
|
---|
44 |
|
---|
45 | if (_params.Contains ("parseable")) {
|
---|
46 | parseableOutput = true;
|
---|
47 | _params.Remove ("parseable");
|
---|
48 | }
|
---|
49 |
|
---|
50 | if (_params.Count == 1) {
|
---|
51 | if (_params [0].EqualsCaseInsensitive ("summary")) {
|
---|
52 | summaryOnly = true;
|
---|
53 | } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params[0], out userIdFilter)) {
|
---|
54 | } else {
|
---|
55 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
56 | if (ci != null) {
|
---|
57 | userIdFilter = ci.InternalId;
|
---|
58 | } else {
|
---|
59 | SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
60 | return;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | } else if (_params.Count >= 2) {
|
---|
64 | if (_params [0].EqualsCaseInsensitive ("nearby")) {
|
---|
65 | try {
|
---|
66 | if (_params.Count == 3) {
|
---|
67 | if (!int.TryParse (_params [1], out closeToDistance)) {
|
---|
68 | SdtdConsole.Instance.Output ("Given length is not an integer!");
|
---|
69 | return;
|
---|
70 | }
|
---|
71 |
|
---|
72 | closeToDistance /= 2;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int entityId = int.Parse (_params [_params.Count - 1]);
|
---|
76 | EntityPlayer ep = w.Players.dict [entityId];
|
---|
77 | closeTo = new Vector3i (ep.GetPosition ());
|
---|
78 | onlyCloseToPlayer = true;
|
---|
79 | } catch (Exception e) {
|
---|
80 | SdtdConsole.Instance.Output ("Error getting current player's position");
|
---|
81 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
82 | return;
|
---|
83 | }
|
---|
84 | } else {
|
---|
85 | SdtdConsole.Instance.Output ("Illegal parameter list");
|
---|
86 | return;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | LandClaimList.OwnerFilter[] ownerFilters = null;
|
---|
92 | if (userIdFilter != null) {
|
---|
93 | ownerFilters = new[] {LandClaimList.UserIdFilter (userIdFilter)};
|
---|
94 | }
|
---|
95 |
|
---|
96 | LandClaimList.PositionFilter[] posFilters = null;
|
---|
97 | if (onlyCloseToPlayer) {
|
---|
98 | posFilters = new[] {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)};
|
---|
99 | }
|
---|
100 |
|
---|
101 | Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
|
---|
102 |
|
---|
103 | foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) {
|
---|
104 | SdtdConsole.Instance.Output (string.Format (
|
---|
105 | "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})",
|
---|
106 | kvp.Key.Name,
|
---|
107 | kvp.Key.InternalId,
|
---|
108 | kvp.Key.LandProtectionActive,
|
---|
109 | kvp.Key.LandProtectionMultiplier,
|
---|
110 | kvp.Value.Count));
|
---|
111 | if (!summaryOnly) {
|
---|
112 | foreach (Vector3i v in kvp.Value) {
|
---|
113 | if (parseableOutput) {
|
---|
114 | SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.InternalId +
|
---|
115 | ", playerName=" + kvp.Key.Name + ", location=" + v);
|
---|
116 | } else {
|
---|
117 | SdtdConsole.Instance.Output (" (" + v + ")");
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | if (userIdFilter == null) {
|
---|
124 | SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|