summaryrefslogtreecommitdiffstats
path: root/src/subconscious/Weapon.java
blob: 3295cb8158fe6675ecc61abed02b51fd66525422 (plain)
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
package subconscious;

public class Weapon {

	private final boolean unbreakable; 
	private final int damage;
	private final int range;

	private String name;
	private int durability;

	// TODO: add bonus / power-ups structure
	// public class PowerUps {}

	// TODO: As a temporary workaround negative durability on the constructor
	//       makes the weapon unbreakable
	public Weapon(String name, int damage, int range, int durability) {
		this.name = name;
		this.damage = damage;
		this.range = range;
		this.unbreakable = (durability < 0);
		this.durability = durability;
	}

	/* accessors */
	public String getName() { return this.name; }
	public int getDamage() { return this.damage; }
	public int getRange() { return this.range; }
	public int getDurability() { return this.durability; }

	public boolean isBroken() {
		if (this.unbreakable)
			return false;

		return this.durability <= 0;
	}

	public boolean damage(Actor attacker, Actor attacked, Map map) {
		if (isBroken()) {
			return false;
		}

		if (map.getTile(attacked.getX(), attacked.getY()).isSelected()) {
			attacked.damage(this.damage);
			this.durability--;
			return true;
		} else {
			return false;
		}
	}

}