v0.8.0: tweaked buff find and detach logic to better handle inheritance
This commit is contained in:
parent
2b6b7c10b4
commit
cc4866cb5b
|
@ -489,6 +489,7 @@ public abstract class Char extends Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
//returns all buffs assignable from the given buff class
|
||||||
public synchronized <T extends Buff> HashSet<T> buffs( Class<T> c ) {
|
public synchronized <T extends Buff> HashSet<T> buffs( Class<T> c ) {
|
||||||
HashSet<T> filtered = new HashSet<>();
|
HashSet<T> filtered = new HashSet<>();
|
||||||
for (Buff b : buffs) {
|
for (Buff b : buffs) {
|
||||||
|
@ -500,9 +501,10 @@ public abstract class Char extends Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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 ) {
|
public synchronized <T extends Buff> T buff( Class<T> c ) {
|
||||||
for (Buff b : buffs) {
|
for (Buff b : buffs) {
|
||||||
if (c.isInstance( b )) {
|
if (b.getClass() == c) {
|
||||||
return (T)b;
|
return (T)b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,12 +79,15 @@ public class Berserk extends Buff {
|
||||||
if (berserking()){
|
if (berserking()){
|
||||||
ShieldBuff buff = target.buff(WarriorShield.class);
|
ShieldBuff buff = target.buff(WarriorShield.class);
|
||||||
if (target.HP <= 0) {
|
if (target.HP <= 0) {
|
||||||
|
int dmg = 1 + (int)Math.ceil(target.shielding() * 0.1f);
|
||||||
if (buff != null && buff.shielding() > 0) {
|
if (buff != null && buff.shielding() > 0) {
|
||||||
buff.absorbDamage(1 + (int)Math.ceil(target.shielding() * 0.1f));
|
buff.absorbDamage(dmg);
|
||||||
} else {
|
} else {
|
||||||
//if there is no shield buff, or it is empty, then try to remove from other shielding buffs
|
//if there is no shield buff, or it is empty, then try to remove from other shielding buffs
|
||||||
buff = target.buff(ShieldBuff.class);
|
for (ShieldBuff s : target.buffs(ShieldBuff.class)){
|
||||||
if (buff != null) buff.absorbDamage(1 + (int)Math.ceil(target.shielding() * 0.1f));
|
dmg = s.absorbDamage(dmg);
|
||||||
|
if (dmg == 0) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (target.shielding() <= 0) {
|
if (target.shielding() <= 0) {
|
||||||
target.die(this);
|
target.die(this);
|
||||||
|
|
|
@ -147,13 +147,9 @@ public class Buff extends Actor {
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void detach( Buff buff ) {
|
public static void detach( Char target, Class<? extends Buff> cl ) {
|
||||||
if (buff != null) {
|
for ( Buff b : target.buffs( cl )){
|
||||||
buff.detach();
|
b.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void detach( Char target, Class<? extends Buff> cl ) {
|
|
||||||
detach( target.buff( cl ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,9 +89,8 @@ public class Invisibility extends FlavourBuff {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dispel() {
|
public static void dispel() {
|
||||||
Invisibility buff = Dungeon.hero.buff( Invisibility.class );
|
for ( Buff invis : Dungeon.hero.buffs( Invisibility.class )){
|
||||||
if (buff != null) {
|
invis.detach();
|
||||||
buff.detach();
|
|
||||||
}
|
}
|
||||||
CloakOfShadows.cloakStealth cloakBuff = Dungeon.hero.buff( CloakOfShadows.cloakStealth.class );
|
CloakOfShadows.cloakStealth cloakBuff = Dungeon.hero.buff( CloakOfShadows.cloakStealth.class );
|
||||||
if (cloakBuff != null) {
|
if (cloakBuff != null) {
|
||||||
|
|
|
@ -511,7 +511,7 @@ public class Hero extends Char {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkVisibleMobs();
|
checkVisibleMobs();
|
||||||
if (buff(FlavourBuff.class) != null) {
|
if (!buffs(FlavourBuff.class).isEmpty()) {
|
||||||
BuffIndicator.refreshHero();
|
BuffIndicator.refreshHero();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user