last_light/game/item/equipped_inventory.go

75 lines
1.4 KiB
Go
Raw Normal View History

2024-05-21 23:08:51 +03:00
package item
2024-05-06 20:43:35 +03:00
2024-05-21 23:08:51 +03:00
import (
"mvvasilev/last_light/engine"
)
2024-05-06 20:43:35 +03:00
type EquippedSlot int
const (
2024-05-21 23:08:51 +03:00
EquippedSlotNone EquippedSlot = 0
EquippedSlotOffhand EquippedSlot = 1
EquippedSlotDominantHand EquippedSlot = 2
EquippedSlotHead EquippedSlot = 3
EquippedSlotChestplate EquippedSlot = 4
EquippedSlotLeggings EquippedSlot = 5
EquippedSlotShoes EquippedSlot = 6
2024-05-06 20:43:35 +03:00
)
type EquippedInventory struct {
2024-05-21 23:08:51 +03:00
offHand Item
dominantHand Item
2024-05-06 20:43:35 +03:00
2024-05-21 23:08:51 +03:00
head Item
chestplate Item
leggings Item
shoes Item
2024-05-06 20:43:35 +03:00
*BasicInventory
}
2024-05-21 23:08:51 +03:00
func CreateEquippedInventory() *EquippedInventory {
2024-05-06 20:43:35 +03:00
return &EquippedInventory{
2024-05-06 21:19:08 +03:00
BasicInventory: CreateInventory(engine.SizeOf(8, 4)),
2024-05-06 20:43:35 +03:00
}
}
2024-05-21 23:08:51 +03:00
func (ei *EquippedInventory) AtSlot(slot EquippedSlot) Item {
2024-05-06 20:43:35 +03:00
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
}
}
2024-05-21 23:08:51 +03:00
func (ei *EquippedInventory) Equip(item Item, slot EquippedSlot) Item {
2024-05-06 20:43:35 +03:00
switch slot {
case EquippedSlotOffhand:
2024-05-21 23:08:51 +03:00
ei.offHand = item
2024-05-06 20:43:35 +03:00
case EquippedSlotDominantHand:
2024-05-21 23:08:51 +03:00
ei.dominantHand = item
2024-05-06 20:43:35 +03:00
case EquippedSlotHead:
2024-05-21 23:08:51 +03:00
ei.head = item
2024-05-06 20:43:35 +03:00
case EquippedSlotChestplate:
2024-05-21 23:08:51 +03:00
ei.chestplate = item
2024-05-06 20:43:35 +03:00
case EquippedSlotLeggings:
2024-05-21 23:08:51 +03:00
ei.leggings = item
2024-05-06 20:43:35 +03:00
case EquippedSlotShoes:
2024-05-21 23:08:51 +03:00
ei.shoes = item
2024-05-06 20:43:35 +03:00
}
2024-05-21 23:08:51 +03:00
return item
2024-05-06 20:43:35 +03:00
}