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