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