semi-idle-arpg/scripts/NPC.gd

59 lines
1.6 KiB
GDScript3
Raw Normal View History

2024-09-19 19:03:06 -06:00
class_name NPC
extends Node2D
2024-09-19 19:03:06 -06:00
enum npcDifficulties { MINION, NORMAL, ELITE, BOSS, ELITEBOSS, BBEG }
enum npcTiers { I, II, III, IV, V, VI, VII, VIII, IX, X }
2024-09-19 19:03:06 -06:00
signal npc_died(npcTier: npcTiers)
@export var charName := "Character"
@export var maxHealth := 10
@export var damageTaken := 0
2024-09-19 19:03:06 -06:00
@export var npcDifficulty: npcDifficulties
@export var npcTier: npcTiers
2024-09-19 19:03:06 -06:00
func _random_mod_health() -> void:
randomize()
# noise factor
var noise_factor = randf_range(7, 10)
self.maxHealth *= noise_factor
# difficulty factor
match self.npcDifficulty:
npcDifficulties.MINION:
self.maxHealth /= 2
npcDifficulties.ELITE:
2024-09-19 19:03:06 -06:00
self.maxHealth *= 2
npcDifficulties.BOSS:
self.maxHealth *= 4
npcDifficulties.ELITEBOSS:
self.maxHealth *= 8
npcDifficulties.BBEG:
self.maxHealth *= 16
# npcTier factor
self.maxHealth *= exp(self.npcTier)
2024-09-19 19:03:06 -06:00
# fun factor (just additional factor to tweak)
self.maxHealth *= 10
func _init() -> void:
self.npcDifficulty = npcDifficulties.NORMAL
self.npcTier = npcTiers.I
func _ready() -> void:
# modify max health value based on the various factors
2024-09-19 19:03:06 -06:00
_random_mod_health()
# set health bar
%Healthbar.max_value = maxHealth
%Healthbar.value = maxHealth
func _process(_delta: float) -> void:
%Healthbar.value = maxHealth - damageTaken
if damageTaken >= maxHealth:
# send signal that I died to be counted, gen loot, etc.
npc_died.emit(self.npcTier)
# delete node
self.free()