-
Notifications
You must be signed in to change notification settings - Fork 0
/
TradeCommand.java
77 lines (74 loc) · 1.46 KB
/
TradeCommand.java
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
/**
*
*/
/** TradeCommand deals with any Commands relating to the player trying to trade an Item with an NPC.
* @author Team Red
*
*/
public class TradeCommand extends Command{
private NPC npc;
private boolean npcProvided;
private Item item;
private boolean itemProvided;
/** Instantiates a TradeCommand with the parameter Item to the parameter NPC
*
* @param npc NPC to trade with
* @param item Item to trade to the parameter NPC
*/
TradeCommand(String npc, String item)
{
GameState state = GameState.instance();
if(item != null)
{
try{
this.item = state.getItemFromInventoryNamed(item);
}catch(Item.NoItemException e){
this.item = null;
}
itemProvided = true;
}
else
{
itemProvided = false;
}
if(npc != null)
{
try{
this.npc = state.getNPCInVicinityNamed(npc);
}catch(NPC.NoNPCException e){
this.npc = null;
}
npcProvided = false;
}
else
{
npcProvided = true;
}
}
/**
* @override From Command
*/
String execute()
{
if(!itemProvided)
{
return "What do you want to trade?\n";
}
if(item == null)
{
return "You can't trade what you don't have!\n";
}
if(!npcProvided)
{
return "Whom do you want to trade with?\n";
}
if(npc == null)
{
return "You can't trade with something you can't see!\n";
}
if(npc.getIsHostile()){
return "Whoa buddy, they're not gonna let you do that.\n";
}
return null; //just making the return happy while working on it
}
}