game: add enemy modifier class
This commit is contained in:
@@ -7,6 +7,7 @@ extends CharacterBody2D
|
|||||||
@export var target_distance: float = 6.0
|
@export var target_distance: float = 6.0
|
||||||
@export var path_update_interval: float = 1.5
|
@export var path_update_interval: float = 1.5
|
||||||
@export var xp_dropped: float = 5.0
|
@export var xp_dropped: float = 5.0
|
||||||
|
var modifiers: Array[EnemyMod] = []
|
||||||
|
|
||||||
@onready var target_cast: RayCast2D = $TargetCast
|
@onready var target_cast: RayCast2D = $TargetCast
|
||||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||||
|
27
scenes/enemies/enemy_mod.gd
Normal file
27
scenes/enemies/enemy_mod.gd
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
class_name EnemyMod
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
enum ModType { ADDITIVE, MULTIPLICATIVE, ABSOLUTE, BOOL }
|
||||||
|
|
||||||
|
@export var mod_property: String
|
||||||
|
@export var mod_value: float
|
||||||
|
@export var mod_value_bool: bool = false
|
||||||
|
@export var mod_type: ModType = ModType.MULTIPLICATIVE
|
||||||
|
|
||||||
|
func get_calculated(enemy: EnemyBase, key: String) -> Variant:
|
||||||
|
assert(enemy.has_property(key), "tried to calculate property '%s' where base value does not exist on %s" % [key, enemy])
|
||||||
|
var base_value = enemy.get(key)
|
||||||
|
var add = 0.0
|
||||||
|
var mul = 1.0
|
||||||
|
for mod in enemy.modifiers:
|
||||||
|
if mod.mod_property == key:
|
||||||
|
match mod.mod_type:
|
||||||
|
ModType.ADDITIVE:
|
||||||
|
add += mod.mod_value
|
||||||
|
ModType.MULTIPLICATIVE:
|
||||||
|
mul *= mod.mod_value
|
||||||
|
ModType.ABSOLUTE:
|
||||||
|
return mod.mod_value
|
||||||
|
ModType.BOOL:
|
||||||
|
return mod.mod_value_bool
|
||||||
|
return (base_value + add) * mul
|
1
scenes/enemies/enemy_mod.gd.uid
Normal file
1
scenes/enemies/enemy_mod.gd.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://d2mvgwmsmcxp4
|
Reference in New Issue
Block a user