/
inventoryitems.go
162 lines (153 loc) · 4.52 KB
/
inventoryitems.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package models
import "github.com/juju/errors"
/*
-- ----------------------------
-- Table structure for `inventoryitems`
-- ----------------------------
DROP TABLE IF EXISTS `inventoryitems`;
CREATE TABLE `inventoryitems` (
`inventoryitemid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`characterid` int(11) DEFAULT NULL,
`storageid` int(10) unsigned DEFAULT NULL,
`itemid` int(11) NOT NULL DEFAULT '0',
`inventorytype` int(11) NOT NULL DEFAULT '0',
`position` int(11) NOT NULL DEFAULT '0',
`quantity` int(11) NOT NULL DEFAULT '0',
`owner` tinytext NOT NULL,
`petid` int(11) NOT NULL DEFAULT '-1',
`expiration` bigint(20) unsigned DEFAULT '0',
PRIMARY KEY (`inventoryitemid`),
KEY `inventoryitems_ibfk_1` (`characterid`),
KEY `characterid` (`characterid`),
KEY `inventorytype` (`inventorytype`),
KEY `storageid` (`storageid`),
KEY `characterid_2` (`characterid`,`inventorytype`),
CONSTRAINT `inventoryitems_ibfk_1` FOREIGN KEY (`characterid`) REFERENCES `characters` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
*/
type InventoryItem struct {
InventoryItemID int64
CharacterID int64
StorageID int
ItemID int
InventoryType int
Position int
Quantity int
Owner string
Expiration int64
UniqueID int64
PetSlot int
}
type CharacterInventoryItem struct {
InventoryItem
InventoryEquipment
}
func SelectCharacterInventoryItemIDsAndPositionByInventoryType(charID int64, inventoryType int) ([]*InventoryItem, error) {
rows, err := GetGlobalDB().Query(`SELECT
itemid,
position,
FROM
inventoryitems WHERE
characterid = ? AND
inventorytype = ?`,
charID, inventoryType)
if nil != err {
return nil, errors.Trace(err)
}
defer rows.Close()
res := make([]*InventoryItem, 0, 32)
for rows.Next() {
var item InventoryItem
if err = rows.Scan(&item); nil != err {
return nil, errors.Trace(err)
}
res = append(res, &item)
}
return res, nil
}
func SelectCharacterInventoryItem(charID int64) ([]*CharacterInventoryItem, error) {
rows, err := GetGlobalDB().Query(`SELECT
inventoryitems.inventoryitemid,
inventoryitems.storageid,
inventoryitems.itemid,
inventoryitems.inventorytype,
inventoryitems.position,
inventoryitems.quantity,
inventoryitems.owner,
inventoryitems.petid,
inventoryitems.expiration,
inventoryitems.uniqueid,
inventoryequipment.inventoryequipmentid,
inventoryequipment.inventoryitemid,
inventoryequipment.upgradeslots,
inventoryequipment.level,
inventoryequipment.str,
inventoryequipment.dex,
inventoryequipment.intt,
inventoryequipment.luk,
inventoryequipment.hp,
inventoryequipment.mp,
inventoryequipment.watk,
inventoryequipment.matk,
inventoryequipment.wdef,
inventoryequipment.mdef,
inventoryequipment.acc,
inventoryequipment.avoid,
inventoryequipment.hands,
inventoryequipment.speed,
inventoryequipment.jump,
inventoryequipment.ringid,
inventoryequipment.locked,
inventoryequipment.vicious,
inventoryequipment.flag
FROM inventoryitems LEFT JOIN inventoryequipment USING (inventoryitemid) WHERE characterid = ?`,
charID)
if nil != err {
return nil, errors.Trace(err)
}
defer rows.Close()
res := make([]*CharacterInventoryItem, 0, 32)
for rows.Next() {
var item CharacterInventoryItem
if err = rows.Scan(
&item.InventoryItem.InventoryItemID,
&item.InventoryItem.CharacterID,
&item.InventoryItem.StorageID,
&item.InventoryItem.ItemID,
&item.InventoryItem.InventoryType,
&item.InventoryItem.Position,
&item.InventoryItem.Quantity,
&item.InventoryItem.Owner,
&item.InventoryItem.Expiration,
&item.InventoryItem.UniqueID,
&item.InventoryEquipment.InventoryEquipmentID,
&item.InventoryEquipment.InventoryItemID,
&item.InventoryEquipment.UpgradeSlots,
&item.InventoryEquipment.Level,
&item.InventoryEquipment.Str,
&item.InventoryEquipment.Dex,
&item.InventoryEquipment.Intt,
&item.InventoryEquipment.Luk,
&item.InventoryEquipment.HP,
&item.InventoryEquipment.MP,
&item.InventoryEquipment.WAtk,
&item.InventoryEquipment.MAtk,
&item.InventoryEquipment.WDef,
&item.InventoryEquipment.MDef,
&item.InventoryEquipment.Acc,
&item.InventoryEquipment.Avoid,
&item.InventoryEquipment.Hands,
&item.InventoryEquipment.Speed,
&item.InventoryEquipment.Jump,
&item.InventoryEquipment.RingID,
&item.InventoryEquipment.Locked,
&item.InventoryEquipment.Vicious,
&item.InventoryEquipment.Flag,
); nil != err {
return nil, errors.Trace(err)
}
item.InventoryItem.CharacterID = charID
res = append(res, &item)
}
return res, nil
}