feat(iframe): PlayerStats.take_damage 时间戳门控无敌窗口 + 复活 PLAYER_DAMAGED emit;移除死订阅
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,7 @@ var xp_to_next: int = 10 # 升级所需 XP
|
|||||||
var cpu_limit: int = 5 # 控制 MAX_OPS = cpu_limit * 40
|
var cpu_limit: int = 5 # 控制 MAX_OPS = cpu_limit * 40
|
||||||
var armor: float = 0.0
|
var armor: float = 0.0
|
||||||
var resistance: float = 0.0 # 0.0~1.0
|
var resistance: float = 0.0 # 0.0~1.0
|
||||||
|
var _invuln_until_msec: int = 0 # < now 表示可受击;受击后设为 now + iframe 窗口
|
||||||
|
|
||||||
# ── 魔力(MVP)─────────────────────────────────────────
|
# ── 魔力(MVP)─────────────────────────────────────────
|
||||||
var mana: float = 100.0
|
var mana: float = 100.0
|
||||||
@@ -30,7 +31,6 @@ var mana_heat: float = 0.0 # 递增蓝耗热值(0=无,1=蓝耗翻倍)
|
|||||||
var mana_leech: float = 0.0 # 击杀回蓝量(换杖/换牌重算)
|
var mana_leech: float = 0.0 # 击杀回蓝量(换杖/换牌重算)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
EventBus.subscribe(EventID.PLAYER_DAMAGED, _on_player_damaged)
|
|
||||||
EventBus.subscribe(EventID.ENEMY_KILLED, _on_enemy_killed)
|
EventBus.subscribe(EventID.ENEMY_KILLED, _on_enemy_killed)
|
||||||
|
|
||||||
func _on_enemy_killed(_payload: Dictionary) -> void:
|
func _on_enemy_killed(_payload: Dictionary) -> void:
|
||||||
@@ -63,11 +63,20 @@ func spend_gold(amount: int) -> bool:
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
func take_damage(amount: float) -> void:
|
func take_damage(amount: float) -> void:
|
||||||
hp = max(0.0, hp - amount * SettingsManager.player_dmg_taken_mult()) # 难度减伤(初学者×0.7)
|
var now: int = Time.get_ticks_msec()
|
||||||
|
if now < _invuln_until_msec:
|
||||||
|
return # 无敌窗口内:忽略外部伤害(多弹同帧只扣一次)
|
||||||
|
var applied: float = amount * SettingsManager.player_dmg_taken_mult() # 难度减伤(初学者×0.7)
|
||||||
|
hp = max(0.0, hp - applied)
|
||||||
|
_invuln_until_msec = now + int(SettingsManager.player_iframe_sec() * 1000.0)
|
||||||
|
EventBus.emit(EventID.PLAYER_DAMAGED, {"damage": applied}) # 复活 hurt 音效 / HUD 钩子
|
||||||
stats_changed.emit()
|
stats_changed.emit()
|
||||||
if hp <= 0.0:
|
if hp <= 0.0:
|
||||||
EventBus.emit(EventID.PLAYER_DIED, {})
|
EventBus.emit(EventID.PLAYER_DIED, {})
|
||||||
|
|
||||||
|
func is_invulnerable() -> bool:
|
||||||
|
return Time.get_ticks_msec() < _invuln_until_msec
|
||||||
|
|
||||||
func heal(amount: float) -> void:
|
func heal(amount: float) -> void:
|
||||||
hp = min(hp_max, hp + amount)
|
hp = min(hp_max, hp + amount)
|
||||||
stats_changed.emit()
|
stats_changed.emit()
|
||||||
@@ -113,9 +122,6 @@ func spend_hp_cost(amount: float) -> void:
|
|||||||
if hp <= 0.0:
|
if hp <= 0.0:
|
||||||
EventBus.emit(EventID.PLAYER_DIED, {})
|
EventBus.emit(EventID.PLAYER_DIED, {})
|
||||||
|
|
||||||
func _on_player_damaged(payload: Dictionary) -> void:
|
|
||||||
take_damage(float(payload.get("damage", 0.0)))
|
|
||||||
|
|
||||||
func reset_for_run() -> void:
|
func reset_for_run() -> void:
|
||||||
hp = hp_max
|
hp = hp_max
|
||||||
mana = mana_max
|
mana = mana_max
|
||||||
@@ -123,6 +129,7 @@ func reset_for_run() -> void:
|
|||||||
xp = 0
|
xp = 0
|
||||||
level = 1
|
level = 1
|
||||||
xp_to_next = xp_for_level(1)
|
xp_to_next = xp_for_level(1)
|
||||||
|
_invuln_until_msec = 0
|
||||||
stats_changed.emit()
|
stats_changed.emit()
|
||||||
|
|
||||||
func get_save_data() -> Dictionary:
|
func get_save_data() -> Dictionary:
|
||||||
|
|||||||
Reference in New Issue
Block a user