Search in sources :

Example 1 with QuestLine

use of com.lilithsthrone.game.character.quests.QuestLine in project liliths-throne-public by Innoxia.

the class PlayerCharacter method loadFromXML.

public static PlayerCharacter loadFromXML(StringBuilder log, Element parentElement, Document doc, CharacterImportSetting... settings) {
    PlayerCharacter character = new PlayerCharacter(new NameTriplet(""), "", 0, Gender.F_V_B_FEMALE, RacialBody.HUMAN, RaceStage.HUMAN, new CharacterInventory(0), WorldType.DOMINION, PlaceType.DOMINION_AUNTS_HOME);
    GameCharacter.loadGameCharacterVariablesFromXML(character, log, parentElement, doc, settings);
    NodeList nodes = parentElement.getElementsByTagName("core");
    Element element = (Element) nodes.item(0);
    String version = "";
    if (element.getElementsByTagName("version").item(0) != null) {
        version = ((Element) element.getElementsByTagName("version").item(0)).getAttribute("value");
    }
    Element playerSpecificElement = (Element) parentElement.getElementsByTagName("playerSpecific").item(0);
    if (playerSpecificElement != null) {
        if (playerSpecificElement.getElementsByTagName("title").getLength() != 0) {
            character.setTitle(((Element) playerSpecificElement.getElementsByTagName("title").item(0)).getAttribute("value"));
        }
        if (playerSpecificElement.getElementsByTagName("karma").getLength() != 0) {
            character.setKarma(Integer.valueOf(((Element) playerSpecificElement.getElementsByTagName("karma").item(0)).getAttribute("value")));
        }
        if (playerSpecificElement.getElementsByTagName("mainQuestUpdated").getLength() != 0) {
            character.setMainQuestUpdated(Boolean.valueOf(((Element) playerSpecificElement.getElementsByTagName("mainQuestUpdated").item(0)).getAttribute("value")));
        }
        if (playerSpecificElement.getElementsByTagName("sideQuestUpdated").getLength() != 0) {
            character.setSideQuestUpdated(Boolean.valueOf(((Element) playerSpecificElement.getElementsByTagName("sideQuestUpdated").item(0)).getAttribute("value")));
        }
        if (playerSpecificElement.getElementsByTagName("romanceQuestUpdated").getLength() != 0) {
            character.setRomanceQuestUpdated(Boolean.valueOf(((Element) playerSpecificElement.getElementsByTagName("romanceQuestUpdated").item(0)).getAttribute("value")));
        }
        try {
            if (playerSpecificElement.getElementsByTagName("racesDiscovered").item(0) != null) {
                for (int i = 0; i < ((Element) playerSpecificElement.getElementsByTagName("racesDiscovered").item(0)).getElementsByTagName("race").getLength(); i++) {
                    Element e = (Element) ((Element) playerSpecificElement.getElementsByTagName("racesDiscovered").item(0)).getElementsByTagName("race").item(i);
                    character.addRaceDiscoveredFromBook(Race.valueOf(e.getAttribute("value")));
                }
            }
        } catch (Exception ex) {
        }
        if (playerSpecificElement.getElementsByTagName("charactersEncountered").item(0) != null) {
            for (int i = 0; i < ((Element) playerSpecificElement.getElementsByTagName("charactersEncountered").item(0)).getElementsByTagName("id").getLength(); i++) {
                Element e = (Element) ((Element) playerSpecificElement.getElementsByTagName("charactersEncountered").item(0)).getElementsByTagName("id").item(i);
                character.addCharacterEncountered(e.getAttribute("value"));
            }
        }
        if (Main.isVersionOlderThan(version, "0.1.99.5")) {
            if (playerSpecificElement.getElementsByTagName("questMap").item(0) != null) {
                for (int i = 0; i < ((Element) playerSpecificElement.getElementsByTagName("questMap").item(0)).getElementsByTagName("entry").getLength(); i++) {
                    Element e = (Element) ((Element) playerSpecificElement.getElementsByTagName("questMap").item(0)).getElementsByTagName("entry").item(i);
                    try {
                        int progress = Integer.valueOf(e.getAttribute("progress"));
                        QuestLine questLine = QuestLine.valueOf(e.getAttribute("questLine"));
                        TreeNode<Quest> q = questLine.getQuestTree();
                        for (int it = 0; it < progress; it++) {
                            if (!q.getChildren().isEmpty()) {
                                q = q.getChildren().get(0);
                            }
                        }
                        // // Add one if quest is complete: (This is due to adding a 'complete quest' at the end of each quest line.)
                        // if(questLine!=QuestLine.MAIN && !q.getChildren().isEmpty() && q.getChildren().get(0).getChildren().isEmpty()) {
                        // q = q.getChildren().get(0);
                        // }
                        character.quests.put(questLine, q.getData());
                    } catch (Exception ex) {
                        System.err.println("ERR Quest!");
                    }
                }
            }
        } else {
            if (playerSpecificElement.getElementsByTagName("questMap").item(0) != null) {
                for (int i = 0; i < ((Element) playerSpecificElement.getElementsByTagName("questMap").item(0)).getElementsByTagName("entry").getLength(); i++) {
                    Element e = (Element) ((Element) playerSpecificElement.getElementsByTagName("questMap").item(0)).getElementsByTagName("entry").item(i);
                    try {
                        character.quests.put(QuestLine.valueOf(e.getAttribute("questLine")), Quest.valueOf(e.getAttribute("quest")));
                    } catch (Exception ex) {
                    }
                }
            }
        }
    }
    return character;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) CharacterInventory(com.lilithsthrone.game.inventory.CharacterInventory) QuestLine(com.lilithsthrone.game.character.quests.QuestLine) Quest(com.lilithsthrone.game.character.quests.Quest)

