-
Notifications
You must be signed in to change notification settings - Fork 1
/
WeaponImpl.java
134 lines (108 loc) · 3.77 KB
/
WeaponImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package infernoinfinity.models;
import infernoinfinity.annotations.CustomInfo;
import infernoinfinity.enums.Gem;
import infernoinfinity.enums.WeaponType;
import infernoinfinity.interfaces.Weapon;
import java.util.Arrays;
@CustomInfo(
author = "Pesho",
revision = 3,
description = "Used for Java OOP Advanced course - Enumerations and Annotations.",
reviewers = {"Pesho", "Svetlio"}
)
public class WeaponImpl implements Weapon, Comparable<Weapon> {
private static final int MIN_DAMAGE_STRENGTH_BONUS = 2;
private static final int MAX_DAMAGE_STRENGTH_BONUS = 3;
private static final int MIN_DAMAGE_AGILITY_BONUS = 1;
private static final int MAX_DAMAGE_AGILITY_BONUS = 4;
private String name;
private WeaponType weaponType;
private Gem[] sockets;
private int minDamage;
private int maxDamage;
public WeaponImpl(String name, WeaponType weaponType) {
this.setName(name);
this.setWeaponType(weaponType);
this.setMaxDamage(weaponType.getMaxDamage());
this.setMinDamage(weaponType.getMinDamage());
this.sockets = new Gem[weaponType.getSocketHoles()];
}
@Override
public String getName() {
return this.name;
}
private void setName(String name) {
this.name = name;
}
public WeaponType getWeaponType() {
return this.weaponType;
}
private void setWeaponType(WeaponType weaponType) {
this.weaponType = weaponType;
}
private void setMinDamage(int minDamage) {
this.minDamage = minDamage;
}
private void setMaxDamage(int maxDamage) {
this.maxDamage = maxDamage;
}
@Override
public void increaseStats(Gem gemType, int socketIndex) {
if (isValidIndex(socketIndex)) {
this.sockets[socketIndex] = gemType;
}
}
@Override
public void decreaseStats(int socketIndex) {
if (isValidIndex(socketIndex)) {
this.sockets[socketIndex] = null;
}
}
@Override
public int getStrength() {
return Arrays.stream(this.sockets).filter(e -> e != null).mapToInt(Gem::getStrength).sum();
}
@Override
public int getAgility() {
return Arrays.stream(this.sockets).filter(e -> e != null).mapToInt(Gem::getAgility).sum();
}
@Override
public int getVitality() {
return Arrays.stream(this.sockets).filter(e -> e != null).mapToInt(Gem::getVitality).sum();
}
@Override
public int getMinDamage() {
return this.minDamage + this.getMinDamageBonus();
}
@Override
public int getMaxDamage() {
return this.maxDamage + this.getMaxDamageBonus();
}
public double getItemLevel() {
return ((this.getMinDamage() + this.getMaxDamage()) / 2.0d) +
this.getStrength() + this.getAgility() + this.getVitality();
}
@Override
public int compareTo(Weapon otherWeapon) {
return Double.compare(this.getItemLevel(), otherWeapon.getItemLevel());
}
private boolean isValidIndex(int socketIndex) {
return socketIndex >= 0 && socketIndex < this.weaponType.getSocketHoles();
}
private int getMinDamageBonus() {
return (this.getStrength() * MIN_DAMAGE_STRENGTH_BONUS) + (this.getAgility() * MIN_DAMAGE_AGILITY_BONUS);
}
private int getMaxDamageBonus() {
return (this.getStrength() * MAX_DAMAGE_STRENGTH_BONUS) + (this.getAgility() * MAX_DAMAGE_AGILITY_BONUS);
}
@Override
public String toString() {
return String.format("%s: %d-%d Damage, +%d Strength, +%d Agility, +%d Vitality",
this.getName(),
this.getMinDamage(),
this.getMaxDamage(),
this.getStrength(),
this.getAgility(),
this.getVitality());
}
}