3 Commits
Author SHA1 Message Date
Ramtin 0afe5c8c69 add skeleton as an enemy 2026-07-09 14:38:34 +03:30
Ramtin dc3f2f53ca enhance entity state modes 2026-07-09 14:38:18 +03:30
Ramtin 498d455277 add enemy and enemy roles 2026-07-09 14:37:30 +03:30
7 changed files with 334 additions and 23 deletions
@@ -2,6 +2,7 @@ package org.project.constants.gameConstant;
public enum EntityState { public enum EntityState {
ALIVE, ALIVE,
DOWNED,
DEAD, DEAD,
FROZEN FROZEN
} }
@@ -228,7 +228,7 @@ public abstract class Entity implements IDamageable, IHealable, IDefendable, IFi
@Override @Override
public ArrayList<FightMoves> GetAvailableMoves() { public ArrayList<FightMoves> GetAvailableMoves() {
if (GetState() == EntityState.FROZEN) return new ArrayList<>(){}; if (GetState() == EntityState.FROZEN || GetState() == EntityState.DEAD) return new ArrayList<>(){};
ArrayList<FightMoves> result = new ArrayList<>(); ArrayList<FightMoves> result = new ArrayList<>();
result.add(FightMoves.DEFEND); result.add(FightMoves.DEFEND);
@@ -0,0 +1,53 @@
package org.project.entity.enemies;
import org.project.constants.gameConstant.AttackPowerUp;
import org.project.constants.gameConstant.EntityState;
import org.project.entity.Entity;
import org.project.entity.players.Player;
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.KeyItem;
import java.util.ArrayList;
public class Dragon extends Enemy {
public Dragon (String name, int maxHealth, int health, long money, int baseDamage, EntityState state, Weapon weapon,
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending,
int healAmount, int stamina, int maxStamina) {
super(name, maxHealth, health, money, baseDamage, state, weapon, shield, costume, inventory, defenseBonus, isDefending, healAmount, stamina, maxStamina);
this.Key = new KeyItem("Dragon Key", this);
}
public Dragon() {
this("Dragon", 5000, 5000, 0, 100, EntityState.ALIVE, null, null, null, new ArrayList<>(){}, 50, false, 50, 500, 500);
}
@Override
public void DropLoot(Player player) {
Key.Owner = player;
player.AddToInventory(Key);
}
@Override
public void SpecialAbility(Entity entity) {
ModifyStamina(SpecialAbilityStamina, false);
Damage(entity, GetDamage() * 2, new AttackPowerUp[]{AttackPowerUp.INEVITABLE, AttackPowerUp.ANTI_SHIELD});
}
@Override
public String GetSpecialAbilityDescription(Entity entity) {
return "Dragon will throw its fiery breath towards " + entity.Name + ". No defense and shield will help";
}
@Override
public String GetSpecialAbilityResultDescription(Entity entity) {
if (entity.IsDefending) {
return "Dragon will threw its fiery breath towards " + entity.Name + ". " + entity.Name + " tries to defend against it, but there's no use";
}
return "Dragon will threw its fiery breath towards " + entity.Name + ". To " + entity.Name + " surprise, their shield had no use";
}
}
@@ -1,34 +1,119 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.item.weapons.Weapon; import org.project.Interface.IDamageable;
import org.project.constants.gameConstant.AttackPowerUp;
import org.project.constants.gameConstant.EntityState;
import org.project.constants.gameConstant.FightMoves;
import org.project.constants.gameConstant.ItemClass;
import org.project.entity.Entity;
import org.project.entity.players.Player;
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.KeyItem;
// TODO: UPDATE IMPLEMENTATION import java.util.ArrayList;
public abstract class Enemy { import java.util.Arrays;
Weapon weapon; import java.util.Objects;
private int hp; import java.util.Random;
private int mp;
public Enemy(int hp, int mp, Weapon weapon) { public abstract class Enemy extends Entity {
this.hp = hp; protected KeyItem Key;
this.mp = mp;
this.weapon = weapon; public Enemy (String name, int maxHealth, int health, long money, int baseDamage, EntityState state, Weapon weapon,
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending,
int healAmount, int stamina, int maxStamina) {
super(name, maxHealth, health, stamina, maxStamina, money, baseDamage, state, weapon, shield, costume, inventory, defenseBonus, isDefending, healAmount);
Key = new KeyItem(null, this);
}
protected Enemy() {
super();
}
public void DropLoot(Player player) {
Random random = new Random();
for (Item item : Inventory) {
int change = random.nextInt(2);
if (change == 0) {
player.AddToInventory(item);
}
}
ArrayList<Item> keys = player.GetInventoryByClass(ItemClass.KEY);
if (keys.stream().noneMatch(obj -> Objects.equals(obj.getName(), Key.getName()))) {
int chance = random.nextInt(5);
if (chance == 0) {
Key.Owner = player;
player.AddToInventory(Key);
}
}
player.ModifyMoney(GetMoney(), true);
}
public FightMoves PlayRound(Player player) {
ArrayList<FightMoves> moves = GetAvailableMoves();
Random random = new Random();
int change = random.nextInt(4);
if (change == 0 && moves.contains(FightMoves.HEAL)) {
HealMove();
return FightMoves.HEAL;
}
else if (change == 1 && moves.contains(FightMoves.DEFEND)) {
defend();
return FightMoves.DEFEND;
}
else if (moves.contains(FightMoves.SPECIAL)) {
SpecialAbility(player);
return FightMoves.SPECIAL;
}
else if (moves.contains(FightMoves.HEAVY_ATTACK)) {
HeavyAttack(player);
return FightMoves.HEAVY_ATTACK;
}
else if (moves.contains(FightMoves.LIGHT_ATTACK)) {
LightAttack(player);
return FightMoves.LIGHT_ATTACK;
}
else return null;
} }
@Override @Override
public void takeDamage(int damage) { public void LightAttack(IDamageable target) {
hp -= damage; int damage = GetDamage();
Damage(target, (int)(damage * 0.4), new AttackPowerUp[]{});
ModifyStamina(MaxStamina/8, true);
} }
public int getHp() { @Override
return hp; public void HeavyAttack(IDamageable target) {
int damage = GetDamage();
ModifyStamina(HeavyAttackStamina, false);
Damage(target, (int)(damage * 0.9), new AttackPowerUp[]{});
} }
public int getMp() { @Override
return mp; public void HealMove() {
super.HealMove();
ModifyStamina(MaxStamina/4, true);
} }
public Weapon getWeapon() { @Override
return weapon; public abstract void SpecialAbility(Entity entity);
}
@Override
public abstract String GetSpecialAbilityDescription(Entity entity);
@Override
public abstract String GetSpecialAbilityResultDescription(Entity entity);
} }
@@ -0,0 +1,43 @@
package org.project.entity.enemies;
import org.project.constants.gameConstant.AttackPowerUp;
import org.project.constants.gameConstant.EntityState;
import org.project.entity.Entity;
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.KeyItem;
import java.util.ArrayList;
public class Goblin extends Enemy {
public Goblin (String name, int maxHealth, int health, long money, int baseDamage, EntityState state, Weapon weapon,
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending,
int healAmount, int stamina, int maxStamina) {
super(name, maxHealth, health, money, baseDamage, state, weapon, shield, costume, inventory, defenseBonus, isDefending, healAmount, stamina, maxStamina);
this.Key = new KeyItem("Goblin Key", this);
}
public Goblin() {
this("Goblin", 75, 75, 100, 10, EntityState.ALIVE, null, null, null, new ArrayList<>(), 5, false, 15, 100, 100);
}
@Override
public void SpecialAbility(Entity entity) {
ModifyStamina(SpecialAbilityStamina, false);
Damage(entity, GetDamage() * 4, new AttackPowerUp[]{});
}
@Override
public String GetSpecialAbilityDescription(Entity entity) {
return "Goblin will rage and cause a critical damage to " + entity.Name;
}
@Override
public String GetSpecialAbilityResultDescription(Entity entity) {
return "Goblin looks at " + entity.Name + ", its eyes are red... He rages and charges " + entity.Name + " with all of its power";
}
}
@@ -1,6 +1,90 @@
package org.project.entity.enemies; package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION import org.project.constants.gameConstant.EntityState;
public class Skeleton { import org.project.constants.gameConstant.FightMoves;
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR import org.project.entity.Entity;
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.KeyItem;
import java.util.ArrayList;
import java.util.Random;
public class Skeleton extends Enemy {
boolean HasRevived = false;
public Skeleton (String name, int maxHealth, int health, long money, int baseDamage, EntityState state, Weapon weapon,
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending,
int healAmount, int stamina, int maxStamina) {
super(name, maxHealth, health, money, baseDamage, state, weapon, shield, costume, inventory, defenseBonus, isDefending, healAmount, stamina, maxStamina);
this.Key = new KeyItem("Skeleton Key", this);
}
public Skeleton() {
this("Skeleton", 125, 125, 200, 15, EntityState.ALIVE, null, null, null, new ArrayList<>(), 5, false, 20, 100, 100);
}
@Override
public ArrayList<FightMoves> GetAvailableMoves() {
if (GetState() == EntityState.FROZEN || GetState() == EntityState.DEAD) return new ArrayList<>(){};
ArrayList<FightMoves> result = new ArrayList<>();
if (GetState() == EntityState.DOWNED) {
if (GetStamina() > MaxStamina / 2 && !HasRevived) {
Random random = new Random();
int chance = random.nextInt(2);
if (chance == 0) {
result.add(FightMoves.SPECIAL);
return result;
}
}
else {
HandleZeroHealth();
}
}
result.add(FightMoves.DEFEND);
result.add(FightMoves.LIGHT_ATTACK);
if (Health < MaxHealth) {
result.add(FightMoves.HEAL);
}
if (GetStamina() > MaxStamina / 4) {
result.add(FightMoves.HEAVY_ATTACK);
}
return result;
}
@Override
public void HandleZeroHealth() {
if (GetState() == EntityState.DOWNED) {
SetState(EntityState.DEAD);
}
SetState(EntityState.DOWNED);
}
@Override
public void SpecialAbility(Entity entity) {
SetState(EntityState.ALIVE);
Health = MaxHealth / 2;
HasRevived = true;
}
@Override
public String GetSpecialAbilityDescription(Entity entity) {
return "Skeleton refuses to die and revives";
}
@Override
public String GetSpecialAbilityResultDescription(Entity entity) {
return "Just as " + entity.Name + " made sure of their victory. The bones started to shake, they gathered once more for Skeleton to shape. \"You need more thank that to kill me\" Says the skeleton";
}
} }
@@ -0,0 +1,45 @@
package org.project.entity.enemies;
import org.project.constants.gameConstant.AttackPowerUp;
import org.project.constants.gameConstant.EntityState;
import org.project.entity.Entity;
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.KeyItem;
import java.util.ArrayList;
public class Vampire extends Enemy {
public Vampire (String name, int maxHealth, int health, long money, int baseDamage, EntityState state, Weapon weapon,
Shield shield, Costume costume, ArrayList<Item> inventory, int defenseBonus, boolean isDefending,
int healAmount, int stamina, int maxStamina) {
super(name, maxHealth, health, money, baseDamage, state, weapon, shield, costume, inventory, defenseBonus, isDefending, healAmount, stamina, maxStamina);
this.Key = new KeyItem("Vampire Key", this);
}
public Vampire() {
this("Vampire", 150, 150, 300, 20, EntityState.ALIVE, null, null, null, new ArrayList<>(), 8, false, 30, 100, 100);
}
@Override
public void SpecialAbility(Entity entity) {
int curHealth = entity.Health;
ModifyStamina(SpecialAbilityStamina, false);
Damage(entity, GetDamage(), new AttackPowerUp[]{AttackPowerUp.INEVITABLE});
Heal(curHealth - entity.Health);
}
@Override
public String GetSpecialAbilityDescription(Entity entity) {
return "Vampire will suck the blood out of " + entity.Name + " and heal themselves while hurting the enemy";
}
@Override
public String GetSpecialAbilityResultDescription(Entity entity) {
return "Vampire attacked " + entity.Name + " and sucked his blood out of his veins. He seems more powerful";
}
}