# base NPC class class_name NPC extends CharacterBody2D enum NPCDifficulties {MINION, NORMAL, ELITE, BOSS, ELITEBOSS, BBEG} enum NPCTiers {I, II, III, IV, V, VI, VII, VIII, IX, X} signal npc_died(npcTier: NPCTiers) @export var charName := "Character" @export var maxHealth := 10 @export var damageTaken := 0 @export var npcDifficulty: NPCDifficulties @export var npcTier: NPCTiers 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: 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) # 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 _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()