71 lines
1.9 KiB
GDScript
71 lines
1.9 KiB
GDScript
# base NPCEnemy class
|
|
class_name NPCEnemy
|
|
extends NPC
|
|
|
|
|
|
var target
|
|
@export var attack_base := 1
|
|
var attack_damage := 0
|
|
var speed := 200
|
|
var prevCollisions := 0
|
|
|
|
|
|
# func _init() -> void:
|
|
# # TODO: randomize within area restrictions? or put this in area?
|
|
# self.npcDifficulty = NPCDifficulty.NORMAL
|
|
# self.npcTier = NPCTier.I
|
|
|
|
|
|
func _ready() -> void:
|
|
# add to enemies
|
|
add_to_group("enemies")
|
|
|
|
# set faction
|
|
self.faction = Globals.World.Faction.CREATURE
|
|
|
|
# randomness
|
|
# TODO: needs to be random from distribution
|
|
# var rand_difficulty = NPC.NPCDifficulty.values().pick_random()
|
|
|
|
# set health
|
|
_random_mod_health()
|
|
|
|
# set health bar
|
|
%Healthbar.max_value = maxHealth
|
|
%Healthbar.value = maxHealth
|
|
|
|
# set damage
|
|
attack_damage = attack_base
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
%Healthbar.value = maxHealth - damageTaken
|
|
if damageTaken >= maxHealth:
|
|
# save vars to emit
|
|
var enemyDifficulty = self.npcDifficulty
|
|
var enemyFaction = self.faction
|
|
var enemyTier = self.npcTier
|
|
# delete node
|
|
# TODO: add fade out for enemy death, Global func doens't work due to
|
|
# the node getting freed, await didn't help. reimpliment here in enemy.
|
|
self.remove_from_group("enemies")
|
|
self.queue_free()
|
|
# send signal that I died to be counted, etc.
|
|
SignalBus.enemy_died.emit(enemyDifficulty, enemyTier, enemyFaction)
|
|
|
|
|
|
func _physics_process(_delta):
|
|
velocity = position.direction_to(target) * speed
|
|
# look_at(target)
|
|
# BUG: want enemy to pause when touching something, to prevent vibrating
|
|
if position.distance_to(target) > 10 and get_slide_collision_count() == prevCollisions:
|
|
move_and_slide()
|
|
prevCollisions = get_slide_collision_count()
|
|
|
|
|
|
func _deal_damage() -> void:
|
|
SignalBus.enemy_damaged_player.emit(attack_damage)
|
|
|
|
func _on_attack_timer_timeout() -> void:
|
|
_deal_damage()
|