GenuineSounds

Elements

May 31st, 2012
189
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.23 KB | None | 0 0
  1. package ltd.genuinesounds.element;
  2.  
  3. public enum ElementType {
  4.     FIRE, WIND, HEAVEN, WATER, EARTH, HELL, NORMAL;
  5.     static {
  6.         // Set diatypes (unsupportive)
  7.         FIRE.setDiatype(HEAVEN); // Heaven calms fire.
  8.         WATER.setDiatype(HELL); // Hell steams water.
  9.         WIND.setDiatype(FIRE); // Fire disrupts wind.
  10.         EARTH.setDiatype(WATER); // Water crumbles earth.
  11.         HEAVEN.setDiatype(WIND); // Wind separates heaven.
  12.         HELL.setDiatype(EARTH); // Earth blocks hell.
  13.         // Set dicotypes (supportive)
  14.         FIRE.setDicotype(WIND); // Wind feeds fire.
  15.         WATER.setDicotype(EARTH); // Earth gives water structure.
  16.         WIND.setDicotype(HEAVEN); // Heaven breathes wind.
  17.         EARTH.setDicotype(HELL); // Hell lava forms earth.
  18.         HEAVEN.setDicotype(WATER); // Water feeds life.
  19.         HELL.setDicotype(FIRE); // Fire breeds hell.
  20.     }
  21.  
  22.     private ElementType diatype;
  23.  
  24.     private ElementType dicotype;
  25.  
  26.     /** Set the Elemental diatype (unsupportive) of this element */
  27.     public void setDiatype(ElementType diatype) {
  28.         this.diatype = diatype;
  29.     }
  30.  
  31.     /** Get the Elemental diatype (unsupportive) of this element */
  32.     public ElementType getDiatype() {
  33.         return diatype;
  34.     }
  35.  
  36.     /** Set the Elemental dicotype (supportive) of this element */
  37.     public void setDicotype(ElementType dicotype) {
  38.         this.dicotype = dicotype;
  39.     }
  40.  
  41.     /** Get the Elemental dicotype (supportive) of this element */
  42.     public ElementType getDicotype() {
  43.         return dicotype;
  44.     }
  45.  
  46.     @Override
  47.     public String toString() {
  48.         return name();
  49.     }
  50. }
  51.  
  52.  
  53. //================================================================================
  54.  
  55.  
  56. package ltd.genuinesounds.element;
  57.  
  58. import java.util.HashMap;
  59. import java.util.Map;
  60.  
  61. public class ElementReaction {
  62.  
  63.     public static final float WEIGHT_PRIME = 75.0f;
  64.  
  65.     public static final float WEIGHT_MAJOR = 50.0f;
  66.  
  67.     public static final float WEIGHT_MINOR = 25.0f;
  68.  
  69.     private Element primeType;
  70.  
  71.     private Element majorType;
  72.  
  73.     private Element minorType;
  74.  
  75.     private float minMax;
  76.  
  77.     private Map<ElementType, Float> elementLevels = new HashMap<ElementType, Float>();
  78.  
  79.     public ElementReaction(Element primeElement, Element majorElement, Element minorElement) {
  80.         primeType = primeElement;
  81.         majorType = majorElement;
  82.         minorType = minorElement;
  83.         for (ElementType type : ElementType.values())
  84.             elementLevels.put(type, 0f);
  85.         generateLevels();
  86.         generateRange();
  87.     }
  88.    
  89.     @Override
  90.     public boolean equals(Object obj) {
  91.         if (obj instanceof ElementReaction)
  92.             return this.elementLevels.equals(((ElementReaction) obj).elementLevels);
  93.         return super.equals(obj);
  94.     }
  95.  
  96.     private void generateRange() {
  97.         for (float floater : elementLevels.values())
  98.             if (Math.abs(floater) > minMax)
  99.                 minMax = Math.abs(floater);
  100.     }
  101.  
  102.     private void generateLevels() {
  103.         if (primeType != null)
  104.             putCalculatedValue(WEIGHT_PRIME, primeType);
  105.         if (majorType != null)
  106.             putCalculatedValue(WEIGHT_MAJOR, majorType);
  107.         if (minorType != null)
  108.             putCalculatedValue(WEIGHT_MINOR, minorType);
  109.     }
  110.  
  111.     public Map<ElementType, Float> getElementValues() {
  112.         return elementLevels;
  113.     }
  114.  
  115.     public Element getPrimeType() {
  116.         return this.primeType;
  117.     }
  118.  
  119.     public Element getMajorType() {
  120.         return this.majorType;
  121.     }
  122.  
  123.     public Element getMinorType() {
  124.         return this.minorType;
  125.     }
  126.  
  127.     public float getRange() {
  128.         return minMax;
  129.     }
  130.  
  131.     @Override
  132.     public String toString() {
  133.         String outcome =
  134.                 "\n---------------------------------------\n" +
  135.                 "Prime: " + primeType + "\n" +
  136.                 "Major: " + majorType + "\n" +
  137.                 "Minor: " + minorType +
  138.                 "\n---------------------------------------\n";
  139.         for (ElementType type : ElementType.values()) {
  140.             outcome += type + " = " + elementLevels.get(type) + "\n";
  141.         }
  142.         return outcome;
  143.     }
  144.  
  145.     private void putCalculatedValue(float weight, Element element) {
  146.         for (ElementType type : ElementType.values()) {
  147.             float total = elementLevels.get(type);
  148.             if (element.getType() == type)
  149.                 total += (primeType.getLevel() * (weight / 100f));
  150.             else {
  151.                 if (element.getType().getDiatype() == type)
  152.                     total -= (primeType.getLevel() * (weight / 100f)) / 2f;
  153.                 if (element.getType().getDicotype() == type)
  154.                     total += (primeType.getLevel() * (weight / 100f)) / 2f;
  155.             }
  156.             elementLevels.put(type, element.isAntiElement() ? -total : total);
  157.         }
  158.     }
  159. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment