|
extends Spatial
|
|
|
|
class_name NPC
|
|
|
|
enum Name {Clark, Guy, Lee, Wally, Jackie, Alexis}
|
|
|
|
export(Name) var who
|
|
export var body_texture: StreamTexture
|
|
export var face_texture: StreamTexture
|
|
export var initial_dialogic_timeline: String
|
|
export var animation_tree: NodePath = "AnimationTree"
|
|
onready var animation_tree_node: AnimationTree = get_node(animation_tree)
|
|
onready var animation_fsm_node: AnimationNodeStateMachine = animation_tree_node.tree_root
|
|
onready var animation_fsm: AnimationNodeStateMachinePlayback = animation_tree_node.get("parameters/playback")
|
|
|
|
func is_male() -> bool:
|
|
return not (who == Name.Jackie or who == Name.Alexis)
|
|
|
|
func set_material():
|
|
var body_mesh: MeshInstance
|
|
if is_male():
|
|
body_mesh = $NPC_Male_Shared/Skeleton/NPC_Male
|
|
else:
|
|
body_mesh = $NPC_female/Skeleton/NPC_Female
|
|
var mat: SpatialMaterial = body_mesh.get_active_material(0).duplicate()
|
|
body_mesh.set_surface_material(0, mat)
|
|
mat.albedo_texture = body_texture
|
|
|
|
if not is_male():
|
|
var face_mat: SpatialMaterial = body_mesh.get_active_material(1).duplicate()
|
|
body_mesh.set_surface_material(1, face_mat)
|
|
face_mat.albedo_texture = face_texture
|
|
|
|
func _ready():
|
|
set_material()
|
|
var _err = $npc_common/Area.connect("body_entered", self, "body_entered")
|
|
_err = $npc_common/Area.connect("body_exited", self, "body_exited")
|
|
|
|
var is_alive = true
|
|
func death():
|
|
is_alive = false
|
|
if animation_fsm_node.has_node("death"):
|
|
animation_fsm.travel("death")
|
|
|
|
func body_entered(body):
|
|
if body.get_parent() == Util.player:
|
|
player_entered()
|
|
|
|
func body_exited(body):
|
|
if body.get_parent() == Util.player:
|
|
player_exited()
|
|
|
|
var dialog = weakref(null)
|
|
|
|
func create_dialog(timeline: String):
|
|
if dialog.get_ref() == null:
|
|
dialog = weakref(Dialogic.start(timeline))
|
|
dialog.get_ref().connect("dialogic_signal", self, "timeline_signal")
|
|
add_child(dialog.get_ref())
|
|
|
|
func close_dialog():
|
|
if dialog.get_ref() == null:
|
|
return
|
|
if is_a_parent_of(dialog.get_ref()):
|
|
call_deferred("remove_child", dialog.get_ref())
|
|
|
|
func player_entered():
|
|
if has_node("npc_common/SignalGenerator"):
|
|
$npc_common.remove_child($npc_common/SignalGenerator)
|
|
if is_alive:
|
|
create_dialog(initial_dialogic_timeline)
|
|
|
|
func player_exited():
|
|
close_dialog()
|
|
|
|
func timeline_signal(what: String):
|
|
if what == "death":
|
|
print("guy died")
|
|
death()
|
|
|