feat: add applyEffectTick to Effect
This commit is contained in:
1 parent
098d58e48e
commit
b5f12ab274
1 file changed
+51
@@ -181,3 +181,54 @@ EffectModifier effectModifiers(const EffectSet& set) {
|
|||||||
return modifier;
|
return modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EffectSet::Pending tickEffects(EffectSet& set) {
|
||||||
|
EffectSet::Pending pending;
|
||||||
|
for (EffectInstance& effect : set.active) {
|
||||||
|
if (effect.durationTicks <= 0) continue;
|
||||||
|
switch (effect.kind) {
|
||||||
|
case EffectKind::InstantHealth:
|
||||||
|
pending.instantHeal +=
|
||||||
|
static_cast<float>(4 << std::min(effect.amplifier, 8)) * effect.potency;
|
||||||
|
break;
|
||||||
|
case EffectKind::InstantDamage:
|
||||||
|
pending.instantDamage +=
|
||||||
|
static_cast<float>(6 << std::min(effect.amplifier, 8)) * effect.potency;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
int interval = periodicIntervalTicks(effect.kind, effect.amplifier);
|
||||||
|
if (interval > 0 && effect.durationTicks % interval == 0) {
|
||||||
|
switch (effect.kind) {
|
||||||
|
case EffectKind::Regeneration: pending.regenerationHeal += 1.0f; break;
|
||||||
|
case EffectKind::Poison: pending.poisonDamage += 1.0f; break;
|
||||||
|
case EffectKind::Wither: pending.witherDamage += 1.0f; break;
|
||||||
|
case EffectKind::Saturation:
|
||||||
|
pending.saturationGain += static_cast<float>(effect.level());
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
--effect.durationTicks;
|
||||||
|
}
|
||||||
|
std::size_t before = set.active.size();
|
||||||
|
set.active.erase(std::remove_if(set.active.begin(), set.active.end(),
|
||||||
|
[](const EffectInstance& e) { return e.durationTicks <= 0; }),
|
||||||
|
set.active.end());
|
||||||
|
pending.expiredCount = static_cast<int>(before - set.active.size());
|
||||||
|
return pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
float applyEffectTick(const EffectSet::Pending& pending, float& health, float maxHealth) {
|
||||||
|
float before = health;
|
||||||
|
float heal = pending.regenerationHeal + pending.instantHeal;
|
||||||
|
if (heal > 0.0f) health = std::min(maxHealth, health + heal);
|
||||||
|
if (pending.poisonDamage > 0.0f) {
|
||||||
|
float survivable = clampZero(health - 1.0f);
|
||||||
|
health -= std::min(pending.poisonDamage, survivable);
|
||||||
|
}
|
||||||
|
float lethal = pending.witherDamage + pending.instantDamage;
|
||||||
|
if (lethal > 0.0f) health = clampZero(health - lethal);
|
||||||
|
return health - before;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace vf
|
||||||
Reference in new issue
Block a user