Search in sources :

Example 1 with Character

use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.

the class UserParser method readConfig.

/**
 * Reads the user file and saves the data to variables.
 */
private void readConfig() {
    InputStream in = null;
    XMLEventReader eventReader = null;
    try {
        /* CREATE XMLInputFactory AND XMLEventReader */
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        in = new FileInputStream(FILE_PATH);
        eventReader = inputFactory.createXMLEventReader(in);
        /* READ XML FILE */
        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();
            if (event.isStartElement()) {
                /* GET AND SAVE MEMORY DIAMOND COUNT */
                if (event.asStartElement().getName().getLocalPart().equals(MEMORY_DIAMONDS)) {
                    event = eventReader.nextEvent();
                    memoryDiamonds = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE MONEY SPENT */
                if (event.asStartElement().getName().getLocalPart().equals(MONEY_SPENT)) {
                    event = eventReader.nextEvent();
                    moneySpent = Double.parseDouble(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE HACKING CRYSTAL COUNT */
                if (event.asStartElement().getName().getLocalPart().equals(HACKING_CRYSTALS)) {
                    event = eventReader.nextEvent();
                    hackingCrystals = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE COL BALANCE */
                if (event.asStartElement().getName().getLocalPart().equals(COL_BALANCE)) {
                    event = eventReader.nextEvent();
                    colBalance = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE TOTAL TICKET SCOUTS */
                if (event.asStartElement().getName().getLocalPart().equals(TOTAL_TICKET_SCOUT)) {
                    event = eventReader.nextEvent();
                    totalTicketScout = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE R2 EXCHANGE SWORDS */
                if (event.asStartElement().getName().getLocalPart().equals(R2_EXCHANGE_SWORDS)) {
                    event = eventReader.nextEvent();
                    r2ExchangeSwords = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE R3 EXCHANGE SWORDS */
                if (event.asStartElement().getName().getLocalPart().equals(R3_EXCHANGE_SWORDS)) {
                    event = eventReader.nextEvent();
                    r3ExchangeSwords = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE R4 EXCHANGE SWORDS */
                if (event.asStartElement().getName().getLocalPart().equals(R4_EXCHANGE_SWORDS)) {
                    event = eventReader.nextEvent();
                    r4ExchangeSwords = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE RAINBOW ESSENCES */
                if (event.asStartElement().getName().getLocalPart().equals(RAINBOW_ESSENCE)) {
                    event = eventReader.nextEvent();
                    rainbowEssence = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE UPGRADE CRYSTALS */
                if (event.asStartElement().getName().getLocalPart().equals(UPGRADE_CRYSTAL)) {
                    event = eventReader.nextEvent();
                    upgradeCrystal = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE MEMORY FRAGMENTS */
                if (event.asStartElement().getName().getLocalPart().equals(MEMORY_FRAGMENT)) {
                    event = eventReader.nextEvent();
                    memoryFragment = Integer.parseInt(event.asCharacters().getData());
                    continue;
                }
                /* GET AND SAVE BANNER INFO */
                if (event.asStartElement().getName().getLocalPart().equals(BANNER)) {
                    String bannerName = "";
                    int bannerData = 0;
                    Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                    while (attributes.hasNext()) {
                        Attribute attribute = attributes.next();
                        if (attribute.getName().toString().equals(B_NAME)) {
                            bannerName = attribute.getValue();
                        }
                        if (attribute.getName().toString().equals(B_DATA)) {
                            bannerData = Integer.parseInt(attribute.getValue());
                        }
                    }
                    bannerInfo.put(bannerName, bannerData);
                }
                /* GET AND SAVE CHARACTER BOX */
                if (event.asStartElement().getName().getLocalPart().equals(CHARACTER)) {
                    Character character = new Character();
                    Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                    while (attributes.hasNext()) {
                        Attribute attribute = attributes.next();
                        if (attribute.getName().toString().equals(CHARACTER_PREFIX)) {
                            character.setPrefix(attribute.getValue());
                        }
                        if (attribute.getName().toString().equals(CHARACTER_NAME)) {
                            character.setName(attribute.getValue());
                        }
                        if (attribute.getName().toString().equals(CHARACTER_RARITY)) {
                            character.setRarity(Integer.parseInt(attribute.getValue()));
                        }
                    }
                    /* GENERATE IMAGE FILE PATH */
                    character.setImagePath("images/System/Character_Placeholder.png");
                    /* ADD CHARACTER TO CHARACTER LIST */
                    characterBox.add(character);
                }
                /* GET AND SAVE WEAPON BOX */
                if (event.asStartElement().getName().getLocalPart().equals(WEAPON)) {
                    Weapon weapon = new Weapon();
                    Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                    while (attributes.hasNext()) {
                        Attribute attribute = attributes.next();
                        if (attribute.getName().toString().equals(WEAPON_NAME)) {
                            weapon.setName(attribute.getValue());
                        }
                        if (attribute.getName().toString().equals(WEAPON_RARITY)) {
                            weapon.setRarity(Integer.parseInt(attribute.getValue()));
                        }
                        if (attribute.getName().toString().equals(WEAPON_COUNT)) {
                            weapon.setCount(Integer.parseInt(attribute.getValue()));
                        }
                    }
                    /* GENERATE IMAGE FILE PATH */
                    weapon.setImagePath("images/System/Weapon_Placeholder.png");
                    /* ADD CHARACTER TO CHARACTER LIST */
                    weaponBox.add(weapon);
                }
            }
        }
        /* GO THROUGH CHARACTER BOX AND COUNT CHARACTERS */
        if (!characterBox.isEmpty()) {
            for (Character c : characterBox) {
                if (c.getRarity() == 5) {
                    pC++;
                } else if (c.getRarity() == 4) {
                    gC++;
                } else if (c.getRarity() == 3) {
                    sC++;
                } else if (c.getRarity() == 2) {
                    cC++;
                }
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (XMLStreamException e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
        /* IGNORED */
        }
        try {
            if (eventReader != null) {
                eventReader.close();
            }
        } catch (XMLStreamException e) {
        /* IGNORED */
        }
    }
}
Also used : Character(io.github.spugn.Sargo.Objects.Character) Weapon(io.github.spugn.Sargo.Objects.Weapon)

Example 2 with Character

use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.

the class Profile method purgeDeletedCharacters.

/**
 * Deletes any gold/platinum character that no longer exists in the
 * Banners.xml file that the user has in their character box.
 *
 * @param gold  List of all gold characters in the banners file
 * @param plat  List of all platinum characters in the banners file
 */
private void purgeDeletedCharacters(List<String> gold, List<String> plat) {
    boolean unsavedChanges = false;
    List<Character> newUserCharacterBox = new ArrayList<>();
    for (Character c : user.getCharacterBox()) {
        if (c.getRarity() == 4) {
            if (gold.contains(c.getPrefix() + c.getName()))
                newUserCharacterBox.add(c);
            else if (!unsavedChanges)
                unsavedChanges = true;
        } else if (c.getRarity() == 5) {
            if (plat.contains(c.getPrefix() + c.getName()))
                newUserCharacterBox.add(c);
            else if (!unsavedChanges)
                unsavedChanges = true;
        } else {
            newUserCharacterBox.add(c);
        }
    }
    if (unsavedChanges) {
        user.setCharacterBox(newUserCharacterBox);
        user.saveData();
        user = new UserParser(DISCORD_ID);
    }
}
Also used : Character(io.github.spugn.Sargo.Objects.Character) UserParser(io.github.spugn.Sargo.XMLParsers.UserParser)

Example 3 with Character

use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.

the class Profile method initBannerInfo.

/**
 * Initializes the banner file and constructs a list of all gold/platinum characters
 * in the banner file.
 *
 * This will also delete any characters that the user has that no longer exists in
 * the banners.xml file.
 */
private void initBannerInfo() {
    /* OPEN BANNERS FILE */
    // BannerParser bannersXML = new BannerParser();
    // List<Banner> banners = bannersXML.getBanners();
    List<Banner> banners = BannerParser.getBanners();
    List<String> allGoldCharacters = new ArrayList<>();
    List<String> allPlatinumCharacters = new ArrayList<>();
    for (Banner b : banners) {
        /* GET CHARACTERS */
        for (Character c : b.getCharacters()) {
            if (c.getRarity() == 4 && !(allGoldCharacters.contains(c.getPrefix() + c.getName()))) {
                goldCount++;
                allGoldCharacters.add(c.getPrefix() + c.getName());
            } else if (c.getRarity() == 5 && !(allPlatinumCharacters.contains(c.getPrefix() + c.getName()))) {
                platinumCount++;
                allPlatinumCharacters.add(c.getPrefix() + c.getName());
            }
        }
        /* CHECK IF BANNER IS NOT NORMAL */
        if (!(b.getBannerType() == 0)) {
            bannerType.put(b.getBannerName(), b.getBannerType());
        }
    }
    purgeDeletedCharacters(allGoldCharacters, allPlatinumCharacters);
}
Also used : Character(io.github.spugn.Sargo.Objects.Character)

Example 4 with Character

use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.

the class Profile method bannerSearchMenu.

/**
 * Searches for characters with the given name and displays a list
 * of all those characters that the user has.
 *
 * @param characterName  Character to be looked up.
 */
private void bannerSearchMenu(String characterName) {
    String characterList = "";
    int characterCount = 0;
    String correctName = "";
    boolean fetchCorrectName = true;
    for (Character c : user.getCharacterBox()) {
        if (c.getName().equalsIgnoreCase(characterName)) {
            characterList += c.toStringNoName() + "\n";
            characterCount++;
            if (fetchCorrectName) {
                fetchCorrectName = false;
                correctName = c.getName();
            }
        }
    }
    if (!characterList.isEmpty()) {
        builder.appendField("Character Search: " + correctName, characterList, false);
        builder.withFooterText(characterCount + " " + correctName + " found.");
    } else {
        builder.appendField("Character Search", "Could not find data for \"" + characterName + "\"", false);
    }
    CHANNEL.sendMessage(builder.build());
}
Also used : Character(io.github.spugn.Sargo.Objects.Character)

Example 5 with Character

use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.

the class BirthdayStepUp method randGoldCharacter.

@Override
protected Character randGoldCharacter() {
    int randIndex = GOLD_BANNERS.get(RNG.nextInt(GOLD_BANNERS.size()));
    Banner randBanner = BANNERS.get(randIndex - 1);
    List<Character> randCharacters = randBanner.getCharacters();
    return randCharacters.get(RNG.nextInt(randCharacters.size()));
}
Also used : Character(io.github.spugn.Sargo.Objects.Character) Banner(io.github.spugn.Sargo.Objects.Banner)

Aggregations

Character (io.github.spugn.Sargo.Objects.Character)25 Banner (io.github.spugn.Sargo.Objects.Banner)13 ImageEditor (io.github.spugn.Sargo.Utilities.ImageEditor)3 Weapon (io.github.spugn.Sargo.Objects.Weapon)2 UserParser (io.github.spugn.Sargo.XMLParsers.UserParser)2 FailedToReadBannerFileException (io.github.spugn.Sargo.Exceptions.FailedToReadBannerFileException)1 GitHubImage (io.github.spugn.Sargo.Utilities.GitHubImage)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DecimalFormat (java.text.DecimalFormat)1 Random (java.util.Random)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Attribute (javax.xml.stream.events.Attribute)1 EndElement (javax.xml.stream.events.EndElement)1 StartElement (javax.xml.stream.events.StartElement)1