diff options
| author | historia <[not public]> | 2026-06-10 01:48:28 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-10 01:48:28 -0400 |
| commit | a226d72e51eecb768b13600303f73483118d9104 (patch) | |
| tree | 458d15ef049732c15dacc591a830d3beddbedfde /internal/player | |
| parent | 6a0f3d7a252de4b1741cfe5e1c561412c602becc (diff) | |
| download | thehouseoficarus-a226d72e51eecb768b13600303f73483118d9104.tar.gz | |
feat: implemented janky object interaction model
Diffstat (limited to 'internal/player')
| -rw-r--r-- | internal/player/player.go | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/internal/player/player.go b/internal/player/player.go index ad56923..d6e450a 100644 --- a/internal/player/player.go +++ b/internal/player/player.go @@ -1,5 +1,6 @@ package player +import "thirdcollapse/internal/action" import "thirdcollapse/internal/object" type SkillName string @@ -83,10 +84,10 @@ type InventorySlot struct { type Player struct { Name string `yaml:"name"` - Skills map[SkillName]int `yaml:"skills"` // xp - Inventory map[int]*InventorySlot `yaml:"inventory"` // slot 0-27 -> item - Equipment map[object.EquipSlot]string `yaml:"equipment"` // slot -> item_id - Toolbelt []string `yaml:"toolbelt"` // item_ids + Skills map[SkillName]int `yaml:"skills"` + Inventory map[int]*InventorySlot `yaml:"inventory"` + Equipment map[object.EquipSlot]string `yaml:"equipment"` + Toolbelt []string `yaml:"toolbelt"` RoomID int `yaml:"room_id"` HP int `yaml:"hp"` Credits int `yaml:"credits"` @@ -94,6 +95,7 @@ type Player struct { AttackStyle AttackStyle `yaml:"attack_style"` Toggles map[string]bool `yaml:"toggles"` RegenerateTick int + Action *action.Action `yaml:"-"` } func (p *Player) InvSlot(i int) *InventorySlot { @@ -189,3 +191,41 @@ func (p *Player) StartRegen() { p.RegenerateTick = 100 } } + +func (p *Player) HasToolbeltItem(itemID string) bool { + for _, id := range p.Toolbelt { + if id == itemID { + return true + } + } + return false +} + +func (p *Player) HasItem(itemID string) bool { + for _, slot := range p.Inventory { + if slot != nil && slot.ItemID == itemID && slot.Quantity > 0 { + return true + } + } + return false +} + +func (p *Player) RemoveItem(itemID string, qty int) bool { + remaining := qty + for i, slot := range p.Inventory { + if slot == nil || slot.ItemID != itemID { + continue + } + if slot.Quantity <= remaining { + remaining -= slot.Quantity + delete(p.Inventory, i) + } else { + slot.Quantity -= remaining + remaining = 0 + } + if remaining <= 0 { + return true + } + } + return remaining <= 0 +} |
