feat(resist): EnemyManager 元素抗性加载+命中查表;enemies.json Fast 种子抗火弱冰
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,8 @@ var _SPEED: Dictionary = {} # type → 移动速度
|
||||
var _ARMOR: Dictionary = {} # type → 护甲
|
||||
var _RENDER_SIZE: Dictionary = {} # type → 渲染直径
|
||||
var _RENDER_COLOR: Dictionary = {} # type → 渲染颜色
|
||||
var _RESIST: Dictionary = {} # type → PackedFloat32Array(6),index=damage_type,[0]物理恒0
|
||||
const _RESIST_ELEMENTS := {"fire": 1, "ice": 2, "lightning": 3, "poison": 4, "arcane": 5}
|
||||
|
||||
const ARCHETYPE_JSON: String = "res://data/enemies.json"
|
||||
|
||||
@@ -61,6 +63,12 @@ func _load_json_archetypes() -> void:
|
||||
_RENDER_SIZE[t] = float(d.get("size", 14.0))
|
||||
var c: Array = d.get("color", [0.9, 0.3, 0.3])
|
||||
_RENDER_COLOR[t] = Color(float(c[0]), float(c[1]), float(c[2]))
|
||||
var rf := PackedFloat32Array([0, 0, 0, 0, 0, 0])
|
||||
var res_d: Dictionary = d.get("resistances", {})
|
||||
for ename in _RESIST_ELEMENTS:
|
||||
if res_d.has(ename):
|
||||
rf[_RESIST_ELEMENTS[ename]] = clampf(float(res_d[ename]), -0.9, 0.9)
|
||||
_RESIST[t] = rf
|
||||
|
||||
var _nav_region: NavigationRegion2D = null # 程序化矩形导航区
|
||||
var _pathfinders: Dictionary = {} # entity_id → {"agent":NavigationAgent2D, "host":Node2D}
|
||||
@@ -247,6 +255,13 @@ func set_entity_pos(entity_id: int, pos: Vector2) -> void:
|
||||
_data[base + 0] = pos.x
|
||||
_data[base + 1] = pos.y
|
||||
|
||||
## 元素抗性查表:越界/缺失回退 0(物理 index 0 恒 0)
|
||||
func _resist_for(etype: int, dtype: int) -> float:
|
||||
var rf: PackedFloat32Array = _RESIST.get(etype, PackedFloat32Array())
|
||||
if dtype < 0 or dtype >= rf.size():
|
||||
return 0.0
|
||||
return rf[dtype]
|
||||
|
||||
## S1 完整伤害接口:从 DamageContextPool 取 context,计算公式后扣 HP
|
||||
## 公式(S1 简化):final_dmg = base_damage * mult
|
||||
## S4 起补充 resistance / armor(参见 combat_mechanics_depth.md §4)
|
||||
@@ -254,7 +269,12 @@ func apply_damage_from_context(entity_id: int, ctx_id: int) -> bool:
|
||||
var ctx: DamageContext = DamageContextPool.get_context(ctx_id)
|
||||
if ctx == null:
|
||||
return false
|
||||
var final_dmg: float = ctx.calc_damage()
|
||||
var slot: int = _entity_index_map.get(entity_id, -1)
|
||||
var res: float = 0.0
|
||||
if slot >= 0:
|
||||
var etype: int = int(_data[slot * ENEMY_STRIDE + 6])
|
||||
res = _resist_for(etype, ctx.damage_type)
|
||||
var final_dmg: float = ctx.calc_damage(0.0, res)
|
||||
return apply_damage(entity_id, final_dmg, ctx.owner_id, true)
|
||||
|
||||
## 直接扣血接口;source_id 用于击杀归属,record_dps 控制是否计入 DPS
|
||||
|
||||
Reference in New Issue
Block a user