P1 iron: nuggets, ore, clay, kiln, smelter, forge, iron tools and arrows, lantern, tool wear and repair

This commit is contained in:
Paul Bailey
2026-11-05 00:31:07 +00:00
parent ab1f417c32
commit 24c280d885
24 changed files with 1334 additions and 43 deletions

View File

@@ -24,11 +24,11 @@ func setup(id: String, w: Node3D, from: Vector3, vel: Vector3, dmg: float, who:
damage = dmg
shooter = who
_start_speed = maxf(vel.length(), 0.1)
gravity = 9.8 if id == "arrow" else 12.0
gravity = 9.8 if ItemDB.get_item(id).has("ammo") else 12.0
var mi := MeshInstance3D.new()
mi.mesh = ItemDB.mesh_for(id)
mi.material_override = ItemDB.item_material()
if id == "spear":
if ItemDB.get_item(id).get("weapon", {}).has("throw"):
# The spear mesh runs along +Y; turn it to fly point-first along -Z.
mi.transform = Transform3D(Basis(Vector3.RIGHT, -PI * 0.5), Vector3(0, 0, 0.35))
add_child(mi)
@@ -83,26 +83,28 @@ func _on_hit(hit: Dictionary) -> void:
return
if c != null and (c as Node).is_in_group("creature"):
var k := clampf(velocity.length() / _start_speed, 0.4, 1.0)
Actions.projectile_hit(shooter, c, damage * k, global_position, item_id if item_id == "arrow" else "")
if item_id == "spear":
Actions.projectile_hit(shooter, c, damage * k, global_position, item_id if ItemDB.get_item(item_id).has("ammo") else "")
if ItemDB.get_item(item_id).get("weapon", {}).has("throw"):
var at: Vector3 = (c as Node3D).global_position + Vector3(0, 0.05, 0)
_drop(Transform3D(Basis(Vector3.UP, randf() * TAU) * Basis(Vector3.FORWARD, PI * 0.5), at))
else:
queue_free()
return
# Stick into whatever it hit, point first, slightly buried.
var at: Vector3 = hit.position - dir * (0.12 if item_id == "arrow" else 0.25)
var at: Vector3 = hit.position - dir * (0.12 if ItemDB.get_item(item_id).has("ammo") else 0.25)
var b := Basis.looking_at(dir, Vector3.UP if absf(dir.y) < 0.99 else Vector3.RIGHT)
if item_id == "spear":
if ItemDB.get_item(item_id).get("weapon", {}).has("throw"):
b = b * Basis(Vector3.RIGHT, -PI * 0.5) # mesh +Y along the flight
_drop(Transform3D(b, at))
func _drop(xf: Transform3D) -> void:
if not visual:
world.drop_item(item_id, 1, xf)
if not visual and not breaks:
world.drop_item(item_id, 1, xf, extra)
queue_free()
## Online, our game shows the server's arrows and spears in flight
## (creature_net.gd). They hit nothing: the server's copy does that, and
## anything that lands comes from the server as a dropped item.
var visual := false
var extra: Dictionary = {} ## carried onto the item where it lands (a spear's wear)
var breaks := false ## its last throw: nothing is left where it lands