Search in sources :

Example 1 with ItemStatModifier

use of net.silentchaos512.gems.api.stats.ItemStatModifier in project SilentGems by SilentChaos512.

the class ToolStats method calculate.

public ToolStats calculate() {
    if (parts.length == 0)
        return this;
    Map<ItemStat, List<ItemStatModifier>> mods = new HashMap<>();
    for (ItemStat stat : ItemStat.ALL_STATS) {
        mods.put(stat, new ArrayList<>());
    }
    Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
    // Head (main) parts
    for (int i = 0; i < parts.length; ++i) {
        ToolPart part = parts[i];
        EnumMaterialGrade grade = grades[i];
        for (ItemStat stat : ItemStat.ALL_STATS) {
            ItemStatModifier statModifier = part.getStatModifier(stat, grade);
            if (statModifier != null) {
                mods.get(stat).add(statModifier);
            }
        }
        // float multi = (100 + grade.bonusPercent) / 100f;
        // durability += part.getDurability() * multi;
        // harvestSpeed += part.getHarvestSpeed() * multi;
        // meleeDamage += part.getMeleeDamage() * multi;
        // magicDamage += part.getMagicDamage() * multi;
        // meleeSpeed += part.getMeleeSpeed() * multi;
        // enchantability += part.getEnchantability() * multi;
        // chargeSpeed += part.getChargeSpeed() * multi;
        // protection += part.getProtection() * multi;
        // harvestLevel = Math.max(harvestLevel, part.getHarvestLevel());
        uniqueParts.add(part);
    }
    // Variety bonus
    int variety = MathHelper.clamp(uniqueParts.size(), 1, GemsConfig.VARIETY_CAP);
    float bonus = 1.0f + GemsConfig.VARIETY_BONUS * (variety - 1);
    mods.get(CommonItemStats.DURABILITY).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.HARVEST_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MELEE_DAMAGE).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MAGIC_DAMAGE).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ATTACK_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.CHARGE_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ENCHANTABILITY).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ARMOR).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MAGIC_ARMOR).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    // Tool class multipliers
    if (tool.getItem() instanceof ITool) {
        ITool itool = (ITool) tool.getItem();
        durability *= itool.getDurabilityMultiplier();
        harvestSpeed *= itool.getHarvestSpeedMultiplier();
    }
    // Rod, tip, grip, frame
    ToolPart partRod = ToolHelper.getConstructionRod(tool);
    ToolPart partTip = ToolHelper.getConstructionTip(tool);
    ToolPart partGrip = ToolHelper.getPart(tool, ToolPartPosition.ROD_GRIP);
    ToolPart partFrame = ArmorHelper.getPart(tool, ArmorPartPosition.FRAME);
    for (ToolPart part : Lists.newArrayList(partRod, partTip, partGrip, partFrame)) {
        if (part != null) {
            for (ItemStat stat : ItemStat.ALL_STATS) {
                ItemStatModifier statModifier = part.getStatModifier(stat, EnumMaterialGrade.NONE);
                if (statModifier != null) {
                    mods.get(stat).add(statModifier);
                }
            }
        }
    }
    durability = calcStat(CommonItemStats.DURABILITY, mods);
    harvestSpeed = calcStat(CommonItemStats.HARVEST_SPEED, mods);
    meleeDamage = calcStat(CommonItemStats.MELEE_DAMAGE, mods);
    magicDamage = calcStat(CommonItemStats.MAGIC_DAMAGE, mods);
    meleeSpeed = calcStat(CommonItemStats.ATTACK_SPEED, mods);
    chargeSpeed = calcStat(CommonItemStats.CHARGE_SPEED, mods);
    enchantability = calcStat(CommonItemStats.ENCHANTABILITY, mods);
    protection = calcStat(CommonItemStats.ARMOR, mods);
    harvestLevel = (int) calcStat(CommonItemStats.HARVEST_LEVEL, mods);
    return this;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) HashMap(java.util.HashMap) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ItemStatModifier(net.silentchaos512.gems.api.stats.ItemStatModifier) ArrayList(java.util.ArrayList) List(java.util.List) ITool(net.silentchaos512.gems.api.ITool) ItemStat(net.silentchaos512.gems.api.stats.ItemStat)

Example 2 with ItemStatModifier

use of net.silentchaos512.gems.api.stats.ItemStatModifier in project SilentGems by SilentChaos512.

the class ToolPartTip method getStatModifier.

@Override
public ItemStatModifier getStatModifier(ItemStat stat, EnumMaterialGrade grade) {
    float val = stats.getStat(stat);
    Operation op = ItemStatModifier.Operation.ADD;
    if (stat == CommonItemStats.ATTACK_SPEED)
        val -= 1f;
    else if (stat == CommonItemStats.HARVEST_LEVEL)
        op = ItemStatModifier.Operation.MAX;
    return new ItemStatModifier(getUnlocalizedName(), val, op);
}
Also used : ItemStatModifier(net.silentchaos512.gems.api.stats.ItemStatModifier) Operation(net.silentchaos512.gems.api.stats.ItemStatModifier.Operation)

Aggregations

ItemStatModifier (net.silentchaos512.gems.api.stats.ItemStatModifier)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ITool (net.silentchaos512.gems.api.ITool)1 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)1 ItemStat (net.silentchaos512.gems.api.stats.ItemStat)1 Operation (net.silentchaos512.gems.api.stats.ItemStatModifier.Operation)1 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)1