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'));
}
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;
}
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);
}
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();
}
}
Aggregations