v0.3.0: reworked acting order, now uses a proper priority system with owned properties

This commit is contained in:
Evan Debenham 2015-05-14 19:47:25 -04:00
parent e60424bf15
commit e8a2004345
8 changed files with 38 additions and 7 deletions

View File

@ -40,6 +40,10 @@ 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;
protected abstract boolean act();
protected void spend( float time ) {
@ -186,12 +190,10 @@ public abstract class Actor implements Bundlable {
Arrays.fill( chars, null );
for (Actor actor : all) {
//Order of actions when time is equal:
//1. Hero
//2. Other Chars
//3. Other Actors (e.g. blobs)
if (actor.time < now || (actor instanceof Hero && actor.time == now)
|| (actor instanceof Char && actor.time == now && !(current instanceof Hero))) {
//some actors will always go before others if time is equal.
if (actor.time < now ||
actor.time == now && actor.actPriority < current.actPriority) {
now = actor.time;
current = actor;
}

View File

@ -28,6 +28,10 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.watabou.utils.Bundle;
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 HEIGHT = Level.HEIGHT;

View File

@ -28,6 +28,10 @@ public class Buff extends Actor {
public Char target;
{
actPriority = 3; //low priority, at the end of a turn
}
//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};

View File

@ -118,6 +118,10 @@ import java.util.Collections;
import java.util.HashSet;
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.";

View File

@ -47,6 +47,10 @@ import com.watabou.utils.Random;
import java.util.HashSet;
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";

View File

@ -31,6 +31,10 @@ public class Pushing extends Actor {
private int to;
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 ) {
sprite = ch.sprite;

View File

@ -215,6 +215,10 @@ public class Bomb extends Item {
public static class Fuse extends Actor{
{
actPriority = 3; //as if it were a buff
}
private Bomb bomb;
public Fuse ignite(Bomb bomb){

View File

@ -445,7 +445,12 @@ public abstract class Level implements Bundlable {
}
public Actor respawner() {
return new Actor() {
return new Actor() {
{
actPriority = 1; //as if it were a buff.
}
@Override
protected boolean act() {
if (mobs.size() < nMobs()) {