use of io.github.spugn.Sargo.Objects.Character 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;
}
use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.
the class UserParser method writeCharacterBox.
/**
* Writes the character box using the List of Characters from the class.
* @param eventWriter Event writer.
* @throws XMLStreamException If there is an errow when writing.
*/
private void writeCharacterBox(XMLEventWriter eventWriter) throws XMLStreamException {
/* INITIALIZE VARIABLES */
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter characterElement;
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent end = eventFactory.createDTD("\n");
XMLEvent tab = eventFactory.createDTD("\t");
/* BUBBLE SORT CHARACTER ARRAY */
Character tempCharacter;
for (int a = 0; a < characterBox.size() + 1; a++) {
for (int b = 1; b < characterBox.size(); b++) {
if (characterBox.get(b - 1).getRarity() <= characterBox.get(b).getRarity()) {
tempCharacter = characterBox.get(b - 1);
characterBox.set(b - 1, characterBox.get(b));
characterBox.set(b, tempCharacter);
}
}
}
/* WRITE characterBox START NODE*/
eventWriter.add(tab);
StartElement sElement = eventFactory.createStartElement("", "", CHARACTER_BOX);
eventWriter.add(sElement);
/* WRITE CHARACTER DATA */
for (Character character : characterBox) {
/* CREATE EMPTY ELEMENT */
characterElement = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(characterElement);
/* WRITE ELEMENT NAME, CHARACTER PREFIX, CHARACTER NAME, AND RARITY */
writer.writeEmptyElement(CHARACTER);
writer.writeAttribute(CHARACTER_PREFIX, character.getPrefix());
writer.writeAttribute(CHARACTER_NAME, character.getName());
writer.writeAttribute(CHARACTER_RARITY, String.valueOf(character.getRarity()));
writer.writeEndDocument();
writer.flush();
writer.close();
/* START NEW LINE AND TAB TWICE */
eventWriter.add(end);
eventWriter.add(tab);
eventWriter.add(tab);
/* WRITE CHARACTER ELEMENT TO FILE */
eventWriter.add(eventFactory.createDTD(characterElement.toString()));
}
/* NEW LINE AND ADD TAB */
eventWriter.add(end);
eventWriter.add(tab);
/* CLOSE CHARACTER BOX ELEMENT */
EndElement eElement = eventFactory.createEndElement("", "", CHARACTER_BOX);
eventWriter.add(eElement);
eventWriter.add(end);
}
use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.
the class BannerInfo method getBannerInfo.
private void getBannerInfo() {
if (bannerID < BANNERS.size() && bannerID >= 0) {
Banner banner = BANNERS.get(bannerID);
BannerInfoMenu menu = new BannerInfoMenu();
Random rng = new Random();
int charIndex = rng.nextInt(banner.getCharacters().size());
menu.setBannerType(banner.bannerTypeToString());
menu.setBannerWepType(banner.getBannerWepType());
menu.setBannerName(banner.getBannerName());
menu.setCharacterAmount(banner.getCharacters().size());
menu.setBannerID(bannerID);
menu.setImageURL(new GitHubImage(banner.getCharacters().get(charIndex).getImagePath()).getURL());
/* CREATE CHARACTER LIST */
String charList = "";
for (Character c : banner.getCharacters()) {
charList += "\n" + c.toString();
}
menu.setCharacterList(charList);
/* IF THERE ARE WEAPONS, CREATE WEAPON LIST */
if (banner.getWeapons().size() > 0) {
String weapList = "";
for (Weapon w : banner.getWeapons()) {
weapList += "\n" + w.toString();
}
menu.setWeaponAmount(banner.getWeapons().size());
menu.setWeaponList(weapList);
}
/* CREATE RATE LIST */
List<Character> goldCharacters = new ArrayList<>();
List<Character> platinumCharacters = new ArrayList<>();
/* SORT GOLD AND PLATINUM CHARACTERS AND STORE THEM IN THEIR OWN ARRAYS */
for (Character character : banner.getCharacters()) {
if (character.getRarity() == 4) {
goldCharacters.add(character);
} else if (character.getRarity() == 5) {
platinumCharacters.add(character);
}
}
/* NO PLATINUM CHARACTER, ADJUST RATES */
if (platinumCharacters.size() <= 0) {
copper += platinum;
platinum = 0;
}
/* IF EVENT SCOUT, SET EVERYTHING BUT GOLD TO 0 */
if (banner.getBannerType() == 9) {
if (goldCharacters.size() > 0) {
copper = 0.0;
silver = 0.0;
gold = 100.0;
platinum = 0.0;
} else {
copper = 0.0;
silver = 0.0;
gold = 0.0;
platinum = 100.0;
}
}
/* IF RECORD CRYSTAL V4, INCREASE PLATINUM RATES BY 1.5 */
if (banner.getBannerType() == 11) {
copper = copper - ((platinum * 1.5) - platinum);
platinum = platinum * 1.5;
}
String ratesList = "";
if (platinum != 0)
ratesList += "[5 ★] " + platinum + "%\n";
ratesList += "[4 ★] " + gold + "%\n";
ratesList += "[3 ★] " + silver + "%\n";
ratesList += "[2 ★] " + copper + "%";
menu.setRatesList(ratesList);
/* BANNER IS STEP UP */
if (banner.getBannerType() == 1) {
double tC = copper - ((gold * 1.5) - gold);
double tS = silver;
double tG = gold * 1.5;
double tP = platinum;
String stepThreeRates = "";
if (tP != 0)
stepThreeRates += "[5 ★] " + tP + "%\n";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(4 ★ Scout Rates 1.5x)**";
menu.setStepThreeRatesList(stepThreeRates);
tC = copper - ((gold * 2.0) - gold);
tS = silver;
tG = gold * 2.0;
tP = platinum;
String stepFiveRates = "";
if (tP != 0)
stepFiveRates += "[5 ★] " + tP + "%\n";
stepFiveRates += "[4 ★] " + tG + "%\n";
stepFiveRates += "[3 ★] " + tS + "%\n";
stepFiveRates += "[2 ★] " + tC + "%\n";
stepFiveRates += "**(4 ★ Scout Rates 2.0x)**";
menu.setStepFiveRatesList(stepFiveRates);
} else /* BANNER IS STEP UP V2 */
if (banner.getBannerType() == 3 || banner.getBannerType() == 10) {
double tC = copper - ((platinum * 1.5) - platinum);
double tS = silver;
double tG = gold;
double tP = platinum * 1.5;
String stepThreeRates = "";
if (tP != 0)
stepThreeRates += "[5 ★] " + tP + "%\n";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(5 ★ Scout Rates 1.5x)**";
menu.setStepThreeRatesList(stepThreeRates);
tC = 0.0;
tS = 0.0;
tG = 0.0;
tP = 100.0;
String stepFiveRates = "";
stepFiveRates += "[5 ★] " + tP + "%\n";
stepFiveRates += "[4 ★] " + tG + "%\n";
stepFiveRates += "[3 ★] " + tS + "%\n";
stepFiveRates += "[2 ★] " + tC + "%\n";
stepFiveRates += "**(For One Character)**";
menu.setStepFiveRatesList(stepFiveRates);
tC = copper - ((platinum * 2.0) - platinum);
tS = silver;
tG = gold;
tP = platinum * 2.0;
String stepSixRates = "";
if (tP != 0)
stepSixRates += "[5 ★] " + tP + "%\n";
stepSixRates += "[4 ★] " + tG + "%\n";
stepSixRates += "[3 ★] " + tS + "%\n";
stepSixRates += "[2 ★] " + tC + "%\n";
stepSixRates += "**(5 ★ Scout Rates 2.0x)**";
menu.setStepSixRatesList(stepSixRates);
} else /* BANNER IS BIRTHDAY STEP UP */
if (banner.getBannerType() == 4) {
double tC = copper - (((platinum * 2.0) - platinum) + ((gold * 2.0) - gold));
double tS = silver;
double tG = gold * 2.0;
double tP = platinum * 2.0;
String stepThreeRates = "";
if (tP != 0)
stepThreeRates += "[5 ★] " + tP + "%\n";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(4+ ★ Scout Rates 2.0x)**";
menu.setStepThreeRatesList(stepThreeRates);
} else /* BANNER IS RECORD CRYSTAL */
if (banner.getBannerType() == 2 || banner.getBannerType() == 5 || banner.getBannerType() == 8 || banner.getBannerType() == 11) {
int counter = 0;
String recordCrystalRates = "";
DecimalFormat df = new DecimalFormat("0.0");
for (double d : recordCrystal) {
if (d != 0) {
recordCrystalRates += "[" + ++counter + " RC] " + df.format((d * 100)) + "%\n";
}
}
menu.setRecordCrystalRatesList(recordCrystalRates);
if (banner.getBannerType() == 8 || banner.getBannerType() == 11) {
int counter2 = 0;
String circluatingRecordCrystalRates = "";
if (banner.getBannerType() == 8) {
for (double d : circulatingRecordCrystal) {
if (d != 0) {
circluatingRecordCrystalRates += "[" + ++counter2 + " RC] " + df.format((d * 100)) + "%\n";
}
}
} else {
for (double d : recordCrystal) {
if (d != 0) {
circluatingRecordCrystalRates += "[" + ++counter2 + " RC] " + df.format((d * 100)) + "%\n";
}
}
}
menu.setCirculatingRecordCrystalRatesList(circluatingRecordCrystalRates);
}
} else /* BANNER IS STEP UP V3 */
if (banner.getBannerType() == 7) {
double tC = copper - ((platinum * 2.0) - platinum);
double tS = silver;
double tG = gold;
double tP = platinum * 2.0;
String stepThreeRates = "";
if (tP != 0)
stepThreeRates += "[5 ★] " + tP + "%\n";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(5 ★ Scout Rates 2.0x)**";
menu.setStepThreeRatesList(stepThreeRates);
}
/* WEAPON BANNER IS STEP UP */
if (banner.getBannerWepType() == 1) {
double tC = (copper + platinum) - ((gold * 2.0) - gold);
double tS = silver;
double tG = gold * 2.0;
String stepThreeRates = "";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(4 ★ Weapon Rates 2.0x)**";
menu.setStepThreeWeaponRatesList(stepThreeRates);
} else /* WEAPON BANNER IS STEP UP V2 */
if (banner.getBannerWepType() == 2) {
double tC = (copper + platinum) - ((gold * 1.5) - gold);
double tS = silver;
double tG = gold * 1.5;
String stepThreeRates = "";
stepThreeRates += "[4 ★] " + tG + "%\n";
stepThreeRates += "[3 ★] " + tS + "%\n";
stepThreeRates += "[2 ★] " + tC + "%\n";
stepThreeRates += "**(4 ★ Weapon Rates 1.5x)**";
menu.setStepThreeWeaponRatesList(stepThreeRates);
tC = 0.0;
tS = 0.0;
tG = 100.0;
String stepFiveRates = "";
stepFiveRates += "[4 ★] " + tG + "%\n";
stepFiveRates += "[3 ★] " + tS + "%\n";
stepFiveRates += "[2 ★] " + tC + "%\n";
stepFiveRates += "**(For One Weapon)**";
menu.setStepFiveWeaponRatesList(stepFiveRates);
tC = (copper + platinum) - ((gold * 2.0) - gold);
tS = silver;
tG = gold * 2.0;
String stepSixRates = "";
stepSixRates += "[4 ★] " + tG + "%\n";
stepSixRates += "[3 ★] " + tS + "%\n";
stepSixRates += "[2 ★] " + tC + "%\n";
stepSixRates += "**(4 ★ Weapon Rates 2.0x)**";
menu.setStepSixWeaponRatesList(stepSixRates);
}
CHANNEL.sendMessage(menu.get().build());
} else {
CHANNEL.sendMessage(new WarningMessage("UNKNOWN BANNER ID", "Use '" + CommandManager.getCommandPrefix() + "**scout**' for a list of banners.").get().build());
}
}
use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.
the class Profile method bannerInfoMenu.
/**
* Displays if the user is missing characters or weapons and if they do happen
* to have the characters or weapons it will tell them that they obtained them
* and for weapons it will tell them how much they have obtained of that weapon.
*
* @param bannerIDString The banner ID in string form.
*/
private void bannerInfoMenu(String bannerIDString) {
int bannerID = Integer.parseInt(bannerIDString) - 1;
/* OPEN BANNERS FILE */
// BannerParser bannersXML = new BannerParser();
// List<Banner> banners = bannersXML.getBanners();
List<Banner> banners = BannerParser.getBanners();
if (bannerID < banners.size() && bannerID >= 0) {
Banner requestedBanner = banners.get(bannerID);
boolean characterFound = false;
int characterCounter = 0;
List<Character> obtainedCharacters = new ArrayList<>();
List<Character> unobtainedCharacters = new ArrayList<>();
for (Character c : requestedBanner.getCharacters()) {
characterCounter++;
/* TRY AND FIND CHARACTER IN USER BOX */
for (Character oC : user.getCharacterBox()) {
if (c.getPrefix().equals(oC.getPrefix()) && c.getName().equals(oC.getName()) && (c.getRarity() == oC.getRarity())) {
/* CHARACTER IS SAME */
characterFound = true;
break;
}
}
/* ADD CHARACTER TO LIST */
if (!characterFound) {
unobtainedCharacters.add(c);
} else {
obtainedCharacters.add(c);
}
characterFound = false;
}
builder.appendField(requestedBanner.getBannerName(), characterCounter + " Characters Available", false);
if (obtainedCharacters.size() > 0) {
String obtainedList = "";
int obtainedCounter = 0;
for (Character c : obtainedCharacters) {
obtainedList += c.toString() + "\n";
obtainedCounter++;
}
builder.appendField(obtainedCounter + " Characters Obtained", obtainedList, false);
}
if (unobtainedCharacters.size() > 0) {
String noHaveList = "";
int noHaveCounter = 0;
for (Character c : unobtainedCharacters) {
noHaveList += c.toString() + "\n";
noHaveCounter++;
}
builder.appendField(noHaveCounter + " Characters Missing", noHaveList, false);
}
/* WEAPON STATS */
boolean weaponFound = false;
int weaponCounter = 0;
List<Weapon> obtainedWeapons = new ArrayList<>();
List<Weapon> unobtainedWeapons = new ArrayList<>();
for (Weapon w : requestedBanner.getWeapons()) {
weaponCounter++;
/* TRY AND FIND WEAPON IN USER BOX */
for (Weapon oW : user.getWeaponBox()) {
if (w.getName().equals(oW.getName())) {
/* WEAPON IS SAME */
w.setCount(oW.getCount());
weaponFound = true;
break;
}
}
/* ADD WEAPON TO LIST */
if (!weaponFound) {
unobtainedWeapons.add(w);
} else {
obtainedWeapons.add(w);
}
weaponFound = false;
}
if (obtainedWeapons.size() > 0) {
String obtainedList = "";
int obtainedCounter = 0;
for (Weapon w : obtainedWeapons) {
obtainedList += w.toStringWithCount() + "\n";
obtainedCounter++;
}
builder.appendField(obtainedCounter + " Weapons Obtained", obtainedList, false);
}
if (unobtainedWeapons.size() > 0) {
String noHaveList = "";
int noHaveCounter = 0;
for (Weapon w : unobtainedWeapons) {
noHaveList += w.toString() + "\n";
noHaveCounter++;
}
builder.appendField(noHaveCounter + " Weapons Missing", noHaveList, false);
}
} else {
CHANNEL.sendMessage(new WarningMessage("UNKNOWN BANNER ID", "Use '" + CommandManager.getCommandPrefix() + "**scout**' for a list of banners.").get().build());
return;
}
CHANNEL.sendMessage(builder.build());
}
use of io.github.spugn.Sargo.Objects.Character in project S-argo by Expugn.
the class RecordCrystalv3 method randGoldCharacter.
@Override
protected Character randGoldCharacter() {
int randIndex = GOLD_BANNERS_V2.get(RNG.nextInt(GOLD_BANNERS_V2.size()));
Banner randBanner = BANNERS.get(randIndex - 1);
List<Character> randCharacters = randBanner.getCharacters();
return randCharacters.get(RNG.nextInt(randCharacters.size()));
}
Aggregations