Added arn to the main repository
This commit is contained in:
44
arn/InventorySlot.go
Normal file
44
arn/InventorySlot.go
Normal file
@ -0,0 +1,44 @@
|
||||
package arn
|
||||
|
||||
import "errors"
|
||||
|
||||
// InventorySlot ...
|
||||
type InventorySlot struct {
|
||||
ItemID string `json:"itemId"`
|
||||
Quantity uint `json:"quantity"`
|
||||
}
|
||||
|
||||
// IsEmpty ...
|
||||
func (slot *InventorySlot) IsEmpty() bool {
|
||||
return slot.ItemID == ""
|
||||
}
|
||||
|
||||
// Item ...
|
||||
func (slot *InventorySlot) Item() *ShopItem {
|
||||
if slot.ItemID == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
item, _ := GetShopItem(slot.ItemID)
|
||||
return item
|
||||
}
|
||||
|
||||
// Decrease reduces the quantity by the given number.
|
||||
func (slot *InventorySlot) Decrease(count uint) error {
|
||||
if slot.Quantity < count {
|
||||
return errors.New("Not enough items")
|
||||
}
|
||||
|
||||
slot.Quantity -= count
|
||||
|
||||
if slot.Quantity == 0 {
|
||||
slot.ItemID = ""
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Increase increases the quantity by the given number.
|
||||
func (slot *InventorySlot) Increase(count uint) {
|
||||
slot.Quantity += count
|
||||
}
|
Reference in New Issue
Block a user