Fish per water type in data/fish.json; worldlets design
- data/fish.json: fish, weights, dawn/dusk odds, bite timing and minimum depth per water type; ItemDB.define_water() registers them - world.water_at(x, z) answers lake / sea / dry land; the float uses it, so a worldlet with a sea only needs a "sea" entry - Clear messages for shallow water and water with nothing to catch - Lake fish: more of them, bigger, nearer the shore, jumping with splash rings - docs/WORLDLETS_DESIGN.md: proposal for data-defined world types
This commit is contained in:
@@ -14,11 +14,14 @@ const ICON_SIZE := 96
|
||||
var items: Dictionary = {} # id -> definition Dictionary
|
||||
var recipes: Dictionary = {} # id -> recipe Dictionary (insertion order kept)
|
||||
var icons: Dictionary = {} # id -> Texture2D
|
||||
## Fishing by water type (data/fish.json): {"modifiers": {...}, "waters": {type: {...}}}.
|
||||
var fishing: Dictionary = {"modifiers": {}, "waters": {}}
|
||||
var _item_mat: StandardMaterial3D
|
||||
|
||||
func _ready() -> void:
|
||||
_load("res://data/items.json", "items", define_item)
|
||||
_load("res://data/recipes.json", "recipes", define_recipe)
|
||||
_load_fishing("res://data/fish.json")
|
||||
if DisplayServer.get_name() != "headless":
|
||||
_render_icons.call_deferred()
|
||||
|
||||
@@ -51,6 +54,31 @@ func define_recipe(r: Dictionary) -> void:
|
||||
r.station = String(r.get("station", ""))
|
||||
recipes[r.id] = r
|
||||
|
||||
func _load_fishing(path: String) -> void:
|
||||
var data = JSON.parse_string(FileAccess.get_file_as_string(path))
|
||||
if typeof(data) != TYPE_DICTIONARY or not data.has("waters"):
|
||||
push_error("ItemDB: could not parse %s" % path)
|
||||
return
|
||||
fishing.modifiers = data.get("modifiers", {})
|
||||
for water in data.waters:
|
||||
define_water(water, data.waters[water])
|
||||
|
||||
## Registers (or replaces) the fish for one water type. Same shape an addon
|
||||
## would use to add, say, a "swamp" water with its own catch.
|
||||
func define_water(water: String, d: Dictionary) -> void:
|
||||
var fish: Array = []
|
||||
for f in d.get("fish", []):
|
||||
if not items.has(f.get("id", "")):
|
||||
push_error("ItemDB: fish '%s' in water '%s' is not an item" % [f.get("id", "?"), water])
|
||||
continue
|
||||
fish.append({"id": f.id, "weight": float(f.get("weight", 1)), "dawn_dusk": float(f.get("dawn_dusk", f.get("weight", 1)))})
|
||||
var w: Array = d.get("bite_wait", [5.0, 14.0])
|
||||
fishing.waters[water] = {"min_depth": float(d.get("min_depth", 0.5)), "bite_wait": [float(w[0]), float(w[1])], "fish": fish}
|
||||
|
||||
## The fishing table for a water type ({} = nothing to catch there).
|
||||
func water_fishing(water: String) -> Dictionary:
|
||||
return fishing.waters.get(water, {})
|
||||
|
||||
func get_item(id: String) -> Dictionary:
|
||||
return items.get(id, {})
|
||||
|
||||
|
||||
@@ -12,9 +12,11 @@ extends Node3D
|
||||
## A line is drawn from the rod tip each frame (hands.gd gives the tip).
|
||||
|
||||
const BITE_WINDOW := 1.5
|
||||
const MIN_DEPTH := 0.5 ## water this deep under the float, or no fish
|
||||
const LINE_LENGTH := 26.0
|
||||
|
||||
var water_type := "" ## "lake", "sea"... (world.water_at)
|
||||
var table: Dictionary = {} ## that water's fishing table (ItemDB.water_fishing)
|
||||
|
||||
var world: Node3D
|
||||
var player: Node3D
|
||||
var state := "flying"
|
||||
@@ -59,20 +61,34 @@ func _physics_process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
_draw_line()
|
||||
|
||||
## How long until the next bite (seconds).
|
||||
func _next_wait() -> float:
|
||||
func _dawn_dusk() -> bool:
|
||||
var h: float = world.day_night.hours()
|
||||
var k := 1.0
|
||||
if (h > 5.0 and h < 8.5) or (h > 17.0 and h < 20.5):
|
||||
k *= 0.6 # fish feed at dawn and dusk
|
||||
if world.weather.precip > 0.3:
|
||||
k *= 0.8
|
||||
return rng.randf_range(5.0, 14.0) * k
|
||||
return (h > 5.0 and h < 8.5) or (h > 17.0 and h < 20.5)
|
||||
|
||||
## How long until the next bite (seconds), from data/fish.json.
|
||||
func _next_wait() -> float:
|
||||
var mods: Dictionary = ItemDB.fishing.modifiers
|
||||
var w: Array = table.get("bite_wait", [5.0, 14.0])
|
||||
var k := 1.0
|
||||
if _dawn_dusk():
|
||||
k *= float(mods.get("dawn_dusk_wait", 0.6)) # fish feed at dawn and dusk
|
||||
if world.weather.precip > 0.3:
|
||||
k *= float(mods.get("rain_wait", 0.8))
|
||||
return rng.randf_range(w[0], w[1]) * k
|
||||
|
||||
## A weighted pick from this water's fish (dawn/dusk weights when they apply).
|
||||
func _pick_fish() -> String:
|
||||
var h: float = world.day_night.hours()
|
||||
var trout := 0.4 if (h > 5.0 and h < 8.5) or (h > 17.0 and h < 20.5) else 0.22
|
||||
return "trout" if rng.randf() < trout else "perch"
|
||||
var fish: Array = table.get("fish", [])
|
||||
var key := "dawn_dusk" if _dawn_dusk() else "weight"
|
||||
var total := 0.0
|
||||
for f in fish:
|
||||
total += float(f[key])
|
||||
var roll := rng.randf() * total
|
||||
for f in fish:
|
||||
roll -= float(f[key])
|
||||
if roll <= 0.0:
|
||||
return f.id
|
||||
return fish[-1].id if not fish.is_empty() else ""
|
||||
|
||||
func step(dt: float) -> void:
|
||||
_t += dt
|
||||
@@ -86,14 +102,24 @@ func step(dt: float) -> void:
|
||||
velocity.y -= 9.8 * dt
|
||||
var p := global_position + velocity * dt
|
||||
var ground: float = terrain.sample_height(p.x, p.z)
|
||||
if p.y <= terrain.water_level and ground < terrain.water_level - MIN_DEPTH:
|
||||
p.y = terrain.water_level
|
||||
state = "floating"
|
||||
wait_left = _next_wait()
|
||||
var water: Dictionary = world.water_at(p.x, p.z)
|
||||
if not water.is_empty() and p.y <= float(water.surface):
|
||||
p.y = water.surface
|
||||
water_type = water.type
|
||||
table = ItemDB.water_fishing(water_type)
|
||||
if table.is_empty() or table.fish.is_empty():
|
||||
state = "landed"
|
||||
Actions.notify.emit("Nothing to catch here")
|
||||
elif float(water.depth) < float(table.min_depth):
|
||||
state = "landed"
|
||||
Actions.notify.emit("Too shallow here: cast further out")
|
||||
else:
|
||||
state = "floating"
|
||||
wait_left = _next_wait()
|
||||
elif p.y <= ground + 0.03:
|
||||
p.y = ground + 0.03
|
||||
state = "landed"
|
||||
Actions.notify.emit("Cast into the water (deeper than this)" if ground < terrain.water_level else "Cast into the water")
|
||||
Actions.notify.emit("Cast into the water")
|
||||
global_position = p
|
||||
"floating":
|
||||
wait_left -= dt
|
||||
@@ -110,7 +136,7 @@ func step(dt: float) -> void:
|
||||
if bite_left <= 0.0:
|
||||
state = "floating"
|
||||
fish = ""
|
||||
wait_left = _next_wait() * 1.3
|
||||
wait_left = _next_wait() * float(ItemDB.fishing.modifiers.get("missed_wait", 1.3))
|
||||
_mesh.position.y = 0.0
|
||||
Actions.notify.emit("It got away")
|
||||
|
||||
|
||||
@@ -487,6 +487,17 @@ func _update_grass_cuts() -> void:
|
||||
xfs.append(p.global_transform)
|
||||
props.set_grass_cuts(xfs, 1.02)
|
||||
|
||||
## What water is at (x, z): {"type": "lake"|"sea", "surface": y, "depth": m},
|
||||
## or {} on dry land. The one place that knows this island's water bodies, so
|
||||
## fishing (and later swimming, boats) work on any world that answers it.
|
||||
func water_at(x: float, z: float) -> Dictionary:
|
||||
var ground: float = terrain.sample_height(x, z)
|
||||
if terrain.inside_boundary(x, z, -2.0) and ground < terrain.water_level:
|
||||
return {"type": "lake", "surface": terrain.water_level, "depth": terrain.water_level - ground}
|
||||
if terrain.sea_weight(x, z) > 0.5 and ground < terrain.sea_level:
|
||||
return {"type": "sea", "surface": terrain.sea_level, "depth": terrain.sea_level - ground}
|
||||
return {}
|
||||
|
||||
## Leaves `count` of an item lying in the world at `xf` (an arrow stuck in a
|
||||
## tree, a thrown spear, meat that didn't fit). Saved with the world.
|
||||
func drop_item(id: String, count: int, xf: Transform3D) -> Node3D:
|
||||
|
||||
Reference in New Issue
Block a user