[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 {
|
---|
[420] | 7 | protected override string getDescription () {
|
---|
[224] | 8 | return "lists all land protection blocks and owners";
|
---|
| 9 | }
|
---|
| 10 |
|
---|
[420] | 11 | protected override string getHelp () {
|
---|
[238] | 12 | return "Usage:\n" +
|
---|
[325] | 13 | " 1. listlandprotection summary\n" +
|
---|
[369] | 14 | " 2. listlandprotection <user id / player name / entity id> [parseable]\n" +
|
---|
[325] | 15 | " 3. listlandprotection nearby [length]\n" +
|
---|
| 16 | "1. Lists only players that own claimstones, the number they own and the protection status\n" +
|
---|
[369] | 17 | "2. Lists only the claims of the player given by his UserID / entity id / playername, including the individual claim positions.\n" +
|
---|
[325] | 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 |
|
---|
[420] | 22 | protected override string[] getCommands () {
|
---|
[325] | 23 | return new[] {"listlandprotection", "llp"};
|
---|
[224] | 24 | }
|
---|
| 25 |
|
---|
[325] | 26 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
[369] | 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 ());
|
---|
[224] | 32 | }
|
---|
[359] | 33 | }
|
---|
[224] | 34 |
|
---|
[359] | 35 | World w = GameManager.Instance.World;
|
---|
| 36 | PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
|
---|
[224] | 37 |
|
---|
[359] | 38 | bool summaryOnly = false;
|
---|
[369] | 39 | PlatformUserIdentifierAbs userIdFilter = null;
|
---|
[359] | 40 | Vector3i closeTo = default (Vector3i);
|
---|
| 41 | bool onlyCloseToPlayer = false;
|
---|
| 42 | int closeToDistance = 32;
|
---|
| 43 | bool parseableOutput = false;
|
---|
[224] | 44 |
|
---|
[359] | 45 | if (_params.Contains ("parseable")) {
|
---|
| 46 | parseableOutput = true;
|
---|
| 47 | _params.Remove ("parseable");
|
---|
| 48 | }
|
---|
[273] | 49 |
|
---|
[359] | 50 | if (_params.Count == 1) {
|
---|
| 51 | if (_params [0].EqualsCaseInsensitive ("summary")) {
|
---|
| 52 | summaryOnly = true;
|
---|
[369] | 53 | } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params[0], out userIdFilter)) {
|
---|
[359] | 54 | } else {
|
---|
| 55 | ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
---|
| 56 | if (ci != null) {
|
---|
[371] | 57 | userIdFilter = ci.InternalId;
|
---|
[224] | 58 | } else {
|
---|
[359] | 59 | SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
|
---|
| 60 | return;
|
---|
[224] | 61 | }
|
---|
[359] | 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;
|
---|
[224] | 70 | }
|
---|
[325] | 71 |
|
---|
[359] | 72 | closeToDistance /= 2;
|
---|
[224] | 73 | }
|
---|
[359] | 74 |
|
---|
[369] | 75 | int entityId = int.Parse (_params [_params.Count - 1]);
|
---|
| 76 | EntityPlayer ep = w.Players.dict [entityId];
|
---|
[359] | 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);
|
---|
[224] | 82 | return;
|
---|
| 83 | }
|
---|
[359] | 84 | } else {
|
---|
| 85 | SdtdConsole.Instance.Output ("Illegal parameter list");
|
---|
| 86 | return;
|
---|
[224] | 87 | }
|
---|
[359] | 88 | }
|
---|
[224] | 89 |
|
---|
| 90 |
|
---|
[359] | 91 | LandClaimList.OwnerFilter[] ownerFilters = null;
|
---|
[369] | 92 | if (userIdFilter != null) {
|
---|
| 93 | ownerFilters = new[] {LandClaimList.UserIdFilter (userIdFilter)};
|
---|
[359] | 94 | }
|
---|
[325] | 95 |
|
---|
[359] | 96 | LandClaimList.PositionFilter[] posFilters = null;
|
---|
| 97 | if (onlyCloseToPlayer) {
|
---|
| 98 | posFilters = new[] {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)};
|
---|
| 99 | }
|
---|
[224] | 100 |
|
---|
[359] | 101 | Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
|
---|
[253] | 102 |
|
---|
[359] | 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,
|
---|
[446] | 107 | kvp.Key.InternalId,
|
---|
[359] | 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) {
|
---|
[446] | 114 | SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.InternalId +
|
---|
[359] | 115 | ", playerName=" + kvp.Key.Name + ", location=" + v);
|
---|
| 116 | } else {
|
---|
| 117 | SdtdConsole.Instance.Output (" (" + v + ")");
|
---|
[224] | 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
[359] | 121 | }
|
---|
[224] | 122 |
|
---|
[369] | 123 | if (userIdFilter == null) {
|
---|
[359] | 124 | SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game");
|
---|
[224] | 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
[325] | 128 | }
|
---|