81 lines
2.6 KiB
GDScript
81 lines
2.6 KiB
GDScript
extends NPC
|
|
|
|
|
|
export(NodePath) var _visibility_path: NodePath
|
|
export(int) var _player_follow_pill_level = 3
|
|
|
|
var _visibility: Area
|
|
var _playerRef
|
|
var _audioPlayer: AudioStreamPlayer3D
|
|
|
|
|
|
func _ready():
|
|
Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
|
|
_visibility = get_node(_visibility_path) as Area
|
|
|
|
_audioPlayer = get_node("AudioStreamPlayer3D") as AudioStreamPlayer3D
|
|
|
|
if _visibility:
|
|
_visibility.connect("body_entered", self, "_on_body_entered_visibility")
|
|
_visibility.connect("body_exited", self, "_on_body_exited_visibility")
|
|
|
|
# TODO: does this implementation have to be that way?
|
|
for player in get_tree().get_nodes_in_group("Player"):
|
|
_playerRef = player
|
|
|
|
|
|
func _process(_delta):
|
|
if current_target:
|
|
# stop following player if pill level is high enough and player is not in an illegal area
|
|
if Pills.get_round_level() > _player_follow_pill_level and _playerRef.Is_in_Illegal_Area() == false:
|
|
Logger.info("player pill level ok and no illegal actions detected!")
|
|
current_target = null
|
|
# otherwise set new position of player
|
|
else:
|
|
current_target = _playerRef.transform.origin
|
|
|
|
|
|
func _on_body_entered_visibility(body: PhysicsBody):
|
|
#Logger.trace("Meldewesen seeing %s" % [body])
|
|
if body.is_in_group("Player"):
|
|
Logger.info("Seeing player!")
|
|
|
|
_audioPlayer.stream = null
|
|
var daytime = Daytime.get_time()
|
|
# do your job
|
|
if body.is_in_workzone():
|
|
Logger.info("say do your job")
|
|
_audioPlayer.stream = load("res://Resources/Audio/do-job.wav")
|
|
# take your pills
|
|
elif Pills.get_level() < Pills.get_max()*0.1:
|
|
Logger.info("say take your pills")
|
|
_audioPlayer.stream = load("res://Resources/Audio/take-pills.wav")
|
|
# go to work
|
|
elif daytime < Daytime.get_max()*0.3:
|
|
Logger.info("say go to work")
|
|
_audioPlayer.stream = load("res://Resources/Audio/to-work.wav")
|
|
# go home
|
|
elif daytime > Daytime.get_max()*0.6:
|
|
Logger.info("say go home")
|
|
_audioPlayer.stream = load("res://Resources/Audio/go-home.wav")
|
|
|
|
if _audioPlayer.stream != null:
|
|
Logger.info("say play sound")
|
|
_audioPlayer.play();
|
|
#yield(audioplayer, "finished")
|
|
|
|
# check if player is in illegal area
|
|
if _playerRef.Is_in_Illegal_Area():
|
|
Logger.info("player is in illegal area - following!")
|
|
current_target = body.transform.origin
|
|
# If the player didn't take enough pills lately, they're suspicious -> Run towards them!
|
|
elif Pills.get_round_level() <= _player_follow_pill_level:
|
|
Logger.info("The player's pill level is too low - following!")
|
|
current_target = body.transform.origin
|
|
|
|
|
|
func _on_body_exited_visibility(body: PhysicsBody):
|
|
if body.is_in_group("Player"):
|
|
Logger.info("Stopped seeing player!")
|
|
current_target = null
|