v2.1.1: improved how barkskin handles being applied by multiple sources

This commit is contained in:
Evan Debenham
2023-06-08 16:56:58 -04:00
parent b4ba9c9b91
commit 2ff3e26bbc
9 changed files with 32 additions and 13 deletions

View File

@@ -85,7 +85,7 @@ actors.buffs.ascensionchallenge.almost=You feel Yog's grip on the amulet begin t
actors.buffs.ascensionchallenge.on_kill=The dark energy consumes you... actors.buffs.ascensionchallenge.on_kill=The dark energy consumes you...
actors.buffs.barkskin.name=barkskin actors.buffs.barkskin.name=barkskin
actors.buffs.barkskin.desc=Your skin is hardened, it feels rough and solid like bark.\n\nThe hardened skin increases your effective armor, allowing you to better defend against physical attack.\n\nYour armor is currently increased by: 0-%d.\nTurns until barkskin weakens: %s. actors.buffs.barkskin.desc=Your skin is hardened, it feels rough and solid like bark.\n\nThe hardened skin increases your effective armor, allowing you to better defend against physical attack.\n\nYour armor is currently increased by: 0-%d.\nTurns until barkskin weakens: %s.\n\nIf you receive barkskin from multiple sources, only the strongest one will apply.
actors.buffs.barrier.name=barrier actors.buffs.barrier.name=barrier
actors.buffs.barrier.desc=A durable bubble of force which blocks all damage.\n\nThe barrier will take damage for whatever it is protecting so long as there is shielding left. The shielding will also slowly decay over time.\n\nShielding remaining: %d. actors.buffs.barrier.desc=A durable bubble of force which blocks all damage.\n\nThe barrier will take damage for whatever it is protecting so long as there is shielding left. The shielding will also slowly decay over time.\n\nShielding remaining: %d.

View File

@@ -576,8 +576,7 @@ public abstract class Char extends Actor {
public int drRoll() { public int drRoll() {
int dr = 0; int dr = 0;
Barkskin bark = buff(Barkskin.class); dr += Random.NormalIntRange( 0 , Barkskin.currentLevel(this) );
if (bark != null) dr += Random.NormalIntRange( 0 , bark.level() );
return dr; return dr;
} }

View File

@@ -21,6 +21,7 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs; package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -59,8 +60,7 @@ public class Barkskin extends Buff {
} }
public void set( int value, int time ) { public void set( int value, int time ) {
//decide whether to override, preferring high value + low interval if (level <= value) {
if (Math.sqrt(interval)*level <= Math.sqrt(time)*value) {
level = value; level = value;
interval = time; interval = time;
spend(time - cooldown() - 1); spend(time - cooldown() - 1);
@@ -108,4 +108,26 @@ public class Barkskin extends Buff {
interval = bundle.getInt( INTERVAL ); interval = bundle.getInt( INTERVAL );
level = bundle.getInt( LEVEL ); level = bundle.getInt( LEVEL );
} }
//These two methods allow for multiple instances of barkskin to stack in terms of duration
// but only the stronger bonus is applied
public static int currentLevel(Char ch ){
int level = 0;
for (Barkskin b : ch.buffs(Barkskin.class)){
level = Math.max(level, b.level);
}
return level;
}
//reset if a matching buff exists, otherwise append
public static void conditionallyAppend(Char ch, int level, int interval){
for (Barkskin b : ch.buffs(Barkskin.class)){
if (b.interval == interval){
b.set(level, interval);
return;
}
}
Buff.append(ch, Barkskin.class).set(level, interval);
}
} }

View File

@@ -819,7 +819,7 @@ public class Hero extends Char {
} }
if(hasTalent(Talent.BARKSKIN) && Dungeon.level.map[pos] == Terrain.FURROWED_GRASS){ if(hasTalent(Talent.BARKSKIN) && Dungeon.level.map[pos] == Terrain.FURROWED_GRASS){
Buff.affect(this, Barkskin.class).set( (lvl*pointsInTalent(Talent.BARKSKIN))/2, 1 ); Barkskin.conditionallyAppend(this, (lvl*pointsInTalent(Talent.BARKSKIN))/2, 1 );
} }
return actResult; return actResult;

View File

@@ -58,7 +58,7 @@ public class FrozenCarpaccio extends Food {
break; break;
case 1: case 1:
GLog.i( Messages.get(FrozenCarpaccio.class, "hard") ); GLog.i( Messages.get(FrozenCarpaccio.class, "hard") );
Buff.affect( hero, Barkskin.class ).set( hero.HT / 4, 1 ); Barkskin.conditionallyAppend( hero, hero.HT / 4, 1 );
break; break;
case 2: case 2:
GLog.i( Messages.get(FrozenCarpaccio.class, "refresh") ); GLog.i( Messages.get(FrozenCarpaccio.class, "refresh") );

View File

@@ -49,7 +49,7 @@ public class PhantomMeat extends Food {
public static void effect(Hero hero){ public static void effect(Hero hero){
Buff.affect( hero, Barkskin.class ).set( hero.HT / 4, 1 ); Barkskin.conditionallyAppend( hero, hero.HT / 4, 1 );
Buff.affect( hero, Invisibility.class, Invisibility.DURATION ); Buff.affect( hero, Invisibility.class, Invisibility.DURATION );
if (hero.HP < hero.HT) { if (hero.HP < hero.HT) {
hero.HP = Math.min( hero.HP + hero.HT / 4, hero.HT ); hero.HP = Math.min( hero.HP + hero.HT / 4, hero.HT );

View File

@@ -22,7 +22,6 @@
package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic; package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@@ -36,7 +35,7 @@ public class PotionOfEarthenArmor extends ExoticPotion {
public void apply( Hero hero ) { public void apply( Hero hero ) {
identify(); identify();
Buff.affect(hero, Barkskin.class).set( 2 + hero.lvl/3, 50 ); Barkskin.conditionallyAppend( hero, 2 + hero.lvl/3, 50 );
} }
} }

View File

@@ -47,7 +47,7 @@ public class Earthroot extends Plant {
if (ch != null){ if (ch != null){
if (ch instanceof Hero && ((Hero) ch).subClass == HeroSubClass.WARDEN) { if (ch instanceof Hero && ((Hero) ch).subClass == HeroSubClass.WARDEN) {
Buff.affect(ch, Barkskin.class).set(Dungeon.hero.lvl + 5, 5); Barkskin.conditionallyAppend(Dungeon.hero, Dungeon.hero.lvl + 5, 5);
} else { } else {
Buff.affect(ch, Armor.class).level(ch.HT); Buff.affect(ch, Armor.class).level(ch.HT);
} }

View File

@@ -27,7 +27,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
@@ -66,7 +65,7 @@ public abstract class Plant implements Bundlable {
if (Dungeon.level.heroFOV[pos] && Dungeon.hero.hasTalent(Talent.NATURES_AID)){ if (Dungeon.level.heroFOV[pos] && Dungeon.hero.hasTalent(Talent.NATURES_AID)){
// 3/5 turns based on talent points spent // 3/5 turns based on talent points spent
Buff.affect(Dungeon.hero, Barkskin.class).set(2, 1 + 2*(Dungeon.hero.pointsInTalent(Talent.NATURES_AID))); Barkskin.conditionallyAppend(Dungeon.hero, 2, 1 + 2*(Dungeon.hero.pointsInTalent(Talent.NATURES_AID)));
} }
wither(); wither();