diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/behavior/behavior.go | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/behavior/behavior.go')
| -rw-r--r-- | internal/behavior/behavior.go | 24 |
1 files changed, 17 insertions, 7 deletions
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. |
