feat: add canBrew and tickBrewing to Brewing
This commit is contained in:
1 parent
d4d5d7b254
commit
be14453cf6
1 file changed
+90
@@ -152,3 +152,93 @@ bool addFuel(BrewingStandState& stand, int blazePowderCount) {
|
|||||||
return true;
|
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<int>(std::floor(static_cast<float>(effect.durationTicks) * 0.75f * potency));
|
||||||
|
if (ticks < 1) return false;
|
||||||
|
effect.durationTicks = ticks;
|
||||||
|
return applyEffect(target, effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace vf
|
||||||
Reference in new issue
Block a user