add player and player roles
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
package org.project.entity;
|
||||
|
||||
import org.project.Interface.IDamageable;
|
||||
import org.project.Interface.IDefendable;
|
||||
import org.project.Interface.IDefender;
|
||||
import org.project.Interface.IHealable;
|
||||
import org.project.constants.gameConstant.AttackPowerUp;
|
||||
import org.project.constants.gameConstant.EntityState;
|
||||
import org.project.constants.gameConstant.ItemClass;
|
||||
import org.project.constants.gameConstant.ItemClassExt;
|
||||
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;
|
||||
@@ -15,22 +9,76 @@ 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 {
|
||||
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;
|
||||
private int BaseDamage;
|
||||
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; }
|
||||
|
||||
public int GetBaseDamage() { return BaseDamage; }
|
||||
@Override
|
||||
public int GetDamage() { return BaseDamage; }
|
||||
|
||||
public long GetMoney() { return Money; }
|
||||
|
||||
@@ -48,6 +96,10 @@ public abstract class Entity implements IDamageable, IHealable, IDefendable {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetState(EntityState state) {
|
||||
State = state;
|
||||
}
|
||||
|
||||
public void ModifyMoney(long amount, boolean dir) {
|
||||
if (dir) {
|
||||
Money += amount;
|
||||
@@ -73,15 +125,28 @@ public abstract class Entity implements IDamageable, IHealable, IDefendable {
|
||||
|
||||
@Override
|
||||
public void TakeDamage(int amount, AttackPowerUp[] powerUps) {
|
||||
if (!defencePowerUps.contains(DefencePowerUp.INVISIBLE)) return;
|
||||
|
||||
IDefender[] defenders = GetDefenders();
|
||||
|
||||
for (IDefender defender : defenders) {
|
||||
if (defender != null) {
|
||||
amount = defender.Apply(amount, powerUps);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Health -= amount;
|
||||
if (amount > 0) {
|
||||
Health -= amount;
|
||||
}
|
||||
|
||||
if (IsDestroyed()) {
|
||||
HandleZeroHealth();
|
||||
@@ -120,4 +185,40 @@ public abstract class Entity implements IDamageable, IHealable, IDefendable {
|
||||
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 FightMoves[] getAvailableMoves() {
|
||||
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.toArray(new FightMoves[0]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user