1 | using AllocsFixes.PersistentData;
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 |
|
---|
5 | namespace AllocsFixes.CustomCommands
|
---|
6 | {
|
---|
7 | public class ShowInventory : ConsoleCmdAbstract {
|
---|
8 |
|
---|
9 | public override string GetDescription () {
|
---|
10 | return "list inventory of a given player";
|
---|
11 | }
|
---|
12 |
|
---|
13 | public override string GetHelp () {
|
---|
14 | 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.";
|
---|
20 | }
|
---|
21 |
|
---|
22 | public override string[] GetCommands () {
|
---|
23 | return new string[] { "showinventory", "si" };
|
---|
24 | }
|
---|
25 |
|
---|
26 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
27 | try {
|
---|
28 | if (_params.Count < 1) {
|
---|
29 | SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
|
---|
30 | return;
|
---|
31 | }
|
---|
32 |
|
---|
33 | string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
|
---|
34 | if (steamid == null) {
|
---|
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).");
|
---|
36 | return;
|
---|
37 | }
|
---|
38 |
|
---|
39 | Player p = PersistentContainer.Instance.Players [steamid, false];
|
---|
40 | PersistentData.Inventory inv = p.Inventory;
|
---|
41 |
|
---|
42 | SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
|
---|
43 | PrintInv (inv.belt);
|
---|
44 | SdtdConsole.Instance.Output (string.Empty);
|
---|
45 |
|
---|
46 | SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
|
---|
47 | PrintInv (inv.bag);
|
---|
48 | SdtdConsole.Instance.Output (string.Empty);
|
---|
49 |
|
---|
50 | SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":");
|
---|
51 | PrintEquipment (inv.equipment);
|
---|
52 |
|
---|
53 | } catch (Exception e) {
|
---|
54 | Log.Out ("Error in ShowInventory.Run: " + e);
|
---|
55 | }
|
---|
56 | }
|
---|
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) {
|
---|
72 | AddEquipment ("head", _equipment, EquipmentSlots.Headgear);
|
---|
73 | AddEquipment ("eyes", _equipment, EquipmentSlots.Eyewear);
|
---|
74 | AddEquipment ("face", _equipment, EquipmentSlots.Face);
|
---|
75 |
|
---|
76 | AddEquipment ("armor", _equipment, EquipmentSlots.ChestArmor);
|
---|
77 | AddEquipment ("jacket", _equipment, EquipmentSlots.Jacket);
|
---|
78 | AddEquipment ("shirt", _equipment, EquipmentSlots.Shirt);
|
---|
79 |
|
---|
80 | AddEquipment ("legarmor", _equipment, EquipmentSlots.LegArmor);
|
---|
81 | AddEquipment ("pants", _equipment, EquipmentSlots.Legs);
|
---|
82 | AddEquipment ("boots", _equipment, EquipmentSlots.Feet);
|
---|
83 |
|
---|
84 | AddEquipment ("gloves", _equipment, EquipmentSlots.Hands);
|
---|
85 | }
|
---|
86 |
|
---|
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;
|
---|
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 |
|
---|
120 | }
|
---|
121 | }
|
---|