From a49eab8ed1d446f8b9f299057f3f389cd6b56fc0 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 23 Oct 2018 17:54:51 -0400 Subject: [PATCH] v0.7.0a: significant code improvements to shield-granting buffs --- .../actors/buffs/Barrier.java | 10 ++------ .../actors/buffs/ShieldBuff.java | 25 ++++++++++++++++++- .../actors/mobs/Succubus.java | 2 +- .../items/BrokenSeal.java | 23 ++++++++--------- .../items/armor/glyphs/Brimstone.java | 11 ++++---- .../potions/elixirs/ElixirOfVitality.java | 2 +- .../potions/exotic/PotionOfShielding.java | 2 +- .../items/wands/WandOfTransfusion.java | 2 +- 8 files changed, 45 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Barrier.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Barrier.java index 6e48aaedb..94fe97215 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Barrier.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Barrier.java @@ -37,7 +37,7 @@ public class Barrier extends ShieldBuff { absorbDamage(1); - if (shielding <= 0){ + if (shielding() <= 0){ detach(); } @@ -46,12 +46,6 @@ public class Barrier extends ShieldBuff { return true; } - public void set( int s ){ - if (shielding < s){ - shielding = s; - } - } - @Override public void fx(boolean on) { if (on) target.sprite.add(CharSprite.State.SHIELDED); @@ -75,6 +69,6 @@ public class Barrier extends ShieldBuff { @Override public String desc() { - return Messages.get(this, "desc", shielding); + return Messages.get(this, "desc", shielding()); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java index 5df55ede5..8ecceef9b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/ShieldBuff.java @@ -26,7 +26,7 @@ import com.watabou.utils.Bundle; public abstract class ShieldBuff extends Buff { - protected int shielding; + private int shielding; @Override public boolean attachTo(Char target) { @@ -48,6 +48,29 @@ public abstract class ShieldBuff extends Buff { return shielding; } + public void setShield( int shield ) { + this.shielding = shield; + target.needsShieldUpdate = true; + } + + public void incShield(){ + incShield(1); + } + + public void incShield( int amt ){ + shielding += amt; + target.needsShieldUpdate = true; + } + + public void decShield(){ + decShield(1); + } + + public void decShield( int amt ){ + shielding -= amt; + target.needsShieldUpdate = true; + } + //returns the amount of damage leftover public int absorbDamage( int dmg ){ if (shielding >= dmg){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java index c094dec75..cf707a934 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java @@ -76,7 +76,7 @@ public class Succubus extends Mob { int shield = (HP - HT) + (5 + damage); if (shield > 0){ HP = HT; - Buff.affect(this, Barrier.class).set(shield); + Buff.affect(this, Barrier.class).setShield(shield); } else { HP += 5 + damage; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/BrokenSeal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/BrokenSeal.java index c077d3e42..fe5d0116f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/BrokenSeal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/BrokenSeal.java @@ -106,17 +106,16 @@ public class BrokenSeal extends Item { @Override public synchronized boolean act() { - if (shielding < maxShield()) { - partialShield += 1/(35*Math.pow(0.885f, (maxShield() - shielding - 1))); + if (shielding() < maxShield()) { + partialShield += 1/(35*Math.pow(0.885f, (maxShield() - shielding() - 1))); } while (partialShield >= 1){ - shielding++; + incShield(); partialShield--; - target.needsShieldUpdate = true; } - if (shielding <= 0 && maxShield() <= 0){ + if (shielding() <= 0 && maxShield() <= 0){ detach(); } @@ -125,9 +124,8 @@ public class BrokenSeal extends Item { } public synchronized void supercharge(int maxShield){ - if (maxShield > shielding){ - shielding = maxShield; - target.needsShieldUpdate = true; + if (maxShield > shielding()){ + setShield(maxShield); } } @@ -146,14 +144,13 @@ public class BrokenSeal extends Item { @Override //logic edited slightly as buff should not detach public int absorbDamage(int dmg) { - if (shielding >= dmg){ - shielding -= dmg; + if (shielding() >= dmg){ + decShield(dmg); dmg = 0; } else { - dmg -= shielding; - shielding = 0; + dmg -= shielding(); + setShield(0); } - target.needsShieldUpdate = true; return dmg; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Brimstone.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Brimstone.java index ef93725df..4ede472e9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Brimstone.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Brimstone.java @@ -64,8 +64,8 @@ public class Brimstone extends Armor.Glyph { if (hero.buff(Burning.class) != null){ //max shielding equal to the armors level (this does mean no shield at lvl 0) - if (shielding < level) { - shielding++; + if (shielding() < level) { + incShield(); //generates 0.2 + 0.1*lvl shield per turn spend( 10f / (2f + level)); @@ -76,8 +76,8 @@ public class Brimstone extends Armor.Glyph { } } else if (hero.buff(Burning.class) == null){ - if (shielding > 0){ - shielding--; + if (shielding() > 0){ + decShield(); //shield decays at a rate of 1 per turn. spend(TICK); @@ -85,7 +85,6 @@ public class Brimstone extends Armor.Glyph { detach(); } } - target.needsShieldUpdate = true; return true; } @@ -100,7 +99,7 @@ public class Brimstone extends Armor.Glyph { super.restoreFromBundle(bundle); //pre-0.7.0 if (bundle.contains("added")){ - shielding = bundle.getInt("added"); + setShield(bundle.getInt("added")); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/elixirs/ElixirOfVitality.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/elixirs/ElixirOfVitality.java index 717024b24..84676f6b6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/elixirs/ElixirOfVitality.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/elixirs/ElixirOfVitality.java @@ -39,7 +39,7 @@ public class ElixirOfVitality 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); - Buff.affect(hero, Barrier.class).set((int)(0.6f*hero.HT + 10)); + Buff.affect(hero, Barrier.class).setShield((int)(0.6f*hero.HT + 10)); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfShielding.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfShielding.java index ca500502d..f0889a8fa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfShielding.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfShielding.java @@ -36,6 +36,6 @@ public class PotionOfShielding extends ExoticPotion { setKnown(); //~75% of a potion of healing - Buff.affect(hero, Barrier.class).set((int)(0.6f*hero.HT + 10)); + Buff.affect(hero, Barrier.class).setShield((int)(0.6f*hero.HT + 10)); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfTransfusion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfTransfusion.java index df268cf74..e9143173c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfTransfusion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfTransfusion.java @@ -83,7 +83,7 @@ public class WandOfTransfusion extends Wand { int shielding = (ch.HP + healing) - ch.HT; if (shielding > 0){ healing -= shielding; - Buff.affect(ch, Barrier.class).set(shielding); + Buff.affect(ch, Barrier.class).setShield(shielding); } else { shielding = 0; }