|
| 1 | +package material.user; |
| 2 | + |
| 3 | +import com.google.gson.JsonObject; |
| 4 | +import utils.HttpUtils; |
| 5 | + |
| 6 | +import java.text.DecimalFormat; |
| 7 | +import java.text.NumberFormat; |
| 8 | + |
| 9 | +public class UserStats { |
| 10 | + |
| 11 | + HttpUtils hu = new HttpUtils(); |
| 12 | + BungieUser bungieUser; |
| 13 | + Character character; |
| 14 | + JsonObject jo; |
| 15 | + JsonObject allPve; |
| 16 | + DecimalFormat df = new DecimalFormat("##.00"); |
| 17 | + |
| 18 | + private int activitiesCleared, activitiesEntered, assists, totalKillDistance, kills, deaths; |
| 19 | + private double pgaAssits, pgaKills, averageKillDistance, pgaSecondsPlayed, pgaDeaths; |
| 20 | + private long secondsPlayed; |
| 21 | + |
| 22 | + /** |
| 23 | + * Gets stats for this user's entire account |
| 24 | + */ |
| 25 | + public UserStats(BungieUser bungieUser) { |
| 26 | + this.bungieUser = bungieUser; |
| 27 | + jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getBungieMembershipID() + "/Stats/"); |
| 28 | + allPve = jo.getAsJsonObject("allPve").getAsJsonObject("allTime"); |
| 29 | + assignValues(); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Gets stats for this user's specific character |
| 34 | + */ |
| 35 | + public UserStats(BungieUser bungieUser, Character character) { |
| 36 | + this.bungieUser = bungieUser; |
| 37 | + jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getBungieMembershipID() + "/Character/" + character.getCharacterID() + "/Stats/").getAsJsonObject("Response").getAsJsonObject("mergedAllCharacters").getAsJsonObject("results"); |
| 38 | + allPve = jo.getAsJsonObject("allPve").getAsJsonObject("allTime"); |
| 39 | + assignValues(); |
| 40 | + } |
| 41 | + |
| 42 | + private void assignValues() { |
| 43 | + activitiesCleared = getBasicPVE("activitiesCleared").get("value").getAsInt(); |
| 44 | + activitiesEntered = getBasicPVE("activitiesEntered").get("value").getAsInt(); |
| 45 | + assists = getBasicPVE("assists").getAsJsonObject("value").getAsInt(); |
| 46 | + pgaAssits = getPGAPVE("assists").get("displayValue").getAsDouble(); |
| 47 | + totalKillDistance = getBasicPVE("totalKillDistance").get("value").getAsInt(); |
| 48 | + kills = getBasicPVE("kills").get("value").getAsInt(); |
| 49 | + pgaKills = getPGAPVE("kills").get("displayValue").getAsDouble(); |
| 50 | + averageKillDistance = getBasicPVE("averageKillDistance").get("displayValue").getAsDouble(); |
| 51 | + secondsPlayed = getBasicPVE("secondsPlayed").get("value").getAsLong(); |
| 52 | + pgaSecondsPlayed = Double.parseDouble(df.format(getPGAPVE("secondsPlayed").get("value").getAsDouble())); |
| 53 | + deaths = getBasicPVE("deaths").get("value").getAsInt(); |
| 54 | + pgaDeaths = Double.parseDouble(df.format(getPGAPVE("deaths").get("value").getAsDouble())); |
| 55 | + } |
| 56 | + |
| 57 | + public double getPgaSecondsPlayed() { |
| 58 | + return pgaSecondsPlayed; |
| 59 | + } |
| 60 | + |
| 61 | + public JsonObject getJsonObject() { |
| 62 | + return jo; |
| 63 | + } |
| 64 | + |
| 65 | + private JsonObject getBasicPVE(String name) { |
| 66 | + return allPve.getAsJsonObject(name).getAsJsonObject("basic"); |
| 67 | + } |
| 68 | + |
| 69 | + private JsonObject getPGAPVE(String name) { |
| 70 | + return allPve.getAsJsonObject(name).getAsJsonObject("pga"); |
| 71 | + } |
| 72 | +} |
0 commit comments