Search in sources :

Example 1 with SlaveImport

use of com.lilithsthrone.game.character.npc.SlaveImport 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);
}
Also used : TestNPC(com.lilithsthrone.game.character.npc.dominion.TestNPC) NPC(com.lilithsthrone.game.character.npc.NPC) GenericFemaleNPC(com.lilithsthrone.game.character.npc.GenericFemaleNPC) GenericAndrogynousNPC(com.lilithsthrone.game.character.npc.GenericAndrogynousNPC) GenericMaleNPC(com.lilithsthrone.game.character.npc.GenericMaleNPC) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Amber(com.lilithsthrone.game.character.npc.dominion.Amber) Arthur(com.lilithsthrone.game.character.npc.dominion.Arthur) EventLogEntry(com.lilithsthrone.game.dialogue.eventLog.EventLogEntry) SlaveryEventLogEntry(com.lilithsthrone.game.dialogue.eventLog.SlaveryEventLogEntry) Element(org.w3c.dom.Element) DialogueNodeOld(com.lilithsthrone.game.dialogue.DialogueNodeOld) ArrayList(java.util.ArrayList) SlaveImport(com.lilithsthrone.game.character.npc.SlaveImport) Document(org.w3c.dom.Document) World(com.lilithsthrone.world.World) Zaranix(com.lilithsthrone.game.character.npc.dominion.Zaranix) WorldType(com.lilithsthrone.world.WorldType) CharacterImportSetting(com.lilithsthrone.game.character.CharacterImportSetting) SupplierPartner(com.lilithsthrone.game.character.npc.dominion.SupplierPartner) NodeList(org.w3c.dom.NodeList) ZaranixMaidKelly(com.lilithsthrone.game.character.npc.dominion.ZaranixMaidKelly) Method(java.lang.reflect.Method) TransformerException(javax.xml.transform.TransformerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Response(com.lilithsthrone.game.dialogue.responses.Response) Generation(com.lilithsthrone.world.Generation) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Ashley(com.lilithsthrone.game.character.npc.dominion.Ashley) File(java.io.File) ZaranixMaidKatherine(com.lilithsthrone.game.character.npc.dominion.ZaranixMaidKatherine) SupplierLeader(com.lilithsthrone.game.character.npc.dominion.SupplierLeader)

Example 2 with SlaveImport

use of com.lilithsthrone.game.character.npc.SlaveImport in project liliths-throne-public by Innoxia.

the class Game method importCharacterAsSlave.

public static GameCharacter importCharacterAsSlave(String name) {
    File file = new File("data/characters/" + 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 characterElement = (Element) doc.getElementsByTagName("exportedCharacter").item(0);
            if (characterElement == null) {
                characterElement = (Element) doc.getElementsByTagName("playerCharacter").item(0);
            }
            // Load NPCs:
            SlaveImport importedSlave = new SlaveImport();
            importedSlave.loadFromXML(characterElement, doc);
            importedSlave.applyNewlyImportedSlaveVariables();
            Main.game.addNPC(importedSlave, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) SlaveImport(com.lilithsthrone.game.character.npc.SlaveImport) Document(org.w3c.dom.Document) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

SlaveImport (com.lilithsthrone.game.character.npc.SlaveImport)2 File (java.io.File)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 CharacterImportSetting (com.lilithsthrone.game.character.CharacterImportSetting)1 GenericAndrogynousNPC (com.lilithsthrone.game.character.npc.GenericAndrogynousNPC)1 GenericFemaleNPC (com.lilithsthrone.game.character.npc.GenericFemaleNPC)1 GenericMaleNPC (com.lilithsthrone.game.character.npc.GenericMaleNPC)1 NPC (com.lilithsthrone.game.character.npc.NPC)1 Amber (com.lilithsthrone.game.character.npc.dominion.Amber)1 Arthur (com.lilithsthrone.game.character.npc.dominion.Arthur)1 Ashley (com.lilithsthrone.game.character.npc.dominion.Ashley)1 SupplierLeader (com.lilithsthrone.game.character.npc.dominion.SupplierLeader)1 SupplierPartner (com.lilithsthrone.game.character.npc.dominion.SupplierPartner)1 TestNPC (com.lilithsthrone.game.character.npc.dominion.TestNPC)1 Zaranix (com.lilithsthrone.game.character.npc.dominion.Zaranix)1