From 2009095a66fe230ae2caf2664d02f7c2a6d3ffbd Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 1 Dec 2017 13:51:35 -0500 Subject: [PATCH] v0.6.3: improved actor priority logic --- .../shatteredpixeldungeon/actors/Actor.java | 17 +++++++++++++---- .../actors/blobs/Blob.java | 2 +- .../actors/blobs/GooWarn.java | 2 +- .../actors/buffs/Buff.java | 2 +- .../actors/buffs/Healing.java | 6 +++--- .../actors/buffs/Preparation.java | 2 +- .../shatteredpixeldungeon/actors/hero/Hero.java | 2 +- .../shatteredpixeldungeon/actors/mobs/Mob.java | 2 +- .../shatteredpixeldungeon/effects/Pushing.java | 2 +- .../shatteredpixeldungeon/items/Bomb.java | 2 +- .../items/artifacts/DriedRose.java | 4 ++-- .../items/wands/WandOfFrost.java | 2 +- .../shatteredpixeldungeon/levels/Level.java | 2 +- .../levels/traps/FlockTrap.java | 2 +- .../levels/traps/GrimTrap.java | 2 +- .../levels/traps/PoisonDartTrap.java | 2 +- .../levels/traps/WornDartTrap.java | 2 +- 17 files changed, 32 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index a2ce76065..3aa02750c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -42,9 +42,18 @@ public abstract class Actor implements Bundlable { private int id = 0; - //used to determine what order actors act in. - //hero should always act on 0, therefore negative is before hero, positive is after hero - protected int actPriority = Integer.MAX_VALUE; + //default priority values for general actor categories + //note that some specific actors pick more specific values + //e.g. a buff acting after all normal buffs might have priority BUFF_PRIO + 1 + protected final int VFX_PRIO = 100; //visual effects take priority + protected final int HERO_PRIO = 0; //positive priority is before hero, negative after + protected final int BLOB_PRIO = -10; //blobs act after hero, before mobs + protected final int MOB_PRIO = -20; //mobs act between buffs and blobd + protected final int BUFF_PRIO = -30; //buffs act last in a turn + private final int DEFAULT = -100; //if no priority is given, act after all else + + //used to determine what order actors act in if their time is equal. Higher values act earlier. + protected int actPriority = DEFAULT; protected abstract boolean act(); @@ -187,7 +196,7 @@ public abstract class Actor implements Bundlable { //some actors will always go before others if time is equal. if (actor.time < now || - actor.time == now && (current == null || actor.actPriority < current.actPriority)) { + actor.time == now && (current == null || actor.actPriority > current.actPriority)) { now = actor.time; current = actor; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java index c1e612971..0f814e956 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java @@ -32,7 +32,7 @@ import com.watabou.utils.Rect; public class Blob extends Actor { { - actPriority = 1; //take priority over mobs, but not the hero + actPriority = BLOB_PRIO; } public int volume = 0; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java index dcd34bcfa..4e06e60d8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java @@ -34,7 +34,7 @@ public class GooWarn extends Blob { { //this one needs to act after the Goo - actPriority = 3; + actPriority = MOB_PRIO - 1; } protected int pos; 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 34635b533..bcfe7e6db 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 @@ -35,7 +35,7 @@ public class Buff extends Actor { public Char target; { - actPriority = 3; //low priority, at the end of a turn + actPriority = BUFF_PRIO; //low priority, towards the end of a turn } //determines how the buff is announced when it is shown. diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Healing.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Healing.java index 9db48a4fd..8491963b8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Healing.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Healing.java @@ -34,9 +34,9 @@ public class Healing extends Buff { private int flatHealPerTick; { - //unlike other buffs, this one acts after the hero and takes priority against enemies - //healing is much more useful if you get some of it off before enemies attack - actPriority = 1; + //unlike other buffs, this one acts after the hero and takes priority against other effects + //healing is much more useful if you get some of it off before taking damage + actPriority = HERO_PRIO - 1; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Preparation.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Preparation.java index 306ecff71..06064bb9c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Preparation.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Preparation.java @@ -48,7 +48,7 @@ public class Preparation extends Buff implements ActionIndicator.Action { { //always acts after other buffs, so invisibility effects can process first - actPriority = 4; + actPriority = BUFF_PRIO - 1; } public enum AttackLevel{ 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 b04b15e58..9ac81f860 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 @@ -130,7 +130,7 @@ import java.util.Collections; public class Hero extends Char { { - actPriority = 0; //acts at priority 0, baseline for the rest of behaviour. + actPriority = HERO_PRIO; alignment = Alignment.ALLY; } 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 e9574cd41..5e7a0309d 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 @@ -61,7 +61,7 @@ public abstract class Mob extends Char { { name = Messages.get(this, "name"); - actPriority = 2; //hero gets priority over mobs. + actPriority = MOB_PRIO; alignment = Alignment.ENEMY; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java index 7bed3c1c3..969e65a41 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java @@ -40,7 +40,7 @@ public class Pushing extends Actor { private Callback callback; { - actPriority = Integer.MIN_VALUE; //it's a visual effect, gets priority no matter what + actPriority = VFX_PRIO; } public Pushing( Char ch, int from, int to ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java index efb1d6f7d..2140f0f58 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java @@ -218,7 +218,7 @@ public class Bomb extends Item { public static class Fuse extends Actor{ { - actPriority = 3; //as if it were a buff + actPriority = BUFF_PRIO; //as if it were a buff } private Bomb bomb; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java index c1d4985df..a0b4b365c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java @@ -383,8 +383,8 @@ public class DriedRose extends Artifact { state = HUNTING; - //after hero, but before mobs - actPriority = 1; + //before other mobs + actPriority = MOB_PRIO + 1; } private DriedRose rose = null; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFrost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFrost.java index 984c85cef..dab6d353c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFrost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFrost.java @@ -107,7 +107,7 @@ public class WandOfFrost extends DamageWand { if (chill != null && Random.IntRange(2, 10) > chill.cooldown()){ //need to delay this through an actor so that the freezing isn't broken by taking damage from the staff hit. new FlavourBuff(){ - {actPriority = Integer.MIN_VALUE;} + {actPriority = VFX_PRIO;} public boolean act() { Buff.affect(target, Frost.class, Frost.duration(target) * Random.Float(1f, 2f)); return super.act(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index a63ce80c0..801f78465 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -494,7 +494,7 @@ public abstract class Level implements Bundlable { return new Actor() { { - actPriority = 1; //as if it were a buff. + actPriority = BUFF_PRIO; //as if it were a buff. } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java index 328b2b7bf..da0b62d58 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java @@ -46,7 +46,7 @@ public class FlockTrap extends Trap { //use an actor as we want to put this on a slight delay so all chars get a chance to act this turn first. Actor.add(new Actor() { - { actPriority = 3; } + { actPriority = BUFF_PRIO; } protected boolean act() { PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java index dbf1974dd..b41b4bb36 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java @@ -82,7 +82,7 @@ public class GrimTrap extends Trap { { //it's a visual effect, gets priority no matter what - actPriority = Integer.MIN_VALUE; + actPriority = VFX_PRIO; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java index 33505e600..c4d48fe4d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PoisonDartTrap.java @@ -70,7 +70,7 @@ public class PoisonDartTrap extends Trap { { //it's a visual effect, gets priority no matter what - actPriority = Integer.MIN_VALUE; + actPriority = VFX_PRIO; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java index d4a5ceadc..eb913f883 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/WornDartTrap.java @@ -68,7 +68,7 @@ public class WornDartTrap extends Trap { { //it's a visual effect, gets priority no matter what - actPriority = Integer.MIN_VALUE; + actPriority = VFX_PRIO; } @Override