Search in sources :

Example 1 with EnumSoulElement

use of net.silentchaos512.gems.lib.soul.EnumSoulElement in project SilentGems by SilentChaos512.

the class PageSoulSkill method getInfoText.

@Override
public String getInfoText() {
    String elementPreference = skill.favoredElements.length == 0 ? "none" : skill.isLockedToFavoredElements() ? "lockedTo" : "favors";
    String elements = "";
    for (EnumSoulElement elem : skill.favoredElements) {
        if (!elements.isEmpty())
            elements += ", ";
        elements += elem.getDisplayName();
    }
    elementPreference = book.loc.getLocalizedString("guide.silentgems:soulSkillPage.elements." + elementPreference, (elementPreference.equals("none") ? new Object[0] : elements));
    String str = book.loc.getLocalizedString("guide", "soulSkillPage", skill.getLocalizedName(null, 0), Integer.toString(skill.maxLevel), Integer.toString(skill.apCost), elementPreference);
    str += "\n\n" + book.loc.getLocalizedString(this.getLocalizationKey());
    return doTextReplacements(str);
}
Also used : EnumSoulElement(net.silentchaos512.gems.lib.soul.EnumSoulElement)

Example 2 with EnumSoulElement

use of net.silentchaos512.gems.lib.soul.EnumSoulElement in project SilentGems by SilentChaos512.

the class SoulSkill method selectSkillToLearn.

public static SoulSkill selectSkillToLearn(ToolSoul soul, ItemStack tool) {
    // if (soul.getLevel() == 5) {
    // return SUPER_SKILL;
    // }
    Map<SoulSkill, Double> candidates = new LinkedHashMap<>();
    // Create list of candidates
    for (SoulSkill skill : SKILL_LIST.values()) {
        if (skill.canLearn(soul, tool)) {
            boolean favorsElement = false;
            // Select a weight based on favored elements.
            double weight = skill.favoredElements.length < 1 ? 20 : 7;
            for (EnumSoulElement elem : skill.favoredElements) {
                if (elem == soul.getPrimaryElement()) {
                    weight = 20;
                    favorsElement = true;
                    break;
                } else if (elem == soul.getSecondaryElement()) {
                    weight = 15;
                    favorsElement = true;
                    break;
                }
            }
            // Favors certain tool types?
            if (skill.favoredType != EnumToolType.NONE) {
                EnumToolType toolType = tool.getItem() instanceof ITool ? ((ITool) tool.getItem()).getToolType() : tool.getItem() instanceof IArmor ? ((IArmor) tool.getItem()).getToolType() : EnumToolType.NONE;
                if (toolType == skill.favoredType) {
                    weight += 5;
                }
            }
            // If skill has a median level, apply that to the weight.
            if (skill.medianXpLevel > 0) {
                int diff = Math.abs(soul.level - skill.medianXpLevel);
                if (diff > 6) {
                    diff = 6;
                }
                weight -= 0.75 * diff;
            }
            // If a lower level of the skill is already known, reduce the weight.
            if (soul.skills.containsKey(skill)) {
                weight -= 2.5 * soul.skills.get(skill);
            }
            // Base weight diff, favors multiplier
            weight += skill.weightDiff;
            if (favorsElement) {
                weight *= skill.favorWeightMulti;
            }
            // Make sure weight is at least 1.
            if (weight < 1) {
                weight = 1;
            }
            candidates.put(skill, weight);
        }
    }
    // Seed based on soul elements, level, and tool UUID.
    Random rand = new Random(soul.getPrimaryElement().ordinal() + (soul.getSecondaryElement().ordinal() << 4) + (soul.getLevel() << 8) + (ToolHelper.getUUID(tool).getLeastSignificantBits() << 16));
    // Weighted random selection.
    SoulSkill selected = null;
    double bestValue = Double.MIN_VALUE;
    for (SoulSkill skill : candidates.keySet()) {
        double value = -Math.log(rand.nextFloat() / candidates.get(skill));
        SilentGems.logHelper.debug(skill.id, candidates.get(skill), value, bestValue);
        if (value > bestValue) {
            bestValue = value;
            selected = skill;
        }
    }
    return selected;
}
Also used : Random(java.util.Random) EnumToolType(net.silentchaos512.gems.lib.EnumToolType) EnumSoulElement(net.silentchaos512.gems.lib.soul.EnumSoulElement) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with EnumSoulElement

