- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/AllocsCommands/Commands/ShowInventory.cs
r297 r325 1 using AllocsFixes.PersistentData;2 1 using System; 3 2 using System.Collections.Generic; 3 using AllocsFixes.PersistentData; 4 4 5 namespace AllocsFixes.CustomCommands 6 { 7 public class ShowInventory : ConsoleCmdAbstract 8 { 9 10 public override string GetDescription () 11 { 5 namespace AllocsFixes.CustomCommands { 6 public class ShowInventory : ConsoleCmdAbstract { 7 public override string GetDescription () { 12 8 return "list inventory of a given player"; 13 9 } 14 10 15 public override string GetHelp () 16 { 11 public override string GetHelp () { 17 12 return "Usage:\n" + 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.";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."; 25 20 } 26 21 27 public override string[] GetCommands () 28 { 29 return new string[] { "showinventory", "si" }; 22 public override string[] GetCommands () { 23 return new[] {"showinventory", "si"}; 30 24 } 31 25 32 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) 33 { 26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 34 27 try { 35 28 if (_params.Count < 1) { … … 40 33 string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true); 41 34 if (steamid == null) { 42 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s)."); 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)."); 43 37 return; 44 38 } … … 52 46 PersistentData.Inventory inv = p.Inventory; 53 47 54 if (tag == null) 48 if (tag == null) { 55 49 SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":"); 50 } 51 56 52 PrintInv (inv.belt, p.EntityID, "belt", tag); 57 if (tag == null) 53 if (tag == null) { 58 54 SdtdConsole.Instance.Output (string.Empty); 55 } 59 56 60 if (tag == null) 57 if (tag == null) { 61 58 SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":"); 59 } 60 62 61 PrintInv (inv.bag, p.EntityID, "backpack", tag); 63 if (tag == null) 62 if (tag == null) { 64 63 SdtdConsole.Instance.Output (string.Empty); 64 } 65 65 66 if (tag == null) 66 if (tag == null) { 67 67 SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":"); 68 } 69 68 70 PrintEquipment (inv.equipment, p.EntityID, "equipment", tag); 69 71 70 if (tag != null) { 71 SdtdConsole.Instance.Output ("tracker_item id=" + p.EntityID + ", tag=" + tag + ", SHOWINVENTORY DONE"); 72 if (tag != null) { 73 SdtdConsole.Instance.Output ("tracker_item id=" + p.EntityID + ", tag=" + tag + 74 ", SHOWINVENTORY DONE"); 72 75 } 73 74 76 } catch (Exception e) { 75 77 Log.Out ("Error in ShowInventory.Run: " + e); … … 77 79 } 78 80 79 private void PrintInv (List<InvItem> _inv, int _entityId, string _location, string _tag) 80 { 81 private void PrintInv (List<InvItem> _inv, int _entityId, string _location, string _tag) { 81 82 for (int i = 0; i < _inv.Count; i++) { 82 83 if (_inv [i] != null) { 83 if (_tag == null) { // no Tag defined -> readable output 84 if (_tag == null) { 85 // no Tag defined -> readable output 84 86 if (_inv [i].quality < 0) { 85 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, _inv [i].count, _inv [i].itemName)); 87 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, 88 _inv [i].count, _inv [i].itemName)); 86 89 } else { 87 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, _inv [i].count, _inv [i].itemName, _inv [i].quality)); 90 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, 91 _inv [i].count, _inv [i].itemName, _inv [i].quality)); 88 92 } 93 89 94 DoParts (_inv [i].parts, 1, null); 90 } else { // Tag defined -> parseable output 91 String partsMsg = DoParts(_inv[i].parts, 1, ""); 92 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 + ")"; 93 SdtdConsole.Instance.Output(msg); 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); 94 102 } 95 103 } … … 97 105 } 98 106 99 private void PrintEquipment (InvItem[] _equipment, int _entityId, string _location, string _tag) 100 { 107 private void PrintEquipment (InvItem[] _equipment, int _entityId, string _location, string _tag) { 101 108 AddEquipment ("head", _equipment, EquipmentSlots.Headgear, _entityId, _location, _tag); 102 109 AddEquipment ("eyes", _equipment, EquipmentSlots.Eyewear, _entityId, _location, _tag); … … 114 121 } 115 122 116 private void AddEquipment (string _slotname, InvItem[] _items, EquipmentSlots _slot, int _entityId, string _location, string _tag)117 {123 private void AddEquipment (string _slotname, InvItem[] _items, EquipmentSlots _slot, int _entityId, 124 string _location, string _tag) { 118 125 int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot); 119 126 … … 121 128 if (_items != null && _items [slotindices [i]] != null) { 122 129 InvItem item = _items [slotindices [i]]; 123 if (_tag == null) { // no Tag defined -> readable output 130 if (_tag == null) { 131 // no Tag defined -> readable output 124 132 if (item.quality < 0) { 125 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, item.itemName)); 133 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, 134 item.itemName)); 126 135 } else { 127 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", _slotname, item.itemName, item.quality)); 136 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", 137 _slotname, item.itemName, item.quality)); 128 138 } 139 129 140 DoParts (_items [slotindices [i]].parts, 1, null); 130 } else { // Tag defined -> parseable output 131 String partsMsg = DoParts(_items[slotindices[i]].parts, 1, ""); 132 String msg = "tracker_item id=" + _entityId + ", tag=" + _tag + ", location=" + _location + ", slot=" + _slotname + ", item=" + item.itemName + ", qnty=1, quality=" + item.quality + ", parts=(" + partsMsg + ")"; 133 SdtdConsole.Instance.Output(msg); 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); 134 148 } 149 135 150 return; 136 151 } … … 138 153 } 139 154 140 private string DoParts (InvItem[] _parts, int _indent, string _currentMessage) 141 { 155 private string DoParts (InvItem[] _parts, int _indent, string _currentMessage) { 142 156 if (_parts != null && _parts.Length > 0) { 143 157 string indenter = new string (' ', _indent * 4); 144 158 for (int i = 0; i < _parts.Length; i++) { 145 159 if (_parts [i] != null) { 146 if (_currentMessage == null) { // no currentMessage given -> readable output 160 if (_currentMessage == null) { 161 // no currentMessage given -> readable output 147 162 if (_parts [i].quality < 0) { 148 SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, _parts [i].itemName)); 163 SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, 164 _parts [i].itemName)); 149 165 } else { 150 SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", indenter, _parts [i].itemName, _parts [i].quality)); 166 SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", 167 indenter, _parts [i].itemName, _parts [i].quality)); 151 168 } 169 152 170 DoParts (_parts [i].parts, _indent + 1, _currentMessage); 153 } else { // currentMessage given -> parseable output 171 } else { 172 // currentMessage given -> parseable output 154 173 if (_currentMessage.Length > 0) { 155 174 _currentMessage += ","; 156 175 } 157 _currentMessage += _parts[i].itemName + "@" + _parts[i].quality; 176 177 _currentMessage += _parts [i].itemName + "@" + _parts [i].quality; 158 178 _currentMessage = DoParts (_parts [i].parts, _indent + 1, _currentMessage); 159 179 } … … 161 181 } 162 182 } 183 163 184 return _currentMessage; 164 185 } 165 166 186 } 167 187 }
Note:
See TracChangeset
for help on using the changeset viewer.