Search in sources :

Example 6 with Banner

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

the class SAOGameFifthAnniversaryStepUp 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)

Example 7 with Banner

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

the class StepUpv2 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)

Example 8 with Banner

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

the class StepUpv3 method randGoldCharacter.

@Override
protected Character randGoldCharacter() {
    /* GET A RANDOM GOLD VARIANT CHARACTER, IF THERE IS A PLATINUM
           VARIANT OF THAT CHARACTER IN THE BANNER THEN GET A NEW CHARACTER. */
    Character c = null;
    boolean charInBanner = true;
    int randIndex;
    Banner randBanner;
    List<Character> randCharacters;
    boolean sameName;
    boolean samePrefix;
    while (charInBanner) {
        randIndex = GOLD_BANNERS_V2.get(RNG.nextInt(GOLD_BANNERS_V2.size()));
        randBanner = BANNERS.get(randIndex - 1);
        randCharacters = randBanner.getCharacters();
        c = randCharacters.get(RNG.nextInt(randCharacters.size()));
        for (Character bc : SELECTED_BANNER.getCharacters()) {
            sameName = c.getName().equalsIgnoreCase(bc.getName());
            samePrefix = c.getPrefix().equalsIgnoreCase(bc.getPrefix());
            if (!(sameName && samePrefix)) {
                charInBanner = false;
            } else {
                charInBanner = true;
                break;
            }
        }
    }
    return c;
}
Also used : Character(io.github.spugn.Sargo.Objects.Character) Banner(io.github.spugn.Sargo.Objects.Banner)

Example 9 with Banner

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

the class BannerParser method tryRead.

private List<Banner> tryRead(String configFile) throws FailedToReadBannerFileException {
    List<Banner> banners = new ArrayList();
    goldBanners = new ArrayList();
    goldBannersv2 = new ArrayList();
    InputStream in;
    XMLEventReader eventReader;
    Banner banner = null;
    ArrayList<Character> characters = null;
    Character character;
    ArrayList<Weapon> weapons = null;
    Weapon weapon;
    /* CREATE XMLInputFactory AND XMLEventReader */
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    try {
        in = new FileInputStream(configFile);
    } catch (FileNotFoundException e) {
        throw new FailedToReadBannerFileException();
    }
    try {
        eventReader = inputFactory.createXMLEventReader(in);
    } catch (XMLStreamException e) {
        try {
            in.close();
        } catch (IOException ex) {
        /* IGNORED */
        }
        throw new FailedToReadBannerFileException();
    }
    /* READ XML FILE */
    while (eventReader.hasNext()) {
        XMLEvent event;
        try {
            event = eventReader.nextEvent();
        } catch (XMLStreamException e) {
            try {
                in.close();
            } catch (IOException ex) {
            /* IGNORED */
            }
            try {
                eventReader.close();
            } catch (XMLStreamException ex) {
            /* IGNORED */
            }
            throw new FailedToReadBannerFileException();
        }
        if (event.isStartElement()) {
            StartElement startElement = event.asStartElement();
            /* CREATE NEW BANNER AND CHARACTER LIST OBJECT */
            if (startElement.getName().getLocalPart().equals("Banner")) {
                banner = new Banner();
                characters = new ArrayList();
                weapons = new ArrayList<>();
                /* GET AND SAVE BANNER ID */
                Iterator<Attribute> attributes = startElement.getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("id")) {
                        banner.setBannerID(Integer.parseInt(attribute.getValue()));
                    }
                }
            }
            /* GET AND SAVE BANNER NAME */
            if (event.isStartElement()) {
                if (event.asStartElement().getName().getLocalPart().equals("name")) {
                    try {
                        event = eventReader.nextEvent();
                    } catch (XMLStreamException e) {
                        try {
                            in.close();
                        } catch (IOException ex) {
                        /* IGNORED */
                        }
                        try {
                            eventReader.close();
                        } catch (XMLStreamException ex) {
                        /* IGNORED */
                        }
                        throw new FailedToReadBannerFileException();
                    }
                    banner.setBannerName(event.asCharacters().getData());
                    continue;
                }
            }
            /* GET AND SAVE BANNER TYPE */
            if (event.asStartElement().getName().getLocalPart().equals("type")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadBannerFileException();
                }
                banner.setBannerType(Integer.parseInt(event.asCharacters().getData()));
                continue;
            }
            /* GET AND SAVE WEAPON BANNER TYPE */
            if (event.asStartElement().getName().getLocalPart().equals("wepType")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadBannerFileException();
                }
                banner.setBannerWepType(Integer.parseInt(event.asCharacters().getData()));
                continue;
            }
            /* GET AND SAVE IF BANNER IS INCLUDED WITH GOLD BANNERS/GOLD BANNERS V2 */
            if (event.asStartElement().getName().getLocalPart().equals("include")) {
                try {
                    event = eventReader.nextEvent();
                } catch (XMLStreamException e) {
                    try {
                        in.close();
                    } catch (IOException ex) {
                    /* IGNORED */
                    }
                    try {
                        eventReader.close();
                    } catch (XMLStreamException ex) {
                    /* IGNORED */
                    }
                    throw new FailedToReadBannerFileException();
                }
                String includeType = event.asCharacters().getData();
                if (includeType.equals("GoldBanners")) {
                    try {
                        goldBanners.add(banner.getBannerID());
                    } catch (NullPointerException e) {
                    /* IGNORED */
                    }
                } else if (includeType.equals("GoldBannersv2")) {
                    try {
                        goldBannersv2.add(banner.getBannerID());
                    } catch (NullPointerException e) {
                    /* IGNORED */
                    }
                }
                continue;
            }
            /* GET AND SAVE CHARACTER */
            if (event.asStartElement().getName().getLocalPart().equals("Character")) {
                character = new Character();
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("prefix")) {
                        character.setPrefix(attribute.getValue());
                    }
                    if (attribute.getName().toString().equals("char")) {
                        character.setName(attribute.getValue());
                    }
                    if (attribute.getName().toString().equals("rarity")) {
                        character.setRarity(Integer.parseInt(attribute.getValue()));
                    }
                }
                /* GENERATE IMAGE FILE PATH*/
                String characterImage = character.getPrefix() + " " + character.getName();
                character.setImagePath("images/Characters/" + characterImage.replaceAll(" ", "_") + ".png");
                /* ADD CHARACTER TO CHARACTER LIST */
                characters.add(character);
            }
            /* GET AND SAVE WEAPON */
            if (event.asStartElement().getName().getLocalPart().equals("Weapon")) {
                weapon = new Weapon();
                Iterator<Attribute> attributes = event.asStartElement().getAttributes();
                while (attributes.hasNext()) {
                    Attribute attribute = attributes.next();
                    if (attribute.getName().toString().equals("name")) {
                        weapon.setName(attribute.getValue());
                    }
                    if (attribute.getName().toString().equals("rarity")) {
                        weapon.setRarity(Integer.parseInt(attribute.getValue()));
                    }
                }
                /* GENERATE IMAGE FILE PATH*/
                weapon.setImagePath("images/Weapons/" + weapon.getName().replaceAll(" ", "_") + ".png");
                /* ADD WEAPON TO WEAPON LIST */
                weapons.add(weapon);
            }
        }
        /* END OF BANNER ELEMENT. FINALIZE CHARACTER LIST AND ADD OBJECT TO ArrayList */
        if (event.isEndElement()) {
            EndElement endElement = event.asEndElement();
            if (endElement.getName().getLocalPart().equals("Banner")) {
                banner.setCharacters(characters);
                banner.setWeapons(weapons);
                banners.add(banner);
            // System.out.println("added " + banner.getBannerName());
            }
        }
    }
    return banners;
}
Also used : FailedToReadBannerFileException(io.github.spugn.Sargo.Exceptions.FailedToReadBannerFileException) Character(io.github.spugn.Sargo.Objects.Character) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) Banner(io.github.spugn.Sargo.Objects.Banner) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Weapon(io.github.spugn.Sargo.Objects.Weapon) FileInputStream(java.io.FileInputStream) StartElement(javax.xml.stream.events.StartElement) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 10 with Banner

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

