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

Last change on this file since 267 was 253, checked in by alloc, 9 years ago

Fixes 6_8_10

File size: 4.3 KB
RevLine 
[224]1using AllocsFixes.PersistentData;
2using System;
3using System.Collections.Generic;
4
5namespace AllocsFixes.CustomCommands
6{
[250]7 public class ShowInventory : ConsoleCmdAbstract {
[253]8
[250]9 public override string GetDescription () {
[238]10 return "list inventory of a given player";
[224]11 }
12
[238]13 public override string GetHelp () {
14 return "Usage:\n" +
[250]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.";
[238]20 }
21
[250]22 public override string[] GetCommands () {
[224]23 return new string[] { "showinventory", "si" };
24 }
25
[250]26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[224]27 try {
[230]28 if (_params.Count < 1) {
29 SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
[224]30 return;
31 }
32
33 string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
34 if (steamid == null) {
[230]35 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s).");
[224]36 return;
37 }
38
[233]39 Player p = PersistentContainer.Instance.Players [steamid, false];
[224]40 PersistentData.Inventory inv = p.Inventory;
41
[230]42 SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
[250]43 PrintInv (inv.belt);
[230]44 SdtdConsole.Instance.Output (string.Empty);
[250]45
[230]46 SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
[250]47 PrintInv (inv.bag);
[230]48 SdtdConsole.Instance.Output (string.Empty);
[250]49
50 SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":");
51 PrintEquipment (inv.equipment);
52
[224]53 } catch (Exception e) {
54 Log.Out ("Error in ShowInventory.Run: " + e);
55 }
56 }
[250]57
58 private void PrintInv (List<InvItem> _inv) {
59 for (int i = 0; i < _inv.Count; i++) {
60 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));
65 }
66 DoParts (_inv [i].parts, 1);
67 }
68 }
69 }
70
71 private void PrintEquipment (InvItem[] _equipment) {
[253]72 AddEquipment ("head", _equipment, EquipmentSlots.Headgear);
73 AddEquipment ("eyes", _equipment, EquipmentSlots.Eyewear);
74 AddEquipment ("face", _equipment, EquipmentSlots.Face);
[250]75
[253]76 AddEquipment ("armor", _equipment, EquipmentSlots.ChestArmor);
77 AddEquipment ("jacket", _equipment, EquipmentSlots.Jacket);
78 AddEquipment ("shirt", _equipment, EquipmentSlots.Shirt);
[250]79
[253]80 AddEquipment ("legarmor", _equipment, EquipmentSlots.LegArmor);
81 AddEquipment ("pants", _equipment, EquipmentSlots.Legs);
82 AddEquipment ("boots", _equipment, EquipmentSlots.Feet);
[250]83
[253]84 AddEquipment ("gloves", _equipment, EquipmentSlots.Hands);
[250]85 }
86
[253]87 private void AddEquipment (string _slotname, InvItem[] _items, EquipmentSlots _slot) {
88 int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot);
89
90 for (int i = 0; i < slotindices.Length; i++) {
91 if (_items != null && _items [slotindices [i]] != null) {
92 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));
97 }
98 DoParts (_items [slotindices [i]].parts, 1);
99 return;
[250]100 }
101 }
102 }
103
104 private void DoParts (InvItem[] _parts, int _indent) {
105 if (_parts != null && _parts.Length > 0) {
106 string indenter = new string (' ', _indent * 4);
107 for (int i = 0; i < _parts.Length; i++) {
108 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));
113 }
114 DoParts (_parts [i].parts, _indent + 1);
115 }
116 }
117 }
118 }
119
[224]120 }
121}
Note: See TracBrowser for help on using the repository browser.