diff options
| author | historia <[not public]> | 2026-06-12 23:52:06 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-12 23:52:06 -0400 |
| commit | a19e6b6ab01670a5932308c7bd0e0e5eed8cbcad (patch) | |
| tree | 80a2e46c3e6cc98bb8b4f708cc403949b14742eb /internal/world | |
| parent | f3a6ae488bbd2128af8356b0da016699c5abb70e (diff) | |
| download | thehouseoficarus-a19e6b6ab01670a5932308c7bd0e0e5eed8cbcad.tar.gz | |
feat: firemaking skill implemented. overhauled how ground items and despawn are handled.
Diffstat (limited to 'internal/world')
| -rw-r--r-- | internal/world/world.go | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/internal/world/world.go b/internal/world/world.go index c8270b1..e2d12ba 100644 --- a/internal/world/world.go +++ b/internal/world/world.go @@ -20,6 +20,8 @@ type GroundItemInfo struct { Quantity int ReservedFor string ReserveTimer int + DespawnTimer int + IsSpawn bool } type groundEntry struct { @@ -63,6 +65,7 @@ type ObjState struct { WanderCounter int SharedMax int SharedTimer int + Quality int } func (w *World) ObjStateKey(roomID int, defID string, index int) string { @@ -76,6 +79,10 @@ func (w *World) objStateKey(roomID int, defID string, index int) string { func (w *World) EnsureObjectStates(roomID int, defIDs []string) { w.mu.Lock() defer w.mu.Unlock() + w.ensureObjectStatesLocked(roomID, defIDs) +} + +func (w *World) ensureObjectStatesLocked(roomID int, defIDs []string) { if w.objStates == nil { w.objStates = make(map[string]*ObjState) } @@ -95,6 +102,55 @@ func (w *World) EnsureObjectStates(roomID int, defIDs []string) { } } +func (w *World) AddObjInstance(roomID int, defID string, quality int) { + w.mu.Lock() + defer w.mu.Unlock() + if w.objStates == nil { + w.objStates = make(map[string]*ObjState) + } + idx := 0 + for { + key := w.objStateKey(roomID, defID, idx) + if _, exists := w.objStates[key]; !exists { + w.objStates[key] = &ObjState{ + DefID: defID, + Name: defID, + Index: idx, + RoomID: roomID, + Quality: quality, + } + return + } + idx++ + } +} + +func (w *World) RemoveObjInstance(roomID int, defID string) { + w.mu.Lock() + defer w.mu.Unlock() + idx := 0 + for { + key := w.objStateKey(roomID, defID, idx) + if _, exists := w.objStates[key]; !exists { + return + } + delete(w.objStates, key) + idx++ + } +} + +func (w *World) AllFireStates() []*ObjState { + w.mu.Lock() + defer w.mu.Unlock() + var out []*ObjState + for _, st := range w.objStates { + if st.DefID == "fire" && st.Quality > 0 { + out = append(out, st) + } + } + return out +} + func (w *World) GetObjState(roomID int, defID string, index int) *ObjState { w.mu.Lock() defer w.mu.Unlock() @@ -152,6 +208,7 @@ func (w *World) FindObjInstances(roomID int, name string) []ObjState { DepleteTimer: st.DepleteTimer, SharedMax: st.SharedMax, SharedTimer: st.SharedTimer, + Quality: st.Quality, }) _ = key } @@ -298,8 +355,10 @@ func (w *World) GroundItemsDetailed(roomID int) []GroundItemInfo { continue } info := GroundItemInfo{ - ItemID: e.itemID, - Quantity: e.quantity, + ItemID: e.itemID, + Quantity: e.quantity, + DespawnTimer: e.despawnTimer, + IsSpawn: e.isSpawn, } if e.reserveTimer > 0 && e.reservedFor != "" { info.ReservedFor = e.reservedFor @@ -338,14 +397,6 @@ func (w *World) AddReservedGroundItem(roomID int, itemID string, qty int, owner func (w *World) AddGroundItem(roomID int, itemID string, qty int) { w.mu.Lock() defer w.mu.Unlock() - for _, e := range w.groundItems[roomID] { - if e.quantity > 0 && strings.EqualFold(e.itemID, itemID) && - (e.reserveTimer <= 0 || e.reservedFor == "") { - e.quantity += qty - e.despawnTimer = DropDespawnTicks - return - } - } e := &groundEntry{ itemID: itemID, quantity: qty, |
