use of delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider in project lotro-tools by dmorcellet.
the class MainTestStatsComputer method doStat.
private void doStat(int itemLevel, String formula) {
ItemStatSliceData slice = SliceFormulaParser.parse(formula);
SlicesBasedItemStatsProvider provider = new SlicesBasedItemStatsProvider();
provider.addSlice(slice);
BasicStatsSet stats = provider.getStats(itemLevel);
System.out.println(stats);
}
use of delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider in project lotro-tools by dmorcellet.
the class LotroPlanItemsDbLoader method buildItemFromLine.
private Item buildItemFromLine(LotroPlanTable table, String line) {
String[] fieldsTrimmed = StringSplitter.split(line.trim(), '\t');
if (line.startsWith("#")) {
System.out.println("Ignored: " + line);
return null;
}
if (fieldsTrimmed.length < 2) {
_section = line.trim();
System.out.println("Section: " + _section);
return null;
}
String[] fields = StringSplitter.split(line, '\t');
// Item level
int itemLevel = NumericTools.parseInt(fields[LotroPlanTable.ITEM_LEVEL_INDEX], -1);
// Stats
ItemStatsProvider provider = table.loadStats(fields);
BasicStatsSet stats = provider.getStats(itemLevel);
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();
}
// ID
String idStr = "";
int notesIndex = table.getNotesIndex();
if (fields.length >= notesIndex) {
idStr = fields[notesIndex].trim();
}
int id = 0;
if (idStr.startsWith("ID:")) {
idStr = idStr.substring(3).trim();
}
id = NumericTools.parseInt(idStr, -1);
if (id != -1) {
item.setIdentifier(id);
}
// Name
String name = fields[LotroPlanTable.NAME_INDEX];
if (name.startsWith("(")) {
int index = name.indexOf(')');
idStr = name.substring(1, index).trim();
id = NumericTools.parseInt(idStr, -1);
item.setIdentifier(id);
name = name.substring(index + 1).trim();
}
if (name.endsWith(":")) {
name = name.substring(0, name.length() - 1);
}
name = name.replace(' ', ' ');
if (name.endsWith("s)")) {
name = name.substring(0, name.length() - 2);
int index = name.lastIndexOf('(');
int nbSlots = NumericTools.parseInt(name.substring(index + 1), 0);
name = name.substring(0, index).trim();
item.setEssenceSlots(nbSlots);
}
if (name.endsWith(")")) {
String newName = name.substring(0, name.length() - 1);
int index = newName.lastIndexOf('(');
String valueStr = newName.substring(index + 1);
int minLevel;
if ("TBD".equals(valueStr)) {
minLevel = -1;
} else {
minLevel = NumericTools.parseInt(valueStr, -1);
name = newName.substring(0, index).trim();
}
if (minLevel > 0) {
item.setMinLevel(Integer.valueOf(minLevel));
}
}
name = name.trim();
item.setName(name);
// Item level
if (itemLevel != -1) {
item.setItemLevel(Integer.valueOf(itemLevel));
}
// Stats
item.getStats().setStats(stats);
String slices = provider.toPersistableString();
int nbSlices = ((SlicesBasedItemStatsProvider) provider).getSlices();
if (nbSlices > 0) {
item.setProperty(ItemPropertyNames.FORMULAS, slices);
}
// Slot
EquipmentLocation slot = null;
if ("Head".equals(_section))
slot = EquipmentLocation.HEAD;
else if ("Shoulders".equals(_section))
slot = EquipmentLocation.SHOULDER;
else if ("Chest".equals(_section))
slot = EquipmentLocation.CHEST;
else if ("Hands".equals(_section))
slot = EquipmentLocation.HAND;
else if ("Legs".equals(_section))
slot = EquipmentLocation.LEGS;
else if ("Feet".equals(_section))
slot = EquipmentLocation.FEET;
else if ("Shields".equals(_section))
slot = EquipmentLocation.OFF_HAND;
else if ("Ears".equals(_section))
slot = EquipmentLocation.EAR;
else if ("Neck".equals(_section))
slot = EquipmentLocation.NECK;
else if ("Wrists".equals(_section))
slot = EquipmentLocation.WRIST;
else if ("Fingers".equals(_section))
slot = EquipmentLocation.FINGER;
else if ("Pockets".equals(_section))
slot = EquipmentLocation.POCKET;
if (slot == null) {
int categoryIndex = table.getCategoryIndex();
if ((categoryIndex > 0) && (fields.length >= categoryIndex)) {
String category = fields[categoryIndex];
slot = getSlotFromCategory(category);
}
}
// Class requirement
String classRequirementStr = "";
int classesIndex = table.getClassesIndex();
if ((classesIndex != -1) && (fields.length >= classesIndex)) {
classRequirementStr = fields[classesIndex].trim();
}
CharacterClass classRequirement = getClassRequirement(classRequirementStr);
if (classRequirement != null) {
item.setRequiredClass(classRequirement);
}
if ("Burglar Signals".equals(_section)) {
item.setSubCategory("Burglar:Signal");
slot = EquipmentLocation.RANGED_ITEM;
item.setRequiredClass(CharacterClass.BURGLAR);
} else if ("Captain Standards".equals(_section)) {
item.setSubCategory("Captain:Standard");
slot = EquipmentLocation.RANGED_ITEM;
item.setRequiredClass(CharacterClass.CAPTAIN);
} else if ("Hunter Tomes".equals(_section)) {
String subCategory = "Tome";
if (name.contains("Wind-rider"))
subCategory = "Wind-rider";
if (name.contains("Whisper-draw"))
subCategory = "Whisper-draw";
item.setSubCategory("Hunter:" + subCategory);
slot = EquipmentLocation.CLASS_SLOT;
item.setRequiredClass(CharacterClass.HUNTER);
} else if ("Lore-master Brooches".equals(_section)) {
item.setSubCategory("Lore-master:Stickpin");
slot = EquipmentLocation.RANGED_ITEM;
item.setRequiredClass(CharacterClass.LORE_MASTER);
} else if ("Minstrel Instruments".equals(_section)) {
item.setSubCategory("Instrument");
slot = EquipmentLocation.RANGED_ITEM;
item.setRequiredClass(CharacterClass.MINSTREL);
} else if ("Rune-keeper Chisels".equals(_section)) {
String subCategory = "Other";
if (name.contains("Riffler"))
subCategory = "Riffler";
if (name.contains("Chisel"))
subCategory = "Chisel";
item.setSubCategory("Rune-keeper:" + subCategory);
slot = EquipmentLocation.RANGED_ITEM;
item.setRequiredClass(CharacterClass.RUNE_KEEPER);
} else if ("Warden Carvings".equals(_section)) {
item.setSubCategory("Warden:Carving");
slot = EquipmentLocation.CLASS_SLOT;
item.setRequiredClass(CharacterClass.WARDEN);
}
if (slot != null) {
item.setEquipmentLocation(slot);
}
return item;
}
use of delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider in project lotro-tools by dmorcellet.
the class LotroPlanTable method loadStats.
/**
* Load stats from fields.
* @param fields Fields to read.
* @return An item stats provider or <code>null</code>.
*/
public ItemStatsProvider loadStats(String[] fields) {
SlicesBasedItemStatsProvider provider = new SlicesBasedItemStatsProvider();
int nbStats = _stats.length;
for (int index = 0; index < nbStats; index++) {
STAT stat = _stats[index];
if (stat == null)
continue;
if (index >= fields.length)
continue;
String valueStr = fields[index];
if (valueStr.contains("CALCSLICE")) {
ItemStatSliceData slice = SliceFormulaParser.parse(valueStr);
if (slice != null) {
provider.addSlice(slice);
}
} else {
FixedDecimalsInteger value = StatValueParser.parseStatValue(valueStr);
if (value != null) {
provider.setStat(stat, value);
}
}
}
return provider;
}
use of delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider in project lotro-tools by dmorcellet.
the class ScalingParametersFinder method findScalingParameters.
private void findScalingParameters(Item item) {
BasicStatsSet stats = item.getStats();
if (stats.getStatsCount() == 0) {
System.err.println("Cannot manage item: " + item + ": no stats");
return;
}
Integer itemLevel = item.getItemLevel();
if (itemLevel == null) {
System.err.println("Cannot manage item: " + item + ": no item level");
return;
}
SliceCountFinder converter = _converters.get(itemLevel);
if (converter == null) {
converter = new SliceCountFinder(itemLevel.intValue());
_converters.put(itemLevel, converter);
}
if (item instanceof Armour) {
Armour armour = (Armour) item;
int armourValue = armour.getArmourValue();
stats.setStat(STAT.ARMOUR, new FixedDecimalsInteger(armourValue));
}
SlicesBasedItemStatsProvider provider = new SlicesBasedItemStatsProvider();
for (STAT stat : stats.getStats()) {
FixedDecimalsInteger value = stats.getStat(stat);
int statValue = value.getInternalValue();
ItemStatSliceData slice = null;
// Specific case for armour
if (stat == STAT.ARMOUR) {
ArmourDescriptionFinder armourConverter = _armourConverters.get(itemLevel);
if (armourConverter == null) {
armourConverter = new ArmourDescriptionFinder(itemLevel.intValue(), false);
_armourConverters.put(itemLevel, armourConverter);
}
ArmourType armourType = ((Armour) item).getArmourType();
EquipmentLocation location = item.getEquipmentLocation();
ItemQuality quality = item.getQuality();
String label = armourConverter.getArmourDescription(statValue, armourType, location, quality);
if (label != null) {
slice = new ItemStatSliceData(stat, null, label);
} else {
System.err.println("Armour not found: " + statValue + " for item " + item + ", quality=" + item.getQuality() + ", slot=" + item.getEquipmentLocation() + ", type=" + armourType);
}
} else if ((stat == STAT.PARRY_PERCENTAGE) || (stat == STAT.RANGED_DEFENCE_PERCENTAGE)) {
// Skip... will be put as raw stats
} else // Other stats
{
Float sliceCount = converter.getSliceCount(stat, statValue);
if (sliceCount != null) {
slice = new ItemStatSliceData(stat, sliceCount, null);
} else {
System.err.println("Stat not found: " + stat + "=" + statValue + " for item " + item + ", quality=" + item.getQuality() + ", slot=" + item.getEquipmentLocation());
}
}
if (slice != null) {
provider.addSlice(slice);
} else {
provider.setStat(stat, value);
}
}
stats.removeStat(STAT.ARMOUR);
String slices = provider.toPersistableString();
item.setProperty(ItemPropertyNames.FORMULAS, slices);
item.setProperty(ItemPropertyNames.SCALING, _scalingId);
}
use of delta.games.lotro.lore.items.stats.SlicesBasedItemStatsProvider in project lotro-tools by dmorcellet.
the class ItemsMerger method inspectScalableItems.
private Item inspectScalableItems(Item item, List<Item> selectedItems, StringBuilder sb) {
List<Item> matchingItems = new ArrayList<Item>();
String slices = item.getProperty(ItemPropertyNames.FORMULAS);
if (slices != null) {
SlicesBasedItemStatsProvider provider = SlicesBasedItemStatsProvider.fromPersistedString(slices);
if (provider != null) {
for (Item selectedItem : selectedItems) {
Integer selectedItemLevel = selectedItem.getItemLevel();
if ((selectedItemLevel != null) && (provider != null)) {
BasicStatsSet scaledStats = provider.getStats(selectedItemLevel.intValue());
scaledStats.removeStat(STAT.ARMOUR);
BasicStatsSet itemStats = selectedItem.getStats();
boolean same = compareStats(itemStats, scaledStats);
if (same) {
// System.out.println("Item " + item + " and " + selectedItem + " are versions of the same scalable item.");
String itemLevels = buildItemLevelProperty(selectedItemLevel, item.getItemLevel());
selectedItem.setProperty(ItemPropertyNames.LEVELS, itemLevels);
matchingItems.add(selectedItem);
} else {
sb.append("Stats are different: " + item + " != " + selectedItem + "\n");
sb.append("Scaled: " + scaledStats + "\n");
sb.append("Expected: " + itemStats + "\n");
}
}
}
}
}
Item matchingItem = null;
if (matchingItems.size() > 0) {
if (matchingItems.size() > 1) {
sb.append("Several matches for " + item + ": " + matchingItems + "\n");
} else {
matchingItem = matchingItems.get(0);
sb.setLength(0);
}
}
return matchingItem;
}
Aggregations