From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/behavior/behavior.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'internal/behavior/behavior.go') diff --git a/internal/behavior/behavior.go b/internal/behavior/behavior.go index e5039af..975624e 100644 --- a/internal/behavior/behavior.go +++ b/internal/behavior/behavior.go @@ -114,11 +114,11 @@ type Trigger struct { // SpawnMobConfig configures a transient mob spawned by a trigger step. The // mob id is required; other fields are optional. type SpawnMobConfig struct { - ID string `yaml:"id"` - OwnerOnly bool `yaml:"owner_only"` - DespawnOnLeave bool `yaml:"despawn_on_leave"` - DespawnRooms []int `yaml:"despawn_rooms"` - DespawnTicks float64 `yaml:"despawn_ticks"` + ID string `yaml:"id" json:"id"` + OwnerOnly bool `yaml:"owner_only" json:"owner_only"` + DespawnOnLeave bool `yaml:"despawn_on_leave" json:"despawn_on_leave"` + DespawnRooms []int `yaml:"despawn_rooms" json:"despawn_rooms"` + DespawnTicks float64 `yaml:"despawn_ticks" json:"despawn_ticks"` } // ShopConfig is a root-level mob property (mob YAML `shop:`). Buy prices are @@ -193,10 +193,20 @@ func (c *ShopConfig) SellPrice(value, stock int) int { // RestockInterval returns the effective restock interval (in ticks) for an item, // honoring the per-item override, then the configurable global default. func (c *ShopConfig) RestockInterval(item *ShopItem) int { + var ticks float64 if item != nil && item.RestockTicks > 0 { - return int(item.RestockTicks) + ticks = item.RestockTicks + } else { + ticks = ShopDefaultRestock } - return int(ShopDefaultRestock) + // restock_ticks is authored as a float, so truncation can turn a valid + // fractional interval (e.g. 0.5) into 0; the shop loop would then + // decrement to -1 and restock every tick. Clamp to at least one tick. + n := int(ticks) + if n < 1 { + n = 1 + } + return n } // FindItem returns the configured shop item with the given id, or nil. -- cgit v1.2.3