game: add enemy mods

This commit is contained in:
2025-08-22 07:49:02 +02:00
parent 40d6162b95
commit 950d177936
14 changed files with 173 additions and 35 deletions

View File

@@ -7,6 +7,7 @@ extends CharacterBody2D
@export var target_distance: float = 6.0
@export var path_update_interval: float = 1.5
@export var xp_dropped: float = 5.0
@export var enemy_rarity: GlobalConst.Rarity = GlobalConst.Rarity.NORMAL
var modifiers: Array[EnemyMod] = []
@onready var target_cast: RayCast2D = $TargetCast
@@ -16,6 +17,7 @@ var modifiers: Array[EnemyMod] = []
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D
@onready var shape_cast_2d: ShapeCast2D = $ShapeCast2D
@onready var sprite_2d: Sprite2D = $Sprite2D
@onready var label: Label = $Label
var player: Player
var enemy_name: String
@@ -28,8 +30,23 @@ var _path_update_timer: float = 0.0
func _ready() -> void:
health = max_health
enemy_name = _gen_name()
match enemy_rarity:
GlobalConst.Rarity.NORMAL:
label.visible = false
GlobalConst.Rarity.RARE:
var mods = EnemyModPool.get_random_mods(2)
label.visible = true
modifiers = mods
GlobalConst.Rarity.EPIC:
var mods = EnemyModPool.get_random_mods(4)
label.visible = true
modifiers = mods
if modifiers.size() > 0:
enemy_name += " the %s" % modifiers.pick_random().adjective
label.add_theme_color_override("font_color", GlobalConst.rarity_to_color(enemy_rarity))
label.text = enemy_name
health = get_calculated("max_health")
shape_cast_2d.shape.radius = collision_shape_2d.shape.radius
shape_cast_2d.enabled = false
sprite_2d.material = sprite_2d.material.duplicate()
@@ -80,7 +97,7 @@ func _do_simple_movement():
var direction = global_position.direction_to(target.global_position)
var distance = global_position.distance_to(target.global_position)
if distance > 4:
velocity = direction * move_speed
velocity = direction * get_calculated("move_speed")
move_and_slide()
@@ -98,7 +115,7 @@ func _do_nav_agent_movement():
if shape_cast_2d.is_colliding():
direction = direction.bounce(shape_cast_2d.get_collision_normal(0)).normalized()
velocity = direction * move_speed
velocity = direction * get_calculated("move_speed")
move_and_slide()
@@ -148,7 +165,7 @@ func die():
func drop_xp_orb() -> void:
var orb: XPOrb = preload("res://scenes/xp_orb.tscn").instantiate()
orb.value = xp_dropped
orb.value = xp_dropped * (1 + (modifiers.size() * 3))
orb.position = position
get_parent().call_deferred("add_child", orb)
@@ -156,3 +173,21 @@ func drop_xp_orb() -> void:
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if is_dead:
queue_free()
func get_calculated(key: String) -> Variant:
# set max move speed to players move speed
if key == "move_speed":
return clampf(
EnemyMod.get_calculated(self, key),
0,
player.player_stats.get_final("move_speed", player.modifiers)
)
return EnemyMod.get_calculated(self, key)
func has_property(key: String) -> bool:
for prop in get_property_list():
if prop.name == key:
return true
return false