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 | if (_params.Length < 1) {
|
---|
26 | m_Console.md000a ("Usage: showinventory <playername|entityid>");
|
---|
27 | return;
|
---|
28 | }
|
---|
29 |
|
---|
30 | int entityId = -1;
|
---|
31 | PlayerDataStuff.PlayerItems items = null;
|
---|
32 | if (int.TryParse (_params [0], out entityId)) {
|
---|
33 | items = PlayerDataStuff.GetPlayerItems (entityId);
|
---|
34 | }
|
---|
35 |
|
---|
36 | if (items == null) {
|
---|
37 | string playerName = _params [0].ToLower ();
|
---|
38 | foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) {
|
---|
39 | if (kvp.Value.EntityName.ToLower ().Equals (playerName)) {
|
---|
40 | entityId = kvp.Key;
|
---|
41 | break;
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 | items = PlayerDataStuff.GetPlayerItems (entityId);
|
---|
46 |
|
---|
47 | if (items == null) {
|
---|
48 | m_Console.md000a ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");
|
---|
49 | return;
|
---|
50 | }
|
---|
51 |
|
---|
52 | m_Console.md000a ("Belt of player:");
|
---|
53 | foreach (KeyValuePair<string, int> kvp in items.belt) {
|
---|
54 | m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
|
---|
55 | }
|
---|
56 | m_Console.md000a (string.Empty);
|
---|
57 | m_Console.md000a ("Bagpack of player:");
|
---|
58 | foreach (KeyValuePair<string, int> kvp in items.bag) {
|
---|
59 | m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
|
---|
60 | }
|
---|
61 | m_Console.md000a (string.Empty);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|