From 1aba2bdd23aebed4032333e74aa553c40a31fcbd Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sun, 14 Jun 2026 21:07:26 -0400 Subject: refactor: added docs, split up some components in game package --- internal/world/doc.go | 18 ++++++++++++++++++ internal/world/world.go | 18 +++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 internal/world/doc.go (limited to 'internal/world') diff --git a/internal/world/doc.go b/internal/world/doc.go new file mode 100644 index 0000000..cc11535 --- /dev/null +++ b/internal/world/doc.go @@ -0,0 +1,18 @@ +// Package world manages rooms, exits, ground items, mob instances, +// and object instance state for the game world. +// +// Rooms are loaded from YAML files on every access (live-editable). Exits +// support conditional blocking via the action.Condition system. Ground +// items have independent despawn timers and combat-loot reservations. +// +// Object instance state (ObjState) tracks per-instance properties: +// depletion with regen timers, shared depletion for trees with countdown, +// quality for fire objects, and wandering for fishing spots. +// +// MobDef and MobInstance cover mob definitions and runtime instances. +// The MobStore manages YAML loading, instance seeding, and per-room +// mob lists. Mobs wander via legal (unconditioned) room exits. +// +// WordPrefixMatch provides bidirectional prefix matching used by +// commands and object lookups. +package world diff --git a/internal/world/world.go b/internal/world/world.go index e2d12ba..ac5345e 100644 --- a/internal/world/world.go +++ b/internal/world/world.go @@ -192,7 +192,7 @@ func (w *World) FindObjInstances(roomID int, name string) []ObjState { defer w.mu.Unlock() var out []ObjState lower := strings.ToLower(name) - for key, st := range w.objStates { + for _, st := range w.objStates { if st.RoomID != roomID { continue } @@ -210,7 +210,6 @@ func (w *World) FindObjInstances(roomID int, name string) []ObjState { SharedTimer: st.SharedTimer, Quality: st.Quality, }) - _ = key } sort.Slice(out, func(i, j int) bool { if out[i].DefID != out[j].DefID { @@ -225,14 +224,11 @@ func wordMatchesObj(lower, defID, objName string) bool { if WordPrefixMatch(lower, objName) { return true } - nameWords := strings.Fields(strings.ToLower(objName)) inputWords := strings.Fields(strings.ToLower(lower)) - // Check defID as whole (bidirectional) if strings.HasPrefix(strings.ToLower(defID), lower) || strings.HasPrefix(lower, strings.ToLower(defID)) { return true } - // Check each defID part (split by underscore) against each input word (bidirectional) for _, part := range strings.Split(defID, "_") { for _, iw := range inputWords { pl := strings.ToLower(part) @@ -241,42 +237,38 @@ func wordMatchesObj(lower, defID, objName string) bool { } } } - _ = nameWords return false } func (w *World) SetObjName(roomID int, defID string, name string) { w.mu.Lock() defer w.mu.Unlock() - for key, st := range w.objStates { + for _, st := range w.objStates { if st.RoomID == roomID && st.DefID == defID { st.Name = name } - _ = key } } func (w *World) SetObjWander(roomID int, defID string, rooms []int, interval int) { w.mu.Lock() defer w.mu.Unlock() - for key, st := range w.objStates { + for _, st := range w.objStates { if st.RoomID == roomID && st.DefID == defID { st.WanderRooms = rooms st.WanderInterval = interval } - _ = key } } -func (w *World) SetObjSharedDeplete(roomID int, defID string, max int) { +func (w *World) SetObjDepleteTimer(roomID int, defID string, max int) { w.mu.Lock() defer w.mu.Unlock() - for key, st := range w.objStates { + for _, st := range w.objStates { if st.RoomID == roomID && st.DefID == defID && st.SharedMax == 0 { st.SharedMax = max st.SharedTimer = max } - _ = key } } -- cgit v1.2.3