aboutsummaryrefslogtreecommitdiff
path: root/internal/behavior/behavior.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/behavior/behavior.go')
-rw-r--r--internal/behavior/behavior.go24
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.