use of delta.games.lotro.utils.FixedDecimalsInteger in project lotro-tools by dmorcellet.
the class ItemsMerger method compareStats.
private boolean compareStats(BasicStatsSet expected, BasicStatsSet actual) {
int expectedCount = expected.getStatsCount();
int actualCount = actual.getStatsCount();
if (expectedCount != actualCount) {
return false;
}
for (STAT stat : expected.getStats()) {
FixedDecimalsInteger expectedValue = expected.getStat(stat);
FixedDecimalsInteger actualValue = actual.getStat(stat);
if (actualValue == null) {
return false;
}
int expectedInternalValue = expectedValue.getInternalValue();
int actualInternalValue = actualValue.getInternalValue();
if (Math.abs(expectedInternalValue - actualInternalValue) > 100) {
return false;
}
}
return true;
}
use of delta.games.lotro.utils.FixedDecimalsInteger in project lotro-tools by dmorcellet.
the class TulkasItemsLoader1 method buildItem.
private Item buildItem(Integer id, HashMap<Object, Object> map) {
String name = (String) map.get("Name");
String slot = (String) map.get("Slot");
EquipmentLocation loc = EquipmentLocation.getByName(slot);
Item ret = null;
@SuppressWarnings("unchecked") HashMap<Object, Object> statsMap = (HashMap<Object, Object>) map.get("Stats");
if (TulkasConstants.isArmor(loc)) {
Armour a = new Armour();
Integer armourValue = (Integer) statsMap.get("Armour");
if (armourValue != null) {
a.setArmourValue(armourValue.intValue());
}
String armourTypeStr = (String) map.get("Type");
ArmourType armourType = ArmourType.getArmourTypeByName(armourTypeStr);
if (loc == EquipmentLocation.OFF_HAND) {
String subSlot = (String) map.get("SubSlot");
if ("Heavy".equals(subSlot))
armourType = ArmourType.HEAVY_SHIELD;
else if ("Light".equals(subSlot))
armourType = ArmourType.SHIELD;
else if ("Warden".equals(subSlot))
armourType = ArmourType.WARDEN_SHIELD;
else {
// SubSlots:
// Heavy, Warden, Light,
_logger.warn("Unmanaged shield type [" + subSlot + "]");
}
} else if (loc == EquipmentLocation.BACK) {
armourType = ArmourType.LIGHT;
}
if (armourType == null) {
_logger.warn("Unknown armour type: [" + armourTypeStr + "] (name=" + name + ")");
}
a.setArmourType(armourType);
ret = a;
} else {
String subSlot = (String) map.get("SubSlot");
WeaponType weaponType = null;
if ((subSlot != null) && (subSlot.length() > 0)) {
weaponType = WeaponType.getWeaponTypeByName(subSlot);
}
if (weaponType != null) {
Weapon w = new Weapon();
w.setWeaponType(weaponType);
@SuppressWarnings("unchecked") HashMap<Object, Object> damageInfo = (HashMap<Object, Object>) statsMap.get("Damage");
if (damageInfo != null) {
Integer minDMG = (Integer) damageInfo.get("MinDMG");
if (minDMG != null) {
w.setMinDamage(minDMG.intValue());
}
Integer maxDMG = (Integer) damageInfo.get("MaxDMG");
if (maxDMG != null) {
w.setMaxDamage(maxDMG.intValue());
}
Object dpsValue = damageInfo.get("DPS");
if (dpsValue instanceof Float) {
w.setDPS(((Float) dpsValue).floatValue());
} else if (dpsValue instanceof Integer) {
w.setDPS(((Integer) dpsValue).floatValue());
}
String typeStr = (String) damageInfo.get("TypeDMG");
DamageType type = DamageType.getDamageTypeByName(typeStr);
if (type == null) {
type = DamageType.COMMON;
_logger.warn("Unmanaged damage type [" + typeStr + "]");
}
w.setDamageType(type);
}
ret = w;
}
if (ret == null) {
ret = new Item();
}
}
// Name
ret.setName(name);
// Slot
ret.setEquipmentLocation(loc);
// Required level
Integer requiredLevel = (Integer) map.get("Level");
ret.setMinLevel(requiredLevel);
// Item level
Integer itemLevel = (Integer) map.get("ItemLevel");
ret.setItemLevel(itemLevel);
// Class
String classStr = (String) map.get("Class");
if ((classStr != null) && (classStr.length() > 0)) {
CharacterClass cClass = CharacterClass.getByName(classStr);
if (cClass != null) {
ret.setRequiredClass(cClass);
} else {
_logger.error("Unknown class: " + classStr);
}
}
// Quality
String colorStr = (String) map.get("Color");
ItemQuality quality = null;
if (colorStr != null) {
quality = ItemQuality.fromColor(colorStr);
}
ret.setQuality((quality != null) ? quality : ItemQuality.COMMON);
// Bonus
if (statsMap != null) {
BasicStatsSet stats = ret.getStats();
final HashMap<String, Object> bonuses = new HashMap<String, Object>();
loadBonusItemsVersion1(bonuses, statsMap);
bonuses.remove("Armour");
for (int index = 0; index < TulkasConstants.BONUS_NAMES.length; index++) {
String bonusName = TulkasConstants.BONUS_NAMES[index];
Object bonusValue = bonuses.get(bonusName);
if (bonusValue != null) {
STAT stat = TulkasConstants.STATS[index];
if (stat != null) {
if (stat == STAT.ALL_SKILL_INDUCTION) {
if (bonusValue instanceof Integer)
bonusValue = Integer.valueOf(-((Integer) bonusValue).intValue());
else if (bonusValue instanceof Float)
bonusValue = Float.valueOf(-((Float) bonusValue).floatValue());
}
FixedDecimalsInteger value = TulkasValuesUtils.fromObjectValue(bonusValue);
stats.setStat(stat, value);
} else {
// _logger.warn("No stat associated to bonus: " + bonusName);
}
bonuses.remove(bonusName);
}
}
if (bonuses.size() > 0) {
_logger.warn("Unmanaged bonuses: " + bonuses);
}
}
return ret;
}
use of delta.games.lotro.utils.FixedDecimalsInteger in project lotro-tools by dmorcellet.
the class RelicsIndexPageParser method parseStats.
private BasicStatsSet parseStats(String statsStr) {
// System.out.println(statsStr);
BasicStatsSet statsSet = new BasicStatsSet();
String[] lines = statsStr.split("\n");
for (String line : lines) {
line = line.trim();
int firstSpaceIndex = line.indexOf(" ");
if (firstSpaceIndex != -1) {
String valueStr = line.substring(0, firstSpaceIndex);
String statName = line.substring(firstSpaceIndex + 1).trim();
// System.out.println("Value: "+valueStr);
// System.out.println("Stat: "+statName);
Float value = parseValue(valueStr);
STAT[] stats = parseStat(statName);
if ((value != null) && (stats != null)) {
for (STAT stat : stats) {
statsSet.addStat(stat, new FixedDecimalsInteger(value.floatValue()));
}
}
} else {
System.err.println("Cannot parse: " + line);
}
}
return statsSet;
}
use of delta.games.lotro.utils.FixedDecimalsInteger in project lotro-tools by dmorcellet.
the class MergeWithLotroPlanDb method mergeItems.
private Item mergeItems(Item source, Item lotroplan) {
int id = source.getIdentifier();
Item result = source;
// Check types
if (source.getClass() != lotroplan.getClass()) {
// System.out.println("ID: " + id+": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
if (source.getClass() == Item.class) {
if (lotroplan instanceof Armour) {
Armour armour = new Armour();
Armour lotroplanArmour = (Armour) lotroplan;
result = armour;
armour.copyFrom(source);
armour.setArmourValue(lotroplanArmour.getArmourValue());
armour.setArmourType(lotroplanArmour.getArmourType());
} else {
System.out.println("ID: " + id + ": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
}
}
if (source.getClass() == Weapon.class) {
if (lotroplan.getClass() == Item.class) {
result = source;
} else {
System.out.println("ID: " + id + ": type conflict: lotroplan=" + lotroplan.getClass() + ", source=" + source.getClass());
}
}
} else {
result = source;
}
// Name
{
String sourceName = source.getName();
/*
String lotroplanName=lotroplan.getName();
if (!lotroplanName.equals(sourceName))
{
System.out.println("ID: " + id+": name conflict: lotroplan=" + lotroplanName + ", source=" + sourceName);
if (lotroplanName!=null)
{
result.setProperty(ItemPropertyNames.LOTRO_PLAN_NAME, lotroplanName);
}
}
*/
result.setName(sourceName);
}
// Armour
{
if (lotroplan instanceof Armour) {
Armour lotroplanArmour = (Armour) lotroplan;
Armour resultArmour = (Armour) result;
// Check values
{
int lotroplanArmourValue = lotroplanArmour.getArmourValue();
/*
int resultArmourValue=resultArmour.getArmourValue();
if (lotroplanArmourValue!=resultArmourValue)
{
System.out.println("ID: " + id+": armour value conflict: lotroplan=" + lotroplanArmourValue + ", source=" + resultArmourValue);
}
*/
resultArmour.setArmourValue(lotroplanArmourValue);
}
}
}
// Item level
{
Integer sourceItemLevel = source.getItemLevel();
Integer lotroPlanItemLevel = lotroplan.getItemLevel();
boolean conflict = false;
if (lotroPlanItemLevel != null) {
if (sourceItemLevel == null) {
conflict = true;
// result.setMinLevel(tulkasMinLevel);
} else {
if (lotroPlanItemLevel.intValue() != sourceItemLevel.intValue()) {
conflict = true;
// result.setMinLevel(tulkasMinLevel);
}
}
} else {
if (sourceItemLevel != null) {
conflict = true;
// result.setMinLevel(sourceMinLevel);
}
}
if (conflict) {
// System.out.println("ID: " + id+": item level conflict: lotroplan=" + lotroPlanItemLevel + ", source=" + sourceItemLevel);
}
result.setItemLevel(lotroplan.getItemLevel());
}
// Stats
{
BasicStatsSet resultStats = result.getStats();
FixedDecimalsInteger stealth = resultStats.getStat(STAT.STEALTH_LEVEL);
FixedDecimalsInteger tacticalCritMultiplier = resultStats.getStat(STAT.TACTICAL_CRITICAL_MULTIPLIER);
resultStats.clear();
resultStats.setStats(lotroplan.getStats());
if (stealth != null) {
resultStats.setStat(STAT.STEALTH_LEVEL, stealth);
}
if (tacticalCritMultiplier != null) {
resultStats.setStat(STAT.TACTICAL_CRITICAL_MULTIPLIER, tacticalCritMultiplier);
}
}
// Essence slots
result.setEssenceSlots(lotroplan.getEssenceSlots());
// Slot
EquipmentLocation lpLocation = lotroplan.getEquipmentLocation();
if (lpLocation != null) {
EquipmentLocation location = result.getEquipmentLocation();
boolean conflict = false;
if ((location != null) && (location != lpLocation)) {
conflict = true;
}
if (conflict) {
System.out.println("ID: " + id + ": slot conflict: lotroplan=" + lpLocation + ", source=" + location);
}
result.setEquipmentLocation(lpLocation);
}
// Sub-category
String lpSubCategory = lotroplan.getSubCategory();
if ((lpSubCategory != null) && (lpSubCategory.length() > 0)) {
/*
String subCategory=result.getSubCategory();
boolean conflict=false;
if ((subCategory!=null) && (!subCategory.equals(lpSubCategory)))
{
conflict=true;
}
if (conflict)
{
System.out.println("ID: " + id+": category conflict: lotroplan=" + lpSubCategory + ", source=" + subCategory);
}
*/
result.setSubCategory("LP:" + lpSubCategory);
}
// Class requirement
CharacterClass lpClass = lotroplan.getRequiredClass();
if (lpClass != null) {
CharacterClass cClass = result.getRequiredClass();
boolean conflict = false;
if ((cClass != null) && (cClass != lpClass)) {
conflict = true;
}
if (conflict) {
System.out.println("ID: " + id + ": class conflict: lotroplan=" + lpClass + ", source=" + cClass);
}
result.setRequiredClass(lpClass);
}
// Properties
result.getProperties().putAll(lotroplan.getProperties());
return result;
}
use of delta.games.lotro.utils.FixedDecimalsInteger in project lotro-tools by dmorcellet.
the class ScalableItemsSamplesLoader method buildItemFromLine.
private Item buildItemFromLine(String line) {
String[] fields = StringSplitter.split(line, '\t');
// Stats
BasicStatsSet stats = new BasicStatsSet();
int nbStats = STATS.length;
for (int i = 0; i < nbStats; i++) {
if ((STATS[i] != null) && (fields.length > i)) {
String valueStr = fields[i];
FixedDecimalsInteger value = StatValueParser.parseStatValue(valueStr);
if (value != null) {
stats.addStat(STATS[i], value);
}
}
}
// Item level
Integer itemLevel = NumericTools.parseInteger(fields[ITEM_LEVEL_INDEX]);
// Build item
FixedDecimalsInteger armorStat = stats.getStat(STAT.ARMOUR);
Item item = null;
Armour armour = null;
if (armorStat != null) {
armour = new Armour();
item = armour;
armour.setArmourValue(armorStat.intValue());
stats.removeStat(STAT.ARMOUR);
} else {
item = new Item();
}
// Item level
item.setItemLevel(itemLevel);
// Name
String name = fields[NAME_INDEX];
name = name.trim();
item.setName(name);
// Slots
String slotStr = fields[SLOTS_INDEX];
int nbSlots = NumericTools.parseInt(slotStr, 0);
item.setEssenceSlots(nbSlots);
// Min level
String requiredLevelStr = fields[REQUIRED_LEVEL_INDEX];
Integer requiredLevel = NumericTools.parseInteger(requiredLevelStr);
if (requiredLevelStr != null) {
item.setMinLevel(requiredLevel);
}
// Stats
item.getStats().setStats(stats);
return item;
}
Aggregations