Advertisement
KeepCoding

Infernal Infinity Fix

Aug 3rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package infernalInferno;
  2.  
  3. import infernalInferno.enums.BaseStats;
  4. import infernalInferno.enums.Gems;
  5.  
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class Weapon {
  10.     private String name;
  11.     private BaseStats stats;
  12.     private int minDamage; //new
  13.     private int maxDamage; //new
  14.     private Map<Integer, Gems> sockets;
  15.  
  16.     public Weapon(String name, String type) {
  17.         this.name = name;
  18.         this.stats = Enum.valueOf(BaseStats.class, type.toUpperCase());
  19.         this.sockets = new HashMap<>(this.stats.getSockets());
  20.     }
  21.  
  22.     public void insertGem(int index, String gemType) {
  23.         if (index >= 0 && index < this.stats.getSockets()) { //changed
  24.             this.sockets.put(index, Enum.valueOf(Gems.class, gemType.toUpperCase()));
  25.         }
  26.     }
  27.  
  28.     protected void upgradeWeapon() { //changed
  29.         this.minDamage = this.stats.getMinDamage();
  30.         this.maxDamage = this.stats.getMaxDamage();
  31.  
  32.         this.minDamage += getSumStrength() * 2 + getSumAgility() * 1;
  33.         this.maxDamage += getSumStrength() * 3 + getSumAgility() * 4;
  34.     }
  35.  
  36.     public void removeGem(int index) {
  37.         this.sockets.remove(index);
  38.     }
  39.  
  40.     protected BaseStats getStats() {
  41.         return this.stats;
  42.     }
  43.  
  44.     protected int getSumStrength() {
  45.         int sum = 0;
  46.         for (Gems gem : sockets.values()) {
  47.             sum += gem.getStrength();
  48.         }
  49.         return sum;
  50.     }
  51.  
  52.     protected int getSumAgility() {
  53.         int sum = 0;
  54.         for (Gems gem : sockets.values()) {
  55.             sum += gem.getAgility();
  56.         }
  57.         return sum;
  58.     }
  59.  
  60.     protected int getSumVitality() {
  61.         int sum = 0;
  62.         for (Gems gem : sockets.values()) {
  63.             sum += gem.getVitality();
  64.         }
  65.         return sum;
  66.     }
  67.  
  68. //    @Override
  69. //    public String toString() {
  70. //        return String.format("%s: ", this.name);
  71. //    }
  72.  
  73.     @Override
  74.     public String toString() { //changed
  75.  
  76.         this.upgradeWeapon();
  77.  
  78.         return String.format("%s: %d-%d Damage, +%d Strength, +%d Agility, +%d Vitality"
  79.                 , this.name
  80.                 , this.minDamage
  81.                 , this.maxDamage
  82.                 , this.getSumStrength()
  83.                 , this.getSumAgility()
  84.                 , this.getSumVitality());
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement