69 lines
2.1 KiB
GDScript
69 lines
2.1 KiB
GDScript
extends Node
|
|
|
|
|
|
func resolve_damage(base_attack: float, action: Resource, judgement: Dictionary, buffs: Variant = null, burst: Variant = null) -> float:
|
|
var action_mult := _resource_float(action, "damage_mult", 1.0)
|
|
var judgement_mult := _judgement_mult(judgement)
|
|
var buff_mult := _provider_mult(buffs, "damage_mult", action)
|
|
var burst_mult := _provider_mult(burst, "damage_mult", action)
|
|
return base_attack * action_mult * judgement_mult * buff_mult * burst_mult
|
|
|
|
|
|
func resolve_cost(action: Resource, burst: Variant = null) -> float:
|
|
var base_cost := _resource_float(action, "base_cost", 0.0)
|
|
var cost := base_cost if base_cost > 0.0 else _resource_float(action, "energy_cost", 0.0)
|
|
var burst_mult := _provider_mult(burst, "cost_mult", action)
|
|
return maxf(0.0, cost * burst_mult)
|
|
|
|
|
|
func resolve_move(action: Resource, judgement: Dictionary, burst: Variant = null) -> Vector2:
|
|
var judgement_mult := _dict_float(judgement, "move_mult", 1.0)
|
|
var burst_mult := _provider_mult(burst, "move_mult", action)
|
|
return Vector2(
|
|
_resource_float(action, "move_mult_x", 0.0),
|
|
_resource_float(action, "move_mult_y", 0.0)
|
|
) * judgement_mult * burst_mult
|
|
|
|
|
|
func _judgement_damage_mult(label: StringName) -> float:
|
|
match label:
|
|
&"perfect":
|
|
return 1.25
|
|
&"good":
|
|
return 1.0
|
|
&"bad":
|
|
return 0.75
|
|
_:
|
|
return 0.0
|
|
|
|
|
|
func _judgement_mult(judgement: Dictionary) -> float:
|
|
if judgement.has("damage_mult"):
|
|
return float(judgement["damage_mult"])
|
|
if judgement.has("label"):
|
|
return _judgement_damage_mult(StringName(str(judgement["label"])))
|
|
return 1.0
|
|
|
|
|
|
func _resource_float(resource: Resource, property_name: String, fallback: float) -> float:
|
|
if resource == null:
|
|
return fallback
|
|
var value = resource.get(property_name)
|
|
if value == null:
|
|
return fallback
|
|
return float(value)
|
|
|
|
|
|
func _dict_float(values: Dictionary, key: String, fallback: float) -> float:
|
|
if not values.has(key):
|
|
return fallback
|
|
return float(values[key])
|
|
|
|
|
|
func _provider_mult(provider, method_name: String, action: Resource) -> float:
|
|
if provider == null:
|
|
return 1.0
|
|
if provider.has_method(method_name):
|
|
return float(provider.call(method_name, action))
|
|
return 1.0
|