Search in sources :

Example 1 with Conversation

use of objects.Conversation in project ultimate-java by pantinor.

the class TestJaxb method parseTlkFiles.

// @Test
public void parseTlkFiles() throws Exception {
    TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
    baseTileSet.setMaps();
    MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
    for (BaseMap map : maps.getMaps()) {
        if (map.getCity() == null || map.getCity().getTlk_fname() == null) {
            continue;
        }
        List<Person> people;
        try {
            people = Utils.getPeople(map.getFname(), Maps.get(map.getId()), null);
        } catch (Exception e) {
            continue;
        }
        List<Conversation> cons = Utils.getDialogs(map.getCity().getTlk_fname());
        if (people == null) {
            continue;
        }
        for (Person p : people) {
            if (p != null) {
                for (Conversation c : cons) {
                    if (c.getIndex() == p.getDialogId()) {
                        p.setConversation(c);
                    }
                }
            }
        }
        for (Person p : people) {
        // System.out.println(p);
        }
        for (Conversation c : cons) {
            System.out.println(c.toXMLString(Maps.get(map.getId())));
        }
        for (Conversation c : cons) {
            Person per = null;
            for (Person p : people) {
                if (c.getIndex() == p.getDialogId()) {
                    per = p;
                }
            }
            if (per == null) {
            // System.out.println("Extra Dialog: " + c);
            }
        }
    }
// System.out.printf("Latitude [%s' %s]", (char) ((int) 54 / 16 + 'A'), (char) ((int) 54 % 16 + 'A'));
// System.out.printf(" Longitude [%s' %s]\n", (char) ((int) 182 / 16 + 'A'), (char) ((int) 182 % 16 + 'A'));
}
Also used : MapSet(objects.MapSet) Conversation(objects.Conversation) TileSet(objects.TileSet) Person(objects.Person) BaseMap(objects.BaseMap)

Example 2 with Conversation

use of objects.Conversation in project ultimate-java by pantinor.

the class Utils method getDialogs.

/**
 * Read the TLK file and parse the conversations
 *
 * @param fname
 * @return
 */
public static List<Conversation> getDialogs(String fname) {
    byte[] bytes;
    try {
        InputStream is = new FileInputStream("assets/data/" + fname);
        bytes = IOUtils.toByteArray(is);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    List<Conversation> dialogs = new ArrayList<>();
    int block = 288;
    for (int i = 0; i < 16; i++) {
        int pos = i * block;
        int questionFlag = 0;
        int respAffectsHumility = 0;
        int probTurnAway = 0;
        CharBuffer bb = BufferUtils.createCharBuffer(block);
        String[] strings = new String[12];
        int stringIndex = 0;
        for (int y = 0; y < block; y++) {
            if (y == 0) {
                questionFlag = bytes[pos];
            } else if (y == 1) {
                respAffectsHumility = bytes[pos];
            } else if (y == 2) {
                probTurnAway = bytes[pos];
            } else if (y > 2) {
                if (bytes[pos] == 0x0 && stringIndex < 12) {
                    bb.flip();
                    strings[stringIndex] = bb.toString().replace("\n", " ");
                    stringIndex++;
                    bb.clear();
                } else {
                    bb.put((char) bytes[pos]);
                }
            }
            pos++;
        }
        Conversation c = new Conversation(i + 1, probTurnAway, questionFlag, respAffectsHumility, strings);
        dialogs.add(c);
    }
    return dialogs;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CharBuffer(java.nio.CharBuffer) Conversation(objects.Conversation) HawkwindConversation(objects.HawkwindConversation) LordBritishConversation(objects.LordBritishConversation) FileInputStream(java.io.FileInputStream)

Example 3 with Conversation

use of objects.Conversation in project ultimate-java by pantinor.

the class Utils method setTMXMap.

public static void setTMXMap(BaseMap map, Maps id, String tmxFile, TileSet ts) {
    List<Person> people = new ArrayList<>();
    Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
    TmxMapLoader loader = new TmxMapLoader();
    TiledMap tm = loader.load("assets/tilemaps/" + tmxFile);
    TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map");
    if (ml != null) {
        FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
        TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(f, f.parent(), false);
        int png_grid_width = 24;
        Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = x + (y * png_grid_width) + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        for (int y = 0; y < map.getHeight(); y++) {
            for (int x = 0; x < map.getWidth(); x++) {
                StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile();
                Tile tile = mapTileIds[tr.getId()];
                if (tile == null) {
                    tile = ts.getTileByIndex(127);
                }
                tiles[x + (y * map.getWidth())] = tile;
            }
        }
    }
    MapLayer objectsLayer = tm.getLayers().get(map.getId() + "-people");
    if (objectsLayer != null) {
        Iterator<MapObject> iter = objectsLayer.getObjects().iterator();
        while (iter.hasNext()) {
            MapObject obj = iter.next();
            Person p = new Person();
            Conversation conv = new Conversation();
            conv.setName(obj.getName());
            conv.setMap(id);
            p.setConversation(conv);
            people.add(p);
            Iterator<String> keys = obj.getProperties().getKeys();
            while (keys.hasNext()) {
                String key = keys.next();
                String value = obj.getProperties().get(key).toString();
                if (key.equals("tileType")) {
                    Tile tile = ts.getTileByName(value);
                    p.setTileIndex(tile.getIndex());
                    p.setTile(tile);
                } else if (key.equals("startX")) {
                    p.setStart_x(new Float(value).intValue());
                } else if (key.equals("startY")) {
                    p.setStart_y(new Float(value).intValue());
                } else if (key.equals("role")) {
                    PersonRole role = new PersonRole();
                    role.setInventoryType(InventoryType.valueOf(value));
                    p.setRole(role);
                } else if (key.equals("movement")) {
                    p.setMovement(ObjectMovementBehavior.valueOf(value));
                } else if (key.startsWith("description")) {
                    conv.setDescription(value);
                    conv.getTopics().add(conv.new Topic(standardQuery[2], value, null, null, null));
                } else if (key.startsWith("topic")) {
                    String[] splits = value.split(",");
                    if (splits.length == 5) {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], splits[2], splits[3], splits[4]));
                    } else {
                        conv.getTopics().add(conv.new Topic(splits[0], splits[1], null, null, null));
                    }
                }
            }
        }
    }
    map.getCity().setPeople(people);
    map.setTiles(tiles);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MapLayer(com.badlogic.gdx.maps.MapLayer) ArrayList(java.util.ArrayList) Conversation(objects.Conversation) HawkwindConversation(objects.HawkwindConversation) LordBritishConversation(objects.LordBritishConversation) PersonRole(objects.PersonRole) TiledMapTileLayer(com.badlogic.gdx.maps.tiled.TiledMapTileLayer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) MapObject(com.badlogic.gdx.maps.MapObject) TmxMapLoader(com.badlogic.gdx.maps.tiled.TmxMapLoader) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMap(com.badlogic.gdx.maps.tiled.TiledMap) Person(objects.Person)

