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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void add( Buff buff ) {
|
public synchronized boolean add( Buff buff ) {
|
||||||
|
|
||||||
if (buff(PotionOfCleansing.Cleanse.class) != null) { //cleansing buff
|
if (buff(PotionOfCleansing.Cleanse.class) != null) { //cleansing buff
|
||||||
if (buff.type == Buff.buffType.NEGATIVE
|
if (buff.type == Buff.buffType.NEGATIVE
|
||||||
&& !(buff instanceof AllyBuff)
|
&& !(buff instanceof AllyBuff)
|
||||||
&& !(buff instanceof LostInventory)){
|
&& !(buff instanceof LostInventory)){
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sprite != null && buff(Challenge.SpectatorFreeze.class) != null){
|
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 );
|
buffs.add( buff );
|
||||||
if (Actor.chars().contains(this)) Actor.add( buff );
|
if (Actor.chars().contains(this)) Actor.add( buff );
|
||||||
|
|
||||||
if (sprite != null && buff.announced)
|
if (sprite != null && buff.announced) {
|
||||||
switch(buff.type){
|
switch (buff.type) {
|
||||||
case POSITIVE:
|
case POSITIVE:
|
||||||
sprite.showStatus(CharSprite.POSITIVE, Messages.titleCase(buff.name()));
|
sprite.showStatus(CharSprite.POSITIVE, Messages.titleCase(buff.name()));
|
||||||
break;
|
break;
|
||||||
case NEGATIVE:
|
case NEGATIVE:
|
||||||
sprite.showStatus(CharSprite.NEGATIVE, Messages.titleCase(buff.name()));
|
sprite.showStatus(CharSprite.NEGATIVE, Messages.titleCase(buff.name()));
|
||||||
break;
|
break;
|
||||||
case NEUTRAL: default:
|
case NEUTRAL:
|
||||||
|
default:
|
||||||
sprite.showStatus(CharSprite.NEUTRAL, Messages.titleCase(buff.name()));
|
sprite.showStatus(CharSprite.NEUTRAL, Messages.titleCase(buff.name()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void remove( Buff buff ) {
|
public synchronized boolean remove( Buff buff ) {
|
||||||
|
|
||||||
buffs.remove( buff );
|
buffs.remove( buff );
|
||||||
Actor.remove( buff );
|
Actor.remove( buff );
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void remove( Class<? extends Buff> buffClass ) {
|
public synchronized void remove( Class<? extends Buff> buffClass ) {
|
||||||
|
|||||||
@@ -67,9 +67,8 @@ public class Buff extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
target.add( this );
|
|
||||||
|
|
||||||
if (target.buffs().contains(this)){
|
if (target.add( this )){
|
||||||
if (target.sprite != null) fx( true );
|
if (target.sprite != null) fx( true );
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -79,8 +78,7 @@ public class Buff extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void detach() {
|
public void detach() {
|
||||||
if (target.sprite != null) fx( false );
|
if (target.remove( this ) && target.sprite != null) fx( false );
|
||||||
target.remove( this );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1767,14 +1767,15 @@ public class Hero extends Char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
|
||||||
if (buff(TimekeepersHourglass.timeStasis.class) != null)
|
if (buff(TimekeepersHourglass.timeStasis.class) != null) {
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
super.add( buff );
|
boolean added = super.add( buff );
|
||||||
|
|
||||||
if (sprite != null && buffs().contains(buff)) {
|
if (sprite != null && added) {
|
||||||
String msg = buff.heroMessage();
|
String msg = buff.heroMessage();
|
||||||
if (msg != null){
|
if (msg != null){
|
||||||
GLog.w(msg);
|
GLog.w(msg);
|
||||||
@@ -1787,13 +1788,17 @@ public class Hero extends Char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BuffIndicator.refreshHero();
|
BuffIndicator.refreshHero();
|
||||||
|
|
||||||
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove( Buff buff ) {
|
public boolean remove( Buff buff ) {
|
||||||
super.remove( buff );
|
if (super.remove( buff )) {
|
||||||
|
BuffIndicator.refreshHero();
|
||||||
BuffIndicator.refreshHero();
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-2
@@ -143,8 +143,9 @@ public class Ratmogrify extends ArmorAbility {
|
|||||||
//preserve champion enemy buffs
|
//preserve champion enemy buffs
|
||||||
HashSet<ChampionEnemy> champBuffs = ch.buffs(ChampionEnemy.class);
|
HashSet<ChampionEnemy> champBuffs = ch.buffs(ChampionEnemy.class);
|
||||||
for (ChampionEnemy champ : champBuffs){
|
for (ChampionEnemy champ : champBuffs){
|
||||||
ch.remove(champ);
|
if (ch.remove(champ)) {
|
||||||
ch.sprite.clearAura();
|
ch.sprite.clearAura();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Actor.remove( ch );
|
Actor.remove( ch );
|
||||||
|
|||||||
+2
-2
@@ -195,8 +195,8 @@ public class Feint extends ArmorAbility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,13 +124,16 @@ public class Bee extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Buff buff) {
|
public boolean add(Buff buff) {
|
||||||
super.add(buff);
|
if (super.add(buff)) {
|
||||||
//TODO maybe handle honeyed bees with their own ally buff?
|
//TODO maybe handle honeyed bees with their own ally buff?
|
||||||
if (buff instanceof AllyBuff){
|
if (buff instanceof AllyBuff) {
|
||||||
intelligentAlly = false;
|
intelligentAlly = false;
|
||||||
setPotInfo(-1, null);
|
setPotInfo(-1, null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-2
@@ -167,11 +167,12 @@ public abstract class Elemental extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
if (harmfulBuffs.contains( buff.getClass() )) {
|
if (harmfulBuffs.contains( buff.getClass() )) {
|
||||||
damage( Random.NormalIntRange( HT/2, HT * 3/5 ), buff );
|
damage( Random.NormalIntRange( HT/2, HT * 3/5 ), buff );
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
super.add( buff );
|
return super.add( buff );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,13 +91,16 @@ public class Mimic extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Buff buff) {
|
public boolean add(Buff buff) {
|
||||||
super.add(buff);
|
if (super.add(buff)) {
|
||||||
if (buff.type == Buff.buffType.NEGATIVE && alignment == Alignment.NEUTRAL){
|
if (buff.type == Buff.buffType.NEGATIVE && alignment == Alignment.NEUTRAL) {
|
||||||
alignment = Alignment.ENEMY;
|
alignment = Alignment.ENEMY;
|
||||||
stopHiding();
|
stopHiding();
|
||||||
if (sprite != null) sprite.idle();
|
if (sprite != null) sprite.idle();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -395,30 +395,36 @@ public abstract class Mob extends Char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
super.add( buff );
|
if (super.add( buff )) {
|
||||||
if (buff instanceof Amok || buff instanceof AllyBuff) {
|
if (buff instanceof Amok || buff instanceof AllyBuff) {
|
||||||
state = HUNTING;
|
state = HUNTING;
|
||||||
} else if (buff instanceof Terror || buff instanceof Dread) {
|
} else if (buff instanceof Terror || buff instanceof Dread) {
|
||||||
state = FLEEING;
|
state = FLEEING;
|
||||||
} else if (buff instanceof Sleep) {
|
} else if (buff instanceof Sleep) {
|
||||||
state = SLEEPING;
|
state = SLEEPING;
|
||||||
postpone( Sleep.SWS );
|
postpone(Sleep.SWS);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove( Buff buff ) {
|
public boolean remove( Buff buff ) {
|
||||||
super.remove( buff );
|
if (super.remove( buff )) {
|
||||||
if ((buff instanceof Terror && buff(Dread.class) == null)
|
if ((buff instanceof Terror && buff(Dread.class) == null)
|
||||||
|| (buff instanceof Dread && buff(Terror.class) == null)) {
|
|| (buff instanceof Dread && buff(Terror.class) == null)) {
|
||||||
if (enemySeen) {
|
if (enemySeen) {
|
||||||
sprite.showStatus(CharSprite.NEGATIVE, Messages.get(this, "rage"));
|
sprite.showStatus(CharSprite.NEGATIVE, Messages.get(this, "rage"));
|
||||||
state = HUNTING;
|
state = HUNTING;
|
||||||
} else {
|
} else {
|
||||||
state = WANDERING;
|
state = WANDERING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean canAttack( Char enemy ) {
|
protected boolean canAttack( Char enemy ) {
|
||||||
|
|||||||
@@ -169,11 +169,12 @@ public class Pylon extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Buff buff) {
|
public boolean add(Buff buff) {
|
||||||
//immune to all buffs/debuffs when inactive
|
//immune to all buffs/debuffs when inactive
|
||||||
if (alignment != Alignment.NEUTRAL) {
|
if (alignment != Alignment.NEUTRAL) {
|
||||||
super.add(buff);
|
return super.add(buff);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -112,11 +112,14 @@ public class Statue extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(Buff buff) {
|
public boolean add(Buff buff) {
|
||||||
super.add(buff);
|
if (super.add(buff)) {
|
||||||
if (state == PASSIVE && buff.type == Buff.buffType.NEGATIVE){
|
if (state == PASSIVE && buff.type == Buff.buffType.NEGATIVE) {
|
||||||
state = HUNTING;
|
state = HUNTING;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -121,10 +121,11 @@ public class Tengu extends Mob {
|
|||||||
|
|
||||||
//Tengu is immune to debuffs and damage when removed from the level
|
//Tengu is immune to debuffs and damage when removed from the level
|
||||||
@Override
|
@Override
|
||||||
public void add(Buff buff) {
|
public boolean add(Buff buff) {
|
||||||
if (Actor.chars().contains(this) || buff instanceof Doom || loading){
|
if (Actor.chars().contains(this) || buff instanceof Doom || loading){
|
||||||
super.add(buff);
|
return super.add(buff);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+4
-2
@@ -264,10 +264,12 @@ public class Blacksmith extends NPC {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-3
@@ -95,13 +95,15 @@ public class Ghost extends NPC {
|
|||||||
protected Char chooseEnemy() {
|
protected Char chooseEnemy() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-3
@@ -78,13 +78,15 @@ public class Imp extends NPC {
|
|||||||
public int defenseSkill( Char enemy ) {
|
public int defenseSkill( Char enemy ) {
|
||||||
return INFINITE_EVASION;
|
return INFINITE_EVASION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-3
@@ -57,13 +57,15 @@ public class RatKing extends NPC {
|
|||||||
protected Char chooseEnemy() {
|
protected Char chooseEnemy() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+4
-2
@@ -63,13 +63,15 @@ public class Sheep extends NPC {
|
|||||||
public int defenseSkill(Char enemy) {
|
public int defenseSkill(Char enemy) {
|
||||||
return INFINITE_EVASION;
|
return INFINITE_EVASION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+6
-2
@@ -72,8 +72,12 @@ public class Shopkeeper extends NPC {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
flee();
|
if (super.add(buff)) {
|
||||||
|
flee();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flee() {
|
public void flee() {
|
||||||
|
|||||||
+5
-3
@@ -76,13 +76,15 @@ public class Wandmaker extends NPC {
|
|||||||
public int defenseSkill( Char enemy ) {
|
public int defenseSkill( Char enemy ) {
|
||||||
return INFINITE_EVASION;
|
return INFINITE_EVASION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-1
@@ -446,10 +446,12 @@ public class WandOfRegrowth extends Wand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-1
@@ -301,10 +301,12 @@ public class SentryRoom extends SpecialRoom {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage( int dmg, Object src ) {
|
public void damage( int dmg, Object src ) {
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add( Buff buff ) {
|
public boolean add( Buff buff ) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user