use of com.lilithsthrone.game.character.CharacterImportSetting 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);
}
Aggregations