add Entity
This commit is contained in:
@@ -1,49 +1,123 @@
|
||||
package org.project.entity;
|
||||
|
||||
import org.project.item.Accessory.Custom;
|
||||
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.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;
|
||||
|
||||
public abstract class Entity {
|
||||
public abstract class Entity implements IDamageable, IHealable, IDefendable {
|
||||
|
||||
public int MaxHealth;
|
||||
public long Money;
|
||||
public int Health;
|
||||
private long Money;
|
||||
private int BaseDamage;
|
||||
private EntityState State;
|
||||
public Weapon Weapon;
|
||||
public Shield Shield;
|
||||
public Costume Costume;
|
||||
public ArrayList<Item> Inventory;
|
||||
|
||||
public int getBaseDamage() {
|
||||
return BaseDamage;
|
||||
public EntityState GetState() { return State; }
|
||||
|
||||
public int GetBaseDamage() { return BaseDamage; }
|
||||
|
||||
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 setBaseDamage(int baseDamage) {
|
||||
BaseDamage = baseDamage;
|
||||
public void ModifyMoney(long amount, boolean dir) {
|
||||
if (dir) {
|
||||
Money += amount;
|
||||
}
|
||||
Money -= amount;
|
||||
}
|
||||
|
||||
void attack(Entity target);
|
||||
public void RestoreHealth() { Health = MaxHealth; }
|
||||
|
||||
void defend();
|
||||
|
||||
void heal(int health);
|
||||
|
||||
void fillMana(int mana);
|
||||
|
||||
void takeDamage(int damage);
|
||||
|
||||
int getMaxHP();
|
||||
|
||||
int getMaxMP();
|
||||
|
||||
public void She() {
|
||||
@Override
|
||||
public void Heal(int amount) {
|
||||
Health += amount;
|
||||
|
||||
if (Health > MaxHealth) {
|
||||
Health = MaxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
@Override
|
||||
public IDefender[] GetDefenders() {
|
||||
return new IDefender[]{Shield, Costume};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void TakeDamage(int amount, AttackPowerUp[] powerUps) {
|
||||
IDefender[] defenders = GetDefenders();
|
||||
|
||||
for (IDefender defender : defenders) {
|
||||
if (defender != null) {
|
||||
amount = defender.Apply(amount, powerUps);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user