CS代考 package dungeonmania.entities;

package dungeonmania.entities;

import java.util.LinkedList;
import java.util.List;

Copyright By PowCoder代写 加微信 powcoder

import java.util.Queue;

import dungeonmania.battles.BattleStatistics;
import dungeonmania.battles.Battleable;
import dungeonmania.entities.collectables.Bomb;
import dungeonmania.entities.collectables.potions.InvincibilityPotion;
import dungeonmania.entities.collectables.potions.Potion;
import dungeonmania.entities.enemies.Enemy;
import dungeonmania.entities.enemies.Mercenary;
import dungeonmania.entities.inventory.Inventory;
import dungeonmania.entities.inventory.InventoryItem;
import dungeonmania.entities.playerState.BaseState;
import dungeonmania.entities.playerState.PlayerState;
import dungeonmania.map.GameMap;
import dungeonmania.util.Direction;
import dungeonmania.util.Position;

public class Player extends Entity implements Battleable {
public static final double DEFAULT_ATTACK = 5.0;
public static final double DEFAULT_HEALTH = 5.0;
private BattleStatistics battleStatistics;
private Inventory inventory;
private Queue queue = new LinkedList<>();
private Potion inEffective = null;
private int nextTrigger = 0;

private PlayerState state;

public Player(Position position, double health, double attack) {
super(position);
battleStatistics = new BattleStatistics(
BattleStatistics.DEFAULT_DAMAGE_MAGNIFIER,
BattleStatistics.DEFAULT_PLAYER_DAMAGE_REDUCER);
inventory = new Inventory();
state = new BaseState(this);

public boolean hasWeapon() {
return inventory.hasWeapon();

public BattleItem getWeapon() {
return inventory.getWeapon();

public List getBuildables() {
return inventory.getBuildables();

public boolean build(String entity, EntityFactory factory) {
InventoryItem item = inventory.checkBuildCriteria(this, true, entity.equals(“shield”), factory);
if (item == null) return false;
return inventory.add(item);

public void move(GameMap map, Direction direction) {
this.setFacing(direction);
map.moveTo(this, Position.translateBy(this.getPosition(), direction));

public void onOverlap(GameMap map, Entity entity) {
if (entity instanceof Enemy) {
if (entity instanceof Mercenary) {
if (((Mercenary) entity).isAllied()) return;
map.getGame().battle(this, (Enemy) entity);

public boolean canMoveOnto(GameMap map, Entity entity) {
return true;

public Entity getEntity(String itemUsedId) {
return inventory.getEntity(itemUsedId);

public boolean pickUp(Entity item) {
return inventory.add((InventoryItem) item);

public Inventory getInventory() {
return inventory;

public Potion getEffectivePotion() {
return inEffective;

public void use(Class itemType) {
T item = inventory.getFirst(itemType);
if (item != null) inventory.remove(item);

public void use(Bomb bomb, GameMap map) {
inventory.remove(bomb);
bomb.onPutDown(map, getPosition());

public void triggerNext(int currentTick) {
if (queue.isEmpty()) {
inEffective = null;
state.transitionBase();
inEffective = queue.remove();
if (inEffective instanceof InvincibilityPotion) {
state.transitionInvincible();
state.transitionInvisible();
nextTrigger = currentTick + inEffective.getDuration();

public void changeState(PlayerState playerState) {
state = playerState;

public void use(Potion potion, int tick) {
inventory.remove(potion);
queue.add(potion);
if (inEffective == null) {
triggerNext(tick);

public void onTick(int tick) {
if (inEffective == null || tick == nextTrigger) {
triggerNext(tick);

public void remove(InventoryItem item) {
inventory.remove(item);

public BattleStatistics getBattleStatistics() {
return battleStatistics;

public int countEntityOfType(Class itemType) {
return inventory.count(itemType);

public BattleStatistics applyBuff(BattleStatistics origin) {
if (state.isInvincible()) {
return BattleStatistics.applyBuff(origin, new BattleStatistics(
} else if (state.isInvisible()) {
return BattleStatistics.applyBuff(origin, new BattleStatistics(
return origin;

public void onMovedAway(GameMap map, Entity entity) {

public void onDestroy(GameMap gameMap) {

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com