Some work on changing how EmcValues work
This commit is contained in:
parent
4a3ddeac6e
commit
0335767923
|
@ -27,7 +27,6 @@ import com.pahimar.ee3.core.helper.VersionHelper;
|
|||
import com.pahimar.ee3.core.proxy.CommonProxy;
|
||||
import com.pahimar.ee3.creativetab.CreativeTabEE3;
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
import com.pahimar.ee3.item.ModItems;
|
||||
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
|
||||
import com.pahimar.ee3.lib.InterModComms;
|
||||
|
@ -173,7 +172,7 @@ public class EquivalentExchange3 {
|
|||
// Initialize the Addon Handler
|
||||
AddonHandler.init();
|
||||
|
||||
EmcRegistry.hasEmcValue(new CustomWrappedStack(Block.wood));
|
||||
EmcRegistry.printDebug();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -4,8 +4,8 @@ import net.minecraft.util.EnumChatFormatting;
|
|||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import com.pahimar.ee3.emc.EmcComponent;
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.emc.EmcType;
|
||||
import com.pahimar.ee3.emc.EmcValue;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
import com.pahimar.ee3.item.OreStack;
|
||||
|
@ -42,11 +42,13 @@ public class ItemTooltipEventHandler {
|
|||
EmcValue emcValue = EmcRegistry.getEmcValue(stack);
|
||||
|
||||
event.toolTip.add("");
|
||||
event.toolTip.add("EMC: " + emcValue.value);
|
||||
event.toolTip.add("EMC: " + emcValue.getValue());
|
||||
|
||||
if (debug) {
|
||||
for (EmcComponent emcComponent : emcValue.getComponents()) {
|
||||
event.toolTip.add(" * " + emcComponent.getType() + ": " + emcValue.getComponentValueByType(emcComponent.getType()));
|
||||
for (EmcType emcType : EmcType.TYPES) {
|
||||
if (emcValue.components[emcType.ordinal()] > 0) {
|
||||
event.toolTip.add(" * " + emcType + ": " + emcValue.components[emcType.ordinal()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ public class EmcHelper {
|
|||
|
||||
EmcValue value = EmcRegistry.getEmcValue(stack);
|
||||
boolean satisfiesFilter = true;
|
||||
float[] valueSubValues = value.getComponentSubValues();
|
||||
float[] filterValueSubValues = filterValue.getComponentSubValues();
|
||||
float[] valueSubValues = value.components;
|
||||
float[] filterValueSubValues = filterValue.components;
|
||||
|
||||
for (int i = 0; i < valueSubValues.length; i++) {
|
||||
if (Float.compare(valueSubValues[i], filterValueSubValues[i]) < 0) {
|
||||
|
|
|
@ -11,13 +11,19 @@ public class EmcComponent implements Comparable<EmcComponent> {
|
|||
public static final EmcComponent AMORPHOUS_UNIT_COMPONENT = new EmcComponent(EmcType.AMORPHOUS);
|
||||
public static final EmcComponent VOID_UNIT_COMPONENT = new EmcComponent(EmcType.VOID);
|
||||
|
||||
private final EmcType type;
|
||||
private final int ratioWeight;
|
||||
public final EmcType type;
|
||||
public final int weight;
|
||||
|
||||
public EmcComponent(EmcType type, int ratioWeight) {
|
||||
public EmcComponent(EmcType type, int weight) {
|
||||
|
||||
this.type = type;
|
||||
this.ratioWeight = ratioWeight;
|
||||
|
||||
if (weight > 0) {
|
||||
this.weight = weight;
|
||||
}
|
||||
else {
|
||||
this.weight = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public EmcComponent(EmcType type) {
|
||||
|
@ -25,16 +31,6 @@ public class EmcComponent implements Comparable<EmcComponent> {
|
|||
this(type, 1);
|
||||
}
|
||||
|
||||
public EmcType getType() {
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getRatioWeight() {
|
||||
|
||||
return ratioWeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
|
||||
|
@ -44,7 +40,7 @@ public class EmcComponent implements Comparable<EmcComponent> {
|
|||
|
||||
EmcComponent emcComponent = (EmcComponent) object;
|
||||
|
||||
return ((this.type == emcComponent.type) && (this.ratioWeight == emcComponent.ratioWeight));
|
||||
return ((this.type == emcComponent.type) && (this.weight == emcComponent.weight));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +48,7 @@ public class EmcComponent implements Comparable<EmcComponent> {
|
|||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(String.format("<EMC Type: %s, Ratio Weight: %s>", type, ratioWeight));
|
||||
stringBuilder.append(String.format("<EMC Type: %s, Weight: %s>", type, weight));
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
@ -62,7 +58,7 @@ public class EmcComponent implements Comparable<EmcComponent> {
|
|||
|
||||
if (emcComponent != null) {
|
||||
if (this.type == emcComponent.type) {
|
||||
return (this.ratioWeight - emcComponent.ratioWeight);
|
||||
return (this.weight - emcComponent.weight);
|
||||
}
|
||||
else {
|
||||
return this.type.compareTo(emcComponent.type);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -10,7 +10,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
import com.pahimar.ee3.item.EnergyStack;
|
||||
import com.pahimar.ee3.item.crafting.RecipeRegistry;
|
||||
|
||||
public class EmcDefaultValues {
|
||||
|
@ -38,85 +37,74 @@ public class EmcDefaultValues {
|
|||
valueMap.put(new CustomWrappedStack(Block.dirt), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.cobblestone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.sand), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
|
||||
valueMap.put(new CustomWrappedStack(Block.leaves), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
|
||||
valueMap.put(new CustomWrappedStack(Block.leaves), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
||||
valueMap.put(new CustomWrappedStack(Block.glass), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.tallGrass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
|
||||
for (int meta = 0; meta < 16; meta ++) {
|
||||
valueMap.put(new CustomWrappedStack(new ItemStack(Block.tallGrass.blockID, 1, meta)), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
|
||||
valueMap.put(new CustomWrappedStack(Block.tallGrass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
||||
for (int meta = 0; meta < 16; meta++) {
|
||||
valueMap.put(new CustomWrappedStack(new ItemStack(Block.tallGrass.blockID, 1, meta)), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
||||
}
|
||||
valueMap.put(new CustomWrappedStack(Block.deadBush), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.ice), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
|
||||
|
||||
valueMap.put(new CustomWrappedStack(Block.wood), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreGold), new EmcValue(2048, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreDiamond), new EmcValue(8192, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreCoal), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.KINETIC, 1))));
|
||||
|
||||
valueMap.put(new CustomWrappedStack(new EnergyStack(EnergyStack.VANILLA_SMELTING_ENERGY_NAME)), new EmcValue(valueMap.get(new CustomWrappedStack(Block.oreCoal)).getComponentValueByType(EmcType.KINETIC) / (8 * EnergyStack.VANILLA_SMELTING_ENERGY_THRESHOLD), EmcComponent.KINETIC_UNIT_COMPONENT));
|
||||
|
||||
// Temp, testing resolution on multiple passes through
|
||||
for (int i = 0; i < 16; i++) {
|
||||
attemptValueAssignment();
|
||||
}
|
||||
// TODO Multiple passes for value computation
|
||||
attemptValueAssignment();
|
||||
}
|
||||
|
||||
private void attemptValueAssignment() {
|
||||
|
||||
|
||||
private List<CustomWrappedStack> attemptValueAssignment() {
|
||||
|
||||
List<CustomWrappedStack> computedStacks = new ArrayList<CustomWrappedStack>();
|
||||
|
||||
for (CustomWrappedStack stack : RecipeRegistry.getDiscoveredStacks()) {
|
||||
|
||||
if (!valueMap.containsKey(stack)) {
|
||||
|
||||
for (CustomWrappedStack recipeOutput : RecipeRegistry.getRecipeMappings().keySet()) {
|
||||
|
||||
if (recipeOutput.getWrappedStack().equals(stack.getWrappedStack())) {
|
||||
Collection<List<CustomWrappedStack>> recipeInputLists = RecipeRegistry.getRecipeMappings().get(recipeOutput);
|
||||
for (List<CustomWrappedStack> recipeInputs : recipeInputLists) {
|
||||
if (listEmcCheck(recipeInputs)) {
|
||||
valueMap.put(stack, computeEmcValueFromList(recipeOutput.getStackSize(), recipeInputs));
|
||||
|
||||
for (List<CustomWrappedStack> recipeInputs : RecipeRegistry.getRecipeMappings().get(recipeOutput)) {
|
||||
|
||||
EmcValue computedValue = computeEmcValueFromList(recipeOutput.getStackSize(), recipeInputs);
|
||||
|
||||
if (computedValue instanceof EmcValue) {
|
||||
valueMap.put(stack, computedValue);
|
||||
computedStacks.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return computedStacks;
|
||||
}
|
||||
|
||||
private boolean listEmcCheck(List<CustomWrappedStack> stacks) {
|
||||
|
||||
boolean everyElementHasEmc = true;
|
||||
|
||||
if (stacks.size() > 0) {
|
||||
for (CustomWrappedStack stack : stacks) {
|
||||
if (!valueMap.containsKey(new CustomWrappedStack(stack.getWrappedStack()))) {
|
||||
everyElementHasEmc = false;
|
||||
|
||||
private EmcValue computeEmcValueFromList(int recipeOutputSize, List<CustomWrappedStack> recipeInputs) {
|
||||
|
||||
float[] computedSubValues = new float[EmcType.TYPES.length];
|
||||
|
||||
for (CustomWrappedStack stack : recipeInputs) {
|
||||
|
||||
EmcValue stackValue = valueMap.get(new CustomWrappedStack(stack.getWrappedStack()));
|
||||
|
||||
if (stackValue != null) {
|
||||
for (EmcType emcType : EmcType.TYPES) {
|
||||
computedSubValues[emcType.ordinal()] += stackValue.components[emcType.ordinal()] * stack.getStackSize() * stackValue.recoveryPercent / recipeOutputSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return everyElementHasEmc;
|
||||
}
|
||||
|
||||
public EmcValue computeEmcValueFromList(int recipeOutputSize, List<CustomWrappedStack> recipeInputs) {
|
||||
|
||||
if (listEmcCheck(recipeInputs)) {
|
||||
EmcValue computedValue = new EmcValue();
|
||||
|
||||
for (CustomWrappedStack stack : recipeInputs) {
|
||||
computedValue = new EmcValue(computedValue.value + (stack.getStackSize() * valueMap.get(new CustomWrappedStack(stack.getWrappedStack())).value));
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO Need to come up with a better way of handling sub values/components of calculated emc values
|
||||
computedValue = new EmcValue(computedValue.value / recipeOutputSize, EmcComponent.OMNI_UNIT_COMPONENT);
|
||||
|
||||
return computedValue;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EmcValue(computedSubValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.pahimar.ee3.core.helper.LogHelper;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
public class EmcRegistry {
|
||||
|
@ -39,18 +39,19 @@ public class EmcRegistry {
|
|||
// Handle the value mappings
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> tempValueMappings = new TreeMap<EmcValue, List<CustomWrappedStack>>();
|
||||
|
||||
for (CustomWrappedStack stack : defaultValues.keySet()) {
|
||||
EmcValue value = defaultValues.get(stack);
|
||||
|
||||
if (tempValueMappings.containsKey(value)) {
|
||||
if (!(tempValueMappings.get(value).contains(stack))) {
|
||||
tempValueMappings.get(value).add(stack);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tempValueMappings.put(value, Arrays.asList(stack));
|
||||
}
|
||||
}
|
||||
// FIXME Crashes when uncommented at the moment
|
||||
// for (CustomWrappedStack stack : defaultValues.keySet()) {
|
||||
// EmcValue value = defaultValues.get(stack);
|
||||
//
|
||||
// if (tempValueMappings.containsKey(value)) {
|
||||
// if (!(tempValueMappings.get(value).contains(stack))) {
|
||||
// tempValueMappings.get(value).add(stack);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// tempValueMappings.put(value, Arrays.asList(stack));
|
||||
// }
|
||||
// }
|
||||
|
||||
valueMappingsBuilder.putAll(tempValueMappings);
|
||||
valueMappings = valueMappingsBuilder.build();
|
||||
|
@ -122,4 +123,12 @@ public class EmcRegistry {
|
|||
|
||||
return stacksInRange;
|
||||
}
|
||||
|
||||
public static void printDebug() {
|
||||
|
||||
lazyInit();
|
||||
for (CustomWrappedStack stack : emcRegistry.stackMappings.keySet()) {
|
||||
LogHelper.debug("Stack: " + stack + ", Value: " + emcRegistry.stackMappings.get(stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,6 @@ public enum EmcType {
|
|||
OMNI, CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID;
|
||||
|
||||
public static final EmcType[] TYPES = EmcType.values();
|
||||
|
||||
public static final EmcType DEFAULT = EmcType.OMNI;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.pahimar.ee3.lib.Strings;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
|
@ -18,92 +15,107 @@ import com.pahimar.ee3.lib.Strings;
|
|||
*/
|
||||
public class EmcValue implements Comparable<EmcValue> {
|
||||
|
||||
public final float value;
|
||||
public final float recoveryPercent;
|
||||
private final List<EmcComponent> components;
|
||||
public final int sumComponentRatios;
|
||||
public final float[] components;
|
||||
|
||||
public EmcValue() {
|
||||
|
||||
this(0F, 1F, new ArrayList<EmcComponent>());
|
||||
this(1F, new float[EmcType.TYPES.length]);
|
||||
}
|
||||
|
||||
public EmcValue(int value) {
|
||||
|
||||
this(Integer.valueOf(value).floatValue(), 1F, new ArrayList<EmcComponent>());
|
||||
this((float) value);
|
||||
}
|
||||
|
||||
public EmcValue(float value) {
|
||||
|
||||
this(value, 1F, new ArrayList<EmcComponent>());
|
||||
}
|
||||
|
||||
public EmcValue(float value, float recoveryPercent) {
|
||||
|
||||
this(value, recoveryPercent, new ArrayList<EmcComponent>());
|
||||
}
|
||||
|
||||
public EmcValue(float value, List<EmcComponent> components) {
|
||||
|
||||
this(value, 1F, collateComponents(components));
|
||||
this(value, 1F);
|
||||
}
|
||||
|
||||
public EmcValue(float value, EmcComponent component) {
|
||||
|
||||
this(value, 1F, Arrays.asList(component));
|
||||
this(value, 1F, component);
|
||||
}
|
||||
|
||||
public EmcValue(float value, float recoveryPercent, List<EmcComponent> components) {
|
||||
public EmcValue(float value, float recoveryPercent, EmcComponent component) {
|
||||
|
||||
this.value = value;
|
||||
this.recoveryPercent = recoveryPercent;
|
||||
this.components = collateComponents(components);
|
||||
|
||||
int count = 0;
|
||||
for (EmcComponent component : components) {
|
||||
count += component.getRatioWeight();
|
||||
}
|
||||
|
||||
this.sumComponentRatios = count;
|
||||
this.components = new float[EmcType.TYPES.length];
|
||||
this.components[component.type.ordinal()] = value;
|
||||
}
|
||||
|
||||
public List<EmcComponent> getComponents() {
|
||||
public EmcValue(int value, float recoveryPercent) {
|
||||
|
||||
return components;
|
||||
this((float) value, recoveryPercent);
|
||||
}
|
||||
|
||||
public EmcComponent getComponentByType(EmcType type) {
|
||||
public EmcValue(float value, float recoveryPercent) {
|
||||
|
||||
for (EmcComponent component : components) {
|
||||
if (component.getType().equals(type)) {
|
||||
return component;
|
||||
this.recoveryPercent = recoveryPercent;
|
||||
this.components = new float[EmcType.TYPES.length];
|
||||
this.components[EmcType.DEFAULT.ordinal()] = value;
|
||||
}
|
||||
|
||||
public EmcValue(float[] components) {
|
||||
|
||||
this(1F, components);
|
||||
}
|
||||
|
||||
public EmcValue(float recoveryPercent, float[] components) {
|
||||
|
||||
this.recoveryPercent = recoveryPercent;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
public EmcValue(int value, List<EmcComponent> componentList) {
|
||||
|
||||
this((float) value, componentList);
|
||||
}
|
||||
|
||||
public EmcValue(float value, List<EmcComponent> componentList) {
|
||||
|
||||
this(value, 1F, componentList);
|
||||
}
|
||||
|
||||
public EmcValue(float value, float recoveryPercent, List<EmcComponent> componentList) {
|
||||
|
||||
this.recoveryPercent = recoveryPercent;
|
||||
this.components = new float[EmcType.TYPES.length];
|
||||
|
||||
List<EmcComponent> collatedComponents = collateComponents(componentList);
|
||||
|
||||
int totalComponents = 0;
|
||||
|
||||
for (EmcComponent component : collatedComponents) {
|
||||
if (component.weight > 0) {
|
||||
totalComponents += component.weight;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
if (totalComponents > 0) {
|
||||
for (EmcComponent component : collatedComponents) {
|
||||
if (component.weight > 0) {
|
||||
this.components[component.type.ordinal()] = value * (component.weight * 1F / totalComponents);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.components[EmcType.DEFAULT.ordinal()] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float getComponentValueByType(EmcType type) {
|
||||
public float getValue() {
|
||||
|
||||
EmcComponent emcComponent = getComponentByType(type);
|
||||
if (emcComponent != null) {
|
||||
if (sumComponentRatios > 0) {
|
||||
return value * (emcComponent.getRatioWeight() / (float) this.sumComponentRatios);
|
||||
float sumSubValues = 0;
|
||||
|
||||
for (float subValue : this.components) {
|
||||
if (subValue > 0) {
|
||||
sumSubValues += subValue;
|
||||
}
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public float[] getComponentSubValues() {
|
||||
|
||||
float[] componentSubValues = new float[EmcType.TYPES.length];
|
||||
|
||||
for (int i = 0; i < componentSubValues.length; i++) {
|
||||
componentSubValues[i] = getComponentValueByType(EmcType.TYPES[i]);
|
||||
}
|
||||
|
||||
return componentSubValues;
|
||||
return sumSubValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,35 +125,16 @@ public class EmcValue implements Comparable<EmcValue> {
|
|||
return false;
|
||||
}
|
||||
|
||||
EmcValue emcValue = (EmcValue) object;
|
||||
|
||||
return (Float.compare(this.value, emcValue.value) == 0) && (Float.compare(this.recoveryPercent, emcValue.recoveryPercent) == 0) && components.equals(emcValue.getComponents());
|
||||
return (compareTo((EmcValue) object) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append(String.format("V:%s%sRP:%s%s[", value, Strings.TOKEN_DELIMITER, recoveryPercent, Strings.TOKEN_DELIMITER));
|
||||
|
||||
List<EmcComponent> componentArray = this.components;
|
||||
Collections.sort(componentArray);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (EmcComponent component : componentArray) {
|
||||
|
||||
stringBuilder.append(String.format("%s:%s", component.getType(), component.getRatioWeight()));
|
||||
|
||||
i++;
|
||||
|
||||
if (i < componentArray.size()) {
|
||||
stringBuilder.append(String.format("%s", Strings.TOKEN_DELIMITER));
|
||||
}
|
||||
}
|
||||
|
||||
stringBuilder.append("]");
|
||||
|
||||
// TODO Intelligible output
|
||||
stringBuilder.append(String.format("%s @ %s", components.toString(), recoveryPercent));
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
@ -151,9 +144,11 @@ public class EmcValue implements Comparable<EmcValue> {
|
|||
|
||||
int hashCode = 1;
|
||||
|
||||
hashCode = 37 * hashCode + Float.floatToIntBits(value);
|
||||
hashCode = 37 * hashCode + Float.floatToIntBits(getValue());
|
||||
hashCode = 37 * hashCode + Float.floatToIntBits(recoveryPercent);
|
||||
hashCode = 37 * hashCode + components.hashCode();
|
||||
for (float subValue : components) {
|
||||
hashCode = 37 * hashCode + Float.floatToIntBits(subValue);
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
@ -162,16 +157,16 @@ public class EmcValue implements Comparable<EmcValue> {
|
|||
public int compareTo(EmcValue emcValue) {
|
||||
|
||||
if (emcValue instanceof EmcValue) {
|
||||
if (Float.compare(this.value, emcValue.value) == 0) {
|
||||
if (Float.compare(this.getValue(), emcValue.getValue()) == 0) {
|
||||
if (Float.compare(this.recoveryPercent, emcValue.recoveryPercent) == 0) {
|
||||
return (this.components.hashCode() - emcValue.components.hashCode());
|
||||
return compareComponents(this.components, emcValue.components);
|
||||
}
|
||||
else {
|
||||
return Float.compare(this.recoveryPercent, emcValue.recoveryPercent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Float.compare(this.value, emcValue.value);
|
||||
return Float.compare(this.getValue(), emcValue.getValue());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -181,14 +176,16 @@ public class EmcValue implements Comparable<EmcValue> {
|
|||
|
||||
private static List<EmcComponent> collateComponents(List<EmcComponent> uncollatedComponents) {
|
||||
|
||||
Integer[] componentCount = new Integer[7];
|
||||
Integer[] componentCount = new Integer[EmcType.TYPES.length];
|
||||
|
||||
for (EmcComponent emcComponent : uncollatedComponents) {
|
||||
if (componentCount[emcComponent.getType().ordinal()] == null) {
|
||||
componentCount[emcComponent.getType().ordinal()] = new Integer(0);
|
||||
if (componentCount[emcComponent.type.ordinal()] == null) {
|
||||
componentCount[emcComponent.type.ordinal()] = new Integer(0);
|
||||
}
|
||||
|
||||
componentCount[emcComponent.getType().ordinal()] = new Integer(componentCount[emcComponent.getType().ordinal()].intValue() + emcComponent.getRatioWeight());
|
||||
if (emcComponent.weight >= 0) {
|
||||
componentCount[emcComponent.type.ordinal()] = new Integer(componentCount[emcComponent.type.ordinal()].intValue() + emcComponent.weight);
|
||||
}
|
||||
}
|
||||
|
||||
List<EmcComponent> collatedComponents = new ArrayList<EmcComponent>();
|
||||
|
@ -203,4 +200,20 @@ public class EmcValue implements Comparable<EmcValue> {
|
|||
|
||||
return collatedComponents;
|
||||
}
|
||||
|
||||
private static int compareComponents(float[] first, float[] second) {
|
||||
|
||||
if (first.length == EmcType.TYPES.length && second.length == EmcType.TYPES.length) {
|
||||
for (EmcType emcType : EmcType.TYPES) {
|
||||
if (Float.compare(first[emcType.ordinal()], second[emcType.ordinal()]) != 0) {
|
||||
return Float.compare(first[emcType.ordinal()], second[emcType.ordinal()]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue