From fe1d1f690f2c12873d53845c83b58d07c740dbb6 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Fri, 24 Jul 2026 11:51:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(resist):=20EnemyManager=20=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=8A=97=E6=80=A7=E5=8A=A0=E8=BD=BD+=E5=91=BD?= =?UTF-8?q?=E4=B8=AD=E6=9F=A5=E8=A1=A8=EF=BC=9Benemies.json=20Fast=20?= =?UTF-8?q?=E7=A7=8D=E5=AD=90=E6=8A=97=E7=81=AB=E5=BC=B1=E5=86=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- data/enemies.json | 2 +- scripts/autoloads/enemy_manager.gd | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/data/enemies.json b/data/enemies.json index b440d86..78c24ee 100644 --- a/data/enemies.json +++ b/data/enemies.json @@ -1,6 +1,6 @@ { "0": { "name": "杂兵 Basic", "speed": 80, "armor": 0, "size": 14, "color": [0.90, 0.32, 0.30] }, - "1": { "name": "快速 Fast", "speed": 140, "armor": 0, "size": 11, "color": [0.95, 0.72, 0.20] }, + "1": { "name": "快速 Fast", "speed": 140, "armor": 0, "size": 11, "color": [0.95, 0.72, 0.20], "resistances": { "fire": 0.5, "ice": -0.5 } }, "2": { "name": "护甲 Armored", "speed": 60, "armor": 5, "size": 16, "color": [0.52, 0.54, 0.62] }, "3": { "name": "精英 Elite", "speed": 90, "armor": 3, "size": 22, "color": [1.00, 0.50, 0.12] }, "4": { "name": "首领 MiniBoss", "speed": 55, "armor": 8, "size": 48, "color": [0.92, 0.22, 0.85] }, diff --git a/scripts/autoloads/enemy_manager.gd b/scripts/autoloads/enemy_manager.gd index bc24f37..4a34811 100644 --- a/scripts/autoloads/enemy_manager.gd +++ b/scripts/autoloads/enemy_manager.gd @@ -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