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]);
}
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;
}
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];
}
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();
}
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;
}
Aggregations