45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
package com.github.dtschust.zork;
|
|
|
|
import java.util.Set;
|
|
|
|
/* Has conditions*/
|
|
public class ZorkConditionHas extends ZorkCondition {
|
|
private final String has;
|
|
private final String owner;
|
|
|
|
public ZorkConditionHas(String has, String object, String owner) {
|
|
super(object);
|
|
this.has = has;
|
|
this.owner = owner;
|
|
}
|
|
|
|
@Override
|
|
public boolean evaluate(Zork zork) {
|
|
/*Inventory is a special case as it isn't the name of any object in the game, check for it specifically*/
|
|
if (owner.equals("inventory")) {
|
|
return evaluateCondition(zork.game.Inventory, object);
|
|
} else {
|
|
/* is it a room?*/
|
|
ZorkRoom roomObject = zork.game.Rooms.get(owner);
|
|
if (roomObject != null) {
|
|
return evaluateCondition(roomObject.item, object);
|
|
}
|
|
/* is it a container?*/
|
|
else {
|
|
ZorkContainer containerObject = zork.game.Containers.get(owner);
|
|
if (containerObject != null) {
|
|
return evaluateCondition(containerObject.item, object);
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private boolean evaluateCondition(Set items, String object){
|
|
if(has.equals("yes")) return items.contains(object);
|
|
else if(has.equals("no")) return !items.contains(object);
|
|
return false;
|
|
}
|
|
}
|