add enemy and enemy roles

This commit is contained in:
2026-07-08 17:32:54 +03:30
parent ddc2b8df73
commit 88a19279d3
5 changed files with 192 additions and 22 deletions
@@ -0,0 +1,52 @@
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) {
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";
}
}
@@ -1,34 +1,103 @@
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 void PlayRound(Player player) {
ArrayList<FightMoves> moves = GetAvailableMoves();
Random random = new Random();
int change = random.nextInt(4);
if (change == 0 && moves.contains(FightMoves.HEAL)) HealMove();
else if (change == 1 && moves.contains(FightMoves.DEFEND)) defend();
else if (moves.contains(FightMoves.SPECIAL)) SpecialAbility(player);
else if (moves.contains(FightMoves.HEAVY_ATTACK)) HeavyAttack(player);
else LightAttack(player);
} }
@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,5 @@
package org.project.entity.enemies;
public class Goblin extends Enemy {
}
@@ -1,6 +1,5 @@
package org.project.entity.enemies; package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION public class Skeleton extends Enemy {
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
} }
@@ -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, 100, 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";
}
}