the class UserParser method writeDefaultBannerData.

/**
 * Write the defaults for banner data.
 *
 * @param eventWriter  Event writer.
 * @throws XMLStreamException  If there is an error when writing.
 */
private void writeDefaultBannerData(XMLEventWriter eventWriter) throws XMLStreamException {
    /* INITIALIZE VARIABLES */
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEvent end = eventFactory.createDTD("\n");
    XMLEvent tab = eventFactory.createDTD("\t");
    BannerParser bannersXML = new BannerParser();
    List<Banner> banners = bannersXML.getBanners();
    eventWriter.add(tab);
    StartElement sElement = eventFactory.createStartElement("", "", BANNER_DATA);
    eventWriter.add(sElement);
    for (Banner b : banners) {
        /* BANNER IS NOT NORMAL */
        if (!(b.getBannerType() == 0)) {
            /* WRITE ELEMENT NAME, BANNER NAME, AND BANNER DATA */
            StringWriter bannerElement = new StringWriter();
            XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bannerElement);
            writer.writeEmptyElement(BANNER);
            writer.writeAttribute(B_NAME, b.getBannerName());
            /* IS STEP UP */
            if (b.getBannerType() == 1 || b.getBannerType() == 3 || b.getBannerType() == 4 || b.getBannerType() == 7 || b.getBannerType() == 10) {
                writer.writeAttribute(B_DATA, DEFAULT_STEP);
            } else /* IS RECORD CRYSTAL */
            if (b.getBannerType() == 2) {
                writer.writeAttribute(B_DATA, DEFAULT_RECORD_CRYSTAL);
            } else /* IS RECORD CRYSTAL v2 AND v3 AND v4 */
            if (b.getBannerType() == 5 || b.getBannerType() == 8 || b.getBannerType() == 11) {
                writer.writeAttribute(B_DATA, DEFAULT_RECORD_CRYSTAL_V2);
            }
            writer.writeEndDocument();
            writer.flush();
            writer.close();
            /* START A NEW LINE AND TAB TWICE */
            eventWriter.add(end);
            eventWriter.add(tab);
            eventWriter.add(tab);
            /* WRITE BANNER DATA ELEMENT TO FILE */
            eventWriter.add(eventFactory.createDTD(bannerElement.toString()));
        }
    }
    eventWriter.add(end);
    eventWriter.add(tab);
    EndElement eElement = eventFactory.createEndElement("", "", BANNER_DATA);
    eventWriter.add(eElement);
    eventWriter.add(end);
}
Also used : Banner(io.github.spugn.Sargo.Objects.Banner)

Aggregations

Banner (io.github.spugn.Sargo.Objects.Banner)14 Character (io.github.spugn.Sargo.Objects.Character)13 FailedToReadBannerFileException (io.github.spugn.Sargo.Exceptions.FailedToReadBannerFileException)1 Weapon (io.github.spugn.Sargo.Objects.Weapon)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)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 XMLEvent (javax.xml.stream.events.XMLEvent)1