/
Inventory.cs
82 lines (76 loc) · 2.94 KB
/
Inventory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using Emulator.ClassMaps;
namespace Emulator {
public class Inventory {
private IList<PlayerItem> items;
private List<PlayerItem> equippedItems = new List<PlayerItem>();
private Gear gear = new Gear();
public IList<PlayerItem> Items {
get { return items; }
}
public List<PlayerItem> EquippedItems {
get { return equippedItems; }
}
public Gear Gear {
get { return gear; }
}
/// <summary>
/// Initializes a new Inventory from a Player Id
/// </summary>
/// <param name="playerId"></param>
public Inventory(int playerId)
{
using(ISession session = Server.Factory.OpenSession())
{
IQuery q = session.CreateQuery("FROM PlayerItem WHERE PlayerId = :playerId");
q.SetParameter("playerId",playerId);
items = q.List<PlayerItem>();
foreach(PlayerItem item in items) {
if((item.Info & 1) == 1) {
equippedItems.Add(item);
switch(item.ItemType)
{
case (int)EquipSlots.Boots:
gear.Boots = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.Gauntlet:
gear.Gauntlet = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.Helmet:
gear.Helmet = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.LowerArmor:
gear.LowerArmor = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.UpperArmor:
gear.UpperArmor = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.Shield:
gear.Shield = (ushort)item.ItemIndex;
break;
case (int)EquipSlots.Weapon:
gear.Weapon = (ushort)item.ItemIndex;
break;
}
}
}
}
}
/// <summary>
/// EquipSlots, Indexes are defined by the ItemTypes table in the database
/// </summary>
public enum EquipSlots {
Boots = 5,
Gauntlet = 6,
Helmet = 7,
LowerArmor = 8,
UpperArmor = 9,
Shield = 10,
Weapon = 11,
}
}
}