Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package infernalInferno;
- import infernalInferno.enums.BaseStats;
- import infernalInferno.enums.Gems;
- import java.util.HashMap;
- import java.util.Map;
- public class Weapon {
- private String name;
- private BaseStats stats;
- private int minDamage; //new
- private int maxDamage; //new
- private Map<Integer, Gems> sockets;
- public Weapon(String name, String type) {
- this.name = name;
- this.stats = Enum.valueOf(BaseStats.class, type.toUpperCase());
- this.sockets = new HashMap<>(this.stats.getSockets());
- }
- public void insertGem(int index, String gemType) {
- if (index >= 0 && index < this.stats.getSockets()) { //changed
- this.sockets.put(index, Enum.valueOf(Gems.class, gemType.toUpperCase()));
- }
- }
- protected void upgradeWeapon() { //changed
- this.minDamage = this.stats.getMinDamage();
- this.maxDamage = this.stats.getMaxDamage();
- this.minDamage += getSumStrength() * 2 + getSumAgility() * 1;
- this.maxDamage += getSumStrength() * 3 + getSumAgility() * 4;
- }
- public void removeGem(int index) {
- this.sockets.remove(index);
- }
- protected BaseStats getStats() {
- return this.stats;
- }
- protected int getSumStrength() {
- int sum = 0;
- for (Gems gem : sockets.values()) {
- sum += gem.getStrength();
- }
- return sum;
- }
- protected int getSumAgility() {
- int sum = 0;
- for (Gems gem : sockets.values()) {
- sum += gem.getAgility();
- }
- return sum;
- }
- protected int getSumVitality() {
- int sum = 0;
- for (Gems gem : sockets.values()) {
- sum += gem.getVitality();
- }
- return sum;
- }
- // @Override
- // public String toString() {
- // return String.format("%s: ", this.name);
- // }
- @Override
- public String toString() { //changed
- this.upgradeWeapon();
- return String.format("%s: %d-%d Damage, +%d Strength, +%d Agility, +%d Vitality"
- , this.name
- , this.minDamage
- , this.maxDamage
- , this.getSumStrength()
- , this.getSumAgility()
- , this.getSumVitality());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement