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

Last change on this file since 434 was 420, checked in by alloc, 20 months ago

A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!

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