using System; using System.Collections.Generic; namespace AllocsFixes.CustomCommands { public class ShowInventory : ConsoleCommand { private GameManager manager; public ShowInventory (ConsoleSdtd cons) : base(cons) { manager = m_Console.gameManager; } public override string Description () { return "list inventory of a given player (entity id or name)"; } public override string[] Names () { return new string[] { "showinventory", "si" }; } public override void Run (string[] _params) { try { if (_params.Length < 1) { m_Console.SendResult ("Usage: showinventory "); return; } int entityId = -1; PlayerDataStuff.PlayerItems items = null; if (int.TryParse (_params [0], out entityId)) { items = PlayerDataStuff.GetPlayerItems (entityId); } if (items == null) { string playerName = _params [0].ToLower (); foreach (KeyValuePair kvp in manager.World.playerEntities.dict) { if (kvp.Value.EntityName.ToLower ().Equals (playerName)) { entityId = kvp.Key; break; } } } items = PlayerDataStuff.GetPlayerItems (entityId); if (items == null) { m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s)."); return; } m_Console.SendResult ("Belt of player:"); foreach (KeyValuePair kvp in items.belt) { m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); } m_Console.SendResult (string.Empty); m_Console.SendResult ("Bagpack of player:"); foreach (KeyValuePair kvp in items.bag) { m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); } m_Console.SendResult (string.Empty); } catch (Exception e) { Log.Out ("Error in ShowInventory.Run: " + e); } } } }