aboutsummaryrefslogtreecommitdiff
path: root/internal/world/world.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-09 17:15:13 -0400
committerhistoria <[not public]>2026-06-09 17:15:13 -0400
commit9edc568e16741d443b67fbd23b0d91790085ced9 (patch)
treed54be40531ba124dcf8299f9e94bfba4ece273ae /internal/world/world.go
parent56be6a3f45830594225a765b406816e6179ccde1 (diff)
downloadthehouseoficarus-9edc568e16741d443b67fbd23b0d91790085ced9.tar.gz
combat, mobs, parsing, toggles, hard disconnect handling
Diffstat (limited to 'internal/world/world.go')
-rw-r--r--internal/world/world.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/internal/world/world.go b/internal/world/world.go
index 265a2f9..1429081 100644
--- a/internal/world/world.go
+++ b/internal/world/world.go
@@ -11,6 +11,14 @@ import (
)
const DropDespawnTicks = 1000
+const ReserveTicks = 100
+
+type GroundItemInfo struct {
+ ItemID string
+ Quantity int
+ ReservedFor string
+ ReserveTimer int
+}
type groundEntry struct {
itemID string
@@ -20,6 +28,8 @@ type groundEntry struct {
respawnQty int
respawnDelay int
despawnTimer int // >0 = counting down to despawn (dropped items)
+ reservedFor string
+ reserveTimer int // >0 = counting down reservation
}
type World struct {
@@ -75,6 +85,27 @@ func (w *World) ResolveExit(input string) ExitDir {
return ""
}
+func (w *World) GroundItemsDetailed(roomID int) []GroundItemInfo {
+ w.mu.Lock()
+ defer w.mu.Unlock()
+ var out []GroundItemInfo
+ for _, e := range w.groundItems[roomID] {
+ if e.quantity <= 0 {
+ continue
+ }
+ info := GroundItemInfo{
+ ItemID: e.itemID,
+ Quantity: e.quantity,
+ }
+ if e.reserveTimer > 0 && e.reservedFor != "" {
+ info.ReservedFor = e.reservedFor
+ info.ReserveTimer = e.reserveTimer
+ }
+ out = append(out, info)
+ }
+ return out
+}
+
func (w *World) GroundItems(roomID int) map[string]int {
w.mu.Lock()
defer w.mu.Unlock()
@@ -87,6 +118,19 @@ func (w *World) GroundItems(roomID int) map[string]int {
return out
}
+func (w *World) AddReservedGroundItem(roomID int, itemID string, qty int, owner string) {
+ w.mu.Lock()
+ defer w.mu.Unlock()
+ e := &groundEntry{
+ itemID: itemID,
+ quantity: qty,
+ despawnTimer: DropDespawnTicks,
+ reservedFor: owner,
+ reserveTimer: ReserveTicks,
+ }
+ w.groundItems[roomID] = append(w.groundItems[roomID], e)
+}
+
func (w *World) AddGroundItem(roomID int, itemID string, qty int) {
w.mu.Lock()
defer w.mu.Unlock()
@@ -98,6 +142,38 @@ func (w *World) AddGroundItem(roomID int, itemID string, qty int) {
w.groundItems[roomID] = append(w.groundItems[roomID], e)
}
+func (w *World) RemoveReservedGroundItem(roomID int, itemID string, qty int, owner string) (int, bool) {
+ w.mu.Lock()
+ defer w.mu.Unlock()
+ removed := 0
+ remaining := qty
+ for _, e := range w.groundItems[roomID] {
+ if remaining <= 0 {
+ break
+ }
+ if !strings.EqualFold(e.itemID, itemID) {
+ continue
+ }
+ if e.quantity <= 0 {
+ continue
+ }
+ if e.reserveTimer > 0 && e.reservedFor != "" && e.reservedFor != owner {
+ return removed, false
+ }
+ take := e.quantity
+ if take > remaining {
+ take = remaining
+ }
+ e.quantity -= take
+ removed += take
+ remaining -= take
+ if e.isSpawn && e.quantity <= 0 && e.respawnDelay > 0 {
+ e.respawnTimer = e.respawnDelay
+ }
+ }
+ return removed, true
+}
+
func (w *World) RemoveGroundItem(roomID int, itemID string, qty int) int {
w.mu.Lock()
defer w.mu.Unlock()
@@ -177,6 +253,12 @@ func (w *World) Tick() {
e.quantity = 0
}
}
+ if e.reserveTimer > 0 {
+ e.reserveTimer--
+ if e.reserveTimer <= 0 {
+ e.reservedFor = ""
+ }
+ }
}
}
}