source: binary-improvements/AllocsCommands/Commands/ShowInventory.cs@ 446

Last change on this file since 446 was 446, checked in by alloc, 17 months ago

24_27_41

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