@Override public void run() { ip = 0; // Gets the actor/scene state. if (actorId != null && World.getInstance().getCurrentScene().getActor(actorId, true).getVerb(verb, target) != null) { state = World.getInstance().getCurrentScene().getActor(actorId, true).getState(); } else if (World.getInstance().getCurrentScene().getVerb(verb) != null) { state = World.getInstance().getCurrentScene().getState(); } nextStep(); }
/** * 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 (split.length < 2) return null; String actorId = split[0]; String verbId = split[1]; int actionPos = -1; if (split.length > 2) actionPos = Integer.parseInt(split[2]); Verb v = null; if (actorId.equals("DEFAULT_VERB")) { 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) return null; v = a.getVerbManager().getVerbs().get(verbId); } } if (v == null) return null; if (split.length == 2) return v; Action action = v.getActions().get(actionPos); if (action instanceof ActionCallback) return (ActionCallback) action; return null; }
@Override public void resume() { World w = World.getInstance(); BaseActor actor = w.getCurrentScene().getActor(characterName, false); if (characterTurn) { characterTurn = false; if (previousAnim != null) { SpriteActor player = World.getInstance().getCurrentScene().getPlayer(); player.startAnimation(previousAnim, null); } if (responseText != null) { // WorldCamera c = World.getInstance().getCamera(); // Vector3 p = c.scene2screen(pos.x, pos.y + actor.getHeight()); World.getInstance() .getTextManager() .addSubtitle( responseText, actor.getX(), actor.getY() + actor.getBBox().getBoundingRectangle().getHeight(), false, Text.Type.TALK, Color.BLACK, this); if (actor instanceof CharacterActor) { startTalkAnim((CharacterActor) actor); } } else { super.resume(); } } else { if (actor instanceof SpriteActor) { ((SpriteActor) actor).startAnimation(previousAnim, null); } super.resume(); } }
private Verb getVerb(String verb, String target, String state) { Verb v = null; if (actorId != null) { BaseActor a = World.getInstance().getCurrentScene().getActor(actorId, true); v = a.getVerbManager().getVerb(verb, state, target); } if (v == null) { v = World.getInstance().getCurrentScene().getVerb(verb); } if (v == null) { v = VerbManager.getWorldVerbs().get(verb); } if (v == null) EngineLogger.error("Cannot find VERB: " + verb + " for ACTOR: " + actorId); return v; }
@Override public boolean run(ActionCallback cb) { setVerbCb(cb); World w = World.getInstance(); DialogOption o = World.getInstance().getCurrentDialog().getCurrentOption(); String playerText = o.getText(); responseText = o.getResponseText(); characterName = w.getCurrentDialog().getActor(); characterTurn = true; previousAnim = null; // If the player or the character is talking restore to 'stand' pose restoreStandPose(w.getCurrentScene().getPlayer()); if (w.getCurrentScene().getActor(characterName, false) instanceof SpriteActor) restoreStandPose((CharacterActor) w.getCurrentScene().getActor(characterName, false)); if (playerText != null) { CharacterActor player = World.getInstance().getCurrentScene().getPlayer(); // WorldCamera c = World.getInstance().getCamera(); // Vector3 p = c.scene2screen(pos.x, pos.y + player.getHeight()); World.getInstance() .getTextManager() .addSubtitle( playerText, player.getX(), player.getY() + player.getHeight(), false, Text.Type.TALK, Color.BLACK, this); startTalkAnim(player); } else { resume(); } return getWait(); }
/** * 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 scene verbs Scene s = World.getInstance().getCurrentScene(); id = find(cb, s); if (id != null) return id; 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"); stringBuilder.append(SEPARATION_SYMBOL).append(id); return stringBuilder.toString(); } } return null; }
@Override public ArrayList<Action> getActions() { Verb v = getVerb(verb, target, state); if (v == null) { EngineLogger.error( MessageFormat.format( "Verb ''{0}'' not found for actor ''{1}({3})'' and target ''{2}''", verb, actorId, target, World.getInstance().getCurrentScene().getActor(actorId, true).getState())); return new ArrayList<Action>(0); } return v.getActions(); }
@Override public boolean run(ActionCallback cb) { if (text != null) { float x = TextManager.POS_CENTER, y = TextManager.POS_CENTER; if (pos != null) { x = pos.x; y = pos.y; } else { if (type == Text.Type.RECTANGLE) { x = y = TextManager.POS_SUBTITLE; } } World.getInstance() .getTextManager() .addText(text, x, y, queue, type, color, style, wait ? cb : null); } return wait; }
@Override public boolean run(VerbRunner cb) { World.getInstance().setCutMode(value); return false; }