extends Spatial var root : NPC = null var investigationPoint : Spatial # var param = task.get_param(0) func _ready(): root = get_parent() investigationPoint = Spatial.new() get_tree().current_scene.call_deferred("add_child", investigationPoint) func task_print(task): if task.get_param_count() > 0: print(task.get_param(0)) task.succeed() func task_has_any_task(task): if root.task == null: task.failed() else: task.succeed() func task_has_investigate(task): if root.investigate == null: task.failed() else: task.succeed() func task_has_currTask(task): if root.currentTask == null: task.failed() else: task.succeed() func task_player_spotted(task): if root.playerTask == null: task.failed() else: print("Player spotted") task.succeed() func task_player_near_sight(task): if root.sightNear: task.succeed() else: task.failed() func task_player_far_sight(task): if root.sightFar: task.succeed() else: task.failed() func task_player_near_hear(task): if root.hearNear: task.succeed() else: task.failed() func task_player_far_hear(task): if root.hearFar: task.succeed() else: task.failed() func task_can_see_player(task): var param = 0.5 if task.get_param_count() > 0: param = task.get_param(0) if root.canSeePlayer(param): print("Can see") task.succeed() else: task.failed() func task_is_aggressive(task): if root.isAggressive: task.succeed() else: task.failed() func task_should_investigate_sounds(task): if root.investigateSounds: task.succeed() else: task.failed() func task_investigate_player_last_seen(task): if root.playerTask == null: task.failed() return investigationPoint.global_transform = root.playerTask.global_transform root.playerTask = null root.investigate = investigationPoint root.task = root.investigate task.succeed() func task_has_heard_something(task): if root.has_heard != null: task.succeed() else: task.failed() func task_investigate_heard(task): if root.has_heard == null: task.failed() return root.investigate = root.has_heard root.task = root.has_heard root.has_heard = null task.succeed() func task_set_action(task): root.action = task.get_param(0) task.succeed() func task_set_speed(task): root.speed = task.get_param(0) task.succeed() func task_moveToTarget(task): if root.reachedTarget(): if root.finishTask(): task.succeed() return root.moveNPC() task.succeed() ### Automatically get most important task func task_get_task(task): ## do priority task if there is one if root.playerTask != null: root.investigate = null root.task = root.playerTask print("detect player") ## investigate a noise elif root.investigate != null: root.task = root.investigate print("detect investigate") ## or do the current task if there is no priority task elif root.currentTask != null: root.task = root.currentTask ## but dont continue if there are no tasks to do and nothing to investigate else: task.failed() return task.succeed()