249 lines
5.7 KiB
Java
249 lines
5.7 KiB
Java
package org.project.managers;
|
|
|
|
import org.project.Colors;
|
|
import org.project.abilities.SpecialAbility;
|
|
import org.project.entity.Entity;
|
|
import org.project.entity.players.Player;
|
|
import org.project.item.armors.Armor;
|
|
import org.project.item.weapons.Weapon;
|
|
import org.project.weaponEffects.StatusEffect;
|
|
|
|
public class ManaCostManager {
|
|
|
|
private final int heavyAttackManaCost = 8;
|
|
private final int defendManaCost = 9;
|
|
private final int healManaCost = 12;
|
|
private final int shieldBashManaCost = 15;
|
|
|
|
// =========================
|
|
// Weapon
|
|
// =========================
|
|
|
|
public void equipWeapon(Player player, Weapon weapon) {
|
|
|
|
int manaCost = getWeaponEquipCost(weapon);
|
|
|
|
if (player.getMp() < manaCost) {
|
|
|
|
System.out.println("Not enough mana to equip weapon!");
|
|
return;
|
|
}
|
|
|
|
player.useMana(manaCost);
|
|
|
|
player.setWeapon(weapon);
|
|
|
|
System.out.println(
|
|
player.getName() +
|
|
" equipped weapon: " +
|
|
weapon.getName()
|
|
);
|
|
|
|
}
|
|
|
|
// =========================
|
|
// Armor
|
|
// =========================
|
|
|
|
public void equipArmor(Player player, Armor armor) {
|
|
|
|
int manaCost = getArmorEquipCost(armor);
|
|
|
|
if (player.getMp() < manaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana to equip armor!" + Colors.RESET);
|
|
return;
|
|
}
|
|
|
|
player.useMana(manaCost);
|
|
|
|
player.setArmor(armor);
|
|
|
|
System.out.println(
|
|
player.getName() +
|
|
Colors.GREEN +
|
|
" equipped armor: " +
|
|
Colors.RESET +
|
|
armor.getName()
|
|
);
|
|
|
|
}
|
|
|
|
// =========================
|
|
// Status Effect
|
|
// =========================
|
|
|
|
public void equipStatusEffect(Player player,
|
|
StatusEffect equippedEffect) {
|
|
|
|
Weapon weapon = player.getWeapon();
|
|
|
|
if (weapon == null) {
|
|
|
|
System.out.println(Colors.RED + "Equip a weapon first!" + Colors.RESET);
|
|
return;
|
|
}
|
|
|
|
int manaCost = equippedEffect.getEquipManaCost();
|
|
|
|
if (player.getMp() < manaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana to equip this effect!" + Colors.RESET);
|
|
return;
|
|
}
|
|
|
|
player.useMana(manaCost);
|
|
|
|
weapon.setEffect(equippedEffect);
|
|
|
|
System.out.println(
|
|
player.getName() +
|
|
Colors.GREEN +
|
|
" equipped effect: " +
|
|
Colors.RESET +
|
|
equippedEffect.getName()
|
|
);
|
|
|
|
}
|
|
|
|
// =========================
|
|
// Special Ability
|
|
// =========================
|
|
|
|
public boolean useSpecialAbility(Entity entity) {
|
|
|
|
SpecialAbility ability = entity.getSpacialAbility();
|
|
|
|
if (ability == null) {
|
|
|
|
System.out.println(Colors.RED + "No special ability equipped!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
int manaCost = ability.getManaCost();
|
|
|
|
if (entity.getMp() < manaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana to use special ability!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
entity.useMana(manaCost);
|
|
|
|
return true;
|
|
}
|
|
|
|
// =========================
|
|
// Heavy Attack
|
|
// =========================
|
|
|
|
public boolean useHeavyAttack(Entity entity) {
|
|
|
|
if (entity.getMp() < heavyAttackManaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
entity.useMana(heavyAttackManaCost);
|
|
|
|
return true;
|
|
}
|
|
|
|
// =========================
|
|
// Defend
|
|
// =========================
|
|
|
|
public boolean useDefend(Entity entity) {
|
|
|
|
if (entity.getMp() < defendManaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
entity.useMana(defendManaCost);
|
|
|
|
return true;
|
|
}
|
|
|
|
// =========================
|
|
// Heal
|
|
// =========================
|
|
|
|
public boolean useHeal(Entity entity) {
|
|
|
|
if (entity.getMp() < healManaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
entity.useMana(healManaCost);
|
|
|
|
return true;
|
|
}
|
|
|
|
// =========================
|
|
// Shield Bash
|
|
// =========================
|
|
|
|
public boolean useShieldBash(Player player) {
|
|
|
|
Armor armor = player.getArmor();
|
|
|
|
if (armor == null) {
|
|
|
|
System.out.println(Colors.RED + "You need armor to use Shield Bash!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
if (armor.getType() != Armor.ArmorType.HEAVY) {
|
|
|
|
System.out.println(Colors.RED + "Shield Bash requires HEAVY armor!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
if (player.getMp() < shieldBashManaCost) {
|
|
|
|
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
|
return false;
|
|
}
|
|
|
|
player.useMana(shieldBashManaCost);
|
|
|
|
return true;
|
|
}
|
|
|
|
// =========================
|
|
// Mana Costs
|
|
// =========================
|
|
|
|
private int getArmorEquipCost(Armor armor) {
|
|
|
|
return switch (armor.getType()) {
|
|
|
|
case LIGHT -> 3;
|
|
|
|
case MEDIUM -> 6;
|
|
|
|
case HEAVY -> 10;
|
|
};
|
|
}
|
|
|
|
private int getWeaponEquipCost(Weapon weapon) {
|
|
|
|
int damage = weapon.getLightAttackDamage();
|
|
|
|
if (damage <= 10) {
|
|
return 3;
|
|
}
|
|
|
|
if (damage <= 20) {
|
|
return 6;
|
|
}
|
|
|
|
return 10;
|
|
}
|
|
}
|