2022-11-19 09:46:28 +00:00
|
|
|
package com.github.dtschust.zork.types;
|
|
|
|
|
|
|
|
import com.github.dtschust.zork.Zork;
|
|
|
|
import com.github.dtschust.zork.ZorkCondition;
|
2022-11-21 15:36:38 +00:00
|
|
|
import com.github.dtschust.zork.parser.ZorkGame;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2022-11-19 07:48:21 +00:00
|
|
|
import java.util.HashSet;
|
2022-11-20 13:11:58 +00:00
|
|
|
import java.util.List;
|
2022-11-19 07:48:21 +00:00
|
|
|
import java.util.Set;
|
2022-11-16 15:18:00 +00:00
|
|
|
|
|
|
|
/* Creature*/
|
2022-11-16 16:18:19 +00:00
|
|
|
public class ZorkCreature extends ZorkObject {
|
2022-11-20 13:11:58 +00:00
|
|
|
public final Set<String> vulnerability = new HashSet<>();
|
|
|
|
public final List<ZorkCondition> conditions = new ArrayList<>();
|
|
|
|
public final List<String> print = new ArrayList<>();
|
|
|
|
public final List<String> action = new ArrayList<>();
|
2022-11-16 15:18:00 +00:00
|
|
|
|
2022-11-20 13:11:58 +00:00
|
|
|
public ZorkCreature(String name, String description) {
|
|
|
|
super(name, description);
|
2022-11-16 15:18:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 13:11:58 +00:00
|
|
|
|
2022-11-16 15:18:00 +00:00
|
|
|
/* Evaluate the success of an attack*/
|
2022-11-21 15:36:38 +00:00
|
|
|
public boolean attack(ZorkGame game, String weapon) {
|
2022-11-19 07:48:21 +00:00
|
|
|
if (!vulnerability.contains(weapon)) {
|
2022-11-16 15:18:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-11-16 15:36:08 +00:00
|
|
|
for (ZorkCondition condition : conditions) {
|
2022-11-21 15:36:38 +00:00
|
|
|
if (!condition.evaluate(game)) {
|
2022-11-16 15:18:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|