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