try to fix an issue with sanity/insanity interactions

This commit is contained in:
2026-05-18 19:46:53 +02:00
parent e9eaa10474
commit 83ebfddde8
2 changed files with 9 additions and 16 deletions
@@ -58,18 +58,17 @@ public class SanityCapability implements ISanity {
} }
public void setBonusMaxSanity(float bonusMaxSanity) { public void setBonusMaxSanity(float bonusMaxSanity) {
float oldMax = getMaxSanity();
this.bonusMaxSanity = Math.max(0f, bonusMaxSanity); this.bonusMaxSanity = Math.max(0f, bonusMaxSanity);
float newMax = getMaxSanity(); clampToMax();
if (oldMax > 0) {
float pct = sanity / oldMax;
sanity = pct * newMax;
}
setSanity(sanity);
setInsanity(insanity);
} }
public float getBonusMaxSanity() { public float getBonusMaxSanity() {
return bonusMaxSanity; return bonusMaxSanity;
} }
private void clampToMax() {
float max = getMaxSanity();
this.sanity = Math.max(0, Math.min(max, this.sanity));
this.insanity = Math.max(0, Math.min(max, this.insanity));
}
} }
@@ -47,17 +47,11 @@ public class TempoCapability implements ITempo {
} }
public void setBonusMaxTempo(float bonusMaxTempo) { public void setBonusMaxTempo(float bonusMaxTempo) {
int oldMax = getMaxTempo();
this.bonusMaxTempo = Math.max(0f, bonusMaxTempo); this.bonusMaxTempo = Math.max(0f, bonusMaxTempo);
int newMax = getMaxTempo(); setTempo(this.tempo);
if (oldMax > 0) {
float pct = (float) tempo / (float) oldMax;
tempo = Math.round(pct * newMax);
}
setTempo(tempo);
} }
public float getBonusMaxTempo() { public float getBonusMaxTempo() {
return bonusMaxTempo; return bonusMaxTempo;
} }
} }