Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove instanceof in Hero.add #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Bleeding.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
public class Bleeding extends Buff {

protected int level;

protected static final String TXT_HERO = "You are bleeding!";
private static final String LEVEL = "level";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
Expand Down
7 changes: 7 additions & 0 deletions src/com/watabou/pixeldungeon/actors/buffs/Blindness.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

public class Blindness extends FlavourBuff {

protected static final String TXT_HERO = "You are blinded!";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public void detach() {
super.detach();
Expand Down
4 changes: 3 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Buff.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
public class Buff extends Actor {

public Char target;

public boolean attachTo( Char target ) {

if (target.immunities().contains( getClass() )) {
Expand All @@ -41,6 +40,9 @@ public void detach() {
target.remove( this );
}

public String getHeroText() { return "";};
public boolean isInterrupting() { return false; };

@Override
public boolean act() {
diactivate();
Expand Down
10 changes: 9 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Burning.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@ public class Burning extends Buff implements Hero.Doom {

private static final String TXT_BURNS_UP = "%s burns up!";
private static final String TXT_BURNED_TO_DEATH = "You burned to death...";

protected static final String TXT_HERO = "You catch fire!";
private static final float DURATION = 8f;

private float left;

private static final String LEFT = "left";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean isInterrupting() { return true; }

@Override
public void storeInBundle( Bundle bundle ) {
Expand Down
7 changes: 7 additions & 0 deletions src/com/watabou/pixeldungeon/actors/buffs/Charm.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
import com.watabou.pixeldungeon.ui.BuffIndicator;

public class Charm extends FlavourBuff {

protected static final String TXT_HERO = "You are charmed!";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean attachTo( Char target ) {
Expand Down
6 changes: 6 additions & 0 deletions src/com/watabou/pixeldungeon/actors/buffs/Cripple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@

public class Cripple extends FlavourBuff {

protected static final String TXT_HERO = "You are crippled!";
public static final float DURATION = 10f;

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public int icon() {
Expand Down
12 changes: 10 additions & 2 deletions src/com/watabou/pixeldungeon/actors/buffs/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@
import com.watabou.pixeldungeon.ui.BuffIndicator;

public class Fury extends Buff {

protected static final String TXT_HERO = "You become furious!";
public static float LEVEL = 0.4f;


@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean isInterrupting() { return true; }

@Override
public boolean act() {
if (target.HP > target.HT * LEVEL) {
Expand Down
10 changes: 8 additions & 2 deletions src/com/watabou/pixeldungeon/actors/buffs/Ooze.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
public class Ooze extends Buff {

private static final String TXT_HERO_KILLED = "%s killed you...";

protected static final String TXT_HERO = "Caustic ooze eats your flesh. Wash away it!";

public int damage = 1;


@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public int icon() {
return BuffIndicator.OOZE;
Expand Down
11 changes: 10 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Paralysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
public class Paralysis extends FlavourBuff {

private static final float DURATION = 10f;

protected static final String TXT_HERO = "You are paralysed!";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean isInterrupting() { return true; }

@Override
public boolean attachTo( Char target ) {
if (super.attachTo( target )) {
Expand Down
15 changes: 12 additions & 3 deletions src/com/watabou/pixeldungeon/actors/buffs/Poison.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@
public class Poison extends Buff implements Hero.Doom {

protected float left;

private static final String LEFT = "left";

protected static final String TXT_HERO = "You are poisoned!";

private static final String LEFT = "left";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean isInterrupting() { return true; }

@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
Expand Down
7 changes: 7 additions & 0 deletions src/com/watabou/pixeldungeon/actors/buffs/Roots.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

public class Roots extends FlavourBuff {

protected static final String TXT_HERO = "You can't move!";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean attachTo( Char target ) {
if (!target.flying && super.attachTo( target )) {
Expand Down
11 changes: 10 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Vertigo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
public class Vertigo extends FlavourBuff {

public static final float DURATION = 10f;

protected static final String TXT_HERO = "Everything is spinning around you!";

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public boolean isInterrupting() { return true; }

@Override
public int icon() {
return BuffIndicator.VERTIGO;
Expand Down
7 changes: 6 additions & 1 deletion src/com/watabou/pixeldungeon/actors/buffs/Weakness.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
import com.watabou.pixeldungeon.ui.BuffIndicator;

public class Weakness extends FlavourBuff {

protected static final String TXT_HERO = "You feel weakened!";
private static final float DURATION = 40f;

@Override
public String getHeroText() {
return TXT_HERO;
}

@Override
public int icon() {
return BuffIndicator.WEAKNESS;
Expand Down
44 changes: 12 additions & 32 deletions src/com/watabou/pixeldungeon/actors/hero/Hero.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ public class Hero extends Char {
"It's easier for you to hit enemies and dodge their attacks.";

public static final String TXT_YOU_NOW_HAVE = "You now have %s";

private static final String TXT_SOMETHING_ELSE = "There is something else here";
private static final String TXT_LOCKED_CHEST = "This chest is locked and you don't have matching key";
private static final String TXT_LOCKED_DOOR = "You don't have a matching key";
private static final String TXT_NOTICED_SMTH = "You noticed something";

private static final String TXT_WAIT = "...";
private static final String TXT_SEARCH = "search";

public static final int STARTING_STR = 10;

private static final float TIME_TO_REST = 1f;
Expand Down Expand Up @@ -1068,45 +1067,26 @@ public void add( Buff buff ) {
super.add( buff );

if (sprite != null) {
if (buff instanceof Burning) {
GLog.w( "You catch fire!" );
interrupt();
} else if (buff instanceof Paralysis) {
GLog.w( "You are paralysed!" );
interrupt();
} else if (buff instanceof Poison) {
GLog.w( "You are poisoned!" );
interrupt();
} else if (buff instanceof Ooze) {
GLog.w( "Caustic ooze eats your flesh. Wash away it!" );
} else if (buff instanceof Roots) {
GLog.w( "You can't move!" );
} else if (buff instanceof Weakness) {
GLog.w( "You feel weakened!" );
} else if (buff instanceof Blindness) {
GLog.w( "You are blinded!" );
} else if (buff instanceof Fury) {
GLog.w( "You become furious!" );
sprite.showStatus( CharSprite.POSITIVE, "furious" );
} else if (buff instanceof Charm) {
GLog.w( "You are charmed!" );
} else if (buff instanceof Cripple) {
GLog.w( "You are crippled!" );
} else if (buff instanceof Bleeding) {
GLog.w( "You are bleeding!" );
} else if (buff instanceof Vertigo) {
GLog.w( "Everything is spinning around you!" );
String heroText = buff.getHeroText();
if (heroText.length() > 0){
GLog.w(heroText);
}
String buffString = buff.toString();

if (buff.isInterrupting()) {
interrupt();
}

else if (buff instanceof Light) {
if (buffString == "Fury") {
sprite.showStatus( CharSprite.POSITIVE, "furious" );
} else if (buffString == "Light") {
sprite.add( CharSprite.State.ILLUMINATED );
}
}

BuffIndicator.refreshHero();
}

@Override
public void remove( Buff buff ) {
super.remove( buff );
Expand Down