use of net.silentchaos512.gems.lib.soul.EnumSoulElement in project SilentGems by SilentChaos512.

the class ToolSoul method randomSoul.

public static ToolSoul randomSoul() {
    ToolSoul soul = new ToolSoul();
    List<EnumSoulElement> elements = new ArrayList<>();
    for (EnumSoulElement elem : EnumSoulElement.values()) {
        if (elem != EnumSoulElement.NONE) {
            elements.add(elem);
        }
    }
    soul.element1 = elements.get(SilentGems.random.nextInt(elements.size()));
    elements.remove(soul.element1);
    elements.add(EnumSoulElement.NONE);
    soul.element2 = elements.get(SilentGems.random.nextInt(elements.size()));
    return soul;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ArrayList(java.util.ArrayList)

Example 4 with EnumSoulElement

use of net.silentchaos512.gems.lib.soul.EnumSoulElement in project SilentGems by SilentChaos512.

the class ToolSoul method construct.

public static ToolSoul construct(ItemSoulGem.Soul... souls) {
    // Soul weight map
    Map<EnumSoulElement, Integer> elements = new HashMap<>();
    for (ItemSoulGem.Soul soul : souls) {
        int current = elements.containsKey(soul.element1) ? elements.get(soul.element1) : 0;
        elements.put(soul.element1, current + 5);
        if (soul.element2 != EnumSoulElement.NONE) {
            current = elements.containsKey(soul.element2) ? elements.get(soul.element2) : 0;
            elements.put(soul.element2, current + 3);
        }
    }
    // Highest weight becomes element 1, second becomes element 2.
    ToolSoul toolSoul = new ToolSoul();
    // Primary
    toolSoul.element1 = selectHighestWeight(elements);
    elements.remove(toolSoul.element1);
    // Secondary (if any are left)
    if (!elements.isEmpty()) {
        toolSoul.element2 = selectHighestWeight(elements);
    }
    return toolSoul;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemSoulGem(net.silentchaos512.gems.item.ItemSoulGem)

Example 5 with EnumSoulElement

use of net.silentchaos512.gems.lib.soul.EnumSoulElement in project SilentGems by SilentChaos512.

the class ToolSoul method readFromNBT.

public static ToolSoul readFromNBT(NBTTagCompound tags) {
    ToolSoul soul = new ToolSoul();
    soul.name = tags.getString("name");
    String e1 = tags.getString("element1");
    String e2 = tags.getString("element2");
    for (EnumSoulElement element : EnumSoulElement.values()) {
        if (element.name().equalsIgnoreCase(e1)) {
            soul.element1 = element;
        } else if (element.name().equalsIgnoreCase(e2)) {
            soul.element2 = element;
        }
    }
    soul.xp = tags.getInteger("xp");
    soul.level = tags.getInteger("level");
    soul.actionPoints = tags.getInteger("ap");
    // Load skills
    soul.skills.clear();
    NBTTagList tagList = tags.getTagList("skills", 10);
    for (int i = 0; i < tagList.tagCount(); ++i) {
        NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
        SoulSkill skill = SoulSkill.getById(tagCompound.getString("id"));
        if (skill != null) {
            int level = tagCompound.getShort("level");
            soul.skills.put(skill, level);
        }
    // Skills with unknown IDs are ignored!
    }
    return soul;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)3 LinkedHashMap (java.util.LinkedHashMap)2 EnumSoulElement (net.silentchaos512.gems.lib.soul.EnumSoulElement)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 IArmor (net.silentchaos512.gems.api.IArmor)1 ITool (net.silentchaos512.gems.api.ITool)1 ItemSoulGem (net.silentchaos512.gems.item.ItemSoulGem)1 EnumToolType (net.silentchaos512.gems.lib.EnumToolType)1