add all managers

This commit is contained in:
2026-05-17 08:53:37 -07:00
parent ab0e9cb3a4
commit 2d2f969fc9
5 changed files with 714 additions and 0 deletions
@@ -0,0 +1,74 @@
package org.project.managers;
import java.util.Random;
import java.util.Scanner;
public class ActionDecisionManager {
public enum actionsType {
lightAttack,
heavyAttack,
defend,
heal,
ability,
shiedbash,
inventory
}
private Random random = new Random();
public actionsType userChooseAction() {
actionsType res = null;
while (true) {
System.out.println("Choose attack type:\n");
System.out.println("1.lightAttack");
System.out.println("2.heavyAttack");
System.out.println("3.heal");
System.out.println("4.defend");
System.out.println("5.ability");
System.out.println("6.shielBash");
System.out.println("7.inventory");
int choice = new Scanner(System.in).nextInt();
switch (choice) {
case 1:
return actionsType.lightAttack;
case 2:
return actionsType.heavyAttack;
case 3:
return actionsType.heal;
case 4:
return actionsType.defend;
case 5:
return actionsType.ability;
case 6:
return actionsType.shiedbash;
case 7:
return actionsType.inventory;
default:
return actionsType.lightAttack;
}
}
}
public actionsType botChooseAction() {
actionsType[] possibleActions = {
actionsType.lightAttack,
actionsType.heavyAttack,
actionsType.defend,
actionsType.heal
};
return possibleActions[random.nextInt(possibleActions.length)];
}
}
@@ -0,0 +1,234 @@
package org.project.managers;
import org.project.Colors;
import org.project.entity.players.Player;
import org.project.item.consumables.HealFlask;
import org.project.item.consumables.ManaFlask;
import org.project.item.weapons.Dagger;
import org.project.item.weapons.Sword;
import org.project.weaponEffects.BurnEffect;
import org.project.weaponEffects.FreezeEffect;
import org.project.weaponEffects.PoisonEffect;
import java.awt.*;
import java.util.Scanner;
public class InventoryManager {
private final HealFlask healFlask = new HealFlask("Heal Flask", 30, 3);
private final ManaFlask manaFlask = new ManaFlask("Mana Flask", 20, 2);
private final Scanner scanner = new Scanner(System.in);
private final ManaCostManager manager = new ManaCostManager();
public void displayInventory(Player player) {
while (true) {
System.out.println("\n========" + Colors.YELLOW + " INVENTORY " + Colors.RESET + "========");
System.out.println("""
1. Equip Armor
2. Equip / Change Weapon
3. Equip / Change Weapon Effect
4. Use Flask
0. Exit
""");
int input = scanner.nextInt();
if (input < 0 || input > 4) {
System.out.println("Enter a number between [0 - 3]");
continue;
}
switch (input) {
// =========================
// Exit
// =========================
case 0:
System.out.println("Closing inventory...");
return;
// =========================
// Armor
// =========================
case 1:
if (player.getArmor() != null) {
System.out.println(
player.getName() +
Color.GREEN+
" already has armor: " +
Colors.RESET +
player.getArmor().getName()
);
} else {
manager.equipArmor(player, player.getPersonalArmor());
}
break;
// =========================
// Weapon
// =========================
case 2:
System.out.println("\n---" + Colors.YELLOW + " Weapons " + Colors.RESET + "---");
System.out.println("""
1. Sword
2. Dagger
0. Back
""");
int choice = scanner.nextInt();
if (choice < 0 || choice > 2) {
System.out.println("Enter a number between [0 - 2]");
continue;
}
switch (choice) {
case 0:
System.out.println("Coming back...");
break;
case 1:
manager.equipWeapon(
player,
new Sword(null)
);
break;
case 2:
manager.equipWeapon(player, new Dagger(null));
break;
}
break;
// =========================
// Weapon Effects
// =========================
case 3:
if (player.getWeapon() == null) {
System.out.println(Colors.RED + "Equip a weapon first!" + Colors.RESET);
break;
}
System.out.println("\n---" + Colors.YELLOW + " Weapon Effects " + Colors.RESET + "---");
System.out.println("""
1. Poison Effect
2. Freeze Effect
3. Burn Effect
0. Back
""");
int choice2 = scanner.nextInt();
if (choice2 < 0 || choice2 > 3) {
System.out.println("Enter a number between [0 - 4]");
continue;
}
switch (choice2) {
case 0:
System.out.println("Coming back...");
break;
case 1:
manager.equipStatusEffect(player, new PoisonEffect());
break;
case 2:
manager.equipStatusEffect(player, new FreezeEffect());
break;
case 3:
manager.equipStatusEffect(player, new BurnEffect());
break;
}
break;
case 4:
System.out.println("\n---" + Colors.YELLOW + " Flasks " + Colors.RESET + "---");
System.out.println("1. Heal Flask (" + healFlask.getCharges() + ")");
System.out.println("2. Mana Flask (" + manaFlask.getCharges() + ")");
System.out.println("0. Back");
int flaskChoice = scanner.nextInt();
if (flaskChoice < 0 || flaskChoice > 2) {
System.out.println("Enter a number between [0 - 2]");
continue;
}
switch (flaskChoice) {
case 0:
System.out.println("Coming back...");
break;
case 1:
if (healFlask.getCharges() <= 0) {
System.out.println(Colors.RED + "No Heal Flask charges left!" + Colors.RESET);
break;
}
healFlask.use(player);
System.out.println(
Colors.GREEN +
"Heal Flask used! Charges left: " +
healFlask.getCharges() +
Colors.RESET
);
break;
case 2:
if (manaFlask.getCharges() <= 0) {
System.out.println(Colors.RED + "No Mana Flask charges left!" + Colors.RESET);
break;
}
manaFlask.use(player);
System.out.println(
Colors.CYAN +
"Mana Flask used! Charges left: " +
manaFlask.getCharges() +
Colors.RESET
);
break;
}
break;
}
}
}
}
@@ -0,0 +1,248 @@
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;
}
}
@@ -0,0 +1,77 @@
package org.project.managers;
import org.project.abilities.*;
import org.project.entity.Entity;
import org.project.item.armors.GoblinArmor;
import javax.swing.text.Position;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class SpecialAbilityManager {
private final Map<Entity, List<SpecialAbility>> activeAbilities =
new HashMap<>();
// =========================
// Add Ability
// =========================
public void addAbility(SpecialAbility ability, Entity target) {
if (ability == null || target == null) {
return;
}
activeAbilities.putIfAbsent(target, new ArrayList<>());
ability.onApply(target);
activeAbilities.get(target).add(ability);
}
// =========================
// Update Ability Effects
// =========================
public void tick(Entity abilityUser, Entity target) {
List<SpecialAbility> abilities = activeAbilities.get(abilityUser);
if (abilities == null || abilities.isEmpty()) {
return;
}
Iterator<SpecialAbility> iterator = abilities.iterator();
while (iterator.hasNext()) {
SpecialAbility ability = iterator.next();
if (ability instanceof GuardianOath || ability instanceof PoisonDagger || ability instanceof LifeSteal)
ability.onTick(abilityUser);
if (ability instanceof InfernoBreath || ability instanceof BoneStrike || ability instanceof ArcaneStorm)
ability.onTick(target);
ability.reduceDuration();
if (ability.getDuration() <= 0) {
ability.onExpire(abilityUser);
iterator.remove();
}
}
// Cleanup empty list
if (abilities.isEmpty()) {
activeAbilities.remove(target);
}
}
}
@@ -0,0 +1,81 @@
package org.project.managers;
import org.project.entity.Entity;
import org.project.weaponEffects.StatusEffect;
import java.util.*;
public class StatusEffectManager {
private Map<Entity, List<StatusEffect>> activeEffects = new HashMap<>();
public void addEffect(StatusEffect newEffect, Entity target) {
if (newEffect == null) return;
activeEffects.putIfAbsent(target, new ArrayList<>());
List<StatusEffect> effects = activeEffects.get(target);
for (StatusEffect existing : effects) {
if (existing.getName().equals(newEffect.getName())) {
if (existing.getStackType() == null) {
return;
} else if (existing.getStackType() == StatusEffect.StackType.duration) {
existing.setDuration(existing.getDuration() + newEffect.getDuration());
} else if (existing.getStackType() == StatusEffect.StackType.damage) {
existing.setDamage(existing.getDamage()+ newEffect.getDamage());
} else if (existing.getStackType() == StatusEffect.StackType.both) {
existing.setDamage(existing.getDamage()+ newEffect.getDamage());
existing.setDuration(existing.getDuration() + newEffect.getDuration());
}
return;
}
}
effects.add(newEffect);
newEffect.onApply(target);
}
public void tick(Entity target) {
List<StatusEffect> effects = activeEffects.get(target);
if (effects == null) return;
Iterator<StatusEffect> iterator = effects.iterator();
while (iterator.hasNext()) {
StatusEffect effect = iterator.next();
effect.onTick(target);
effect.reduceDuration();
if (effect.getDuration() <= 0) {
effect.onExpire(target);
iterator.remove();
}
}
}
public boolean hasEffect(Entity target, String name) {
List<StatusEffect> effects = activeEffects.get(target);
if (effects == null) return false;
for (StatusEffect effect : effects) {
if (effect.getName().equals(name))
return true;
}
return false;
}
}