Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ltd.genuinesounds.element;
- public enum ElementType {
- FIRE, WIND, HEAVEN, WATER, EARTH, HELL, NORMAL;
- static {
- // Set diatypes (unsupportive)
- FIRE.setDiatype(HEAVEN); // Heaven calms fire.
- WATER.setDiatype(HELL); // Hell steams water.
- WIND.setDiatype(FIRE); // Fire disrupts wind.
- EARTH.setDiatype(WATER); // Water crumbles earth.
- HEAVEN.setDiatype(WIND); // Wind separates heaven.
- HELL.setDiatype(EARTH); // Earth blocks hell.
- // Set dicotypes (supportive)
- FIRE.setDicotype(WIND); // Wind feeds fire.
- WATER.setDicotype(EARTH); // Earth gives water structure.
- WIND.setDicotype(HEAVEN); // Heaven breathes wind.
- EARTH.setDicotype(HELL); // Hell lava forms earth.
- HEAVEN.setDicotype(WATER); // Water feeds life.
- HELL.setDicotype(FIRE); // Fire breeds hell.
- }
- private ElementType diatype;
- private ElementType dicotype;
- /** Set the Elemental diatype (unsupportive) of this element */
- public void setDiatype(ElementType diatype) {
- this.diatype = diatype;
- }
- /** Get the Elemental diatype (unsupportive) of this element */
- public ElementType getDiatype() {
- return diatype;
- }
- /** Set the Elemental dicotype (supportive) of this element */
- public void setDicotype(ElementType dicotype) {
- this.dicotype = dicotype;
- }
- /** Get the Elemental dicotype (supportive) of this element */
- public ElementType getDicotype() {
- return dicotype;
- }
- @Override
- public String toString() {
- return name();
- }
- }
- //================================================================================
- package ltd.genuinesounds.element;
- import java.util.HashMap;
- import java.util.Map;
- public class ElementReaction {
- public static final float WEIGHT_PRIME = 75.0f;
- public static final float WEIGHT_MAJOR = 50.0f;
- public static final float WEIGHT_MINOR = 25.0f;
- private Element primeType;
- private Element majorType;
- private Element minorType;
- private float minMax;
- private Map<ElementType, Float> elementLevels = new HashMap<ElementType, Float>();
- public ElementReaction(Element primeElement, Element majorElement, Element minorElement) {
- primeType = primeElement;
- majorType = majorElement;
- minorType = minorElement;
- for (ElementType type : ElementType.values())
- elementLevels.put(type, 0f);
- generateLevels();
- generateRange();
- }
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof ElementReaction)
- return this.elementLevels.equals(((ElementReaction) obj).elementLevels);
- return super.equals(obj);
- }
- private void generateRange() {
- for (float floater : elementLevels.values())
- if (Math.abs(floater) > minMax)
- minMax = Math.abs(floater);
- }
- private void generateLevels() {
- if (primeType != null)
- putCalculatedValue(WEIGHT_PRIME, primeType);
- if (majorType != null)
- putCalculatedValue(WEIGHT_MAJOR, majorType);
- if (minorType != null)
- putCalculatedValue(WEIGHT_MINOR, minorType);
- }
- public Map<ElementType, Float> getElementValues() {
- return elementLevels;
- }
- public Element getPrimeType() {
- return this.primeType;
- }
- public Element getMajorType() {
- return this.majorType;
- }
- public Element getMinorType() {
- return this.minorType;
- }
- public float getRange() {
- return minMax;
- }
- @Override
- public String toString() {
- String outcome =
- "\n---------------------------------------\n" +
- "Prime: " + primeType + "\n" +
- "Major: " + majorType + "\n" +
- "Minor: " + minorType +
- "\n---------------------------------------\n";
- for (ElementType type : ElementType.values()) {
- outcome += type + " = " + elementLevels.get(type) + "\n";
- }
- return outcome;
- }
- private void putCalculatedValue(float weight, Element element) {
- for (ElementType type : ElementType.values()) {
- float total = elementLevels.get(type);
- if (element.getType() == type)
- total += (primeType.getLevel() * (weight / 100f));
- else {
- if (element.getType().getDiatype() == type)
- total -= (primeType.getLevel() * (weight / 100f)) / 2f;
- if (element.getType().getDicotype() == type)
- total += (primeType.getLevel() * (weight / 100f)) / 2f;
- }
- elementLevels.put(type, element.isAntiElement() ? -total : total);
- }
- }
- }
Advertisement