last_light/game/model/player_inventory.go

73 lines
1.3 KiB
Go
Raw Normal View History

2024-05-06 20:43:35 +03:00
package model
2024-05-06 21:19:08 +03:00
import "mvvasilev/last_light/engine"
2024-05-06 20:43:35 +03:00
type EquippedSlot int
const (
EquippedSlotOffhand EquippedSlot = iota
EquippedSlotDominantHand
EquippedSlotHead
EquippedSlotChestplate
EquippedSlotLeggings
EquippedSlotShoes
)
type EquippedInventory struct {
offHand *Item
dominantHand *Item
head *Item
chestplate *Item
leggings *Item
shoes *Item
*BasicInventory
}
func CreatePlayerInventory() *EquippedInventory {
return &EquippedInventory{
2024-05-06 21:19:08 +03:00
BasicInventory: CreateInventory(engine.SizeOf(8, 4)),
2024-05-06 20:43:35 +03:00
}
}
func (ei *EquippedInventory) AtSlot(slot EquippedSlot) *Item {
switch slot {
case EquippedSlotOffhand:
return ei.offHand
case EquippedSlotDominantHand:
return ei.dominantHand
case EquippedSlotHead:
return ei.head
case EquippedSlotChestplate:
return ei.chestplate
case EquippedSlotLeggings:
return ei.leggings
case EquippedSlotShoes:
return ei.shoes
default:
return nil
}
}
func (ei *EquippedInventory) Equip(item Item, slot EquippedSlot) *Item {
ref := &item
switch slot {
case EquippedSlotOffhand:
ei.offHand = ref
case EquippedSlotDominantHand:
ei.dominantHand = ref
case EquippedSlotHead:
ei.head = ref
case EquippedSlotChestplate:
ei.chestplate = ref
case EquippedSlotLeggings:
ei.leggings = ref
case EquippedSlotShoes:
ei.shoes = ref
}
return ref
}