252 lines
6.4 KiB
Java
252 lines
6.4 KiB
Java
package org.project.entity;
|
|
|
|
import org.project.Interface.*;
|
|
import org.project.constants.gameConstant.*;
|
|
import org.project.item.Accessory.Costume;
|
|
import org.project.item.Accessory.Shield;
|
|
import org.project.item.Accessory.Weapon;
|
|
import org.project.item.Item;
|
|
import org.project.item.SellableItem;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
|
|
public abstract class Entity implements IDamageable, IHealable, IDefendable, IFighter, IDamager {
|
|
|
|
public String Name;
|
|
public int MaxHealth;
|
|
public int Health;
|
|
private int Stamina;
|
|
protected int MaxStamina;
|
|
private long Money;
|
|
protected int BaseDamage;
|
|
private EntityState State;
|
|
public Weapon Weapon;
|
|
public Shield Shield;
|
|
public Costume Costume;
|
|
public ArrayList<Item> Inventory;
|
|
protected int DefenseBonus;
|
|
public boolean IsDefending;
|
|
public ArrayList<DefencePowerUp> defencePowerUps;
|
|
protected int HealAmount;
|
|
protected int HeavyAttackStamina;
|
|
protected int SpecialAbilityStamina;
|
|
|
|
public Entity(String name, int maxHealth, int health, int stamina, int maxStamina, long money, int baseDamage, EntityState state, Weapon weapon,
|
|
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending, int healAmount) {
|
|
|
|
Name = name;
|
|
MaxHealth = maxHealth;
|
|
Health = health;
|
|
Stamina = stamina;
|
|
MaxStamina = maxStamina;
|
|
Money = money;
|
|
BaseDamage = baseDamage;
|
|
State = state;
|
|
Weapon = weapon;
|
|
Shield = shield;
|
|
Costume = costume;
|
|
Inventory = inventory;
|
|
DefenseBonus = defenseBonus;
|
|
IsDefending = isDefending;
|
|
HealAmount = healAmount;
|
|
HeavyAttackStamina = 50;
|
|
SpecialAbilityStamina = 100;
|
|
}
|
|
|
|
protected Entity() {}
|
|
|
|
public int GetStamina() { return Stamina; }
|
|
|
|
public void ResetStamina() { Stamina = MaxStamina; }
|
|
|
|
public void ModifyStamina(int amount, boolean dir) {
|
|
if (dir) {
|
|
Stamina += amount;
|
|
|
|
if (Stamina > MaxStamina) {
|
|
Stamina = MaxStamina;
|
|
}
|
|
}
|
|
|
|
Stamina -= amount;
|
|
if (Stamina < 0) {
|
|
Stamina = 0;
|
|
}
|
|
}
|
|
|
|
public EntityState GetState() { return State; }
|
|
|
|
@Override
|
|
public int GetDamage() {
|
|
int damage = BaseDamage;
|
|
IDamageUtil[] utils = GetDamageUtils();
|
|
|
|
for (IDamageUtil util : utils) {
|
|
if (util != null) {
|
|
damage += util.GetDamage();
|
|
}
|
|
}
|
|
|
|
return damage;
|
|
}
|
|
|
|
@Override
|
|
public IDamageUtil[] GetDamageUtils() {
|
|
return new IDamageUtil[] {Weapon};
|
|
}
|
|
|
|
@Override
|
|
public void Damage(IDamageable target, int amount, AttackPowerUp[] powerUps) {
|
|
target.TakeDamage(amount, powerUps);
|
|
}
|
|
|
|
public long GetMoney() { return Money; }
|
|
|
|
public ArrayList<Item> GetInventory() { return Inventory; }
|
|
|
|
public ArrayList<Item> GetInventoryByClass(ItemClass itemClass) {
|
|
ArrayList<Item> result = new ArrayList<>();
|
|
|
|
for (Item item : Inventory) {
|
|
if (ItemClassExt.Matches(itemClass, item)) {
|
|
result.add(item);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public void SetState(EntityState state) {
|
|
State = state;
|
|
}
|
|
|
|
public void ModifyMoney(long amount, boolean dir) {
|
|
if (dir) {
|
|
Money += amount;
|
|
}
|
|
Money -= amount;
|
|
}
|
|
|
|
public void RestoreHealth() { Health = MaxHealth; }
|
|
|
|
@Override
|
|
public void Heal(int amount) {
|
|
Health += amount;
|
|
|
|
if (Health > MaxHealth) {
|
|
Health = MaxHealth;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public IDefender[] GetDefenders() {
|
|
return new IDefender[]{Shield, Costume};
|
|
}
|
|
|
|
@Override
|
|
public void TakeDamage(int amount, AttackPowerUp[] powerUps) {
|
|
if (!defencePowerUps.contains(DefencePowerUp.INVISIBLE)) return;
|
|
|
|
IDefender[] defenders = GetDefenders();
|
|
|
|
if (Arrays.binarySearch(powerUps, AttackPowerUp.INEVITABLE) < 0) {
|
|
for (IDefender defender : defenders) {
|
|
if (defender != null) {
|
|
amount = defender.Apply(amount, powerUps);
|
|
}
|
|
}
|
|
|
|
if (IsDefending) {
|
|
if (Arrays.binarySearch(powerUps, AttackPowerUp.INEVITABLE) < 0) {
|
|
amount -= DefenseBonus;
|
|
}
|
|
IsDefending = false;
|
|
}
|
|
}
|
|
|
|
if (amount > 0) {
|
|
Health -= amount;
|
|
}
|
|
|
|
if (IsDestroyed()) {
|
|
HandleZeroHealth();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean IsDestroyed() {
|
|
return Health <= 0;
|
|
}
|
|
|
|
@Override
|
|
public void HandleZeroHealth() {
|
|
this.State = EntityState.DEAD;
|
|
}
|
|
|
|
public void SellItem(SellableItem item) {
|
|
int price = item.GetPrice();
|
|
RemoveFromInventory(item);
|
|
|
|
Money += price;
|
|
}
|
|
|
|
public void SellByClass(ItemClass itemClass) {
|
|
ArrayList<Item> items = GetInventoryByClass(itemClass);
|
|
|
|
for (Item item : items) {
|
|
SellItem((SellableItem) item);
|
|
}
|
|
}
|
|
|
|
public void AddToInventory(Item item) {
|
|
Inventory.add(item);
|
|
}
|
|
|
|
public void RemoveFromInventory(Item item) {
|
|
Inventory.remove(item);
|
|
}
|
|
|
|
@Override
|
|
public abstract void LightAttack(IDamageable target);
|
|
@Override
|
|
public abstract void HeavyAttack(IDamageable target);
|
|
@Override
|
|
public void defend() {
|
|
IsDefending = true;
|
|
}
|
|
@Override
|
|
public void HealMove() {
|
|
Heal(HealAmount);
|
|
}
|
|
@Override
|
|
public abstract void SpecialAbility(Entity entity);
|
|
@Override
|
|
public abstract String GetSpecialAbilityDescription(Entity entity);
|
|
@Override
|
|
public abstract String GetSpecialAbilityResultDescription(Entity entity);
|
|
|
|
@Override
|
|
public ArrayList<FightMoves> GetAvailableMoves() {
|
|
if (GetState() == EntityState.FROZEN) return new ArrayList<>(){};
|
|
|
|
ArrayList<FightMoves> result = new ArrayList<>();
|
|
result.add(FightMoves.DEFEND);
|
|
result.add(FightMoves.LIGHT_ATTACK);
|
|
|
|
if (Health < MaxHealth) {
|
|
result.add(FightMoves.HEAL);
|
|
}
|
|
|
|
if (Stamina > MaxStamina / 2) {
|
|
result.add(FightMoves.SPECIAL);
|
|
}
|
|
|
|
if (Stamina > MaxStamina / 4) {
|
|
result.add(FightMoves.HEAVY_ATTACK);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|