Skip to content

Commit

Permalink
Now parsing to find CDR for items
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Rua committed Jul 21, 2014
1 parent 4c39cc6 commit c825107
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 35 deletions.
38 changes: 27 additions & 11 deletions src/lib/orianna/api/JSONConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lib.orianna.type.champion.ChampionStatus;
import lib.orianna.type.game.Game;
Expand Down Expand Up @@ -72,6 +74,8 @@
* @author Rob Rua (FatalElement - NA) ([email protected])
*/
public class JSONConverter {
private static final Pattern ITEM_CDR_PATTERN = Pattern.compile("\\+(\\d+)% Cooldown Reduction *(<br>|</stats>|$)");

private static Integer convertInteger(final Object object) {
final Long longVersion = (Long)object;
if(longVersion == null) {
Expand Down Expand Up @@ -590,6 +594,7 @@ public BasicDataStats getBasicDataStatsFromJSON(final JSONObject basicDataStatsI
final Double percentArmorMod = (Double)basicDataStatsInfo.get("PercentArmorMod");
final Double percentAttackSpeedMod = (Double)basicDataStatsInfo.get("PercentAttackSpeedMod");
final Double percentBlockMod = (Double)basicDataStatsInfo.get("PercentBlockMod");
final Double percentCooldownMod = (Double)basicDataStatsInfo.get("PercentCooldownMod");
final Double percentCritChanceMod = (Double)basicDataStatsInfo.get("PercentCritChanceMod");
final Double percentCritDamageMod = (Double)basicDataStatsInfo.get("PercentCritDamageMod");
final Double percentDodgeMod = (Double)basicDataStatsInfo.get("PercentDodgeMod");
Expand Down Expand Up @@ -639,16 +644,16 @@ public BasicDataStats getBasicDataStatsFromJSON(final JSONObject basicDataStatsI

return new BasicDataStats(flatArmorMod, flatAttackSpeedMod, flatBlockMod, flatCritChanceMod, flatCritDamageMod, flatEXPBonus, flatEnergyPoolMod,
flatEnergyRegenMod, flatHPPoolMod, flatHPRegenMod, flatMPPoolMod, flatMPRegenMod, flatMagicDamageMod, flatMovementSpeedMod,
flatPhysicalDamageMod, flatSpellBlockMod, percentArmorMod, percentAttackSpeedMod, percentBlockMod, percentCritChanceMod, percentCritDamageMod,
percentDodgeMod, percentEXPBonus, percentHPPoolMod, percentHPRegenMod, percentLifeStealMod, percentMPPoolMod, percentMPRegenMod,
percentMagicDamageMod, percentMovementSpeedMod, percentPhysicalDamageMod, percentSpellBlockMod, percentSpellVampMod, rFlatArmorModPerLevel,
rFlatArmorPenetrationMod, rFlatArmorPenetrationModPerLevel, rFlatCritChanceModPerLevel, rFlatCritDamageModPerLevel, rFlatDodgeMod,
rFlatDodgeModPerLevel, rFlatEnergyModPerLevel, rFlatEnergyRegenModPerLevel, rFlatGoldPer10Mod, rFlatHPModPerLevel, rFlatHPRegenModPerLevel,
rFlatMPModPerLevel, rFlatMPRegenModPerLevel, rFlatMagicDamageModPerLevel, rFlatMagicPenetrationMod, rFlatMagicPenetrationModPerLevel,
rFlatMovementSpeedModPerLevel, rFlatPhysicalDamageModPerLevel, rFlatSpellBlockModPerLevel, rFlatTimeDeadMod, rFlatTimeDeadModPerLevel,
rPercentArmorPenetrationMod, rPercentArmorPenetrationModPerLevel, rPercentAttackSpeedModPerLevel, rPercentCooldownMod,
rPercentCooldownModPerLevel, rPercentMagicPenetrationMod, rPercentMagicPenetrationModPerLevel, rPercentMovementSpeedModPerLevel,
rPercentTimeDeadMod, rPercentTimeDeadModPerLevel);
flatPhysicalDamageMod, flatSpellBlockMod, percentArmorMod, percentAttackSpeedMod, percentBlockMod, percentCooldownMod, percentCritChanceMod,
percentCritDamageMod, percentDodgeMod, percentEXPBonus, percentHPPoolMod, percentHPRegenMod, percentLifeStealMod, percentMPPoolMod,
percentMPRegenMod, percentMagicDamageMod, percentMovementSpeedMod, percentPhysicalDamageMod, percentSpellBlockMod, percentSpellVampMod,
rFlatArmorModPerLevel, rFlatArmorPenetrationMod, rFlatArmorPenetrationModPerLevel, rFlatCritChanceModPerLevel, rFlatCritDamageModPerLevel,
rFlatDodgeMod, rFlatDodgeModPerLevel, rFlatEnergyModPerLevel, rFlatEnergyRegenModPerLevel, rFlatGoldPer10Mod, rFlatHPModPerLevel,
rFlatHPRegenModPerLevel, rFlatMPModPerLevel, rFlatMPRegenModPerLevel, rFlatMagicDamageModPerLevel, rFlatMagicPenetrationMod,
rFlatMagicPenetrationModPerLevel, rFlatMovementSpeedModPerLevel, rFlatPhysicalDamageModPerLevel, rFlatSpellBlockModPerLevel, rFlatTimeDeadMod,
rFlatTimeDeadModPerLevel, rPercentArmorPenetrationMod, rPercentArmorPenetrationModPerLevel, rPercentAttackSpeedModPerLevel,
rPercentCooldownMod, rPercentCooldownModPerLevel, rPercentMagicPenetrationMod, rPercentMagicPenetrationModPerLevel,
rPercentMovementSpeedModPerLevel, rPercentTimeDeadMod, rPercentTimeDeadModPerLevel);
}

public Block getBlockFromJSON(final JSONObject blockInfo) {
Expand Down Expand Up @@ -905,7 +910,6 @@ public Item getItemFromJSON(final JSONObject itemInfo) {
final Gold gold = getGoldFromJSON((JSONObject)itemInfo.get("gold"));
final Image image = getImageFromJSON((JSONObject)itemInfo.get("image"));
final MetaData rune = getMetaDataFromJSON((JSONObject)itemInfo.get("rune"));
final BasicDataStats stats = getBasicDataStatsFromJSON((JSONObject)itemInfo.get("stats"));
final List<String> from = getStringList(itemInfo, "from");
final List<String> into = getStringList(itemInfo, "into");
final List<String> tags = getStringList(itemInfo, "tags");
Expand All @@ -914,6 +918,18 @@ public Item getItemFromJSON(final JSONObject itemInfo) {
maps = Collections.unmodifiableMap(maps);
}

final JSONObject statsObj = (JSONObject)itemInfo.get("stats");
/*
* Riot doesn't send CDR for items as a stat yet, so we have to parse it
* out of the description and add it ourselves.
*/
// TODO: Remove this after rito fixes it.
final Matcher matcher = ITEM_CDR_PATTERN.matcher(description);
if(matcher.find()) {
statsObj.put("PercentCooldownMod", new Double(matcher.group(1)));
}
final BasicDataStats stats = getBasicDataStatsFromJSON((JSONObject)itemInfo.get("stats"));

return new Item(colloq, description, group, name, plaintext, requiredChampion, sanitizedDescription, consumeOnFull, consumed, hideFromAll, inStore,
depth, ID, specialRecipe, stacks, from, into, tags, gold, image, maps, rune, stats);
}
Expand Down
63 changes: 39 additions & 24 deletions src/lib/orianna/type/staticdata/BasicDataStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@
import java.util.Map;

public class BasicDataStats implements Serializable {
private static final long serialVersionUID = 1594413878340877864L;
private static final long serialVersionUID = -2608389900646702437L;
public final Double flatArmorMod, flatAttackSpeedMod, flatBlockMod, flatCritChanceMod, flatCritDamageMod, flatEXPBonus, flatEnergyPoolMod,
flatEnergyRegenMod, flatHPPoolMod, flatHPRegenMod, flatMPPoolMod, flatMPRegenMod, flatMagicDamageMod, flatMovementSpeedMod, flatPhysicalDamageMod,
flatSpellBlockMod, percentArmorMod, percentAttackSpeedMod, percentBlockMod, percentCritChanceMod, percentCritDamageMod, percentDodgeMod,
percentEXPBonus, percentHPPoolMod, percentHPRegenMod, percentLifeStealMod, percentMPPoolMod, percentMPRegenMod, percentMagicDamageMod,
percentMovementSpeedMod, percentPhysicalDamageMod, percentSpellBlockMod, percentSpellVampMod, rFlatArmorModPerLevel, rFlatArmorPenetrationMod,
rFlatArmorPenetrationModPerLevel, rFlatCritChanceModPerLevel, rFlatCritDamageModPerLevel, rFlatDodgeMod, rFlatDodgeModPerLevel,
rFlatEnergyModPerLevel, rFlatEnergyRegenModPerLevel, rFlatGoldPer10Mod, rFlatHPModPerLevel, rFlatHPRegenModPerLevel, rFlatMPModPerLevel,
rFlatMPRegenModPerLevel, rFlatMagicDamageModPerLevel, rFlatMagicPenetrationMod, rFlatMagicPenetrationModPerLevel, rFlatMovementSpeedModPerLevel,
rFlatPhysicalDamageModPerLevel, rFlatSpellBlockModPerLevel, rFlatTimeDeadMod, rFlatTimeDeadModPerLevel, rPercentArmorPenetrationMod,
rPercentArmorPenetrationModPerLevel, rPercentAttackSpeedModPerLevel, rPercentCooldownMod, rPercentCooldownModPerLevel, rPercentMagicPenetrationMod,
rPercentMagicPenetrationModPerLevel, rPercentMovementSpeedModPerLevel, rPercentTimeDeadMod, rPercentTimeDeadModPerLevel;
flatSpellBlockMod, percentArmorMod, percentAttackSpeedMod, percentBlockMod, percentCooldownMod, percentCritChanceMod, percentCritDamageMod,
percentDodgeMod, percentEXPBonus, percentHPPoolMod, percentHPRegenMod, percentLifeStealMod, percentMPPoolMod, percentMPRegenMod,
percentMagicDamageMod, percentMovementSpeedMod, percentPhysicalDamageMod, percentSpellBlockMod, percentSpellVampMod, rFlatArmorModPerLevel,
rFlatArmorPenetrationMod, rFlatArmorPenetrationModPerLevel, rFlatCritChanceModPerLevel, rFlatCritDamageModPerLevel, rFlatDodgeMod,
rFlatDodgeModPerLevel, rFlatEnergyModPerLevel, rFlatEnergyRegenModPerLevel, rFlatGoldPer10Mod, rFlatHPModPerLevel, rFlatHPRegenModPerLevel,
rFlatMPModPerLevel, rFlatMPRegenModPerLevel, rFlatMagicDamageModPerLevel, rFlatMagicPenetrationMod, rFlatMagicPenetrationModPerLevel,
rFlatMovementSpeedModPerLevel, rFlatPhysicalDamageModPerLevel, rFlatSpellBlockModPerLevel, rFlatTimeDeadMod, rFlatTimeDeadModPerLevel,
rPercentArmorPenetrationMod, rPercentArmorPenetrationModPerLevel, rPercentAttackSpeedModPerLevel, rPercentCooldownMod, rPercentCooldownModPerLevel,
rPercentMagicPenetrationMod, rPercentMagicPenetrationModPerLevel, rPercentMovementSpeedModPerLevel, rPercentTimeDeadMod,
rPercentTimeDeadModPerLevel;

public BasicDataStats(final Double flatArmorMod, final Double flatAttackSpeedMod, final Double flatBlockMod, final Double flatCritChanceMod,
final Double flatCritDamageMod, final Double flatEXPBonus, final Double flatEnergyPoolMod, final Double flatEnergyRegenMod,
final Double flatHPPoolMod, final Double flatHPRegenMod, final Double flatMPPoolMod, final Double flatMPRegenMod, final Double flatMagicDamageMod,
final Double flatMovementSpeedMod, final Double flatPhysicalDamageMod, final Double flatSpellBlockMod, final Double percentArmorMod,
final Double percentAttackSpeedMod, final Double percentBlockMod, final Double percentCritChanceMod, final Double percentCritDamageMod,
final Double percentDodgeMod, final Double percentEXPBonus, final Double percentHPPoolMod, final Double percentHPRegenMod,
final Double percentLifeStealMod, final Double percentMPPoolMod, final Double percentMPRegenMod, final Double percentMagicDamageMod,
final Double percentMovementSpeedMod, final Double percentPhysicalDamageMod, final Double percentSpellBlockMod, final Double percentSpellVampMod,
final Double rFlatArmorModPerLevel, final Double rFlatArmorPenetrationMod, final Double rFlatArmorPenetrationModPerLevel,
final Double rFlatCritChanceModPerLevel, final Double rFlatCritDamageModPerLevel, final Double rFlatDodgeMod, final Double rFlatDodgeModPerLevel,
final Double rFlatEnergyModPerLevel, final Double rFlatEnergyRegenModPerLevel, final Double rFlatGoldPer10Mod, final Double rFlatHPModPerLevel,
final Double rFlatHPRegenModPerLevel, final Double rFlatMPModPerLevel, final Double rFlatMPRegenModPerLevel,
final Double rFlatMagicDamageModPerLevel, final Double rFlatMagicPenetrationMod, final Double rFlatMagicPenetrationModPerLevel,
final Double rFlatMovementSpeedModPerLevel, final Double rFlatPhysicalDamageModPerLevel, final Double rFlatSpellBlockModPerLevel,
final Double rFlatTimeDeadMod, final Double rFlatTimeDeadModPerLevel, final Double rPercentArmorPenetrationMod,
final Double rPercentArmorPenetrationModPerLevel, final Double rPercentAttackSpeedModPerLevel, final Double rPercentCooldownMod,
final Double rPercentCooldownModPerLevel, final Double rPercentMagicPenetrationMod, final Double rPercentMagicPenetrationModPerLevel,
final Double rPercentMovementSpeedModPerLevel, final Double rPercentTimeDeadMod, final Double rPercentTimeDeadModPerLevel) {
final Double percentAttackSpeedMod, final Double percentBlockMod, final Double percentCooldownMod, final Double percentCritChanceMod,
final Double percentCritDamageMod, final Double percentDodgeMod, final Double percentEXPBonus, final Double percentHPPoolMod,
final Double percentHPRegenMod, final Double percentLifeStealMod, final Double percentMPPoolMod, final Double percentMPRegenMod,
final Double percentMagicDamageMod, final Double percentMovementSpeedMod, final Double percentPhysicalDamageMod, final Double percentSpellBlockMod,
final Double percentSpellVampMod, final Double rFlatArmorModPerLevel, final Double rFlatArmorPenetrationMod,
final Double rFlatArmorPenetrationModPerLevel, final Double rFlatCritChanceModPerLevel, final Double rFlatCritDamageModPerLevel,
final Double rFlatDodgeMod, final Double rFlatDodgeModPerLevel, final Double rFlatEnergyModPerLevel, final Double rFlatEnergyRegenModPerLevel,
final Double rFlatGoldPer10Mod, final Double rFlatHPModPerLevel, final Double rFlatHPRegenModPerLevel, final Double rFlatMPModPerLevel,
final Double rFlatMPRegenModPerLevel, final Double rFlatMagicDamageModPerLevel, final Double rFlatMagicPenetrationMod,
final Double rFlatMagicPenetrationModPerLevel, final Double rFlatMovementSpeedModPerLevel, final Double rFlatPhysicalDamageModPerLevel,
final Double rFlatSpellBlockModPerLevel, final Double rFlatTimeDeadMod, final Double rFlatTimeDeadModPerLevel,
final Double rPercentArmorPenetrationMod, final Double rPercentArmorPenetrationModPerLevel, final Double rPercentAttackSpeedModPerLevel,
final Double rPercentCooldownMod, final Double rPercentCooldownModPerLevel, final Double rPercentMagicPenetrationMod,
final Double rPercentMagicPenetrationModPerLevel, final Double rPercentMovementSpeedModPerLevel, final Double rPercentTimeDeadMod,
final Double rPercentTimeDeadModPerLevel) {
this.flatArmorMod = flatArmorMod;
this.flatAttackSpeedMod = flatAttackSpeedMod;
this.flatBlockMod = flatBlockMod;
Expand All @@ -56,6 +58,7 @@ public BasicDataStats(final Double flatArmorMod, final Double flatAttackSpeedMod
this.percentArmorMod = percentArmorMod;
this.percentAttackSpeedMod = percentAttackSpeedMod;
this.percentBlockMod = percentBlockMod;
this.percentCooldownMod = percentCooldownMod;
this.percentCritChanceMod = percentCritChanceMod;
this.percentCritDamageMod = percentCritDamageMod;
this.percentDodgeMod = percentDodgeMod;
Expand Down Expand Up @@ -268,6 +271,14 @@ else if(!percentAttackSpeedMod.equals(other.percentAttackSpeedMod)) {
else if(!percentBlockMod.equals(other.percentBlockMod)) {
return false;
}
if(percentCooldownMod == null) {
if(other.percentCooldownMod != null) {
return false;
}
}
else if(!percentCooldownMod.equals(other.percentCooldownMod)) {
return false;
}
if(percentCritChanceMod == null) {
if(other.percentCritChanceMod != null) {
return false;
Expand Down Expand Up @@ -662,6 +673,7 @@ public int hashCode() {
result = prime * result + (percentArmorMod == null ? 0 : percentArmorMod.hashCode());
result = prime * result + (percentAttackSpeedMod == null ? 0 : percentAttackSpeedMod.hashCode());
result = prime * result + (percentBlockMod == null ? 0 : percentBlockMod.hashCode());
result = prime * result + (percentCooldownMod == null ? 0 : percentCooldownMod.hashCode());
result = prime * result + (percentCritChanceMod == null ? 0 : percentCritChanceMod.hashCode());
result = prime * result + (percentCritDamageMod == null ? 0 : percentCritDamageMod.hashCode());
result = prime * result + (percentDodgeMod == null ? 0 : percentDodgeMod.hashCode());
Expand Down Expand Up @@ -775,6 +787,9 @@ public Map<String, Double> nonNullStats() {
if(percentBlockMod != null) {
nonNull.put("percentBlockMod", percentBlockMod);
}
if(percentCooldownMod != null) {
nonNull.put("percentCooldownMod", percentCooldownMod);
}
if(percentCritChanceMod != null) {
nonNull.put("percentCritChanceMod", percentCritChanceMod);
}
Expand Down

0 comments on commit c825107

Please sign in to comment.