v0.8.0: tweaked buff find and detach logic to better handle inheritance

This commit is contained in:
Evan Debenham 2019-11-13 14:12:37 -05:00
parent 2b6b7c10b4
commit cc4866cb5b
5 changed files with 15 additions and 15 deletions

View File

@ -489,6 +489,7 @@ public abstract class Char extends Actor {
}
@SuppressWarnings("unchecked")
//returns all buffs assignable from the given buff class
public synchronized <T extends Buff> HashSet<T> buffs( Class<T> c ) {
HashSet<T> filtered = new HashSet<>();
for (Buff b : buffs) {
@ -500,9 +501,10 @@ public abstract class Char extends Actor {
}
@SuppressWarnings("unchecked")
//returns an instance of the specific buff class, if it exists. Not just assignable
public synchronized <T extends Buff> T buff( Class<T> c ) {
for (Buff b : buffs) {
if (c.isInstance( b )) {
if (b.getClass() == c) {
return (T)b;
}
}

View File

@ -79,12 +79,15 @@ public class Berserk extends Buff {
if (berserking()){
ShieldBuff buff = target.buff(WarriorShield.class);
if (target.HP <= 0) {
int dmg = 1 + (int)Math.ceil(target.shielding() * 0.1f);
if (buff != null && buff.shielding() > 0) {
buff.absorbDamage(1 + (int)Math.ceil(target.shielding() * 0.1f));
buff.absorbDamage(dmg);
} else {
//if there is no shield buff, or it is empty, then try to remove from other shielding buffs
buff = target.buff(ShieldBuff.class);
if (buff != null) buff.absorbDamage(1 + (int)Math.ceil(target.shielding() * 0.1f));
for (ShieldBuff s : target.buffs(ShieldBuff.class)){
dmg = s.absorbDamage(dmg);
if (dmg == 0) break;
}
}
if (target.shielding() <= 0) {
target.die(this);

View File

@ -147,13 +147,9 @@ public class Buff extends Actor {
return buff;
}
public static void detach( Buff buff ) {
if (buff != null) {
buff.detach();
public static void detach( Char target, Class<? extends Buff> cl ) {
for ( Buff b : target.buffs( cl )){
b.detach();
}
}
public static void detach( Char target, Class<? extends Buff> cl ) {
detach( target.buff( cl ) );
}
}

View File

@ -89,9 +89,8 @@ public class Invisibility extends FlavourBuff {
}
public static void dispel() {
Invisibility buff = Dungeon.hero.buff( Invisibility.class );
if (buff != null) {
buff.detach();
for ( Buff invis : Dungeon.hero.buffs( Invisibility.class )){
invis.detach();
}
CloakOfShadows.cloakStealth cloakBuff = Dungeon.hero.buff( CloakOfShadows.cloakStealth.class );
if (cloakBuff != null) {

View File

@ -511,7 +511,7 @@ public class Hero extends Char {
}
checkVisibleMobs();
if (buff(FlavourBuff.class) != null) {
if (!buffs(FlavourBuff.class).isEmpty()) {
BuffIndicator.refreshHero();
}