close #189 (anything under 1 tick is a no-op)

This commit is contained in:
gamma-delta 2022-07-26 11:49:25 -05:00
parent 868086009f
commit 81e5f8581e

View file

@ -26,11 +26,15 @@ class OpPotionEffect(
val target = args.getChecked<LivingEntity>(0, argc) val target = args.getChecked<LivingEntity>(0, argc)
if (target is ArmorStand) if (target is ArmorStand)
throw MishapInvalidIota.ofClass(SpellDatum.make(target), 0, LivingEntity::class.java) throw MishapInvalidIota.ofClass(SpellDatum.make(target), 0, LivingEntity::class.java)
val duration = max(args.getChecked(1, argc), 0.0) val duration = max(args.getChecked(1, argc), 0.0)
ctx.assertEntityInRange(target)
val potency = if (this.allowPotency) val potency = if (this.allowPotency)
args.getChecked<Double>(2, argc).coerceIn(1.0, 128.0) args.getChecked<Double>(2, argc).coerceIn(1.0, 128.0)
else 1.0 else
1.0
ctx.assertEntityInRange(target)
val cost = this.baseCost * duration * if (potencyCubic) { val cost = this.baseCost * duration * if (potencyCubic) {
potency * potency * potency potency * potency * potency
@ -47,8 +51,10 @@ class OpPotionEffect(
private class Spell(val effect: MobEffect, val target: LivingEntity, val duration: Double, val potency: Double) : private class Spell(val effect: MobEffect, val target: LivingEntity, val duration: Double, val potency: Double) :
RenderedSpell { RenderedSpell {
override fun cast(ctx: CastingContext) { override fun cast(ctx: CastingContext) {
if (duration > 1.0 / 20.0) {
val effectInst = MobEffectInstance(effect, (duration * 20).toInt(), potency.toInt() - 1) val effectInst = MobEffectInstance(effect, (duration * 20).toInt(), potency.toInt() - 1)
target.addEffect(effectInst) target.addEffect(effectInst)
} }
} }
} }
}