v2.0.1: refactored adding and removing buffs to return success/fail
This commit is contained in:
@@ -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<? extends Buff> buffClass ) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -143,8 +143,9 @@ public class Ratmogrify extends ArmorAbility {
|
||||
//preserve champion enemy buffs
|
||||
HashSet<ChampionEnemy> 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 );
|
||||
|
||||
@@ -195,8 +195,8 @@ public class Feint extends ArmorAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( Buff buff ) {
|
||||
|
||||
public boolean add( Buff buff ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user