-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeaponItem.java
More file actions
37 lines (31 loc) · 1.01 KB
/
WeaponItem.java
File metadata and controls
37 lines (31 loc) · 1.01 KB
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
package APCSA.APCSA_Code_Your_Own;
public class WeaponItem extends Item {
private int damageInfliction;
private int maxDurability;
private int currentDurability;
private NonPlayerCharacter target;
public WeaponItem(String description, int damageInfliction, int MaxDurability) {
super(description, new String[] { "attack" });
this.damageInfliction = damageInfliction;
this.maxDurability = MaxDurability;
this.currentDurability = currentDurability;
}
public boolean useAbility(String selectedAbility, Player player) {
if (hasAbility(selectedAbility)) {
attack();
return true;
}
return false;
}
public void setTarget(NonPlayerCharacter target) {
this.target = target;
}
private boolean attack() {
target.takeDamage(damageInfliction);
currentDurability -= 2;
return currentDurability < 0;
}
public void repair() {
currentDurability = maxDurability;
}
}