Files
spellforge/scripts/autoloads/damage_context.gd
T
2026-07-20 10:56:52 +08:00

29 lines
1004 B
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## DamageContext — 伤害上下文数据类(必须单独放在此文件)
## 权威来源:implementation_plan.md §2.1 E-N2 P6-N49
## 禁止将 class_name DamageContext 写入 damage_context_pool.gd
extends RefCounted
class_name DamageContext
var base_damage: float = 0.0
var mult: float = 1.0
var damage_type: int = 0 # DamageType.PHYSICAL
var owner_id: int = -1
var source_tags: int = 0
var is_crit: bool = false
var pierce_rate: float = 0.0 # 护甲穿透率 0.0~1.0
func reset() -> void:
base_damage = 0.0
mult = 1.0
damage_type = 0
owner_id = -1
source_tags = 0
is_crit = false
pierce_rate = 0.0
## 伤害公式:((base_damage + add) × mult) × (1 resistance) armor
## S1 简化版:返回 base_damage * mult
func calc_damage(armor: float = 0.0, resistance: float = 0.0) -> float:
var effective_armor: float = armor * (1.0 - pierce_rate)
return max(0.0, base_damage * mult * (1.0 - resistance) - effective_armor)