[224] | 1 | using AllocsFixes.PersistentData;
|
---|
| 2 | using System;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 |
|
---|
| 5 | namespace AllocsFixes.CustomCommands
|
---|
| 6 | {
|
---|
[250] | 7 | public class ShowInventory : ConsoleCmdAbstract {
|
---|
| 8 | public override string GetDescription () {
|
---|
[238] | 9 | return "list inventory of a given player";
|
---|
[224] | 10 | }
|
---|
| 11 |
|
---|
[238] | 12 | public override string GetHelp () {
|
---|
| 13 | return "Usage:\n" +
|
---|
[250] | 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.";
|
---|
[238] | 19 | }
|
---|
| 20 |
|
---|
[250] | 21 | public override string[] GetCommands () {
|
---|
[224] | 22 | return new string[] { "showinventory", "si" };
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[250] | 25 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
|
---|
[224] | 26 | try {
|
---|
[230] | 27 | if (_params.Count < 1) {
|
---|
| 28 | SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
|
---|
[224] | 29 | return;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
|
---|
| 33 | if (steamid == null) {
|
---|
[230] | 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).");
|
---|
[224] | 35 | return;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[233] | 38 | Player p = PersistentContainer.Instance.Players [steamid, false];
|
---|
[224] | 39 | PersistentData.Inventory inv = p.Inventory;
|
---|
| 40 |
|
---|
[230] | 41 | SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
|
---|
[250] | 42 | PrintInv (inv.belt);
|
---|
[230] | 43 | SdtdConsole.Instance.Output (string.Empty);
|
---|
[250] | 44 |
|
---|
[230] | 45 | SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
|
---|
[250] | 46 | PrintInv (inv.bag);
|
---|
[230] | 47 | SdtdConsole.Instance.Output (string.Empty);
|
---|
[250] | 48 |
|
---|
| 49 | SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":");
|
---|
| 50 | PrintEquipment (inv.equipment);
|
---|
| 51 |
|
---|
[224] | 52 | } catch (Exception e) {
|
---|
| 53 | Log.Out ("Error in ShowInventory.Run: " + e);
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
[250] | 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 |
|
---|
[224] | 115 | }
|
---|
| 116 | }
|
---|