Search in sources :

Example 1 with Scene

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

the class DefaultSceneScreen method sceneClick.

private void sceneClick(int button, int count) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(viewport, unprojectTmp);
    Scene s = w.getCurrentScene();
    CharacterActor player = s.getPlayer();
    if (currentActor != null) {
        if (EngineLogger.debugMode()) {
            EngineLogger.debug(currentActor.toString());
        }
        // DOUBLE CLICK: Fastwalk when leaving scene.
        if (count > 1) {
            if (count == 2 && fastLeave && !recorder.isRecording() && player != null && currentActor.getVerb(Verb.LEAVE_VERB) != null) {
                player.fastWalk();
            }
            return;
        }
        actorClick(currentActor, button);
    } else if (player != null) {
        if (count > 1)
            return;
        if (s.getPlayer().getVerb("goto") != null) {
            runVerb(s.getPlayer(), "goto", null);
        } else {
            Vector2 pos = new Vector2(unprojectTmp.x, unprojectTmp.y);
            if (recorder.isRecording()) {
                recorder.add(pos);
            }
            player.goTo(pos, null, false);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene) CharacterActor(com.bladecoder.engine.model.CharacterActor)

Example 2 with Scene

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

the class TesterBot method update.

public void update(float d) {
    if (!enabled)
        return;
    World w = World.getInstance();
    deltaTime += d;
    inSceneTimeDelta += d;
    if (w.inCutMode() && isPassTexts())
        w.getTextManager().next();
    if (deltaTime > waitInverval && !w.inCutMode()) {
        deltaTime = 0;
        waitInverval = MathUtils.random(maxWaitInverval);
        boolean isWalking = false;
        SpriteActor player = w.getCurrentScene().getPlayer();
        if (player != null) {
            if (((AnimationRenderer) player.getRenderer()).getCurrentAnimationId().startsWith(CharacterActor.DEFAULT_WALK_ANIM))
                isWalking = true;
        }
        if (isWaitWhenWalking() && isWalking)
            return;
        Scene s = w.getCurrentScene();
        if (w.getCurrentDialog() == null) {
            // Select actor or goto
            boolean chooseActor = MathUtils.randomBoolean(.75f);
            if (!isRunGoto() || chooseActor) {
                // Select scene or actor inventory
                boolean chooseSceneActor = MathUtils.randomBoolean();
                if (chooseSceneActor && s.getActors().size() > 0) {
                    // SCENE ACTOR
                    int pos = MathUtils.random(s.getActors().size() - 1);
                    BaseActor a = (BaseActor) (s.getActors().values().toArray()[pos]);
                    if (!(a instanceof InteractiveActor))
                        return;
                    InteractiveActor scnActor = (InteractiveActor) a;
                    if (excludeList.contains(scnActor.getId()) || !scnActor.isVisible() || !scnActor.canInteract())
                        return;
                    String verb;
                    if (scnActor.getVerb(Verb.LEAVE_VERB) != null) {
                        verb = Verb.LEAVE_VERB;
                    } else if (MathUtils.randomBoolean(0.33f)) {
                        // LOOKAT
                        verb = Verb.LOOKAT_VERB;
                    } else {
                        // ACTION
                        verb = scnActor.getVerb(Verb.TALKTO_VERB) != null ? Verb.TALKTO_VERB : Verb.ACTION_VERB;
                    }
                    if (!(verb.equals(Verb.LEAVE_VERB) && (!runLeaveVerbs || inSceneTime > inSceneTimeDelta))) {
                        EngineLogger.debug("<TESTERBOT>: " + scnActor.getId() + "::" + verb);
                        scnActor.runVerb(verb);
                        if (verb.equals(Verb.LEAVE_VERB))
                            inSceneTimeDelta = 0;
                    }
                } else if (w.getInventory().getNumItems() > 0 && w.getInventory().isVisible()) {
                    // INVENTORY ACTOR
                    int pos = MathUtils.random(w.getInventory().getNumItems() - 1);
                    SpriteActor invActor = w.getInventory().get(pos);
                    if (excludeList.contains(invActor.getId()))
                        return;
                    // Select lookat, action or use
                    int choosedVerb = MathUtils.random(3);
                    if (choosedVerb == 0) {
                        EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.LOOKAT_VERB);
                        invActor.runVerb(Verb.LOOKAT_VERB);
                    } else if (choosedVerb == 1 && inventoryAction) {
                        EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.ACTION_VERB);
                        invActor.runVerb(Verb.ACTION_VERB);
                    } else {
                        // 2 and 3
                        InteractiveActor targetActor = null;
                        if (w.getInventory().getNumItems() > 1 && MathUtils.randomBoolean(0.33f)) {
                            // CHOOSE TARGET FROM INVENTORY
                            int pos2 = MathUtils.random(w.getInventory().getNumItems() - 1);
                            if (pos2 == pos)
                                pos2 = (pos2 + 1) % w.getInventory().getNumItems();
                            targetActor = w.getInventory().get(pos2);
                            if (excludeList.contains(targetActor.getId()))
                                return;
                            EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.USE_VERB + "::" + targetActor.getId());
                            if (invActor.getVerb(Verb.USE_VERB, targetActor.getId()) != null)
                                invActor.runVerb(Verb.USE_VERB, targetActor.getId());
                            else
                                targetActor.runVerb(Verb.USE_VERB, invActor.getId());
                        } else {
                            int pos2 = MathUtils.random(s.getActors().size() - 1);
                            if (!(s.getActors().values().toArray()[pos2] instanceof InteractiveActor))
                                return;
                            targetActor = (InteractiveActor) (s.getActors().values().toArray()[pos2]);
                            if (!excludeList.contains(targetActor.getId()) && targetActor.isVisible() && targetActor.canInteract()) {
                                EngineLogger.debug("<TESTERBOT> INVENTORY: " + invActor.getId() + "::" + Verb.USE_VERB + "::" + targetActor.getId());
                                if (invActor.getVerb(Verb.USE_VERB, targetActor.getId()) != null)
                                    invActor.runVerb(Verb.USE_VERB, targetActor.getId());
                                else
                                    targetActor.runVerb(Verb.USE_VERB, invActor.getId());
                            }
                        }
                    }
                }
            } else if (s.getPlayer() != null) {
                gotoVector.x = MathUtils.random() * w.getCurrentScene().getCamera().getScrollingWidth();
                gotoVector.y = MathUtils.random() * w.getCurrentScene().getCamera().getScrollingHeight();
                if (s.getPlayer().getVerb(Verb.GOTO_VERB) != null) {
                    EngineLogger.debug("<TESTERBOT> GOTO: GOTO VERB");
                    s.getPlayer().runVerb(Verb.GOTO_VERB);
                } else {
                    EngineLogger.debug("<TESTERBOT> GOTO: " + gotoVector);
                    s.getPlayer().goTo(gotoVector, null, false);
                }
            }
        } else {
            // DIALOG MODE
            List<String> visibleOptions = w.getDialogOptions();
            if (visibleOptions.size() > 0) {
                int pos = MathUtils.random(visibleOptions.size() - 1);
                EngineLogger.debug("<TESTERBOT> SELECT OPTION: " + pos);
                w.selectDialogOption(pos);
            }
        }
    }
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) SpriteActor(com.bladecoder.engine.model.SpriteActor) BaseActor(com.bladecoder.engine.model.BaseActor) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene)

