mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 23:14:36 +01:00
simplify reused code
This commit is contained in:
@@ -53,6 +53,30 @@ func ReadWarehouseItem(bf *byteframe.ByteFrame) MHFItemStack {
|
||||
return item
|
||||
}
|
||||
|
||||
func DiffItemStacks(o []MHFItemStack, u []MHFItemStack) []MHFItemStack {
|
||||
// o = old, u = update, f = final
|
||||
var f []MHFItemStack
|
||||
for _, uItem := range u {
|
||||
exists := false
|
||||
for i := range o {
|
||||
if o[i].WarehouseID == uItem.WarehouseID {
|
||||
exists = true
|
||||
o[i].Quantity = uItem.Quantity
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
uItem.WarehouseID = token.RNG.Uint32()
|
||||
f = append(f, uItem)
|
||||
}
|
||||
}
|
||||
for _, oItem := range o {
|
||||
if oItem.Quantity > 0 {
|
||||
f = append(f, oItem)
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (is MHFItemStack) ToBytes() []byte {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.WriteUint32(is.WarehouseID)
|
||||
|
||||
Reference in New Issue
Block a user