Example 4 with Conversation

use of objects.Conversation in project ultimate-java by pantinor.

the class ConversationDialog method initialize.

private void initialize() {
    screen.gameTimer.active = false;
    setModal(true);
    defaults().space(10);
    add(internalTable = new Table(Ultima4.skin)).expand().fill();
    row();
    internalTable.defaults().pad(1);
    scrollPane = new LogScrollPane(Ultima4.skin, width);
    scrollPane.setHeight(height);
    input = new TextField("", Ultima4.skin);
    input.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField tf, char key) {
            if (key == '\r') {
                if (tf.getText().length() == 0) {
                    if (!cancelHide) {
                        hide();
                    }
                    cancelHide = false;
                }
                Conversation conversation = person.getConversation();
                if (conversation != null) {
                    if (conversation instanceof CustomInputConversation) {
                        ((CustomInputConversation) conversation).setParty(screen.context.getParty());
                    }
                    String query = tf.getText();
                    Topic t = conversation.matchTopic(query);
                    if (t != null) {
                        if (t.getQuery() != null && t.getQuery().equals("join")) {
                            String name = conversation.getName();
                            Virtue virtue = screen.context.getParty().getVirtueForJoinable(name);
                            if (virtue != null) {
                                CannotJoinError join = screen.context.getParty().join(name);
                                if (join == CannotJoinError.JOIN_SUCCEEDED) {
                                    scrollPane.add("I am honored to join thee!");
                                    screen.context.getCurrentMap().removeJoinedPartyMemberFromPeopleList(screen.context.getParty());
                                } else {
                                    scrollPane.add("Thou art not " + (join == CannotJoinError.JOIN_NOT_VIRTUOUS ? virtue.getDescription() : "experienced") + " enough for me to join thee.");
                                }
                            } else {
                                scrollPane.add("I cannot join thee.");
                            }
                        } else {
                            if (!conversation.isStandardQuery(query)) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), t.getPhrase());
                            }
                            scrollPane.add(t.getPhrase());
                            if (t.getQuestion() != null) {
                                scrollPane.add(t.getQuestion());
                            }
                        }
                        previousTopic = t;
                    } else {
                        if (previousTopic != null && previousTopic.getQuestion() != null) {
                            if (query.toLowerCase().contains("y")) {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getYesResponse());
                                scrollPane.add(previousTopic.getYesResponse());
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.BRAGGED);
                                }
                            } else {
                                screen.context.addEntry(conversation.getName(), conversation.getMap(), previousTopic.getNoResponse());
                                scrollPane.add(previousTopic.getNoResponse());
                                if (previousTopic.isLbHeal()) {
                                    for (PartyMember pm : screen.context.getParty().getMembers()) {
                                        pm.heal(HealType.CURE);
                                        pm.heal(HealType.FULLHEAL);
                                    }
                                    Sounds.play(Sound.HEALING);
                                }
                                if (conversation.getRespAffectsHumility() > 0) {
                                    screen.context.getParty().adjustKarma(KarmaAction.HUMBLE);
                                }
                            }
                        } else {
                            scrollPane.add("That I cannot help thee with.");
                        }
                        previousTopic = null;
                    }
                } else if (person.getRole() != null && vendor != null) {
                    String input = tf.getText();
                    vendor.setResponse(input);
                    vendor.nextDialog();
                }
                tf.setText("");
            }
        }
    });
    defaults().pad(5);
    internalTable.add(scrollPane).maxWidth(width).width(width);
    internalTable.row();
    internalTable.add(input).maxWidth(width).width(width);
    focusListener = new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        @Override
        public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
            if (!focused) {
                focusChanged(event);
            }
        }

        private void focusChanged(FocusEvent event) {
            Stage stage = getStage();
            if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == ConversationDialog.this) {
                Actor newFocusedActor = event.getRelatedActor();
                if (newFocusedActor != null && !newFocusedActor.isDescendantOf(ConversationDialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) {
                    event.cancel();
                }
            }
        }
    };
    person.setTalking(true);
    if (person.getConversation() != null) {
        if (person.getRole() != null && person.getRole().getRole().equals("lordbritish")) {
            LordBritishConversation conv = (LordBritishConversation) person.getConversation();
            scrollPane.add(conv.intro(screen.context));
            SequenceAction seq = Actions.action(SequenceAction.class);
            Party party = screen.context.getParty();
            if (party.getMember(0).getPlayer().status == StatusType.DEAD) {
                party.getMember(0).heal(HealType.RESURRECT);
                party.getMember(0).heal(HealType.FULLHEAL);
                seq.addAction(Actions.run(new LBAction(Sound.HEALING, "I resurrect thee.")));
                seq.addAction(Actions.delay(3f));
            }
            for (int i = 0; i < party.getMembers().size(); i++) {
                PartyMember pm = party.getMember(i);
                if (pm.getPlayer().advanceLevel()) {
                    seq.addAction(Actions.run(new LBAction(Sound.MAGIC, pm.getPlayer().name + " thou art now level " + pm.getPlayer().getLevel())));
                    seq.addAction(Actions.delay(3f));
                }
            }
            stage.addAction(seq);
        } else if (person.getRole() != null && person.getRole().getRole().equals("hawkwind")) {
            HawkwindConversation conv = (HawkwindConversation) person.getConversation();
            conv.setParty(screen.context.getParty());
            scrollPane.add(conv.intro());
        } else {
            scrollPane.add("You meet " + person.getConversation().getDescription().toLowerCase() + ".");
        }
    } else if (person.getRole() != null && person.getRole().getInventoryType() != null) {
        vendor = Ultima4.vendorClassSet.getVendorImpl(person.getRole().getInventoryType(), Maps.get(screen.context.getCurrentMap().getId()), screen.context);
        vendor.setScreen(screen);
        vendor.setScrollPane(scrollPane);
        vendor.nextDialog();
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) PartyMember(objects.Party.PartyMember) LordBritishConversation(objects.LordBritishConversation) LogScrollPane(util.LogScrollPane) Conversation(objects.Conversation) CustomInputConversation(objects.CustomInputConversation) LordBritishConversation(objects.LordBritishConversation) HawkwindConversation(objects.HawkwindConversation) HawkwindConversation(objects.HawkwindConversation) Party(objects.Party) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) Topic(objects.Conversation.Topic) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction) CustomInputConversation(objects.CustomInputConversation)

Aggregations

Conversation (objects.Conversation)4 HawkwindConversation (objects.HawkwindConversation)3 LordBritishConversation (objects.LordBritishConversation)3 ArrayList (java.util.ArrayList)2 Person (objects.Person)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 MapLayer (com.badlogic.gdx.maps.MapLayer)1 MapObject (com.badlogic.gdx.maps.MapObject)1 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)1 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)1 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)1 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1