Search in sources :

Example 1 with LordBritishConversation

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

the class Utils method getPeople.

/**
 * Read the ULT file and parse the people
 *
 * @param fname
 * @return
 */
public static List<Person> getPeople(String fname, Maps map, TileSet ts) {
    byte[] bytes;
    try {
        InputStream is = new FileInputStream("assets/data/" + fname);
        bytes = IOUtils.toByteArray(is);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    Person[] people = new Person[32];
    int MAX_PEOPLE = 32;
    int MAP_WIDTH = 32;
    int startOffset = MAP_WIDTH * MAP_WIDTH;
    int end = startOffset + MAX_PEOPLE;
    int count = 0;
    for (int i = startOffset; i < end; i++) {
        int index = bytes[i] & 0xff;
        if (index == 0) {
            count++;
            continue;
        }
        Person p = new Person();
        p.setId(count);
        p.setTileIndex(index);
        if (ts != null) {
            Tile t = ts.getTileByIndex(index);
            if (t == null) {
                System.err.printf("tile index %s could not be found.\n", index);
            }
            p.setTile(t);
        }
        people[count] = p;
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 1;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int start_x = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setStart_x(start_x);
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 2;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int start_y = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setStart_y(start_y);
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 6;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int m = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        if (m == 0) {
            p.setMovement(ObjectMovementBehavior.FIXED);
        } else if (m == 1) {
            p.setMovement(ObjectMovementBehavior.WANDER);
        } else if (m == 0x80) {
            p.setMovement(ObjectMovementBehavior.FOLLOW_AVATAR);
        } else if (m == 0xFF) {
            p.setMovement(ObjectMovementBehavior.ATTACK_AVATAR);
        }
        count++;
    }
    startOffset = MAP_WIDTH * MAP_WIDTH + MAX_PEOPLE * 7;
    end = startOffset + MAX_PEOPLE;
    count = 0;
    for (int i = startOffset; i < end; i++) {
        int id = bytes[i] & 0xff;
        Person p = people[count];
        if (p == null) {
            count++;
            continue;
        }
        p.setDialogId(id);
        count++;
    }
    List<Person> peeps = new ArrayList<>();
    for (int i = 0; i < people.length; i++) {
        if (people[i] != null) {
            peeps.add(people[i]);
            if (map == Maps.CASTLE_OF_LORD_BRITISH_2 && people[i].getId() == 31) {
                people[i].setConversation(new LordBritishConversation());
            }
            if (map == Maps.CASTLE_OF_LORD_BRITISH_1 && people[i].getId() == 29) {
                people[i].setConversation(new HawkwindConversation());
            }
            if (map == Maps.SKARABRAE && people[i].getId() == 10) {
                // isaac
                people[i].setRemovedFromMap(true);
            }
        }
    }
    return peeps;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LordBritishConversation(objects.LordBritishConversation) ArrayList(java.util.ArrayList) DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) HawkwindConversation(objects.HawkwindConversation) Person(objects.Person) FileInputStream(java.io.FileInputStream)

Example 2 with LordBritishConversation

use of objects.LordBritishConversation 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

HawkwindConversation (objects.HawkwindConversation)2 LordBritishConversation (objects.LordBritishConversation)2 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 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)1 FocusListener (com.badlogic.gdx.scenes.scene2d.utils.FocusListener)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Conversation (objects.Conversation)1 Topic (objects.Conversation.Topic)1 CustomInputConversation (objects.CustomInputConversation)1 Party (objects.Party)1 PartyMember (objects.Party.PartyMember)1 Person (objects.Person)1 Tile (objects.Tile)1