use of com.lilithsthrone.game.dialogue.eventLog.EventLogEntry in project liliths-throne-public by Innoxia.
the class Game method importGame.
public static void importGame(String name) {
Game newGame = new Game();
Main.game = newGame;
File file = new File("data/saves/" + name + ".xml");
if (file.exists()) {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(file);
// Cast magic:
doc.getDocumentElement().normalize();
Element gameElement = (Element) doc.getElementsByTagName("game").item(0);
Element informationNode = (Element) gameElement.getElementsByTagName("coreInfo").item(0);
String version = informationNode.getAttribute("version");
newGame.minutesPassed = Long.valueOf(informationNode.getAttribute("minutesPassed"));
newGame.debugMode = Boolean.valueOf(informationNode.getAttribute("debugMode"));
newGame.imperialMeasurements = Boolean.valueOf(informationNode.getAttribute("imperialMeasurements"));
newGame.currentWeather = Weather.valueOf(informationNode.getAttribute("weather"));
newGame.nextStormTime = Long.valueOf(informationNode.getAttribute("nextStormTime"));
newGame.weatherTimeRemaining = Integer.valueOf(informationNode.getAttribute("weatherTimeRemaining"));
Element dateNode = (Element) gameElement.getElementsByTagName("date").item(0);
newGame.startingDate = LocalDateTime.of(Integer.valueOf(dateNode.getAttribute("year")), Integer.valueOf(dateNode.getAttribute("month")), Integer.valueOf(dateNode.getAttribute("dayOfMonth")), Integer.valueOf(dateNode.getAttribute("hour")), Integer.valueOf(dateNode.getAttribute("minute")));
newGame.dialogueFlags = DialogueFlags.loadFromXML((Element) gameElement.getElementsByTagName("dialogueFlags").item(0), doc);
for (int i = 0; i < ((Element) gameElement.getElementsByTagName("eventLog").item(0)).getElementsByTagName("eventLogEntry").getLength(); i++) {
Element e = (Element) ((Element) gameElement.getElementsByTagName("eventLog").item(0)).getElementsByTagName("eventLogEntry").item(i);
newGame.eventLog.add(EventLogEntry.loadFromXML(e, doc));
}
newGame.eventLog.sort(Comparator.comparingLong(EventLogEntry::getTime));
NodeList nodes = gameElement.getElementsByTagName("slaveryEventLog");
Element extraEffectNode = (Element) nodes.item(0);
if (extraEffectNode != null) {
for (int i = 0; i < extraEffectNode.getElementsByTagName("day").getLength(); i++) {
Element e = (Element) gameElement.getElementsByTagName("day").item(i);
int day = Integer.valueOf(e.getAttribute("value"));
newGame.slaveryEventLog.put(day, new ArrayList<>());
for (int j = 0; j < e.getElementsByTagName("eventLogEntry").getLength(); j++) {
Element entry = (Element) e.getElementsByTagName("eventLogEntry").item(j);
newGame.slaveryEventLog.get(day).add(SlaveryEventLogEntry.loadFromXML(entry, doc));
}
}
}
// Maps:
for (int i = 0; i < ((Element) gameElement.getElementsByTagName("maps").item(0)).getElementsByTagName("world").getLength(); i++) {
Element e = (Element) ((Element) gameElement.getElementsByTagName("maps").item(0)).getElementsByTagName("world").item(i);
if ((!e.getAttribute("worldType").equals("SEWERS") || !Main.isVersionOlderThan(version, "0.2.0.5")) && (!e.getAttribute("worldType").equals("SUBMISSION") || !Main.isVersionOlderThan(version, "0.2.1.5")) && (!e.getAttribute("worldType").equals("DOMINION") || !Main.isVersionOlderThan(version, "0.2.1.5")) && (!e.getAttribute("worldType").equals("HARPY_NEST") || !Main.isVersionOlderThan(version, "0.2.1.5"))) {
World world = World.loadFromXML(e, doc);
newGame.worlds.put(world.getWorldType(), world);
}
}
// Add missing world types:
for (WorldType wt : WorldType.values()) {
Generation gen = new Generation();
if (Main.isVersionOlderThan(version, "0.1.99.5")) {
gen.worldGeneration(WorldType.SHOPPING_ARCADE);
}
if (Main.isVersionOlderThan(version, "0.2.1.5")) {
gen.worldGeneration(WorldType.SUBMISSION);
gen.worldGeneration(WorldType.DOMINION);
gen.worldGeneration(WorldType.HARPY_NEST);
}
if (newGame.worlds.get(wt) == null) {
gen.worldGeneration(wt);
}
}
newGame.player = PlayerCharacter.loadFromXML(null, (Element) ((Element) gameElement.getElementsByTagName("playerCharacter").item(0)), doc);
List<String> addedIds = new ArrayList<>();
List<NPC> slaveImports = new ArrayList<>();
// Load NPCs:
for (int i = 0; i < gameElement.getElementsByTagName("NPC").getLength(); i++) {
Element e = (Element) gameElement.getElementsByTagName("NPC").item(i);
if (!addedIds.contains(((Element) e.getElementsByTagName("id").item(0)).getAttribute("value"))) {
@SuppressWarnings("unchecked") Class<? extends NPC> npcClass = (Class<? extends NPC>) Class.forName(((Element) e.getElementsByTagName("pathName").item(0)).getAttribute("value"));
Method m = npcClass.getMethod("loadFromXML", Element.class, Document.class, CharacterImportSetting[].class);
NPC npc = npcClass.getDeclaredConstructor(boolean.class).newInstance(true);
m.invoke(npc, e, doc, new CharacterImportSetting[] {});
newGame.addNPC(npc, true);
addedIds.add(npc.getId());
// To fix issues with older versions hair length:
if (Main.isVersionOlderThan(version, "0.1.90.5")) {
npc.getBody().getHair().setLength(null, npc.isFeminine() ? RacialBody.valueOfRace(npc.getRace()).getFemaleHairLength() : RacialBody.valueOfRace(npc.getRace()).getMaleHairLength());
}
// Generate desires in non-unique NPCs:
if (Main.isVersionOlderThan(version, "0.1.98.5") && !npc.isUnique() && npc.getFetishDesireMap().isEmpty()) {
CharacterUtils.generateDesires(npc);
}
if (Main.isVersionOlderThan(version, "0.2.0") && npc.getFetishDesireMap().size() > 10) {
npc.clearFetishDesires();
CharacterUtils.generateDesires(npc);
}
if (npc instanceof SlaveImport) {
slaveImports.add(npc);
}
} else {
System.err.println("duplicate character attempted to be imported");
}
}
// Add in new NPCS:
if (!newGame.NPCMap.containsKey(newGame.getUniqueNPCId(Zaranix.class))) {
Zaranix zaranix = new Zaranix();
newGame.addNPC(zaranix, false);
ZaranixMaidKatherine katherine = new ZaranixMaidKatherine();
newGame.addNPC(katherine, false);
ZaranixMaidKelly kelly = new ZaranixMaidKelly();
newGame.addNPC(kelly, false);
Amber amber = new Amber();
newGame.addNPC(amber, false);
zaranix.setAffection(katherine, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
zaranix.setAffection(kelly, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
zaranix.setAffection(amber, AffectionLevel.POSITIVE_FOUR_LOVE.getMedianValue());
amber.setAffection(zaranix, AffectionLevel.POSITIVE_FOUR_LOVE.getMedianValue());
amber.setAffection(kelly, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
amber.setAffection(katherine, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
kelly.setAffection(zaranix, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
kelly.setAffection(katherine, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
kelly.setAffection(amber, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
katherine.setAffection(zaranix, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
katherine.setAffection(kelly, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
katherine.setAffection(amber, AffectionLevel.POSITIVE_THREE_CARING.getMedianValue());
newGame.addNPC(new Arthur(), false);
}
if (!newGame.NPCMap.containsKey(newGame.getUniqueNPCId(Ashley.class))) {
newGame.addNPC(new Ashley(), false);
}
if (!newGame.NPCMap.containsKey(newGame.getUniqueNPCId(SupplierLeader.class))) {
newGame.addNPC(new SupplierLeader(), false);
}
if (!newGame.NPCMap.containsKey(newGame.getUniqueNPCId(SupplierPartner.class))) {
newGame.addNPC(new SupplierPartner(), false);
}
// To prevent errors from previous versions, reset Zaranix progress if prior to 0.1.95:
if (Main.isVersionOlderThan(version, "0.1.90.5")) {
if (Main.game.getPlayer().getWorldLocation() == WorldType.ZARANIX_HOUSE_GROUND_FLOOR || Main.game.getPlayer().getWorldLocation() == WorldType.ZARANIX_HOUSE_FIRST_FLOOR) {
Main.game.getPlayer().setLocation(WorldType.DOMINION, PlaceType.DOMINION_DEMON_HOME, false);
ZaranixHomeGroundFloor.resetHouseAfterLeaving();
Main.game.getDialogueFlags().setFlag(DialogueFlagValue.zaranixDiscoveredHome, false);
Main.game.getDialogueFlags().setFlag(DialogueFlagValue.zaranixKickedDownDoor, false);
Main.game.getDialogueFlags().setFlag(DialogueFlagValue.zaranixKnockedOnDoor, false);
Main.game.getDialogueFlags().setFlag(DialogueFlagValue.zaranixMaidsHostile, false);
Main.game.getArthur().setLocation(WorldType.ZARANIX_HOUSE_FIRST_FLOOR, PlaceType.ZARANIX_FF_OFFICE, true);
if (Main.game.getPlayer().isQuestProgressGreaterThan(QuestLine.MAIN, Quest.MAIN_1_H_THE_GREAT_ESCAPE)) {
Main.game.getPlayer().setQuestProgress(QuestLine.MAIN, Quest.MAIN_1_H_THE_GREAT_ESCAPE);
}
}
}
if (Main.isVersionOlderThan(version, "0.1.95")) {
if (Main.game.getPlayer().isQuestProgressGreaterThan(QuestLine.MAIN, Quest.MAIN_1_H_THE_GREAT_ESCAPE)) {
Main.game.getArthur().setLocation(WorldType.LILAYAS_HOUSE_GROUND_FLOOR, PlaceType.LILAYA_HOME_LAB, true);
}
}
Main.game.pendingSlaveInStocksReset = false;
} catch (Exception e) {
e.printStackTrace();
}
}
Main.game.setRenderMap(true);
Main.game.setRenderAttributesSection(true);
Main.game.started = true;
DialogueNodeOld startingDialogueNode = Main.game.getPlayerCell().getPlace().getDialogue(false);
Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "[style.colourGood(Game loaded)]", "data/saves/" + name + ".xml"), false);
Main.game.setContent(new Response(startingDialogueNode.getLabel(), startingDialogueNode.getDescription(), startingDialogueNode), false);
newGame.endTurn(0);
}
use of com.lilithsthrone.game.dialogue.eventLog.EventLogEntry in project liliths-throne-public by Innoxia.
the class GameCharacter method addItem.
/**
* Add an item to this character's inventory. If the inventory is full, the item is dropped in the character's current location.
*
* @param removingFromFloor true if this item should be removed from the floor of the area the character is currently in on a successful pick up.
* @return Description of what happened.
*/
public String addItem(AbstractItem item, boolean removingFromFloor, boolean appendTextToEventLog) {
if (removingFromFloor) {
if (inventory.addItem(item)) {
updateInventoryListeners();
Main.game.getWorlds().get(getWorldLocation()).getCell(location).getInventory().removeItem(item);
if (appendTextToEventLog) {
Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "Item Added", item.getName()), false);
}
return "<p style='text-align:center;'>" + addedItemToInventoryText(item) + "</p>";
} else {
return inventoryFullText() + droppedItemText(item);
}
} else {
if (inventory.addItem(item)) {
updateInventoryListeners();
if (appendTextToEventLog) {
Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "Item Added", item.getName()), false);
}
return "<p style='text-align:center;'>" + addedItemToInventoryText(item) + "</p>";
} else {
Main.game.getWorlds().get(getWorldLocation()).getCell(location).getInventory().addItem(item);
return inventoryFullText() + droppedItemText(item);
}
}
}
use of com.lilithsthrone.game.dialogue.eventLog.EventLogEntry in project liliths-throne-public by Innoxia.
the class Game method exportGame.
public static void exportGame(String exportFileName, boolean allowOverwrite) {
File dir = new File("data/");
dir.mkdir();
dir = new File("data/saves");
dir.mkdir();
boolean overwrite = false;
if (dir.isDirectory()) {
File[] directoryListing = dir.listFiles((path, filename) -> filename.endsWith(".xml"));
if (directoryListing != null) {
for (File child : directoryListing) {
if (child.getName().equals(exportFileName + ".xml")) {
if (!allowOverwrite) {
Main.game.flashMessage(Colour.GENERIC_BAD, "Name already exists!");
return;
} else {
overwrite = true;
}
}
}
}
}
try {
if (timeLog) {
timeStart = System.nanoTime();
System.out.println(timeStart);
}
// Starting stuff:
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
// Writing game stuff to export:
Element game = doc.createElement("game");
doc.appendChild(game);
Element informationNode = doc.createElement("coreInfo");
game.appendChild(informationNode);
CharacterUtils.addAttribute(doc, informationNode, "version", Main.VERSION_NUMBER);
CharacterUtils.addAttribute(doc, informationNode, "minutesPassed", String.valueOf(Main.game.minutesPassed));
CharacterUtils.addAttribute(doc, informationNode, "debugMode", String.valueOf(Main.game.debugMode));
CharacterUtils.addAttribute(doc, informationNode, "imperialMeasurements", String.valueOf(Main.game.imperialMeasurements));
CharacterUtils.addAttribute(doc, informationNode, "weather", Main.game.currentWeather.toString());
CharacterUtils.addAttribute(doc, informationNode, "nextStormTime", String.valueOf(Main.game.nextStormTime));
CharacterUtils.addAttribute(doc, informationNode, "weatherTimeRemaining", String.valueOf(Main.game.weatherTimeRemaining));
Element dateNode = doc.createElement("date");
informationNode.appendChild(dateNode);
CharacterUtils.addAttribute(doc, dateNode, "year", String.valueOf(Main.game.startingDate.getYear()));
CharacterUtils.addAttribute(doc, dateNode, "month", String.valueOf(Main.game.startingDate.getMonthValue()));
CharacterUtils.addAttribute(doc, dateNode, "dayOfMonth", String.valueOf(Main.game.startingDate.getDayOfMonth()));
CharacterUtils.addAttribute(doc, dateNode, "hour", String.valueOf(Main.game.startingDate.getHour()));
CharacterUtils.addAttribute(doc, dateNode, "minute", String.valueOf(Main.game.startingDate.getMinute()));
Main.game.dialogueFlags.saveAsXML(game, doc);
Element eventLogNode = doc.createElement("eventLog");
game.appendChild(eventLogNode);
for (EventLogEntry event : Main.game.getEventLog().subList(Math.max(0, Main.game.getEventLog().size() - 50), Main.game.getEventLog().size())) {
event.saveAsXML(eventLogNode, doc);
}
Element slaveryEventLogNode = doc.createElement("slaveryEventLog");
game.appendChild(slaveryEventLogNode);
for (int day : Main.game.getSlaveryEventLog().keySet()) {
Element element = doc.createElement("day");
slaveryEventLogNode.appendChild(element);
CharacterUtils.addAttribute(doc, element, "value", String.valueOf(day));
for (SlaveryEventLogEntry event : Main.game.getSlaveryEventLog().get(day)) {
event.saveAsXML(element, doc);
}
}
// Add maps:
Element mapNode = doc.createElement("maps");
game.appendChild(mapNode);
for (World world : Main.game.getWorlds().values()) {
if (world != null) {
world.saveAsXML(mapNode, doc);
}
}
// Add player:
Element characterNode = doc.createElement("playerCharacter");
game.appendChild(characterNode);
Main.game.getPlayer().saveAsXML(characterNode, doc);
// Add all NPCs:
for (GameCharacter character : Main.game.getNPCMap().values()) {
characterNode = doc.createElement("NPC");
game.appendChild(characterNode);
character.saveAsXML(characterNode, doc);
}
// Ending stuff:
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer1 = tf.newTransformer();
transformer1.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer1.transform(new DOMSource(doc), new StreamResult(writer));
// Save this xml:
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(doc);
String saveLocation = "data/saves/" + exportFileName + ".xml";
StreamResult result = new StreamResult(new File(saveLocation));
transformer.transform(source, result);
if (!exportFileName.startsWith("AutoSave")) {
if (overwrite) {
Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "[style.colourGood(Game saved)]", saveLocation), false);
Main.game.setContent(new Response("", "", Main.game.getCurrentDialogueNode()), false, Colour.GENERIC_GOOD, "Save game overwritten!");
} else {
Main.game.addEvent(new EventLogEntry(Main.game.getMinutesPassed(), "[style.colourGood(Game saved)]", saveLocation), false);
Main.game.setContent(new Response("", "", Main.game.getCurrentDialogueNode()), false, Colour.GENERIC_GOOD, "Game saved!");
}
}
if (timeLog) {
System.out.println("Difference: " + (System.nanoTime() - timeStart) / 1000000000f);
}
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
}
Aggregations