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