aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/game/items/Item.java
blob: d5aad7c9e65991b5a68d7cba8b67cb2142f8c1a1 (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
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
package esieequest.game.items;

import lombok.Getter;
import net.pacien.util.Mappable;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import esieequest.engine.utils.EnumUtils;
import esieequest.engine.utils.SerialisableObject;
import esieequest.game.Game;
import esieequest.game.Text;
import esieequest.ui.View;

public enum Item implements Mappable<String>, SerialisableObject {

	// @formatter:off
	
	// secret corridor
	STORAGE_CUBE(new SimpleItem("Weighted Storage Cube", 5, true)),
	SAFETY_CUBE(new SimpleItem("Edgeless Safety Cube", 5, true)),
	BLACK_HOLE(new SimpleItem("Portable black-hole", -10, false)),
	
	KEYCARD(new SimpleItem("KeyCard", 0, false)),

	BEAMER(new Beamer("Beamer")),
	
	// scenario
	NOTE(new Note("Note", Text.NOTE_ATHANASE.toString())),
	BANANA(new Banana()),
	PORTABLE_CONSOLE(new PortableConsole()),
	DISK(new Disk()),
	
	;
	
	// @formatter:on

	@Getter
	private final SimpleItem item;

	Item(final SimpleItem item) {
		this.item = item;
	}

	/**
	 * Returns the description of the item.
	 * 
	 * @return the description
	 */
	public String getName() {
		return this.item.getName();
	}

	/**
	 * Returns the weight of the item.
	 * 
	 * @return the weight
	 */
	public int getWeight() {
		return this.item.getWeight();
	}

	/**
	 * Tells whether the item is droppable.
	 * 
	 * @return the droppability of the item.
	 */
	public boolean isDroppable() {
		return this.item.isDroppable();
	}

	/**
	 * Performs actions when the player uses the Item.
	 * 
	 * @param game
	 *            the Game model
	 * @param view
	 *            the View
	 */
	public void use(final Game game, final View view) {
		this.item.use(game, view);
	}

	@Override
	public String getKey() {
		return this.item.getName().toLowerCase();
	}

	@Override
	public JSONObject serialise() {
		return this.item.serialise();
	}

	@Override
	public void deserialise(final JSONObject o) {
		this.item.deserialise(o);
	}

	public static JSONArray serialiseAll() {
		return EnumUtils.serialiseEnumObjects(Item.values());
	}

	public static void deserialiseAll(final JSONArray a) {
		EnumUtils.deserialiseEnumObjects(Item.class, a);
	}

}