1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | namespace AllocsFixes.CustomCommands
|
---|
5 | {
|
---|
6 | public class ListLandProtection : ConsoleCmdAbstract
|
---|
7 | {
|
---|
8 | public override string GetDescription ()
|
---|
9 | {
|
---|
10 | return "lists all land protection blocks and owners";
|
---|
11 | }
|
---|
12 |
|
---|
13 | public override string[] GetCommands ()
|
---|
14 | {
|
---|
15 | return new string[] { "listlandprotection", "llp" };
|
---|
16 | }
|
---|
17 |
|
---|
18 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
---|
19 | {
|
---|
20 | try {
|
---|
21 | if (_senderInfo.RemoteClientInfo != null) {
|
---|
22 | if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
|
---|
23 | _params.Add (_senderInfo.RemoteClientInfo.playerId);
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | World w = GameManager.Instance.World;
|
---|
28 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
29 |
|
---|
30 | bool summaryOnly = false;
|
---|
31 | string steamIdFilter = string.Empty;
|
---|
32 | Vector3i closeTo = default(Vector3i);
|
---|
33 | bool onlyCloseToPlayer = false;
|
---|
34 | int closeToDistance = 32;
|
---|
35 |
|
---|
36 | if (_params.Count == 1) {
|
---|
37 | long tempLong;
|
---|
38 |
|
---|
39 | if (_params [0].ToLower ().Equals ("summary")) {
|
---|
40 | summaryOnly = true;
|
---|
41 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
|
---|
42 | steamIdFilter = _params [0];
|
---|
43 | } else {
|
---|
44 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
45 | if (ci != null) {
|
---|
46 | steamIdFilter = ci.playerId;
|
---|
47 | } else {
|
---|
48 | SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
49 | return;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | } else if (_params.Count >= 2) {
|
---|
53 | if (_params [0].ToLower ().Equals ("nearby")) {
|
---|
54 | try {
|
---|
55 | if (_params.Count == 3) {
|
---|
56 | if (!int.TryParse (_params[1], out closeToDistance)) {
|
---|
57 | SdtdConsole.Instance.Output ("Given radius is not an integer!");
|
---|
58 | }
|
---|
59 | }
|
---|
60 | ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
|
---|
61 | EntityPlayer ep = w.Players.dict [ci.entityId];
|
---|
62 | closeTo = new Vector3i (ep.GetPosition ());
|
---|
63 | onlyCloseToPlayer = true;
|
---|
64 | } catch (Exception e) {
|
---|
65 | SdtdConsole.Instance.Output ("Error getting current player's position");
|
---|
66 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
67 | }
|
---|
68 | } else {
|
---|
69 | SdtdConsole.Instance.Output ("Illegal parameter list");
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
|
---|
75 | if (d != null) {
|
---|
76 | Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
|
---|
77 | foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
|
---|
78 | if (!onlyCloseToPlayer || (Math.Abs (kvp.Key.x - closeTo.x) <= closeToDistance && Math.Abs (kvp.Key.z - closeTo.z) <= closeToDistance)) {
|
---|
79 | if (!owners.ContainsKey (kvp.Value)) {
|
---|
80 | owners.Add (kvp.Value, new List<Vector3i> ());
|
---|
81 | }
|
---|
82 | owners [kvp.Value].Add (kvp.Key);
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
|
---|
87 | if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
|
---|
88 | PersistentData.Player p = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId, false];
|
---|
89 | string name = string.Empty;
|
---|
90 | if (p != null) {
|
---|
91 | name = p.Name;
|
---|
92 | }
|
---|
93 | name += " (" + kvp.Key.PlayerId + ")";
|
---|
94 |
|
---|
95 | SdtdConsole.Instance.Output (String.Format ("Player \"{0}\" owns {3} keystones (protected: {1}, current hardness multiplier: {2})", name, w.LandClaimIsActive (kvp.Key), w.LandClaimPower (kvp.Key), kvp.Value.Count));
|
---|
96 | if (!summaryOnly) {
|
---|
97 | foreach (Vector3i v in kvp.Value) {
|
---|
98 | SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (steamIdFilter.Length == 0)
|
---|
106 | SdtdConsole.Instance.Output ("Total of " + d.Count + " keystones in the game");
|
---|
107 | } catch (Exception e) {
|
---|
108 | Log.Out ("Error in ListLandProtection.Run: " + e);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|