This commit is contained in:
karl 2020-01-28 14:12:22 +01:00
commit 2d167726b3

View File

@ -1,7 +1,6 @@
extends NPC
#export(NodePath) var _visibility_path: NodePath
export(int) var _player_follow_pill_level = 3
onready var visibility_cone_mesh = get_node("Visibility/VisibilityCone")
@ -33,12 +32,19 @@ var _interactArea: Area
var _audioPlayer: AudioStreamPlayer3D
var _playerRef
onready var _start_pos = transform.origin
onready var _start_rot: Vector3 = rotation_degrees
var _followingPlayer = false # true if Meldewesen finds player "suspicios" and follows
var _huntingPlayer = false # active if the Meldewesen wants to "catch" the player
var _seeingPlayer = false # as long as player is in visible range
var _lastSound = 0 # timestamp of last played message
var _countCmds = 0 # count of spoken commands -> after MAX_CMDS Meldewesen gets pissy
# test only
var _prev_target = null
func _ready():
#Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
@ -68,18 +74,27 @@ func _ready():
func _process(_delta):
# movement
if current_target:
if _prev_target != current_target:
Logger.info("current target: " + String(current_target))
_prev_target = current_target
# continue following player after illegal action or low pill level
if _huntingPlayer or (_followingPlayer and Pills.get_round_level() <= _player_follow_pill_level):
current_target = _playerRef.transform.origin
# stop following player if pill level is high enough and player is not in an illegal area
else:
Logger.info("player pill level ok and no illegal actions detected!")
_followingPlayer = false
current_target = null
if _followingPlayer:
Logger.info("player pill level ok and no illegal actions detected!")
_followingPlayer = false
current_target = _start_pos
elif current_target == _start_pos and transform.origin.distance_to(current_target) < 0.1:
Logger.info("the watch begins")
current_target = null
current_look_target = null
rotation_degrees = _start_rot
if _seeingPlayer:
# logic
_set_behavior()
_set_behavior() # logic
# audio
if _audioPlayer.stream != null:
@ -97,8 +112,9 @@ func _on_area_entered (area: Area):
func change_visibility_cone_color(new_color: Color):
visibility_cone_mesh.get_surface_material(0).albedo_color = new_color
visibility_cone_mesh.get_surface_material(0).albedo_color.a = VISIBILITY_CONE_ALPHA
if visibility_cone_mesh.get_surface_material(0).albedo_color != new_color:
visibility_cone_mesh.get_surface_material(0).albedo_color = new_color
visibility_cone_mesh.get_surface_material(0).albedo_color.a = VISIBILITY_CONE_ALPHA
func _load_sound ():
@ -189,8 +205,7 @@ func _on_body_entered_visibility (body: PhysicsBody):
if body.is_in_group("Player"):
Logger.info("Seeing player!")
_seeingPlayer = true
_set_behavior()
#_set_behavior()
func _on_body_exited_visibility(body: PhysicsBody):
@ -199,4 +214,6 @@ func _on_body_exited_visibility(body: PhysicsBody):
_seeingPlayer = false
_countCmds = 0
if _huntingPlayer == false and _followingPlayer == false:
current_target = null
# dirty quickfix: TODO: refactor
if current_target != _start_pos:
current_target = null