31 lines
1.2 KiB
Java
31 lines
1.2 KiB
Java
package com.github.dtschust.zork;
|
|
|
|
/* Has conditions*/
|
|
public class ZorkConditionHas extends ZorkCondition {
|
|
public String has;
|
|
public String owner;
|
|
|
|
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 zork.game.Inventory.get(object) != null && has.equals("yes") || zork.game.Inventory.get(object) == null && has.equals("no");
|
|
} else {
|
|
/* is it a room?*/
|
|
ZorkRoom roomObject = zork.game.Rooms.get(owner);
|
|
if (roomObject != null) {
|
|
return (roomObject).item.get(object) != null && has.equals("yes") || (roomObject).item.get(object) == null && has.equals("no");
|
|
}
|
|
/* is it a container?*/
|
|
else {
|
|
ZorkContainer containerObject = zork.game.Containers.get(owner);
|
|
if (containerObject != null) {
|
|
return (containerObject).item.get(object) != null && has.equals("yes") || (containerObject).item.get(object) == null && has.equals("no");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|