Search in sources :

Example 26 with Affinity

use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.

the class SetAffinityCommand method processCommand.

@Override
public void processCommand(ICommandSender var1, String[] var2) {
    if (var2.length != 3 && var2.length != 2) {
        throw new WrongUsageException(this.getCommandUsage(var1), new Object[0]);
    }
    EntityPlayer player = null;
    String affinity = "";
    float depth = 0f;
    if (var2.length == 3) {
        player = getPlayer(var1, var2[0]);
        affinity = var2[1].toUpperCase();
        depth = tryParseInt(var2[2]);
    } else {
        player = getCommandSenderAsPlayer(var1);
        affinity = var2[0].toUpperCase();
        depth = tryParseInt(var2[1]);
    }
    if (player == null)
        return;
    Affinity enumAffinity;
    try {
        enumAffinity = Affinity.valueOf(affinity);
    } catch (Throwable t) {
        player.addChatMessage(new ChatComponentText("Unknown affinity name specified."));
        return;
    }
    AffinityData.For(player).setAffinityAndDepth(enumAffinity, depth);
    AffinityData.For(player).forceSync();
    func_152373_a(var1, this, "Setting " + player.getCommandSenderName() + "'s " + affinity + " affinity level to " + depth, new Object[0]);
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Affinity(am2.api.spell.enums.Affinity) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 27 with Affinity

use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.

the class SpellUtils method AffinityFor.

public HashMap<Affinity, Float> AffinityFor(ItemStack stack) {
    HashMap<Affinity, Integer> affinityFrequency = new HashMap<Affinity, Integer>();
    HashMap<Affinity, Float> affinities = new HashMap<Affinity, Float>();
    float totalAffinityEntries = 0;
    if (stack.stackTagCompound.hasKey(ForcedAffinity)) {
        int aff = stack.stackTagCompound.getInteger(ForcedAffinity);
        affinities.put(Affinity.values()[aff], 100f);
        return affinities;
    }
    for (int i = 0; i < numStages(stack); ++i) {
        for (ISpellComponent comp : getComponentsForStage(stack, i)) {
            if (comp == SkillManager.instance.missingComponent)
                continue;
            EnumSet<Affinity> affList = comp.getAffinity();
            for (Affinity affinity : affList) {
                totalAffinityEntries++;
                if (!affinityFrequency.containsKey(affinity)) {
                    affinityFrequency.put(affinity, 1);
                } else {
                    int old = affinityFrequency.get(affinity);
                    affinityFrequency.put(affinity, old + 1);
                }
            }
        }
    }
    for (Affinity key : affinityFrequency.keySet()) {
        int count = affinityFrequency.get(key);
        float percent = (totalAffinityEntries > 0) ? count / totalAffinityEntries : 0;
        affinities.put(key, percent);
    }
    return affinities;
}
Also used : HashMap(java.util.HashMap) Affinity(am2.api.spell.enums.Affinity)

Example 28 with Affinity

use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.

the class SpellUtils method mainAffinityFor.

public Affinity mainAffinityFor(ItemStack stack) {
    if (!stack.hasTagCompound())
        return Affinity.NONE;
    if (stack.stackTagCompound.hasKey(ForcedAffinity)) {
        int aff = stack.stackTagCompound.getInteger(ForcedAffinity);
        return Affinity.values()[aff];
    }
    HashMap<Integer, Integer> affinityFrequency = new HashMap<Integer, Integer>();
    for (int i = 0; i < numStages(stack); ++i) {
        for (ISpellComponent comp : getComponentsForStage(stack, i)) {
            EnumSet<Affinity> affList = comp.getAffinity();
            for (Affinity affinity : affList) {
                if (!affinityFrequency.containsKey(affinity.ordinal())) {
                    affinityFrequency.put(affinity.ordinal(), 1);
                } else {
                    int old = affinityFrequency.get(affinity.ordinal());
                    affinityFrequency.put(affinity.ordinal(), old + 1);
                }
            }
        }
    }
    int highestCount = 0;
    int highestID = 0;
    for (Integer key : affinityFrequency.keySet()) {
        int count = affinityFrequency.get(key);
        if (count > highestCount) {
            highestID = key;
            highestCount = count;
        }
    }
    return Affinity.values()[highestID];
}
Also used : HashMap(java.util.HashMap) Affinity(am2.api.spell.enums.Affinity)

Example 29 with Affinity

use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.

the class AffinityData method incrementAffinity.

/**
 * Increments the affinity by the specified amount, and decrements other affinities by an amount related to
 * how much in opposition they are to the specified affinity.
 *
 * @param affinity The affinity to increase
 * @param amt      The amount to increase the affinity by
 */
@Override
public void incrementAffinity(Affinity affinity, float amt) {
    if (affinity == Affinity.NONE || isLocked)
        return;
    float adjacentDecrement = amt * ADJACENT_FACTOR;
    float minorOppositeDecrement = amt * MINOR_OPPOSING_FACTOR;
    float majorOppositeDecrement = amt * MAJOR_OPPOSING_FACTOR;
    addToAffinity(affinity, amt);
    if (getAffinityDepth(affinity) * MAX_DEPTH == MAX_DEPTH) {
        isLocked = true;
    }
    for (Affinity adjacent : affinity.getAdjacentAffinities()) {
        subtractFromAffinity(adjacent, adjacentDecrement);
    }
    for (Affinity minorOpposite : affinity.getMinorOpposingAffinities()) {
        subtractFromAffinity(minorOpposite, minorOppositeDecrement);
    }
    for (Affinity majorOpposite : affinity.getMajorOpposingAffinities()) {
        subtractFromAffinity(majorOpposite, majorOppositeDecrement);
    }
    Affinity directOpposite = affinity.getOpposingAffinity();
    if (directOpposite != null) {
        subtractFromAffinity(directOpposite, amt);
    }
    this.hasUpdate = true;
    updateHighestAffinities();
}
Also used : Affinity(am2.api.spell.enums.Affinity)

Example 30 with Affinity

use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.

the class ItemFlickerJar method getItemStackDisplayName.

@Override
public String getItemStackDisplayName(ItemStack stack) {
    int meta = stack.getItemDamage();
    String baseName = StatCollector.translateToLocal("am2.item.flickerJar");
    if (meta == 0)
        return String.format(StatCollector.translateToLocal("item.arsmagica2:flickerJar.name"), StatCollector.translateToLocal("am2.tooltip.empty"));
    Affinity aff = Affinity.values()[meta];
    baseName = String.format(StatCollector.translateToLocal("item.arsmagica2:flickerJar.name"), toProperCase(aff.name()));
    return baseName;
}
Also used : Affinity(am2.api.spell.enums.Affinity)

Aggregations

Affinity (am2.api.spell.enums.Affinity)27 AffinityData (am2.playerextensions.AffinityData)6 ItemStack (net.minecraft.item.ItemStack)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 TileEntity (net.minecraft.tileentity.TileEntity)4 ArrayList (java.util.ArrayList)3 AMVector2 (am2.api.math.AMVector2)2 AMVector3 (am2.api.math.AMVector3)2 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)2 AMParticle (am2.particles.AMParticle)2 Colour (am2.spell.modifiers.Colour)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 ManaCostEvent (am2.api.events.ManaCostEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1