diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 62e15308b..7572d7d43 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -846,43 +846,48 @@ public abstract class Char extends Actor { return false; } - public synchronized void add( Buff buff ) { + public synchronized boolean add( Buff buff ) { if (buff(PotionOfCleansing.Cleanse.class) != null) { //cleansing buff if (buff.type == Buff.buffType.NEGATIVE && !(buff instanceof AllyBuff) && !(buff instanceof LostInventory)){ - return; + return false; } } if (sprite != null && buff(Challenge.SpectatorFreeze.class) != null){ - return; //can't add buffs while frozen and game is loaded + return false; //can't add buffs while frozen and game is loaded } buffs.add( buff ); if (Actor.chars().contains(this)) Actor.add( buff ); - if (sprite != null && buff.announced) - switch(buff.type){ + if (sprite != null && buff.announced) { + switch (buff.type) { case POSITIVE: sprite.showStatus(CharSprite.POSITIVE, Messages.titleCase(buff.name())); break; case NEGATIVE: sprite.showStatus(CharSprite.NEGATIVE, Messages.titleCase(buff.name())); break; - case NEUTRAL: default: + case NEUTRAL: + default: sprite.showStatus(CharSprite.NEUTRAL, Messages.titleCase(buff.name())); break; } + } + + return true; } - public synchronized void remove( Buff buff ) { + public synchronized boolean remove( Buff buff ) { buffs.remove( buff ); Actor.remove( buff ); + return true; } public synchronized void remove( Class buffClass ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java index 08959cb45..877b855b2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java @@ -67,9 +67,8 @@ public class Buff extends Actor { } this.target = target; - target.add( this ); - if (target.buffs().contains(this)){ + if (target.add( this )){ if (target.sprite != null) fx( true ); return true; } else { @@ -79,8 +78,7 @@ public class Buff extends Actor { } public void detach() { - if (target.sprite != null) fx( false ); - target.remove( this ); + if (target.remove( this ) && target.sprite != null) fx( false ); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 1ac7729f2..3b487e101 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -1767,14 +1767,15 @@ public class Hero extends Char { } @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { - if (buff(TimekeepersHourglass.timeStasis.class) != null) - return; + if (buff(TimekeepersHourglass.timeStasis.class) != null) { + return false; + } - super.add( buff ); + boolean added = super.add( buff ); - if (sprite != null && buffs().contains(buff)) { + if (sprite != null && added) { String msg = buff.heroMessage(); if (msg != null){ GLog.w(msg); @@ -1787,13 +1788,17 @@ public class Hero extends Char { } BuffIndicator.refreshHero(); + + return added; } @Override - public void remove( Buff buff ) { - super.remove( buff ); - - BuffIndicator.refreshHero(); + public boolean remove( Buff buff ) { + if (super.remove( buff )) { + BuffIndicator.refreshHero(); + return true; + } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/Ratmogrify.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/Ratmogrify.java index 5568228b7..03fba0648 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/Ratmogrify.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/Ratmogrify.java @@ -143,8 +143,9 @@ public class Ratmogrify extends ArmorAbility { //preserve champion enemy buffs HashSet champBuffs = ch.buffs(ChampionEnemy.class); for (ChampionEnemy champ : champBuffs){ - ch.remove(champ); - ch.sprite.clearAura(); + if (ch.remove(champ)) { + ch.sprite.clearAura(); + } } Actor.remove( ch ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/Feint.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/Feint.java index 42a847cce..8d22e7a92 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/Feint.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/abilities/duelist/Feint.java @@ -195,8 +195,8 @@ public class Feint extends ArmorAbility { } @Override - public void add( Buff buff ) { - + public boolean add( Buff buff ) { + return false; } { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java index 1d59e67de..40eb14ddc 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java @@ -124,13 +124,16 @@ public class Bee extends Mob { } @Override - public void add(Buff buff) { - super.add(buff); - //TODO maybe handle honeyed bees with their own ally buff? - if (buff instanceof AllyBuff){ - intelligentAlly = false; - setPotInfo(-1, null); + public boolean add(Buff buff) { + if (super.add(buff)) { + //TODO maybe handle honeyed bees with their own ally buff? + if (buff instanceof AllyBuff) { + intelligentAlly = false; + setPotInfo(-1, null); + } + return true; } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java index 0cab80d48..e1fcadf47 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Elemental.java @@ -167,11 +167,12 @@ public abstract class Elemental extends Mob { } @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { if (harmfulBuffs.contains( buff.getClass() )) { damage( Random.NormalIntRange( HT/2, HT * 3/5 ), buff ); + return false; } else { - super.add( buff ); + return super.add( buff ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java index 84234c78f..03920a9a1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java @@ -91,13 +91,16 @@ public class Mimic extends Mob { } @Override - public void add(Buff buff) { - super.add(buff); - if (buff.type == Buff.buffType.NEGATIVE && alignment == Alignment.NEUTRAL){ - alignment = Alignment.ENEMY; - stopHiding(); - if (sprite != null) sprite.idle(); + public boolean add(Buff buff) { + if (super.add(buff)) { + if (buff.type == Buff.buffType.NEGATIVE && alignment == Alignment.NEUTRAL) { + alignment = Alignment.ENEMY; + stopHiding(); + if (sprite != null) sprite.idle(); + } + return true; } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 863090bbb..d71f750fd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -395,30 +395,36 @@ public abstract class Mob extends Char { } @Override - public void add( Buff buff ) { - super.add( buff ); - if (buff instanceof Amok || buff instanceof AllyBuff) { - state = HUNTING; - } else if (buff instanceof Terror || buff instanceof Dread) { - state = FLEEING; - } else if (buff instanceof Sleep) { - state = SLEEPING; - postpone( Sleep.SWS ); + public boolean add( Buff buff ) { + if (super.add( buff )) { + if (buff instanceof Amok || buff instanceof AllyBuff) { + state = HUNTING; + } else if (buff instanceof Terror || buff instanceof Dread) { + state = FLEEING; + } else if (buff instanceof Sleep) { + state = SLEEPING; + postpone(Sleep.SWS); + } + return true; } + return false; } @Override - public void remove( Buff buff ) { - super.remove( buff ); - if ((buff instanceof Terror && buff(Dread.class) == null) - || (buff instanceof Dread && buff(Terror.class) == null)) { - if (enemySeen) { - sprite.showStatus(CharSprite.NEGATIVE, Messages.get(this, "rage")); - state = HUNTING; - } else { - state = WANDERING; + public boolean remove( Buff buff ) { + if (super.remove( buff )) { + if ((buff instanceof Terror && buff(Dread.class) == null) + || (buff instanceof Dread && buff(Terror.class) == null)) { + if (enemySeen) { + sprite.showStatus(CharSprite.NEGATIVE, Messages.get(this, "rage")); + state = HUNTING; + } else { + state = WANDERING; + } } + return true; } + return false; } protected boolean canAttack( Char enemy ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java index 3a68cb08d..f92b1c5ba 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Pylon.java @@ -169,11 +169,12 @@ public class Pylon extends Mob { } @Override - public void add(Buff buff) { + public boolean add(Buff buff) { //immune to all buffs/debuffs when inactive if (alignment != Alignment.NEUTRAL) { - super.add(buff); + return super.add(buff); } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java index f89662b4c..f76bab815 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java @@ -112,11 +112,14 @@ public class Statue extends Mob { } @Override - public void add(Buff buff) { - super.add(buff); - if (state == PASSIVE && buff.type == Buff.buffType.NEGATIVE){ - state = HUNTING; + public boolean add(Buff buff) { + if (super.add(buff)) { + if (state == PASSIVE && buff.type == Buff.buffType.NEGATIVE) { + state = HUNTING; + } + return true; } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java index ebdd6e0c3..f1d375b23 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java @@ -121,10 +121,11 @@ public class Tengu extends Mob { //Tengu is immune to debuffs and damage when removed from the level @Override - public void add(Buff buff) { + public boolean add(Buff buff) { if (Actor.chars().contains(this) || buff instanceof Doom || loading){ - super.add(buff); + return super.add(buff); } + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java index 27c09f7f0..6b3d66c8e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Blacksmith.java @@ -264,10 +264,12 @@ public class Blacksmith extends NPC { @Override public void damage( int dmg, Object src ) { + //do nothing } - + @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java index fb2dd6475..a5495bed6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Ghost.java @@ -95,13 +95,15 @@ public class Ghost extends NPC { protected Char chooseEnemy() { return null; } - + @Override public void damage( int dmg, Object src ) { + //do nothing } - + @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java index b36152baf..c58bacd7b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Imp.java @@ -78,13 +78,15 @@ public class Imp extends NPC { public int defenseSkill( Char enemy ) { return INFINITE_EVASION; } - + @Override public void damage( int dmg, Object src ) { + //do nothing } - + @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java index 6a0555c5b..b6c17c9dc 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/RatKing.java @@ -57,13 +57,15 @@ public class RatKing extends NPC { protected Char chooseEnemy() { return null; } - + @Override public void damage( int dmg, Object src ) { + //do nothing } - + @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java index 1ee5ce870..5c2d5400d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Sheep.java @@ -63,13 +63,15 @@ public class Sheep extends NPC { public int defenseSkill(Char enemy) { return INFINITE_EVASION; } - + @Override public void damage( int dmg, Object src ) { + //do nothing } @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java index d287c1ad4..0b5e2fde7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Shopkeeper.java @@ -72,8 +72,12 @@ public class Shopkeeper extends NPC { } @Override - public void add( Buff buff ) { - flee(); + public boolean add( Buff buff ) { + if (super.add(buff)) { + flee(); + return true; + } + return false; } public void flee() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java index cd8076d8d..f3799821a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java @@ -76,13 +76,15 @@ public class Wandmaker extends NPC { public int defenseSkill( Char enemy ) { return INFINITE_EVASION; } - + @Override public void damage( int dmg, Object src ) { + //do nothing } - + @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java index eb55c6ce3..cebfc5a3e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java @@ -446,10 +446,12 @@ public class WandOfRegrowth extends Wand { @Override public void damage( int dmg, Object src ) { + //do nothing } @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java index ba68f2817..9e9fd87f8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/rooms/special/SentryRoom.java @@ -301,10 +301,12 @@ public class SentryRoom extends SpecialRoom { @Override public void damage( int dmg, Object src ) { + //do nothing } @Override - public void add( Buff buff ) { + public boolean add( Buff buff ) { + return false; } @Override