retrace/Characters/Meldewesen/Meldewesen.gd

52 lines
1.6 KiB
GDScript3
Raw Normal View History

extends NPC
export(NodePath) var _visibility_path: NodePath
export(int) var _player_follow_pill_level = 3
var _visibility: Area
2019-12-27 20:21:52 +01:00
var _playerRef
func _ready():
Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
_visibility = get_node(_visibility_path) as Area
if _visibility:
_visibility.connect("body_entered", self, "_on_body_entered_visibility")
_visibility.connect("body_exited", self, "_on_body_exited_visibility")
2019-12-27 20:21:52 +01:00
# TODO: does this implementation have to be that way?
for player in get_tree().get_nodes_in_group("Player"):
_playerRef = player
func _process(_delta):
2019-12-27 20:21:52 +01:00
# stop following player if pill level is high enough and player is not in an illegal area
if current_target and 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
func _on_body_entered_visibility(body: PhysicsBody):
2019-12-14 21:05:09 +01:00
#Logger.trace("Meldewesen seeing %s" % [body])
if body.is_in_group("Player"):
2019-11-02 20:06:20 +01:00
Logger.info("Seeing player!")
2019-12-27 20:21:52 +01:00
# 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!
if 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"):
2019-11-02 20:06:20 +01:00
Logger.info("Stopped seeing player!")
current_target = null