2024-10-16 15:16:54 -06:00
|
|
|
# base NPC class
|
2024-09-19 19:03:06 -06:00
|
|
|
class_name NPC
|
2024-10-15 15:04:40 -06:00
|
|
|
extends CharacterBody2D
|
2024-09-19 19:03:06 -06:00
|
|
|
|
|
|
|
|
2024-10-18 13:24:11 -06:00
|
|
|
enum NPCDifficulty {MINION, NORMAL, ELITE, BOSS, ELITEBOSS, BBEG}
|
|
|
|
enum NPCTier {I, II, III, IV, V, VI, VII, VIII, IX, X}
|
2024-09-19 19:03:06 -06:00
|
|
|
|
2024-10-18 13:24:11 -06:00
|
|
|
signal npc_died(npcTier: NPCTier)
|
2024-10-15 08:14:02 -06:00
|
|
|
|
|
|
|
@export var charName := "Character"
|
|
|
|
@export var maxHealth := 10
|
|
|
|
@export var damageTaken := 0
|
2024-10-18 13:24:11 -06:00
|
|
|
@export var npcDifficulty: NPCDifficulty
|
|
|
|
@export var npcTier: NPCTier
|
2024-10-20 16:44:08 -06:00
|
|
|
@export var faction: Globals.World.Faction
|
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:
|
2024-10-18 13:24:11 -06:00
|
|
|
NPCDifficulty.MINION:
|
2024-09-19 19:03:06 -06:00
|
|
|
self.maxHealth /= 2
|
2024-10-18 13:24:11 -06:00
|
|
|
NPCDifficulty.ELITE:
|
2024-09-19 19:03:06 -06:00
|
|
|
self.maxHealth *= 2
|
2024-10-18 13:24:11 -06:00
|
|
|
NPCDifficulty.BOSS:
|
2024-09-19 19:03:06 -06:00
|
|
|
self.maxHealth *= 4
|
2024-10-18 13:24:11 -06:00
|
|
|
NPCDifficulty.ELITEBOSS:
|
2024-09-19 19:03:06 -06:00
|
|
|
self.maxHealth *= 8
|
2024-10-18 13:24:11 -06:00
|
|
|
NPCDifficulty.BBEG:
|
2024-09-19 19:03:06 -06:00
|
|
|
self.maxHealth *= 16
|
2024-10-01 14:13:54 -06:00
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2024-10-20 16:44:08 -06:00
|
|
|
# func _init() -> void:
|
|
|
|
# self.npcDifficulty = NPCDifficulty.NORMAL
|
|
|
|
# self.npcTier = NPCTier.I
|
2024-10-09 20:55:46 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
# modify max health value based on the various factors
|
2024-09-19 19:03:06 -06:00
|
|
|
_random_mod_health()
|
2024-10-09 20:55:46 -06:00
|
|
|
|
2024-10-15 08:14:02 -06:00
|
|
|
# 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()
|