Example 2 with QuestLine

use of com.lilithsthrone.game.character.quests.QuestLine in project liliths-throne-public by Innoxia.

the class PlayerCharacter method saveAsXML.

@Override
public Element saveAsXML(Element parentElement, Document doc) {
    Element properties = super.saveAsXML(parentElement, doc);
    Element playerSpecific = doc.createElement("playerSpecific");
    properties.appendChild(playerSpecific);
    CharacterUtils.createXMLElementWithValue(doc, playerSpecific, "title", this.getTitle());
    CharacterUtils.createXMLElementWithValue(doc, playerSpecific, "karma", String.valueOf(this.getKarma()));
    Element questUpdatesElement = doc.createElement("questUpdates");
    playerSpecific.appendChild(questUpdatesElement);
    CharacterUtils.createXMLElementWithValue(doc, playerSpecific, "mainQuestUpdated", String.valueOf(this.mainQuestUpdated));
    CharacterUtils.createXMLElementWithValue(doc, playerSpecific, "sideQuestUpdated", String.valueOf(this.sideQuestUpdated));
    CharacterUtils.createXMLElementWithValue(doc, playerSpecific, "romanceQuestUpdated", String.valueOf(this.romanceQuestUpdated));
    Element innerElement = doc.createElement("racesDiscovered");
    playerSpecific.appendChild(innerElement);
    for (Race race : racesDiscoveredFromBook) {
        if (race != null) {
            CharacterUtils.createXMLElementWithValue(doc, innerElement, "race", race.toString());
        }
    }
    Element charactersEncounteredElement = doc.createElement("charactersEncountered");
    playerSpecific.appendChild(charactersEncounteredElement);
    for (String id : charactersEncountered) {
        CharacterUtils.createXMLElementWithValue(doc, charactersEncounteredElement, "id", id);
    }
    innerElement = doc.createElement("questMap");
    playerSpecific.appendChild(innerElement);
    for (Entry<QuestLine, Quest> entry : quests.entrySet()) {
        Element e = doc.createElement("entry");
        innerElement.appendChild(e);
        CharacterUtils.addAttribute(doc, e, "questLine", entry.getKey().toString());
        CharacterUtils.addAttribute(doc, e, "quest", String.valueOf(entry.getValue()));
    }
    return properties;
}
Also used : Element(org.w3c.dom.Element) Race(com.lilithsthrone.game.character.race.Race) QuestLine(com.lilithsthrone.game.character.quests.QuestLine) Quest(com.lilithsthrone.game.character.quests.Quest)

Aggregations

Quest (com.lilithsthrone.game.character.quests.Quest)2 QuestLine (com.lilithsthrone.game.character.quests.QuestLine)2 Element (org.w3c.dom.Element)2 Race (com.lilithsthrone.game.character.race.Race)1 CharacterInventory (com.lilithsthrone.game.inventory.CharacterInventory)1 NodeList (org.w3c.dom.NodeList)1