summaryrefslogtreecommitdiffstats
path: root/src/subconscious/Weapon.java
blob: 8533b9f0b4d80da7f19ef5a3ca8935d1d8d1a5cf (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
package subconscious;

// TODO: there are object such as "puch" that need infinite durability
public class Weapon {
	// TODO: if possible make final
	private int damage;
	private int durability;
	private int range;
	private String name;

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

	public Weapon(String name, int damage, int range, int durability) {
		this.name = name;
		this.damage = damage;
		this.range = range;
		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() {
		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;
		}
	}

}