[224] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
[325] | 3 | using AllocsFixes.PersistentData;
|
---|
[224] | 4 |
|
---|
[325] | 5 | namespace AllocsFixes.CustomCommands {
|
---|
| 6 | public class ShowInventory : ConsoleCmdAbstract {
|
---|
| 7 | public override string GetDescription () {
|
---|
[238] | 8 | return "list inventory of a given player";
|
---|
[224] | 9 | }
|
---|
| 10 |
|
---|
[325] | 11 | public override string GetHelp () {
|
---|
[238] | 12 | return "Usage:\n" +
|
---|
[325] | 13 | " showinventory <steam id / player name / entity id> [tag]\n" +
|
---|
| 14 | "Show the inventory of the player given by his SteamID, player name or\n" +
|
---|
| 15 | "entity id (as given by e.g. \"lpi\").\n" +
|
---|
| 16 | "Optionally specify a tag that is included in each line of the output. In\n" +
|
---|
| 17 | "this case output is designed to be easily parseable by tools.\n" +
|
---|
| 18 | "Note: This only shows the player's inventory after it was first sent to\n" +
|
---|
| 19 | "the server which happens at least every 30 seconds.";
|
---|
[238] | 20 | }
|
---|
| 21 |
|
---|
[325] | 22 | public override string[] GetCommands () {
|
---|
| 23 | return new[] {"showinventory", "si"};
|
---|
[224] | 24 | }
|
---|
| 25 |
|
---|
[325] | 26 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
[224] | 27 | try {
|
---|
[230] | 28 | if (_params.Count < 1) {
|
---|
[273] | 29 | SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid> [tag]");
|
---|
[224] | 30 | return;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
|
---|
| 34 | if (steamid == null) {
|
---|
[325] | 35 | SdtdConsole.Instance.Output (
|
---|
| 36 | "Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s).");
|
---|
[224] | 37 | return;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[273] | 40 | string tag = null;
|
---|
| 41 | if (_params.Count > 1 && _params [1].Length > 0) {
|
---|
| 42 | tag = _params [1];
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[233] | 45 | Player p = PersistentContainer.Instance.Players [steamid, false];
|
---|
[224] | 46 | PersistentData.Inventory inv = p.Inventory;
|
---|
| 47 |
|
---|
[325] | 48 | if (tag == null) {
|
---|
[273] | 49 | SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
|
---|
[325] | 50 | }
|
---|
| 51 |
|
---|
[273] | 52 | PrintInv (inv.belt, p.EntityID, "belt", tag);
|
---|
[325] | 53 | if (tag == null) {
|
---|
[273] | 54 | SdtdConsole.Instance.Output (string.Empty);
|
---|
[325] | 55 | }
|
---|
[250] | 56 |
|
---|
[325] | 57 | if (tag == null) {
|
---|
[273] | 58 | SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
|
---|
[325] | 59 | }
|
---|
| 60 |
|
---|
[273] | 61 | PrintInv (inv.bag, p.EntityID, "backpack", tag);
|
---|
[325] | 62 | if (tag == null) {
|
---|
[273] | 63 | SdtdConsole.Instance.Output (string.Empty);
|
---|
[325] | 64 | }
|
---|
[250] | 65 |
|
---|
[325] | 66 | if (tag == null) {
|
---|
[273] | 67 | SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":");
|
---|
[325] | 68 | }
|
---|
| 69 |
|
---|
[273] | 70 | PrintEquipment (inv.equipment, p.EntityID, "equipment", tag);
|
---|
[250] | 71 |
|
---|
[325] | 72 | if (tag != null) {
|
---|
| 73 | SdtdConsole.Instance.Output ("tracker_item id=" + p.EntityID + ", tag=" + tag +
|
---|
| 74 | ", SHOWINVENTORY DONE");
|
---|
[297] | 75 | }
|
---|
[224] | 76 | } catch (Exception e) {
|
---|
| 77 | Log.Out ("Error in ShowInventory.Run: " + e);
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[250] | 80 |
|
---|
[325] | 81 | private void PrintInv (List<InvItem> _inv, int _entityId, string _location, string _tag) {
|
---|
[250] | 82 | for (int i = 0; i < _inv.Count; i++) {
|
---|
| 83 | if (_inv [i] != null) {
|
---|
[325] | 84 | if (_tag == null) {
|
---|
| 85 | // no Tag defined -> readable output
|
---|
[273] | 86 | if (_inv [i].quality < 0) {
|
---|
[325] | 87 | SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i,
|
---|
| 88 | _inv [i].count, _inv [i].itemName));
|
---|
[273] | 89 | } else {
|
---|
[325] | 90 | SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i,
|
---|
| 91 | _inv [i].count, _inv [i].itemName, _inv [i].quality));
|
---|
[273] | 92 | }
|
---|
[325] | 93 |
|
---|
[273] | 94 | DoParts (_inv [i].parts, 1, null);
|
---|
[325] | 95 | } else {
|
---|
| 96 | // Tag defined -> parseable output
|
---|
| 97 | string partsMsg = DoParts (_inv [i].parts, 1, "");
|
---|
| 98 | string msg = "tracker_item id=" + _entityId + ", tag=" + _tag + ", location=" + _location +
|
---|
| 99 | ", slot=" + i + ", item=" + _inv [i].itemName + ", qnty=" + _inv [i].count +
|
---|
| 100 | ", quality=" + _inv [i].quality + ", parts=(" + partsMsg + ")";
|
---|
| 101 | SdtdConsole.Instance.Output (msg);
|
---|
[250] | 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[325] | 107 | private void PrintEquipment (InvItem[] _equipment, int _entityId, string _location, string _tag) {
|
---|
[273] | 108 | AddEquipment ("head", _equipment, EquipmentSlots.Headgear, _entityId, _location, _tag);
|
---|
| 109 | AddEquipment ("eyes", _equipment, EquipmentSlots.Eyewear, _entityId, _location, _tag);
|
---|
| 110 | AddEquipment ("face", _equipment, EquipmentSlots.Face, _entityId, _location, _tag);
|
---|
[250] | 111 |
|
---|
[273] | 112 | AddEquipment ("armor", _equipment, EquipmentSlots.ChestArmor, _entityId, _location, _tag);
|
---|
| 113 | AddEquipment ("jacket", _equipment, EquipmentSlots.Jacket, _entityId, _location, _tag);
|
---|
| 114 | AddEquipment ("shirt", _equipment, EquipmentSlots.Shirt, _entityId, _location, _tag);
|
---|
[250] | 115 |
|
---|
[273] | 116 | AddEquipment ("legarmor", _equipment, EquipmentSlots.LegArmor, _entityId, _location, _tag);
|
---|
| 117 | AddEquipment ("pants", _equipment, EquipmentSlots.Legs, _entityId, _location, _tag);
|
---|
| 118 | AddEquipment ("boots", _equipment, EquipmentSlots.Feet, _entityId, _location, _tag);
|
---|
[250] | 119 |
|
---|
[273] | 120 | AddEquipment ("gloves", _equipment, EquipmentSlots.Hands, _entityId, _location, _tag);
|
---|
[250] | 121 | }
|
---|
| 122 |
|
---|
[325] | 123 | private void AddEquipment (string _slotname, InvItem[] _items, EquipmentSlots _slot, int _entityId,
|
---|
| 124 | string _location, string _tag) {
|
---|
[253] | 125 | int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot);
|
---|
| 126 |
|
---|
| 127 | for (int i = 0; i < slotindices.Length; i++) {
|
---|
| 128 | if (_items != null && _items [slotindices [i]] != null) {
|
---|
| 129 | InvItem item = _items [slotindices [i]];
|
---|
[325] | 130 | if (_tag == null) {
|
---|
| 131 | // no Tag defined -> readable output
|
---|
[273] | 132 | if (item.quality < 0) {
|
---|
[325] | 133 | SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname,
|
---|
| 134 | item.itemName));
|
---|
[273] | 135 | } else {
|
---|
[325] | 136 | SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}",
|
---|
| 137 | _slotname, item.itemName, item.quality));
|
---|
[273] | 138 | }
|
---|
[325] | 139 |
|
---|
[273] | 140 | DoParts (_items [slotindices [i]].parts, 1, null);
|
---|
[325] | 141 | } else {
|
---|
| 142 | // Tag defined -> parseable output
|
---|
| 143 | string partsMsg = DoParts (_items [slotindices [i]].parts, 1, "");
|
---|
| 144 | string msg = "tracker_item id=" + _entityId + ", tag=" + _tag + ", location=" + _location +
|
---|
| 145 | ", slot=" + _slotname + ", item=" + item.itemName + ", qnty=1, quality=" +
|
---|
| 146 | item.quality + ", parts=(" + partsMsg + ")";
|
---|
| 147 | SdtdConsole.Instance.Output (msg);
|
---|
[253] | 148 | }
|
---|
[325] | 149 |
|
---|
[253] | 150 | return;
|
---|
[250] | 151 | }
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[325] | 155 | private string DoParts (InvItem[] _parts, int _indent, string _currentMessage) {
|
---|
[250] | 156 | if (_parts != null && _parts.Length > 0) {
|
---|
| 157 | string indenter = new string (' ', _indent * 4);
|
---|
| 158 | for (int i = 0; i < _parts.Length; i++) {
|
---|
| 159 | if (_parts [i] != null) {
|
---|
[325] | 160 | if (_currentMessage == null) {
|
---|
| 161 | // no currentMessage given -> readable output
|
---|
[273] | 162 | if (_parts [i].quality < 0) {
|
---|
[325] | 163 | SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter,
|
---|
| 164 | _parts [i].itemName));
|
---|
[273] | 165 | } else {
|
---|
[325] | 166 | SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}",
|
---|
| 167 | indenter, _parts [i].itemName, _parts [i].quality));
|
---|
[273] | 168 | }
|
---|
[325] | 169 |
|
---|
[273] | 170 | DoParts (_parts [i].parts, _indent + 1, _currentMessage);
|
---|
[325] | 171 | } else {
|
---|
| 172 | // currentMessage given -> parseable output
|
---|
[273] | 173 | if (_currentMessage.Length > 0) {
|
---|
| 174 | _currentMessage += ",";
|
---|
| 175 | }
|
---|
[325] | 176 |
|
---|
| 177 | _currentMessage += _parts [i].itemName + "@" + _parts [i].quality;
|
---|
[273] | 178 | _currentMessage = DoParts (_parts [i].parts, _indent + 1, _currentMessage);
|
---|
[250] | 179 | }
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
[325] | 183 |
|
---|
[273] | 184 | return _currentMessage;
|
---|
[250] | 185 | }
|
---|
[224] | 186 | }
|
---|
[325] | 187 | }
|
---|