From 8e348b56693ae9ad75a396a6bba249c2bd010df1 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 6 May 2022 11:40:31 -0400 Subject: [PATCH] v1.3.0: improved logic for 'on death' badges and bleeding --- .../actors/buffs/Bleeding.java | 24 +++++++++++++++++-- .../items/weapon/curses/Sacrificial.java | 2 +- .../levels/features/Chasm.java | 7 +++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Bleeding.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Bleeding.java index d735acd90..29adb7df2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Bleeding.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Bleeding.java @@ -21,8 +21,11 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs; +import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.Splash; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.curses.Sacrificial; +import com.shatteredpixel.shatteredpixeldungeon.levels.features.Chasm; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; @@ -40,27 +43,39 @@ public class Bleeding extends Buff { protected float level; + //used in specific cases where the source of the bleed is important for death logic + private Class source; + public float level(){ return level; } private static final String LEVEL = "level"; + private static final String SOURCE = "source"; @Override public void storeInBundle( Bundle bundle ) { super.storeInBundle( bundle ); bundle.put( LEVEL, level ); - + bundle.put( SOURCE, source ); } @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); level = bundle.getFloat( LEVEL ); + source = bundle.getClass( SOURCE ); } public void set( float level ) { - this.level = Math.max(this.level, level); + set( level, null ); + } + + public void set( float level, Class source ){ + if (this.level < level) { + this.level = Math.max(this.level, level); + this.source = source; + } } @Override @@ -94,6 +109,11 @@ public class Bleeding extends Buff { } if (target == Dungeon.hero && !target.isAlive()) { + if (source == Chasm.class){ + Badges.validateDeathFromFalling(); + } else if (source == Sacrificial.class){ + Badges.validateDeathFromFriendlyMagic(); + } Dungeon.fail( getClass() ); GLog.n( Messages.get(this, "ondeath") ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/curses/Sacrificial.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/curses/Sacrificial.java index 9212f7188..090e42a08 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/curses/Sacrificial.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/curses/Sacrificial.java @@ -37,7 +37,7 @@ public class Sacrificial extends Weapon.Enchantment { float procChance = 1/12f * procChanceMultiplier(attacker); if (Random.Float() < procChance) { - Buff.affect(attacker, Bleeding.class).set(Math.max(1, attacker.HP/6)); + Buff.affect(attacker, Bleeding.class).set(Math.max(1, attacker.HP/6), getClass()); } return damage; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java index a25b24533..6f8d6d8dd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/features/Chasm.java @@ -149,7 +149,7 @@ public class Chasm implements Hero.Doom { //The lower the hero's HP, the more bleed and the less upfront damage. //Hero has a 50% chance to bleed out at 66% HP, and begins to risk instant-death at 25% - Buff.affect( hero, FallBleed.class).set( Math.round(hero.HT / (6f + (6f*(hero.HP/(float)hero.HT))))); + Buff.affect( hero, Bleeding.class).set( Math.round(hero.HT / (6f + (6f*(hero.HP/(float)hero.HT)))), Chasm.class); hero.damage( Math.max( hero.HP / 2, Random.NormalIntRange( hero.HP / 2, hero.HT / 4 )), new Chasm() ); } @@ -172,9 +172,10 @@ public class Chasm implements Hero.Doom { return true; } } - + + //pre-1.3.0 public static class FallBleed extends Bleeding implements Hero.Doom { - + @Override public void onDeath() { Badges.validateDeathFromFalling();