Search in sources :

Example 6 with BaseActor

use of com.bladecoder.engine.model.BaseActor 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 7 with BaseActor

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

the class DropItemAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene ts = null;
    if (scene == null)
        ts = World.getInstance().getCurrentScene();
    else
        ts = World.getInstance().getScene(scene);
    BaseActor a;
    if (actor != null) {
        a = World.getInstance().getInventory().get(actor);
        if (a == null) {
            EngineLogger.error(MessageFormat.format("DropItemAction -  Item not found: {0}", actor));
            return false;
        }
        removeActor(ts, a);
    } else {
        int n = World.getInstance().getInventory().getNumItems();
        for (int i = n - 1; i >= 0; i--) {
            a = World.getInstance().getInventory().get(i);
            removeActor(ts, a);
        }
    }
    return false;
}
Also used : BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 8 with BaseActor

use of com.bladecoder.engine.model.BaseActor 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 9 with BaseActor

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

the class SetActorAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = actor.getScene();
    BaseActor a = s.getActor(actor.getActorId(), true);
    if (a == null) {
        EngineLogger.error("SetActorAttr - Actor not found:" + this.actor.getActorId());
        return false;
    }
    if (visible != null)
        a.setVisible(visible);
    if (interaction != null) {
        if (a instanceof InteractiveActor)
            ((InteractiveActor) a).setInteraction(interaction);
        else
            EngineLogger.error("'Interaction' property not supported for actor:" + a.getId());
    }
    if (layer != null) {
        if (a instanceof InteractiveActor) {
            InteractiveActor iActor = (InteractiveActor) a;
            String oldLayer = iActor.getLayer();
            s.getLayer(oldLayer).remove(iActor);
            iActor.setLayer(layer);
            SceneLayer l = s.getLayer(layer);
            l.add(iActor);
            if (!l.isDynamic())
                l.orderByZIndex();
        } else
            EngineLogger.error("'layer' property not supported for actor:" + a.getId());
    }
    if (zIndex != null) {
        if (a instanceof InteractiveActor) {
            InteractiveActor iActor = (InteractiveActor) a;
            iActor.setZIndex(zIndex);
            SceneLayer l = s.getLayer(iActor.getLayer());
            if (!l.isDynamic())
                l.orderByZIndex();
        } else
            EngineLogger.error("'zIndex' property not supported for actor:" + a.getId());
    }
    if (scale != null) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).setScale(scale);
        else
            EngineLogger.error("'scale' property not supported for actor:" + a.getId());
    }
    if (rotation != null) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).setRot(rotation);
        else
            EngineLogger.error("'rotation' property not supported for actor:" + a.getId());
    }
    if (tint != null) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).setTint(tint);
        else
            EngineLogger.error("'tint' property not supported for actor:" + a.getId());
    }
    if (fakeDepth != null) {
        if (a instanceof SpriteActor) {
            ((SpriteActor) a).setFakeDepth(fakeDepth);
        } else
            EngineLogger.error("'fakeDepth' property not supported for actor:" + a.getId());
    }
    if (standAnimation != null) {
        if (a instanceof CharacterActor)
            ((CharacterActor) a).setStandAnim(standAnimation);
        else
            EngineLogger.error("'standAnimation' property not supported for actor:" + a.getId());
    }
    if (walkAnimation != null) {
        if (a instanceof CharacterActor)
            ((CharacterActor) a).setWalkAnim(walkAnimation);
        else
            EngineLogger.error("'walkAnimation' property not supported for actor:" + a.getId());
    }
    if (talkAnimation != null) {
        if (a instanceof CharacterActor)
            ((CharacterActor) a).setTalkAnim(talkAnimation);
        else
            EngineLogger.error("'talkAnimation' property not supported for actor:" + a.getId());
    }
    if (walkingSpeed != null) {
        if (a instanceof CharacterActor)
            ((CharacterActor) a).setWalkingSpeed(walkingSpeed);
        else
            EngineLogger.error("'walkingSpeed' property not supported for actor:" + a.getId());
    }
    if (uiActor != null) {
        if (a instanceof InteractiveActor) {
            if (uiActor)
                setUIActor(s, (InteractiveActor) a);
            else
                removeUIActor(s, (InteractiveActor) a);
        } else
            EngineLogger.error("'uiActor' property not supported for actor:" + a.getId());
    }
    return false;
}
Also used : SceneLayer(com.bladecoder.engine.model.SceneLayer) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) BaseActor(com.bladecoder.engine.model.BaseActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 10 with BaseActor

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

the class ModelTools method addCutMode.

public static final void addCutMode() {
    Map<String, Scene> scenes = World.getInstance().getScenes();
    for (Scene scn : scenes.values()) {
        Map<String, BaseActor> actors = scn.getActors();
        for (BaseActor a : actors.values()) {
            if (a instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) a;
                HashMap<String, Verb> verbs = ia.getVerbManager().getVerbs();
                for (Verb v : verbs.values()) {
                    ArrayList<Action> actions = v.getActions();
                    // Don't process verbs for inventory
                    if (v.getState() != null && v.getState().equalsIgnoreCase("INVENTORY"))
                        continue;
                    if (actions.size() == 1) {
                        Action act = actions.get(0);
                        if (act instanceof LookAtAction || act instanceof SayAction) {
                            actions.clear();
                            SetCutmodeAction cma1 = new SetCutmodeAction();
                            SetCutmodeAction cma2 = new SetCutmodeAction();
                            try {
                                ActionUtils.setParam(cma1, "value", "true");
                                ActionUtils.setParam(cma2, "value", "false");
                            } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
                                EditorLogger.printStackTrace(e);
                            }
                            actions.add(cma1);
                            actions.add(act);
                            actions.add(cma2);
                        }
                    }
                }
            }
        }
    }
    Ctx.project.setModified();
}
Also used : LookAtAction(com.bladecoder.engine.actions.LookAtAction) SayAction(com.bladecoder.engine.actions.SayAction) SetCutmodeAction(com.bladecoder.engine.actions.SetCutmodeAction) Action(com.bladecoder.engine.actions.Action) LookAtAction(com.bladecoder.engine.actions.LookAtAction) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SayAction(com.bladecoder.engine.actions.SayAction) Scene(com.bladecoder.engine.model.Scene) SetCutmodeAction(com.bladecoder.engine.actions.SetCutmodeAction) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor)

Aggregations

BaseActor (com.bladecoder.engine.model.BaseActor)40 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)26 Scene (com.bladecoder.engine.model.Scene)16 SpriteActor (com.bladecoder.engine.model.SpriteActor)13 CharacterActor (com.bladecoder.engine.model.CharacterActor)12 Vector2 (com.badlogic.gdx.math.Vector2)8 Verb (com.bladecoder.engine.model.Verb)8 Polygon (com.badlogic.gdx.math.Polygon)7 World (com.bladecoder.engine.model.World)7 Rectangle (com.badlogic.gdx.math.Rectangle)5 Action (com.bladecoder.engine.actions.Action)5 AnchorActor (com.bladecoder.engine.model.AnchorActor)5 LookAtAction (com.bladecoder.engine.actions.LookAtAction)4 SayAction (com.bladecoder.engine.actions.SayAction)4 SetCutmodeAction (com.bladecoder.engine.actions.SetCutmodeAction)4 Dialog (com.bladecoder.engine.model.Dialog)4 DialogOption (com.bladecoder.engine.model.DialogOption)4 ObstacleActor (com.bladecoder.engine.model.ObstacleActor)4 SceneLayer (com.bladecoder.engine.model.SceneLayer)4 Color (com.badlogic.gdx.graphics.Color)3