1 | using AllocsFixes.PersistentData;
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 |
|
---|
5 | namespace AllocsFixes.CustomCommands
|
---|
6 | {
|
---|
7 | public class ShowInventory : ConsoleCmdAbstract {
|
---|
8 | public override string GetDescription () {
|
---|
9 | return "list inventory of a given player";
|
---|
10 | }
|
---|
11 |
|
---|
12 | public override string GetHelp () {
|
---|
13 | return "Usage:\n" +
|
---|
14 | " showinventory <steam id / player name / entity id>\n" +
|
---|
15 | "Show the inventory of the player given by his SteamID, player name or\n" +
|
---|
16 | "entity id (as given by e.g. \"lpi\")." +
|
---|
17 | "Note: This only shows the player's inventory after it was first sent to\n" +
|
---|
18 | "the server which happens at least every 30 seconds.";
|
---|
19 | }
|
---|
20 |
|
---|
21 | public override string[] GetCommands () {
|
---|
22 | return new string[] { "showinventory", "si" };
|
---|
23 | }
|
---|
24 |
|
---|
25 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
26 | try {
|
---|
27 | if (_params.Count < 1) {
|
---|
28 | SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
|
---|
29 | return;
|
---|
30 | }
|
---|
31 |
|
---|
32 | string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
|
---|
33 | if (steamid == null) {
|
---|
34 | 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 | return;
|
---|
36 | }
|
---|
37 |
|
---|
38 | Player p = PersistentContainer.Instance.Players [steamid, false];
|
---|
39 | PersistentData.Inventory inv = p.Inventory;
|
---|
40 |
|
---|
41 | SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
|
---|
42 | PrintInv (inv.belt);
|
---|
43 | SdtdConsole.Instance.Output (string.Empty);
|
---|
44 |
|
---|
45 | SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
|
---|
46 | PrintInv (inv.bag);
|
---|
47 | SdtdConsole.Instance.Output (string.Empty);
|
---|
48 |
|
---|
49 | SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":");
|
---|
50 | PrintEquipment (inv.equipment);
|
---|
51 |
|
---|
52 | } catch (Exception e) {
|
---|
53 | Log.Out ("Error in ShowInventory.Run: " + e);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void PrintInv (List<InvItem> _inv) {
|
---|
58 | for (int i = 0; i < _inv.Count; i++) {
|
---|
59 | if (_inv [i] != null) {
|
---|
60 | if (_inv [i].quality < 0) {
|
---|
61 | SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, _inv [i].count, _inv [i].itemName));
|
---|
62 | } else {
|
---|
63 | SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, _inv [i].count, _inv [i].itemName, _inv [i].quality));
|
---|
64 | }
|
---|
65 | DoParts (_inv [i].parts, 1);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void PrintEquipment (InvItem[] _equipment) {
|
---|
71 | AddEquipment ("head", _equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle);
|
---|
72 | AddEquipment ("eyes", _equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle);
|
---|
73 | AddEquipment ("face", _equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle);
|
---|
74 |
|
---|
75 | AddEquipment ("armor", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer);
|
---|
76 | AddEquipment ("jacket", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle);
|
---|
77 | AddEquipment ("shirt", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner);
|
---|
78 |
|
---|
79 | AddEquipment ("legarmor", _equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer);
|
---|
80 | AddEquipment ("pants", _equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner);
|
---|
81 | AddEquipment ("boots", _equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner);
|
---|
82 |
|
---|
83 | AddEquipment ("gloves", _equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner);
|
---|
84 | AddEquipment ("backpack", _equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer);
|
---|
85 | }
|
---|
86 |
|
---|
87 | private void AddEquipment (string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) {
|
---|
88 | int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count;
|
---|
89 | if (_items != null && _items [index] != null) {
|
---|
90 | if (_items [index].quality < 0) {
|
---|
91 | SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, _items [index].itemName));
|
---|
92 | } else {
|
---|
93 | SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", _slotname, _items [index].itemName, _items [index].quality));
|
---|
94 | }
|
---|
95 | DoParts (_items [index].parts, 1);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | private void DoParts (InvItem[] _parts, int _indent) {
|
---|
100 | if (_parts != null && _parts.Length > 0) {
|
---|
101 | string indenter = new string (' ', _indent * 4);
|
---|
102 | for (int i = 0; i < _parts.Length; i++) {
|
---|
103 | if (_parts [i] != null) {
|
---|
104 | if (_parts [i].quality < 0) {
|
---|
105 | SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, _parts [i].itemName));
|
---|
106 | } else {
|
---|
107 | SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", indenter, _parts [i].itemName, _parts [i].quality));
|
---|
108 | }
|
---|
109 | DoParts (_parts [i].parts, _indent + 1);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|
116 | }
|
---|