Example 3 with Scene

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

the class RetroSceneScreen method sceneClick.

private void sceneClick(int button) {
    World w = World.getInstance();
    w.getSceneCamera().getInputUnProject(worldViewport, unprojectTmp);
    Scene s = w.getCurrentScene();
    if (currentActor != null) {
        if (EngineLogger.debugMode()) {
            EngineLogger.debug(currentActor.toString());
        }
        actorClick(currentActor, button);
    } else if (s.getPlayer() != null) {
        if (s.getPlayer().getVerb("goto") != null) {
            runVerb(s.getPlayer(), "goto", null);
        } else {
            Vector2 pos = new Vector2(unprojectTmp.x, unprojectTmp.y);
            if (recorder.isRecording()) {
                recorder.add(pos);
            }
            s.getPlayer().goTo(pos, null, false);
        }
    }
}
Also used : Vector2(com.badlogic.gdx.math.Vector2) World(com.bladecoder.engine.model.World) Scene(com.bladecoder.engine.model.Scene)

Example 4 with Scene

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

the class ActionCallbackSerialization method find.

/**
 * Generates a String for serialization that allows locate the
 * ActionCallback
 *
 * @param cb
 *            The ActionCallback to serialize
 * @return The generated location string
 */
public static String find(ActionCallback cb) {
    String id = null;
    if (cb == null)
        return null;
    // search in UIActors
    id = find(cb, World.getInstance().getUIActors());
    if (id != null)
        return id;
    // search in inventory
    id = find(cb, World.getInstance().getInventory());
    if (id != null)
        return id;
    // search in inkManager actions
    id = find(cb, World.getInstance().getInkManager());
    if (id != null)
        return id;
    // search in scene verbs
    Scene s = World.getInstance().getCurrentScene();
    id = find(cb, s);
    if (id != null)
        return id;
    // search in player
    id = find(cb, s.getPlayer());
    if (id != null)
        return id;
    // search in actors
    for (BaseActor a : s.getActors().values()) {
        if (!(a instanceof InteractiveActor))
            continue;
        id = find(cb, (InteractiveActor) a);
        if (id != null)
            return id;
    }
    // search in worldVerbs
    for (Verb v : World.getInstance().getVerbManager().getVerbs().values()) {
        id = find(cb, v);
        if (id != null) {
            StringBuilder stringBuilder = new StringBuilder(DEFAULT_VERB_TAG);
            stringBuilder.append(SEPARATION_SYMBOL).append(id);
            return stringBuilder.toString();
        }
    }
    return null;
}
Also used : InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Verb(com.bladecoder.engine.model.Verb) BaseActor(com.bladecoder.engine.model.BaseActor) Scene(com.bladecoder.engine.model.Scene)

