v0.3.0: BIG refactor to buff display, more clear and extendable code, instead of a nest of instanceof statements
This commit is contained in:
@@ -21,6 +21,10 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Amok extends FlavourBuff {
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
|
||||
@@ -28,6 +28,10 @@ import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
public class Bleeding extends Buff {
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
protected int level;
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Blindness extends FlavourBuff {
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
|
||||
@@ -27,6 +27,11 @@ public class Buff extends Actor {
|
||||
|
||||
public Char target;
|
||||
|
||||
//determines how the buff is announced when it is shown.
|
||||
//buffs that work behind the scenes, or have other visual indicators can usually be silent.
|
||||
public enum buffType {POSITIVE, NEGATIVE, NEUTRAL, SILENT};
|
||||
public buffType type = buffType.SILENT;
|
||||
|
||||
public HashSet<Class<?>> resistances = new HashSet<Class<?>>();
|
||||
|
||||
public HashSet<Class<?>> immunities = new HashSet<Class<?>>();
|
||||
@@ -40,10 +45,15 @@ public class Buff extends Actor {
|
||||
this.target = target;
|
||||
target.add( this );
|
||||
|
||||
return target.buffs().contains(this);
|
||||
if (target.buffs().contains(this)){
|
||||
if (target.sprite != null) fx( true );
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
fx( false );
|
||||
target.remove( this );
|
||||
}
|
||||
|
||||
@@ -57,6 +67,14 @@ public class Buff extends Actor {
|
||||
return BuffIndicator.NONE;
|
||||
}
|
||||
|
||||
public void fx(boolean on) {
|
||||
//do nothing by default
|
||||
};
|
||||
|
||||
public String desc(){
|
||||
return "";
|
||||
}
|
||||
|
||||
public static<T extends Buff> T append( Char target, Class<T> buffClass ) {
|
||||
try {
|
||||
T buff = buffClass.newInstance();
|
||||
@@ -103,8 +121,4 @@ public class Buff extends Actor {
|
||||
public static void detach( Char target, Class<? extends Buff> cl ) {
|
||||
detach( target.buff( cl ) );
|
||||
}
|
||||
|
||||
public String desc(){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resis
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.utils.Bundle;
|
||||
@@ -49,6 +50,10 @@ public class Burning extends Buff implements Hero.Doom {
|
||||
private float left;
|
||||
|
||||
private static final String LEFT = "left";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
@@ -133,7 +138,13 @@ public class Burning extends Buff implements Hero.Doom {
|
||||
public int icon() {
|
||||
return BuffIndicator.FIRE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.BURNING);
|
||||
else target.sprite.remove(CharSprite.State.BURNING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Burning";
|
||||
|
||||
@@ -28,6 +28,10 @@ public class Charm extends FlavourBuff {
|
||||
|
||||
private static final String OBJECT = "object";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
super.storeInBundle( bundle );
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.FrozenCarpaccio;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.utils.Random;
|
||||
@@ -19,6 +20,10 @@ public class Chill extends FlavourBuff {
|
||||
|
||||
private static final String TXT_FREEZES = "%s freezes!";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo(Char target) {
|
||||
//can't chill what's frozen!
|
||||
@@ -70,6 +75,12 @@ public class Chill extends FlavourBuff {
|
||||
return BuffIndicator.FROST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.CHILLED);
|
||||
else target.sprite.remove(CharSprite.State.CHILLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Chilled";
|
||||
|
||||
@@ -22,6 +22,10 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
public class Cripple extends FlavourBuff {
|
||||
|
||||
public static final float DURATION = 10f;
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
|
||||
@@ -23,6 +23,10 @@ import com.watabou.utils.Random;
|
||||
|
||||
public class Drowsy extends Buff {
|
||||
|
||||
{
|
||||
type = buffType.NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
return BuffIndicator.DROWSY;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resistance;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
|
||||
@@ -35,6 +36,10 @@ public class Frost extends FlavourBuff {
|
||||
private static final String TXT_FREEZES = "%s freezes!";
|
||||
|
||||
private static final float DURATION = 5f;
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo( Char target ) {
|
||||
@@ -91,7 +96,13 @@ public class Frost extends FlavourBuff {
|
||||
public int icon() {
|
||||
return BuffIndicator.FROST;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.FROZEN);
|
||||
else target.sprite.remove(CharSprite.State.FROZEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Frozen";
|
||||
|
||||
@@ -22,6 +22,10 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
public class Fury extends Buff {
|
||||
|
||||
public static float LEVEL = 0.4f;
|
||||
|
||||
{
|
||||
type = buffType.POSITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean act() {
|
||||
@@ -41,6 +45,6 @@ public class Fury extends Buff {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Fury";
|
||||
return "Furious";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,16 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.CloakOfShadows;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Invisibility extends FlavourBuff {
|
||||
|
||||
public static final float DURATION = 15f;
|
||||
|
||||
{
|
||||
type = buffType.POSITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo( Char target ) {
|
||||
@@ -48,7 +53,13 @@ public class Invisibility extends FlavourBuff {
|
||||
public int icon() {
|
||||
return BuffIndicator.INVISIBLE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add( CharSprite.State.INVISIBLE );
|
||||
else if (target.invisible == 0) target.sprite.remove( CharSprite.State.INVISIBLE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Invisible";
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Levitation extends FlavourBuff {
|
||||
@@ -47,7 +48,13 @@ public class Levitation extends FlavourBuff {
|
||||
public int icon() {
|
||||
return BuffIndicator.LEVITATION;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.LEVITATING);
|
||||
else target.sprite.remove(CharSprite.State.LEVITATING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Levitating";
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Light extends FlavourBuff {
|
||||
@@ -50,7 +51,13 @@ public class Light extends FlavourBuff {
|
||||
public int icon() {
|
||||
return BuffIndicator.LIGHT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.ILLUMINATED);
|
||||
else target.sprite.remove(CharSprite.State.ILLUMINATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Illuminated";
|
||||
|
||||
@@ -28,6 +28,10 @@ public class MagicalSleep extends Buff {
|
||||
private static final float STEP = 1f;
|
||||
public static final float SWS = 1.5f;
|
||||
|
||||
{
|
||||
type = buffType.NEUTRAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo( Char target ) {
|
||||
if (super.attachTo( target ) && !target.immunities().contains(Sleep.class)) {
|
||||
|
||||
@@ -25,6 +25,10 @@ public class MindVision extends FlavourBuff {
|
||||
public static final float DURATION = 20f;
|
||||
|
||||
public int distance = 2;
|
||||
|
||||
{
|
||||
type = buffType.POSITIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
|
||||
@@ -28,6 +28,10 @@ import com.watabou.utils.Random;
|
||||
public class Ooze extends Buff {
|
||||
|
||||
private static final String TXT_HERO_KILLED = "%s killed you...";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
|
||||
@@ -19,11 +19,16 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resistance;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Paralysis extends FlavourBuff {
|
||||
|
||||
private static final float DURATION = 10f;
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo( Char target ) {
|
||||
@@ -45,7 +50,13 @@ public class Paralysis extends FlavourBuff {
|
||||
public int icon() {
|
||||
return BuffIndicator.PARALYSIS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.add(CharSprite.State.PARALYSED);
|
||||
else target.sprite.remove(CharSprite.State.PARALYSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Paralysed";
|
||||
|
||||
@@ -22,10 +22,11 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ResultDescriptions;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.PoisonParticle;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resistance;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.Utils;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
||||
public class Poison extends Buff implements Hero.Doom {
|
||||
@@ -33,6 +34,10 @@ public class Poison extends Buff implements Hero.Doom {
|
||||
protected float left;
|
||||
|
||||
private static final String LEFT = "left";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
@@ -60,7 +65,16 @@ public class Poison extends Buff implements Hero.Doom {
|
||||
public String toString() {
|
||||
return "Poisoned";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean attachTo(Char target) {
|
||||
if (super.attachTo(target)){
|
||||
CellEmitter.center(target.pos).burst( PoisonParticle.SPLASH, 5 );
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean act() {
|
||||
if (target.isAlive()) {
|
||||
|
||||
@@ -21,6 +21,10 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Roots extends FlavourBuff {
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachTo( Char target ) {
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
|
||||
|
||||
public class Sleep extends FlavourBuff {
|
||||
|
||||
|
||||
@Override
|
||||
public void fx(boolean on) {
|
||||
if (on) target.sprite.idle();
|
||||
}
|
||||
|
||||
public static final float SWS = 1.5f;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
|
||||
|
||||
public class Slow extends FlavourBuff {
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
private static final float DURATION = 10f;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,6 +29,10 @@ public class Terror extends FlavourBuff {
|
||||
|
||||
private static final String OBJECT = "object";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
super.storeInBundle(bundle);
|
||||
@@ -48,7 +52,7 @@ public class Terror extends FlavourBuff {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Terror";
|
||||
return "Terrified";
|
||||
}
|
||||
|
||||
public static void recover( Char target ) {
|
||||
|
||||
@@ -14,6 +14,10 @@ public class Venom extends Poison implements Hero.Doom {
|
||||
|
||||
private static final String DAMAGE = "damage";
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeInBundle( Bundle bundle ) {
|
||||
super.storeInBundle( bundle );
|
||||
|
||||
@@ -24,6 +24,10 @@ public class Vertigo extends FlavourBuff {
|
||||
|
||||
public static final float DURATION = 10f;
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
return BuffIndicator.VERTIGO;
|
||||
|
||||
@@ -26,6 +26,10 @@ public class Weakness extends FlavourBuff {
|
||||
|
||||
private static final float DURATION = 40f;
|
||||
|
||||
{
|
||||
type = buffType.NEGATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
return BuffIndicator.WEAKNESS;
|
||||
|
||||
Reference in New Issue
Block a user