v0.3.0: reworked acting order, now uses a proper priority system with owned properties
This commit is contained in:
parent
e60424bf15
commit
e8a2004345
|
@ -40,6 +40,10 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
private int id = 0;
|
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;
|
||||||
|
|
||||||
protected abstract boolean act();
|
protected abstract boolean act();
|
||||||
|
|
||||||
protected void spend( float time ) {
|
protected void spend( float time ) {
|
||||||
|
@ -186,12 +190,10 @@ public abstract class Actor implements Bundlable {
|
||||||
Arrays.fill( chars, null );
|
Arrays.fill( chars, null );
|
||||||
|
|
||||||
for (Actor actor : all) {
|
for (Actor actor : all) {
|
||||||
//Order of actions when time is equal:
|
|
||||||
//1. Hero
|
//some actors will always go before others if time is equal.
|
||||||
//2. Other Chars
|
if (actor.time < now ||
|
||||||
//3. Other Actors (e.g. blobs)
|
actor.time == now && actor.actPriority < current.actPriority) {
|
||||||
if (actor.time < now || (actor instanceof Hero && actor.time == now)
|
|
||||||
|| (actor instanceof Char && actor.time == now && !(current instanceof Hero))) {
|
|
||||||
now = actor.time;
|
now = actor.time;
|
||||||
current = actor;
|
current = actor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
||||||
import com.watabou.utils.Bundle;
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
public class Blob extends Actor {
|
public class Blob extends Actor {
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 1; //take prioerity over mobs, but not the hero
|
||||||
|
}
|
||||||
|
|
||||||
public static final int WIDTH = Level.WIDTH;
|
public static final int WIDTH = Level.WIDTH;
|
||||||
public static final int HEIGHT = Level.HEIGHT;
|
public static final int HEIGHT = Level.HEIGHT;
|
||||||
|
|
|
@ -28,6 +28,10 @@ public class Buff extends Actor {
|
||||||
|
|
||||||
public Char target;
|
public Char target;
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 3; //low priority, at the end of a turn
|
||||||
|
}
|
||||||
|
|
||||||
//determines how the buff is announced when it is shown.
|
//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.
|
//buffs that work behind the scenes, or have other visual indicators can usually be silent.
|
||||||
public enum buffType {POSITIVE, NEGATIVE, NEUTRAL, SILENT};
|
public enum buffType {POSITIVE, NEGATIVE, NEUTRAL, SILENT};
|
||||||
|
|
|
@ -118,6 +118,10 @@ import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class Hero extends Char {
|
public class Hero extends Char {
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 0; //acts at priority 0, baseline for the rest of behaviour.
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TXT_LEAVE = "One does not simply leave Pixel Dungeon.";
|
private static final String TXT_LEAVE = "One does not simply leave Pixel Dungeon.";
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,10 @@ import com.watabou.utils.Random;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public abstract class Mob extends Char {
|
public abstract class Mob extends Char {
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 2; //hero gets priority over mobs.
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TXT_DIED = "You hear something died in the distance";
|
private static final String TXT_DIED = "You hear something died in the distance";
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,10 @@ public class Pushing extends Actor {
|
||||||
private int to;
|
private int to;
|
||||||
|
|
||||||
private Effect effect;
|
private Effect effect;
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = Integer.MIN_VALUE; //it's a visual effect, gets priority no matter what
|
||||||
|
}
|
||||||
|
|
||||||
public Pushing( Char ch, int from, int to ) {
|
public Pushing( Char ch, int from, int to ) {
|
||||||
sprite = ch.sprite;
|
sprite = ch.sprite;
|
||||||
|
|
|
@ -215,6 +215,10 @@ public class Bomb extends Item {
|
||||||
|
|
||||||
public static class Fuse extends Actor{
|
public static class Fuse extends Actor{
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 3; //as if it were a buff
|
||||||
|
}
|
||||||
|
|
||||||
private Bomb bomb;
|
private Bomb bomb;
|
||||||
|
|
||||||
public Fuse ignite(Bomb bomb){
|
public Fuse ignite(Bomb bomb){
|
||||||
|
|
|
@ -445,7 +445,12 @@ public abstract class Level implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Actor respawner() {
|
public Actor respawner() {
|
||||||
return new Actor() {
|
return new Actor() {
|
||||||
|
|
||||||
|
{
|
||||||
|
actPriority = 1; //as if it were a buff.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean act() {
|
protected boolean act() {
|
||||||
if (mobs.size() < nMobs()) {
|
if (mobs.size() < nMobs()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user