From be14453cf67292cdf1374adb647aa05f3c471ee4 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Sun, 6 Sep 2026 19:32:48 +0200 Subject: [PATCH] feat: add canBrew and tickBrewing to Brewing --- core/src/Brewing.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/core/src/Brewing.cpp b/core/src/Brewing.cpp index 3a9a38a..ad1cee2 100644 --- a/core/src/Brewing.cpp +++ b/core/src/Brewing.cpp @@ -152,3 +152,93 @@ bool addFuel(BrewingStandState& stand, int blazePowderCount) { return true; } +bool canBrew(const BrewingStandState& stand) { + if (stand.fuel <= 0) return false; + if (stand.ingredient == Ingredient::None || stand.ingredientCount <= 0) return false; + for (const BrewingSlot& bottle : stand.bottles) { + if (!bottle.occupied) continue; + bool changed = false; + brewResult(bottle.potion, stand.ingredient, changed); + if (changed) return true; + } + return false; +} + +bool tickBrewing(BrewingStandState& stand) { + if (!canBrew(stand)) { + stand.brewing = false; + stand.progressTicks = 0; + return false; + } + stand.brewing = true; + ++stand.progressTicks; + if (stand.progressTicks < brewDurationTicks) return false; + + for (BrewingSlot& bottle : stand.bottles) { + if (!bottle.occupied) continue; + bool changed = false; + PotionItem brewed = brewResult(bottle.potion, stand.ingredient, changed); + if (changed) bottle.potion = brewed; + } + if (--stand.ingredientCount <= 0) { + stand.ingredientCount = 0; + stand.ingredient = Ingredient::None; + } + --stand.fuel; + stand.progressTicks = 0; + stand.brewing = false; + return true; +} + +bool potionHasEffect(const PotionItem& potion) { + return profileFor(potion.kind).kind != EffectKind::Count; +} + +EffectInstance potionEffect(const PotionItem& potion) { + const PotionProfile& profile = profileFor(potion.kind); + if (profile.kind == EffectKind::Count) { + return EffectInstance{EffectKind::Count, 0, 0, 1.0f, false}; + } + + int level = 1; + int duration = profile.baseTicks; + if (potion.upgraded && profile.upgradedTicks > 0) { + level = profile.upgradedLevel; + duration = profile.upgradedTicks; + } else if (potion.extended && profile.extendedTicks > 0) { + duration = profile.extendedTicks; + } + return makeEffect(profile.kind, level, duration); +} + +bool drinkPotion(EffectSet& target, const PotionItem& potion) { + if (potion.form != PotionItem::Form::Drinkable) return false; + if (!potionHasEffect(potion)) return false; + return applyEffect(target, potionEffect(potion)); +} + +float splashPotency(float distance, float radius) { + if (radius <= 0.0f) return 0.0f; + float potency = 1.0f - distance / radius; + return std::max(0.0f, std::min(1.0f, potency)); +} + +bool splashPotion(EffectSet& target, const PotionItem& potion, float distance, float radius) { + if (potion.form != PotionItem::Form::Splash) return false; + if (!potionHasEffect(potion)) return false; + float potency = splashPotency(distance, radius); + if (potency <= 0.0f) return false; + + EffectInstance effect = potionEffect(potion); + if (isInstantEffect(effect.kind)) { + effect.potency = potency; + return applyEffect(target, effect); + } + int ticks = + static_cast(std::floor(static_cast(effect.durationTicks) * 0.75f * potency)); + if (ticks < 1) return false; + effect.durationTicks = ticks; + return applyEffect(target, effect); +} + +} // namespace vf