Search in sources :

Example 1 with VerbRunner

use of com.bladecoder.engine.model.VerbRunner in project bladecoder-adventure-engine by bladecoder.

the class RepeatAction method run.

@Override
public boolean run(VerbRunner cb) {
    VerbRunner v = (VerbRunner) cb;
    currentRepeat++;
    if (currentRepeat > repeat && repeat >= 0) {
        final int ip = skipControlIdBlock(v.getActions(), v.getIP());
        v.setIP(ip);
        currentRepeat = 0;
    }
    return false;
}
Also used : VerbRunner(com.bladecoder.engine.model.VerbRunner)

Example 2 with VerbRunner

use of com.bladecoder.engine.model.VerbRunner in project bladecoder-adventure-engine by bladecoder.

the class CancelVerbAction method run.

@Override
public boolean run(VerbRunner cb) {
    VerbRunner v = null;
    if (verb == null) {
        v = (VerbRunner) cb;
    }
    if (v == null && actor != null) {
        BaseActor a = World.getInstance().getCurrentScene().getActor(actor, true);
        v = ((InteractiveActor) a).getVerb(verb, target);
    }
    if (v == null) {
        v = World.getInstance().getCurrentScene().getVerb(verb);
    }
    if (v == null) {
        v = World.getInstance().getVerbManager().getVerb(verb, null, null);
    }
    if (v != null)
        v.cancel();
    else
        EngineLogger.error("Cannot find VERB: " + verb + " for ACTOR: " + actor);
    return false;
}
Also used : VerbRunner(com.bladecoder.engine.model.VerbRunner) BaseActor(com.bladecoder.engine.model.BaseActor)

Example 3 with VerbRunner

use of com.bladecoder.engine.model.VerbRunner in project bladecoder-adventure-engine by bladecoder.

the class EndAction method run.

@Override
public boolean run(VerbRunner cb) {
    // FIXME: This is now more generic than before, but also less optimized (we always get our "parent")
    final VerbRunner v = (VerbRunner) cb;
    final List<Action> actions = v.getActions();
    final int ip = v.getIP();
    final int parentIp = getParentControlAction(caID, actions, ip);
    final AbstractControlAction parent = (AbstractControlAction) actions.get(parentIp);
    if (parent instanceof RepeatAction) {
        v.setIP(parentIp - 1);
    } else if (parent instanceof AbstractIfAction) {
        // goto Else
        int newIp = skipControlIdBlock(actions, parentIp);
        // goto EndIf
        newIp = skipControlIdBlock(actions, newIp);
        v.setIP(newIp);
    }
    return false;
}
Also used : VerbRunner(com.bladecoder.engine.model.VerbRunner)

Example 4 with VerbRunner

use of com.bladecoder.engine.model.VerbRunner in project bladecoder-adventure-engine by bladecoder.

the class IfAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    final String actorId = actor.getActorId();
    if (actorId == null) {
        // if called inside a scene verb and no actor is specified, return
        EngineLogger.error(getClass() + ": No actor specified");
        return false;
    }
    BaseActor a = s.getActor(actorId, true);
    if (attr.equals(ActorAttribute.STATE) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getState())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.VISIBLE)) {
        boolean val = Boolean.parseBoolean(value);
        if (val != a.isVisible()) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.INTERACTIVE)) {
        boolean val = Boolean.parseBoolean(value);
        if (a instanceof InteractiveActor) {
            if (val != ((InteractiveActor) a).getInteraction()) {
                gotoElse((VerbRunner) cb);
            }
        } else if (val == true) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_INVENTORY)) {
        boolean val = Boolean.parseBoolean(value);
        SpriteActor item = null;
        if (a != null)
            item = World.getInstance().getInventory().get(a.getId());
        if ((val && item == null) || (!val && item != null)) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.TARGET)) {
        if (!ActionUtils.compareNullStr(value, cb.getCurrentTarget())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.IN_SCENE)) {
        boolean val = Boolean.parseBoolean(value);
        BaseActor a2 = s.getActor(actorId, false);
        if ((val && a2 == null) || (!val && a2 != null))
            gotoElse((VerbRunner) cb);
    } else if (attr.equals(ActorAttribute.LAYER) && a instanceof InteractiveActor) {
        InteractiveActor ia = (InteractiveActor) a;
        if (!ActionUtils.compareNullStr(value, ia.getLayer())) {
            gotoElse((VerbRunner) cb);
        }
    } else if (attr.equals(ActorAttribute.DIRECTION) && a instanceof SpriteActor) {
        SpriteActor sa = (SpriteActor) a;
        if (sa.getRenderer() instanceof AnimationRenderer) {
            String dir = null;
            String anim = ((AnimationRenderer) sa.getRenderer()).getCurrentAnimationId();
            int idx = anim.lastIndexOf('.');
            if (idx != -1)
                dir = anim.substring(idx + 1);
            if (!ActionUtils.compareNullStr(value, dir)) {
                gotoElse((VerbRunner) cb);
            }
        }
    }
    return false;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) VerbRunner(com.bladecoder.engine.model.VerbRunner) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) AnimationRenderer(com.bladecoder.engine.model.AnimationRenderer)

Example 5 with VerbRunner

use of com.bladecoder.engine.model.VerbRunner in project bladecoder-adventure-engine by bladecoder.

the class RunOnceAction method run.

@Override
public boolean run(VerbRunner cb) {
    VerbRunner v = (VerbRunner) cb;
    if (executed) {
        final int ip = skipControlIdBlock(v.getActions(), v.getIP());
        v.setIP(ip);
    }
    executed = true;
    return false;
}
Also used : VerbRunner(com.bladecoder.engine.model.VerbRunner)

Aggregations

VerbRunner (com.bladecoder.engine.model.VerbRunner)8 BaseActor (com.bladecoder.engine.model.BaseActor)2 Scene (com.bladecoder.engine.model.Scene)2 Action (com.bladecoder.engine.actions.Action)1 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)1 CharacterActor (com.bladecoder.engine.model.CharacterActor)1 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)1 SpriteActor (com.bladecoder.engine.model.SpriteActor)1