blob: 16327e4ed07c1f5e3ac460106ccbae6fb85ae34e (
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 esieequest.controller.commands;
import esieequest.model.Game;
import esieequest.model.Text;
import esieequest.model.items.Item;
import esieequest.model.map.Room;
import esieequest.model.map.Side;
import esieequest.view.Viewable;
/**
* Allows the player to take an Item from a Room and transfer it to his
* inventory.
*
* @author Pacien TRAN-GIRARD
*/
public class TakeCommand implements Executable {
@Override
public void execute(final String argument, final Game game, final Viewable view) {
Item item;
if (argument != null) {
final String itemName = argument;
final Room currentRoom = game.getPlayer().getCurrentRoom();
if (!currentRoom.hasItem(itemName)) {
view.echo(Text.NO_SUCH_ITEM.getText());
return;
}
item = currentRoom.getItem(itemName);
} else {
final Side currentSide = game.getPlayer().getCurrentSide();
if (!currentSide.hasItem()) {
view.echo(Text.NO_ITEM.getText());
return;
}
item = currentSide.getItem();
}
// handle inventory weight limit
final int maximumWeight = game.getPlayer().getInventoryWeightLimit();
final int futureWeight = game.getPlayer().getItemsWeight() + item.getWeight();
if (futureWeight > maximumWeight) {
view.echo(Text.INVENTORY_FULL.getText());
return;
}
game.getPlayer().getCurrentRoom().removeItem(item);
game.getPlayer().addItem(item);
}
}
|