v0.7.3b: fixed rare crash bugs caused by assuming hunger is present

This commit is contained in:
Evan Debenham 2019-05-30 18:22:40 -04:00
parent 0b9b46a065
commit fff6687f50
7 changed files with 14 additions and 10 deletions

View File

@ -1315,7 +1315,7 @@ public class Hero extends Char {
}
public boolean isStarving() {
return buff(Hunger.class) != null && ((Hunger)buff( Hunger.class )).isStarving();
return Buff.affect(this, Hunger.class).isStarving();
}
@Override
@ -1656,9 +1656,9 @@ public class Hero extends Char {
if (!Dungeon.level.locked) {
if (cursed) {
GLog.n(Messages.get(this, "search_distracted"));
buff(Hunger.class).reduceHunger(TIME_TO_SEARCH - (2 * HUNGER_FOR_SEARCH));
Buff.affect(this, Hunger.class).reduceHunger(TIME_TO_SEARCH - (2 * HUNGER_FOR_SEARCH));
} else {
buff(Hunger.class).reduceHunger(TIME_TO_SEARCH - HUNGER_FOR_SEARCH);
Buff.affect(this, Hunger.class).reduceHunger(TIME_TO_SEARCH - HUNGER_FOR_SEARCH);
}
}
spendAndNext(TIME_TO_SEARCH);

View File

@ -540,7 +540,7 @@ public abstract class Mob extends Char {
if (buff(SoulMark.class) != null) {
int restoration = Math.min(damage, HP);
Dungeon.hero.buff(Hunger.class).satisfy(restoration);
Buff.affect(Dungeon.hero, Hunger.class).satisfy(restoration);
Dungeon.hero.HP = (int)Math.ceil(Math.min(Dungeon.hero.HT, Dungeon.hero.HP+(restoration*0.33f)));
Dungeon.hero.sprite.emitter().burst( Speck.factory(Speck.HEALING), 1 );
}

View File

@ -22,6 +22,7 @@
package com.shatteredpixel.shatteredpixeldungeon.items.armor.curses;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
@ -46,7 +47,7 @@ public class Metabolism extends Glyph {
if (healing > 0) {
Hunger hunger = defender.buff( Hunger.class );
Hunger hunger = Buff.affect(defender, Hunger.class);
if (hunger != null && !hunger.isStarving()) {

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
@ -84,9 +85,10 @@ public class HornOfPlenty extends Artifact {
else if (charge == 0) GLog.i( Messages.get(this, "no_food") );
else {
//consume as much food as it takes to be full, to a minimum of 1
int chargesToUse = Math.max( 1, hero.buff(Hunger.class).hunger() / (int)(Hunger.STARVING/10));
Hunger hunger = Buff.affect(Dungeon.hero, Hunger.class);
int chargesToUse = Math.max( 1, hunger.hunger() / (int)(Hunger.STARVING/10));
if (chargesToUse > charge) chargesToUse = charge;
hero.buff(Hunger.class).satisfy((Hunger.STARVING/10) * chargesToUse);
hunger.satisfy((Hunger.STARVING/10) * chargesToUse);
Food.foodProc( hero );

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
@ -250,7 +251,7 @@ public class TimekeepersHourglass extends Artifact {
((Hero) target).spendAndNext(5*usedCharge);
//shouldn't punish the player for going into stasis frequently
Hunger hunger = target.buff(Hunger.class);
Hunger hunger = Buff.affect(target, Hunger.class);
if (hunger != null && !hunger.isStarving())
hunger.satisfy(5*usedCharge);

View File

@ -90,7 +90,7 @@ public class Food extends Item {
}
protected void satisfy( Hero hero ){
(hero.buff( Hunger.class )).satisfy( energy );
Buff.affect(hero, Hunger.class).satisfy( energy );
}
public static void foodProc( Hero hero ){

View File

@ -45,7 +45,7 @@ public class ElixirOfHoneyedHealing extends Elixir {
public void apply(Hero hero) {
Buff.affect( hero, Healing.class ).setHeal((int)(0.8f*hero.HT + 14), 0.25f, 0);
PotionOfHealing.cure(hero);
hero.buff(Hunger.class).satisfy(Hunger.STARVING/5f);
Buff.affect(hero, Hunger.class).satisfy(Hunger.STARVING/5f);
}
@Override