- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/AllocsCommands/Commands/ShowInventory.cs
r446 r455 1 1 using System.Collections.Generic; 2 2 using AllocsFixes.PersistentData; 3 using JetBrains.Annotations; 3 4 4 5 namespace AllocsFixes.CustomCommands { 6 [UsedImplicitly] 5 7 public class ShowInventory : ConsoleCmdAbstract { 6 8 protected override string getDescription () { … … 44 46 45 47 if (tag == null) { 46 SdtdConsole.Instance.Output ( "Belt of player " + p.Name + ":");48 SdtdConsole.Instance.Output ($"Belt of player {p.Name}:"); 47 49 } 48 50 … … 53 55 54 56 if (tag == null) { 55 SdtdConsole.Instance.Output ( "Bagpack of player " + p.Name + ":");57 SdtdConsole.Instance.Output ($"Bagpack of player {p.Name}:"); 56 58 } 57 59 … … 62 64 63 65 if (tag == null) { 64 SdtdConsole.Instance.Output ( "Equipment of player " + p.Name + ":");66 SdtdConsole.Instance.Output ($"Equipment of player {p.Name}:"); 65 67 } 66 68 … … 68 70 69 71 if (tag != null) { 70 SdtdConsole.Instance.Output ("tracker_item id=" + p.EntityID + ", tag=" + tag + 71 ", SHOWINVENTORY DONE"); 72 SdtdConsole.Instance.Output ($"tracker_item id={p.EntityID}, tag={tag}, SHOWINVENTORY DONE"); 72 73 } 73 74 } 74 75 75 private void PrintInv (List<InvItem> _inv, int _entityId, string _location, string _tag) {76 private static void PrintInv (IReadOnlyList<InvItem> _inv, int _entityId, string _location, string _tag) { 76 77 for (int i = 0; i < _inv.Count; i++) { 77 if (_inv [i] != null) { 78 if (_tag == null) { 79 // no Tag defined -> readable output 80 if (_inv [i].quality < 0) { 81 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, 82 _inv [i].count, _inv [i].itemName)); 83 } else { 84 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, 85 _inv [i].count, _inv [i].itemName, _inv [i].quality)); 86 } 78 if (_inv[i] == null) { 79 continue; 80 } 87 81 88 DoParts (_inv [i].parts, 1, null); 82 if (_tag == null) { 83 // no Tag defined -> readable output 84 if (_inv [i].quality < 0) { 85 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, 86 _inv [i].count, _inv [i].itemName)); 89 87 } 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); 88 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, 89 _inv [i].count, _inv [i].itemName, _inv [i].quality)); 96 90 } 91 92 DoParts (_inv [i].parts, 1, null); 93 } else { 94 // Tag defined -> parseable output 95 string partsMsg = DoParts (_inv [i].parts, 1, ""); 96 string msg = "tracker_item id=" + _entityId + ", tag=" + _tag + ", location=" + _location + 97 ", slot=" + i + ", item=" + _inv [i].itemName + ", qnty=" + _inv [i].count + 98 ", quality=" + _inv [i].quality + ", parts=(" + partsMsg + ")"; 99 SdtdConsole.Instance.Output (msg); 97 100 } 98 101 } 99 102 } 100 103 101 private void PrintEquipment (InvItem[]_equipment, int _entityId, string _location, string _tag) {104 private static void PrintEquipment (IReadOnlyList<InvItem> _equipment, int _entityId, string _location, string _tag) { 102 105 AddEquipment ("head", _equipment, EquipmentSlots.Headgear, _entityId, _location, _tag); 103 106 AddEquipment ("eyes", _equipment, EquipmentSlots.Eyewear, _entityId, _location, _tag); … … 115 118 } 116 119 117 private void AddEquipment (string _slotname, InvItem[]_items, EquipmentSlots _slot, int _entityId,120 private static void AddEquipment (string _slotname, IReadOnlyList<InvItem> _items, EquipmentSlots _slot, int _entityId, 118 121 string _location, string _tag) { 119 122 int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot); 120 123 121 124 for (int i = 0; i < slotindices.Length; i++) { 122 if (_items != null && _items [slotindices [i]] != null) { 123 InvItem item = _items [slotindices [i]]; 124 if (_tag == null) { 125 // no Tag defined -> readable output 126 if (item.quality < 0) { 127 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, 128 item.itemName)); 129 } else { 130 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", 131 _slotname, item.itemName, item.quality)); 132 } 125 if (_items == null || _items[slotindices[i]] == null) { 126 continue; 127 } 133 128 134 DoParts (_items [slotindices [i]].parts, 1, null); 129 InvItem item = _items [slotindices [i]]; 130 if (_tag == null) { 131 // no Tag defined -> readable output 132 if (item.quality < 0) { 133 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, 134 item.itemName)); 135 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); 136 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", 137 _slotname, item.itemName, item.quality)); 142 138 } 143 139 144 return; 140 DoParts (_items [slotindices [i]].parts, 1, null); 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}, slot={_slotname}, item={item.itemName}, qnty=1, quality={item.quality}, parts=({partsMsg})"; 145 SdtdConsole.Instance.Output (msg); 145 146 } 147 148 return; 146 149 } 147 150 } 148 151 149 private string DoParts (InvItem[] _parts, int _indent, string _currentMessage) { 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) { 154 if (_currentMessage == null) { 155 // no currentMessage given -> readable output 156 if (_parts [i].quality < 0) { 157 SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, 158 _parts [i].itemName)); 159 } else { 160 SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", 161 indenter, _parts [i].itemName, _parts [i].quality)); 162 } 152 private static string DoParts (IReadOnlyList<InvItem> _parts, int _indent, string _currentMessage) { 153 if (_parts == null || _parts.Count <= 0) { 154 return _currentMessage; 155 } 163 156 164 DoParts (_parts [i].parts, _indent + 1, null); 165 } else { 166 // currentMessage given -> parseable output 167 if (_currentMessage.Length > 0) { 168 _currentMessage += ","; 169 } 157 string indenter = new string (' ', _indent * 4); 158 for (int i = 0; i < _parts.Count; i++) { 159 if (_parts[i] == null) { 160 continue; 161 } 170 162 171 _currentMessage += _parts [i].itemName + "@" + _parts [i].quality; 172 _currentMessage = DoParts (_parts [i].parts, _indent + 1, _currentMessage); 173 } 163 if (_currentMessage == null) { 164 // no currentMessage given -> readable output 165 if (_parts [i].quality < 0) { 166 SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, 167 _parts [i].itemName)); 168 } else { 169 SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", 170 indenter, _parts [i].itemName, _parts [i].quality)); 174 171 } 172 173 DoParts (_parts [i].parts, _indent + 1, null); 174 } else { 175 // currentMessage given -> parseable output 176 if (_currentMessage.Length > 0) { 177 _currentMessage += ","; 178 } 179 180 _currentMessage += $"{_parts[i].itemName}@{_parts[i].quality}"; 181 _currentMessage = DoParts (_parts [i].parts, _indent + 1, _currentMessage); 175 182 } 176 183 }
Note:
See TracChangeset
for help on using the changeset viewer.