mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
warehouse equipment updates
This commit is contained in:
@@ -8,10 +8,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WarehouseStack struct {
|
type WarehouseStack struct {
|
||||||
ID uint32
|
ID uint32
|
||||||
Index uint16
|
Index uint16
|
||||||
ItemID uint16
|
EquipType uint16
|
||||||
Quantity uint16
|
ItemID uint16
|
||||||
|
Quantity uint16
|
||||||
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgMhfUpdateWarehouse represents the MSG_MHF_UPDATE_WAREHOUSE
|
// MsgMhfUpdateWarehouse represents the MSG_MHF_UPDATE_WAREHOUSE
|
||||||
@@ -41,12 +43,22 @@ func (m *MsgMhfUpdateWarehouse) Parse(bf *byteframe.ByteFrame, ctx *clientctx.Cl
|
|||||||
changes := int(bf.ReadUint16())
|
changes := int(bf.ReadUint16())
|
||||||
var stackUpdate WarehouseStack
|
var stackUpdate WarehouseStack
|
||||||
for i := 0; i < changes; i++ {
|
for i := 0; i < changes; i++ {
|
||||||
stackUpdate.ID = bf.ReadUint32()
|
switch boxType {
|
||||||
stackUpdate.Index = bf.ReadUint16()
|
case 0:
|
||||||
stackUpdate.ItemID = bf.ReadUint16()
|
stackUpdate.ID = bf.ReadUint32()
|
||||||
stackUpdate.Quantity = bf.ReadUint16()
|
stackUpdate.Index = bf.ReadUint16()
|
||||||
_ = bf.ReadUint16() // Unk
|
stackUpdate.ItemID = bf.ReadUint16()
|
||||||
m.Updates = append(m.Updates, stackUpdate)
|
stackUpdate.Quantity = bf.ReadUint16()
|
||||||
|
_ = bf.ReadUint16() // Unk
|
||||||
|
m.Updates = append(m.Updates, stackUpdate)
|
||||||
|
case 1:
|
||||||
|
stackUpdate.ID = bf.ReadUint32()
|
||||||
|
stackUpdate.Index = bf.ReadUint16()
|
||||||
|
stackUpdate.EquipType = bf.ReadUint16()
|
||||||
|
stackUpdate.ItemID = bf.ReadUint16()
|
||||||
|
stackUpdate.Data = bf.ReadBytes(56)
|
||||||
|
m.Updates = append(m.Updates, stackUpdate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ = bf.ReadUint16()
|
_ = bf.ReadUint16()
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -434,11 +434,19 @@ func getWarehouseBox(s *Session, boxType string, boxIndex uint8) []mhfpacket.War
|
|||||||
numStacks := box.ReadUint16()
|
numStacks := box.ReadUint16()
|
||||||
stacks := make([]mhfpacket.WarehouseStack, numStacks)
|
stacks := make([]mhfpacket.WarehouseStack, numStacks)
|
||||||
for i := 0; i < int(numStacks); i++ {
|
for i := 0; i < int(numStacks); i++ {
|
||||||
stacks[i].ID = box.ReadUint32()
|
if boxType == "item" {
|
||||||
stacks[i].Index = box.ReadUint16()
|
stacks[i].ID = box.ReadUint32()
|
||||||
stacks[i].ItemID = box.ReadUint16()
|
stacks[i].Index = box.ReadUint16()
|
||||||
stacks[i].Quantity = box.ReadUint16()
|
stacks[i].ItemID = box.ReadUint16()
|
||||||
box.ReadUint16()
|
stacks[i].Quantity = box.ReadUint16()
|
||||||
|
box.ReadUint16()
|
||||||
|
} else {
|
||||||
|
stacks[i].ID = box.ReadUint32()
|
||||||
|
stacks[i].Index = box.ReadUint16()
|
||||||
|
stacks[i].EquipType = box.ReadUint16()
|
||||||
|
stacks[i].ItemID = box.ReadUint16()
|
||||||
|
stacks[i].Data = box.ReadBytes(56)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return stacks
|
return stacks
|
||||||
} else {
|
} else {
|
||||||
@@ -446,15 +454,23 @@ func getWarehouseBox(s *Session, boxType string, boxIndex uint8) []mhfpacket.War
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func boxToBytes(stacks []mhfpacket.WarehouseStack) []byte {
|
func boxToBytes(stacks []mhfpacket.WarehouseStack, boxType string) []byte {
|
||||||
bf := byteframe.NewByteFrame()
|
bf := byteframe.NewByteFrame()
|
||||||
bf.WriteUint16(uint16(len(stacks)))
|
bf.WriteUint16(uint16(len(stacks)))
|
||||||
for _, stack := range stacks {
|
for i, stack := range stacks {
|
||||||
bf.WriteUint32(stack.ID)
|
if boxType == "item" {
|
||||||
bf.WriteUint16(stack.Index)
|
bf.WriteUint32(stack.ID)
|
||||||
bf.WriteUint16(stack.ItemID)
|
bf.WriteUint16(uint16(i + 1))
|
||||||
bf.WriteUint16(stack.Quantity)
|
bf.WriteUint16(stack.ItemID)
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(stack.Quantity)
|
||||||
|
bf.WriteUint16(0)
|
||||||
|
} else {
|
||||||
|
bf.WriteUint32(stack.ID)
|
||||||
|
bf.WriteUint16(uint16(i + 1))
|
||||||
|
bf.WriteUint16(stack.EquipType)
|
||||||
|
bf.WriteUint16(stack.ItemID)
|
||||||
|
bf.WriteBytes(stack.Data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bf.WriteUint16(0)
|
bf.WriteUint16(0)
|
||||||
return bf.Data()
|
return bf.Data()
|
||||||
@@ -464,7 +480,7 @@ func handleMsgMhfEnumerateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
pkt := p.(*mhfpacket.MsgMhfEnumerateWarehouse)
|
pkt := p.(*mhfpacket.MsgMhfEnumerateWarehouse)
|
||||||
box := getWarehouseBox(s, pkt.BoxType, pkt.BoxIndex)
|
box := getWarehouseBox(s, pkt.BoxType, pkt.BoxIndex)
|
||||||
if len(box) > 0 {
|
if len(box) > 0 {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, boxToBytes(box))
|
doAckBufSucceed(s, pkt.AckHandle, boxToBytes(box, pkt.BoxType))
|
||||||
} else {
|
} else {
|
||||||
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
@@ -477,11 +493,21 @@ func handleMsgMhfUpdateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
var newStacks []mhfpacket.WarehouseStack
|
var newStacks []mhfpacket.WarehouseStack
|
||||||
for _, update := range pkt.Updates {
|
for _, update := range pkt.Updates {
|
||||||
exists := false
|
exists := false
|
||||||
for i, stack := range box {
|
if pkt.BoxType == "item" {
|
||||||
if stack.ItemID == update.ItemID {
|
for i, stack := range box {
|
||||||
box[i].Quantity = update.Quantity
|
if stack.Index == update.Index {
|
||||||
exists = true
|
exists = true
|
||||||
break
|
box[i].Quantity = update.Quantity
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i, stack := range box {
|
||||||
|
if stack.Index == update.Index {
|
||||||
|
exists = true
|
||||||
|
box[i].ItemID = update.ItemID
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if exists == false {
|
if exists == false {
|
||||||
@@ -495,10 +521,16 @@ func handleMsgMhfUpdateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
// Slice empty stacks
|
// Slice empty stacks
|
||||||
var cleanedBox []mhfpacket.WarehouseStack
|
var cleanedBox []mhfpacket.WarehouseStack
|
||||||
for _, stack := range box {
|
for _, stack := range box {
|
||||||
if stack.Quantity > 0 {
|
if pkt.BoxType == "item" {
|
||||||
cleanedBox = append(cleanedBox, stack)
|
if stack.Quantity > 0 {
|
||||||
|
cleanedBox = append(cleanedBox, stack)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if stack.ItemID != 0 {
|
||||||
|
cleanedBox = append(cleanedBox, stack)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.server.db.Exec(fmt.Sprintf("UPDATE warehouse SET %s%d=$1 WHERE character_id=$2", pkt.BoxType, pkt.BoxIndex), boxToBytes(cleanedBox), s.charID)
|
s.server.db.Exec(fmt.Sprintf("UPDATE warehouse SET %s%d=$1 WHERE character_id=$2", pkt.BoxType, pkt.BoxIndex), boxToBytes(cleanedBox, pkt.BoxType), s.charID)
|
||||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user