package dungeonmania.entities.enemies;
import java.util.List;
import java.util.Random;
Copyright By PowCoder代写 加微信 powcoder
import java.util.stream.Collectors;
import dungeonmania.Game;
import dungeonmania.entities.Entity;
import dungeonmania.entities.Interactable;
import dungeonmania.entities.Player;
import dungeonmania.entities.collectables.Treasure;
import dungeonmania.map.GameMap;
import dungeonmania.util.Position;
public class Mercenary extends Enemy implements Interactable {
public static final int DEFAULT_BRIBE_AMOUNT = 1;
public static final int DEFAULT_BRIBE_RADIUS = 1;
public static final double DEFAULT_ATTACK = 5.0;
public static final double DEFAULT_HEALTH = 10.0;
private int bribeAmount = Mercenary.DEFAULT_BRIBE_AMOUNT;
private int bribeRadius = Mercenary.DEFAULT_BRIBE_RADIUS;
private boolean allied = false;
public Mercenary(Position position, double health, double attack, int bribeAmount, int bribeRadius) {
super(position, health, attack);
this.bribeAmount = bribeAmount;
this.bribeRadius = bribeRadius;
public boolean isAllied() {
return allied;
public void onOverlap(GameMap map, Entity entity) {
if (allied) return;
super.onOverlap(map, entity);
* check whether the current merc can be bribed
* @param player
private boolean canBeBribed(Player player) {
return bribeRadius >= 0 && player.countEntityOfType(Treasure.class) >= bribeAmount;
* bribe the merc
private void bribe(Player player) {
for (int i = 0; i < bribeAmount; i++) {
player.use(Treasure.class);
public void interact(Player player, Game game) {
allied = true;
bribe(player);
public void move(Game game) {
Position nextPos;
GameMap map = game.getMap();
if (allied) {
// Move random
Random randGen = new Random();
List
.filter(p -> map.canMoveTo(this, p)).collect(Collectors.toList());
if (pos.size() == 0) {
nextPos = getPosition();
map.moveTo(this, nextPos);
nextPos = pos.get(randGen.nextInt(pos.size()));
map.moveTo(this, nextPos);
// Follow hostile
nextPos = map.dijkstraPathFind(getPosition(), map.getPlayer().getPosition(), this);
map.moveTo(this, nextPos);
public boolean isInteractable(Player player) {
return !allied && canBeBribed(player);
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com