※ 引述《reinforce15 (可鲁贝洛斯)》之铭言:
: ※ [本文转录自 Gossiping 看板 #1Pfw8CCA ]
: 作者: reinforce15 (可鲁贝洛斯) 看板: Gossiping
: 标题: Re: [问卦] 宁宁鸡写程式时是用space还是tab缩排
: 时间: Thu Aug 31 13:43:38 2017
: ※ 引述《justwe5566 (杰士塔纱路的老公)》之铭言:
: //
: void DestructibleActor::ReceiveDamage(float sourceDamage)
: {
: //
: auto resolvedDamage = sourceDamage;
: for (const auto& debuf:m_debufs)
: {
: resolvedDamage = debuf.ApplyToDamage(resolvedDamage);
: m_currentHealth -= resolvedDamage
: if (m_currentHealth <= 0.f)
: {
: m_currentHealth = 0.f;
: DestroyMe();
: }
: }
: }
: //
: void DestructibleActor::ReceiveDamage(float sourceDamage)
: {
: //
: auto resolvedDamage = sourceDamage;
: for (const auto& debuf:m_debufs)
: {
: resolvedDamage = debuf.ApplyToDamage(resolvedDamage);
: }
: m_currentHealth -= resolvedDamage
: if (m_currentHealth <= 0.f)
: {
: m_currentHealth = 0.f;
: DestroyMe();
: }
: }
恕删
虽然照这样修改可以避免DestroyMe()后再次呼叫
但是这样一来和原本的逻辑有些许差异
如果debuf.ApplyToDamage后得出的结果会有负值
就有可能造成原本会死亡的结果变成不会
试想原本HP有100
第一个Debuf 扣 200
第二个Debuf 反而加 150
原本的逻辑在第一次伤害后就会触发 DestroyMe => 角色死亡
但修改后最后HP还剩50 => 角色存活
一点浅见