feat: implement Tekton NPC with core movement, combat, carrying, throwing, and grid interaction logic, alongside its static controller.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
extends Node
|
||||
|
||||
@export var throw_interval_min: float = 4.0
|
||||
@export var throw_interval_max: float = 7.0
|
||||
@export var throw_interval_min: float = 2.0
|
||||
@export var throw_interval_max: float = 4.0
|
||||
@export var throw_range: int = 6
|
||||
|
||||
var tekton: Node3D
|
||||
@@ -43,18 +43,18 @@ func _on_timer_timeout():
|
||||
_start_timer()
|
||||
return
|
||||
|
||||
print("[StaticTekton] Timer timeout. Attempting throw...")
|
||||
# print("[StaticTekton] Timer timeout. Attempting throw...")
|
||||
_attempt_throw()
|
||||
|
||||
func _attempt_throw():
|
||||
# Find target
|
||||
var target = _find_empty_tile()
|
||||
if target == Vector2i(-1, -1):
|
||||
print("[StaticTekton] No valid target found.")
|
||||
# print("[StaticTekton] No valid target found.")
|
||||
_start_timer()
|
||||
return
|
||||
|
||||
print("[StaticTekton] Target found: %s" % target)
|
||||
# print("[StaticTekton] Target found: %s" % target)
|
||||
# Execute Throw
|
||||
# 1. Face target
|
||||
var target_world_pos = Vector3(target.x + 0.5, 0, target.y + 0.5)
|
||||
@@ -71,8 +71,11 @@ func _attempt_throw():
|
||||
if tekton.has_method("play_animation_rpc"):
|
||||
tekton.rpc("play_animation_rpc", "tekton_throw_tile")
|
||||
|
||||
# 3. Sync projectile/effect (Delay for animation sync?)
|
||||
# Assuming animation takes ~1.0s, throw happens at ~0.5s?
|
||||
# 3. Create Projectile Visual (Synced)
|
||||
if tekton.has_method("spawn_projectile_rpc"):
|
||||
tekton.rpc("spawn_projectile_rpc", target_world_pos, 0.5)
|
||||
|
||||
# 4. Impact / Spawn
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
|
||||
var main = tekton.get_tree().get_root().get_node_or_null("Main")
|
||||
@@ -81,11 +84,8 @@ func _attempt_throw():
|
||||
var item_id = randi_range(7, 10)
|
||||
main.rpc("sync_grid_item", target.x, 1, target.y, item_id)
|
||||
|
||||
# Optional: Spawn Projectile Visual?
|
||||
# For now, instant spawn is safest, or we can add a projectile RPC later.
|
||||
|
||||
# 4. Resume Idle
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
# 5. Resume Idle
|
||||
await get_tree().create_timer(0.5).timeout # Small delay after throw
|
||||
if tekton.has_method("play_animation_rpc"):
|
||||
tekton.rpc("play_animation_rpc", "tekton_idle")
|
||||
|
||||
|
||||
@@ -351,6 +351,31 @@ func spawn_tiles_around(count: int = 4):
|
||||
func play_animation_rpc(anim_name: String):
|
||||
play_animation(anim_name)
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func spawn_projectile_rpc(target_pos: Vector3, duration: float):
|
||||
var projectile = MeshInstance3D.new()
|
||||
var box = BoxMesh.new()
|
||||
box.size = Vector3(0.4, 0.1, 0.4)
|
||||
projectile.mesh = box
|
||||
var mat = StandardMaterial3D.new()
|
||||
mat.albedo_color = Color(1, 0.5, 0) # Orange
|
||||
projectile.material_override = mat
|
||||
|
||||
get_parent().add_child(projectile)
|
||||
projectile.global_position = global_position + Vector3(0, 2.0, 0)
|
||||
|
||||
var tween = create_tween()
|
||||
tween.set_parallel(true)
|
||||
tween.tween_property(projectile, "global_position:x", target_pos.x, duration).set_trans(Tween.TRANS_LINEAR)
|
||||
tween.tween_property(projectile, "global_position:z", target_pos.z, duration).set_trans(Tween.TRANS_LINEAR)
|
||||
|
||||
var mid_y = max(global_position.y, target_pos.y) + 3.0
|
||||
var tween_y = create_tween()
|
||||
tween_y.tween_property(projectile, "global_position:y", mid_y, duration/2).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_OUT)
|
||||
tween_y.tween_property(projectile, "global_position:y", target_pos.y, duration/2).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN).set_delay(duration/2)
|
||||
|
||||
tween.chain().tween_callback(projectile.queue_free)
|
||||
|
||||
func play_animation(anim_name: String):
|
||||
# Try specific user path first
|
||||
var anim_player = get_node_or_null("Visuals/tekton/Armature/AnimationPlayer")
|
||||
|
||||
Reference in New Issue
Block a user