v2.3.0: fixed rounding errors in tipped dart durability

This commit is contained in:
Evan Debenham
2024-01-04 15:27:00 -05:00
parent cfedb7aaf2
commit f9e6fbc942
3 changed files with 23 additions and 11 deletions

View File

@@ -314,6 +314,11 @@ abstract public class MissileWeapon extends Weapon {
}
public float durabilityPerUse(){
//classes that override durabilityPerUse can turn rounding off, to do their own rounding after more logic
return durabilityPerUse(true);
}
protected final float durabilityPerUse( boolean rounded){
float usages = baseUses * (float)(Math.pow(3, level()));
//+50%/75% durability
@@ -323,16 +328,20 @@ abstract public class MissileWeapon extends Weapon {
if (holster) {
usages *= MagicalHolster.HOLSTER_DURABILITY_FACTOR;
}
usages *= RingOfSharpshooting.durabilityMultiplier( Dungeon.hero );
//at 100 uses, items just last forever.
if (usages >= 100f) return 0;
usages = Math.round(usages);
//add a tiny amount to account for rounding error for calculations like 1/3
return (MAX_DURABILITY/usages) + 0.001f;
if (rounded){
usages = Math.round(usages);
//add a tiny amount to account for rounding error for calculations like 1/3
return (MAX_DURABILITY/usages) + 0.001f;
} else {
//rounding can be disabled for classes that override durability per use
return MAX_DURABILITY/usages;
}
}
protected void decrementDurability(){

View File

@@ -52,6 +52,6 @@ public class RotDart extends TippedDart {
@Override
public float durabilityPerUse() {
return 20f;
return MAX_DURABILITY/5f; //always 5 uses
}
}

View File

@@ -151,7 +151,7 @@ public abstract class TippedDart extends Dart {
@Override
public float durabilityPerUse() {
float use = super.durabilityPerUse();
float use = super.durabilityPerUse(false);
use /= (1 + Dungeon.hero.pointsInTalent(Talent.DURABLE_TIPS));
@@ -179,12 +179,15 @@ public abstract class TippedDart extends Dart {
}
use *= (1f - lotusPreserve);
float usages = Math.round(MAX_DURABILITY/use);
//grants 4 extra uses with charged shot
if (Dungeon.hero.buff(Crossbow.ChargedShot.class) != null){
use = 100f/((100f/use) + 4f) + 0.001f;
usages += 4;
}
return use;
//add a tiny amount to account for rounding error for calculations like 1/3
return (MAX_DURABILITY/usages) + 0.001f;
}
@Override