Search in sources :

Example 6 with Scene

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

the class RemoveInventoryItemAction method run.

@Override
public boolean run(VerbRunner cb) {
    Scene s = World.getInstance().getScene(scene);
    if (id != null) {
        SpriteActor a = World.getInstance().getInventory().removeItem(id);
        if (a != null) {
            if (s != World.getInstance().getCurrentScene())
                a.dispose();
            s.addActor(a);
        } else {
            EngineLogger.debug("RemoveInventoryAction - Inventory actor not found: " + id);
        }
    } else {
        int n = World.getInstance().getInventory().getNumItems();
        for (int i = 0; i < n; i++) {
            SpriteActor a = World.getInstance().getInventory().get(i);
            s.addActor(a);
        }
        World.getInstance().getInventory().removeAllItems();
    }
    return false;
}
Also used : SpriteActor(com.bladecoder.engine.model.SpriteActor) Scene(com.bladecoder.engine.model.Scene)

Example 7 with Scene

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

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

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

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

the class SetDialogOptionAttrAction method run.

@Override
public boolean run(VerbRunner cb) {
    final Scene s = actor.getScene();
    CharacterActor a = (CharacterActor) s.getActor(actor.getActorId(), true);
    Dialog d = a.getDialog(dialog);
    if (d == null) {
        EngineLogger.error("SetDialogOptionAttrAction: Dialog '" + dialog + "' not found");
        return false;
    }
    DialogOption o = d.getOptions().get(option);
    if (o == null) {
        EngineLogger.error("SetDialogOptionAttrAction: Option '" + option + "' not found");
        return false;
    }
    if (visible != null)
        o.setVisible(visible);
    return false;
}
Also used : Dialog(com.bladecoder.engine.model.Dialog) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor) DialogOption(com.bladecoder.engine.model.DialogOption)

Aggregations

Scene (com.bladecoder.engine.model.Scene)35 InteractiveActor (com.bladecoder.engine.model.InteractiveActor)18 BaseActor (com.bladecoder.engine.model.BaseActor)16 Verb (com.bladecoder.engine.model.Verb)9 Vector2 (com.badlogic.gdx.math.Vector2)8 CharacterActor (com.bladecoder.engine.model.CharacterActor)8 SpriteActor (com.bladecoder.engine.model.SpriteActor)8 Action (com.bladecoder.engine.actions.Action)6 World (com.bladecoder.engine.model.World)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 Polygon (com.badlogic.gdx.math.Polygon)3 AnchorActor (com.bladecoder.engine.model.AnchorActor)3 UndoDeleteScene (com.bladecoder.engineeditor.undo.UndoDeleteScene)3 AnimationRenderer (com.bladecoder.engine.model.AnimationRenderer)2 SceneLayer (com.bladecoder.engine.model.SceneLayer)2 VerbRunner (com.bladecoder.engine.model.VerbRunner)2