[93] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
[130] | 4 | namespace AllocsFixes.CustomCommands
|
---|
[93] | 5 | {
|
---|
[130] | 6 | public class ShowInventory : ConsoleCommand
|
---|
[93] | 7 | {
|
---|
[130] | 8 | private GameManager manager;
|
---|
[93] | 9 |
|
---|
[130] | 10 | public ShowInventory (ConsoleSdtd cons) : base(cons)
|
---|
| 11 | {
|
---|
| 12 | manager = m_Console.gameManager;
|
---|
| 13 | }
|
---|
[93] | 14 |
|
---|
[130] | 15 | public override string Description ()
|
---|
| 16 | {
|
---|
| 17 | return "list inventory of a given player (entity id or name)";
|
---|
| 18 | }
|
---|
[93] | 19 |
|
---|
[130] | 20 | public override string[] Names ()
|
---|
| 21 | {
|
---|
| 22 | return new string[] { "showinventory", "si" };
|
---|
| 23 | }
|
---|
[93] | 24 |
|
---|
[130] | 25 | public override void Run (string[] _params)
|
---|
| 26 | {
|
---|
| 27 | try {
|
---|
| 28 | if (_params.Length < 1) {
|
---|
| 29 | m_Console.SendResult ("Usage: showinventory <playername|entityid>");
|
---|
| 30 | return;
|
---|
| 31 | }
|
---|
[93] | 32 |
|
---|
[130] | 33 | int entityId = -1;
|
---|
| 34 | PlayerDataStuff.PlayerItems items = null;
|
---|
| 35 | if (int.TryParse (_params [0], out entityId)) {
|
---|
| 36 | items = PlayerDataStuff.GetPlayerItems (entityId);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | if (items == null) {
|
---|
| 40 | string playerName = _params [0].ToLower ();
|
---|
| 41 | foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) {
|
---|
| 42 | if (kvp.Value.EntityName.ToLower ().Equals (playerName)) {
|
---|
| 43 | entityId = kvp.Key;
|
---|
| 44 | break;
|
---|
| 45 | }
|
---|
[103] | 46 | }
|
---|
[93] | 47 | }
|
---|
[130] | 48 | items = PlayerDataStuff.GetPlayerItems (entityId);
|
---|
[93] | 49 |
|
---|
[130] | 50 | if (items == null) {
|
---|
| 51 | m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");
|
---|
| 52 | return;
|
---|
| 53 | }
|
---|
[93] | 54 |
|
---|
[130] | 55 | m_Console.SendResult ("Belt of player:");
|
---|
| 56 | foreach (KeyValuePair<string, int> kvp in items.belt) {
|
---|
| 57 | m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
|
---|
| 58 | }
|
---|
| 59 | m_Console.SendResult (string.Empty);
|
---|
| 60 | m_Console.SendResult ("Bagpack of player:");
|
---|
| 61 | foreach (KeyValuePair<string, int> kvp in items.bag) {
|
---|
| 62 | m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
|
---|
| 63 | }
|
---|
| 64 | m_Console.SendResult (string.Empty);
|
---|
| 65 | } catch (Exception e) {
|
---|
| 66 | Log.Out ("Error in ShowInventory.Run: " + e);
|
---|
[103] | 67 | }
|
---|
[93] | 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|