Example 5 with Scene

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

the class ActionCallbackSerialization method find.

/**
 * Searches for the ActionCallback represented by the id string.
 *
 * @param id
 */
public static ActionCallback find(String id) {
    if (id == null)
        return null;
    Scene s = World.getInstance().getCurrentScene();
    String[] split = id.split(SEPARATION_SYMBOL);
    if (id.startsWith(INK_MANAGER_TAG)) {
        if (split.length == 1)
            return World.getInstance().getInkManager();
        int actionPos = Integer.parseInt(split[1]);
        Action action = World.getInstance().getInkManager().getActions().get(actionPos);
        if (action instanceof ActionCallback)
            return (ActionCallback) action;
    }
    if (split.length < 2)
        return null;
    String actorId;
    String verbId;
    int actionPos = -1;
    if (id.startsWith(UIACTORS_TAG) || id.startsWith(INVENTORY_TAG)) {
        actorId = split[1];
        verbId = split[2];
        if (split.length > 3)
            actionPos = Integer.parseInt(split[3]);
    } else {
        actorId = split[0];
        verbId = split[1];
        if (split.length > 2)
            actionPos = Integer.parseInt(split[2]);
    }
    Verb v = null;
    if (actorId.equals(DEFAULT_VERB_TAG)) {
        v = World.getInstance().getVerbManager().getVerb(verbId, null, null);
    } else {
        InteractiveActor a;
        if (actorId.equals(s.getId())) {
            v = s.getVerbManager().getVerbs().get(verbId);
        } else {
            a = (InteractiveActor) s.getActor(actorId, true);
            if (a == null) {
                EngineLogger.error("ActionCallbackSerialization - Actor not found: " + actorId + " cb: " + id);
                return null;
            }
            v = a.getVerbManager().getVerbs().get(verbId);
        }
    }
    if (v == null) {
        EngineLogger.error("ActionCallbackSerialization - Verb not found: " + verbId + " cb: " + id);
        return null;
    }
    if (actionPos == -1)
        return v;
    Action action = v.getActions().get(actionPos);
    if (action instanceof ActionCallback)
        return (ActionCallback) action;
    EngineLogger.error("ActionCallbackSerialization - CB not found: " + id);
    return null;
}
Also used : Action(com.bladecoder.engine.actions.Action) ActionCallback(com.bladecoder.engine.actions.ActionCallback) Verb(com.bladecoder.engine.model.Verb) InteractiveActor(com.bladecoder.engine.model.InteractiveActor) Scene(com.bladecoder.engine.model.Scene)

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