meat_madness_redux/godot/assets/meat_bore/npcs/npc.gd

80 lines
2.2 KiB
GDScript3
Raw Normal View History

2023-01-02 22:35:37 -07:00
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
2023-01-03 01:54:59 -07:00
export var initial_dialogic_timeline: String
2023-01-03 11:35:05 -07:00
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")
2023-01-02 22:35:37 -07:00
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()
2023-01-03 01:54:59 -07:00
var _err = $npc_common/Area.connect("body_entered", self, "body_entered")
_err = $npc_common/Area.connect("body_exited", self, "body_exited")
2023-01-03 11:35:05 -07:00
var is_alive = true
func death():
is_alive = false
if animation_fsm_node.has_node("death"):
animation_fsm.travel("death")
2023-01-03 01:54:59 -07:00
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)
2023-01-03 11:35:05 -07:00
func create_dialog(timeline: String):
2023-01-03 01:54:59 -07:00
if dialog.get_ref() == null:
2023-01-03 11:35:05 -07:00
dialog = weakref(Dialogic.start(timeline))
dialog.get_ref().connect("dialogic_signal", self, "timeline_signal")
2023-01-03 01:54:59 -07:00
add_child(dialog.get_ref())
2023-01-03 11:35:05 -07:00
func close_dialog():
2023-01-03 01:54:59 -07:00
if dialog.get_ref() == null:
return
if is_a_parent_of(dialog.get_ref()):
call_deferred("remove_child", dialog.get_ref())
2023-01-03 11:35:05 -07:00
func player_entered():
2023-01-04 02:31:56 -07:00
if has_node("npc_common/SignalGenerator"):
$npc_common.remove_child($npc_common/SignalGenerator)
2023-01-03 11:35:05 -07:00
create_dialog(initial_dialogic_timeline)
func player_exited():
close_dialog()
func timeline_signal(what: String):
if what == "death":
print("guy died")
death()