add combat
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package org.project.combat;
|
||||
|
||||
public class AttackResult {
|
||||
|
||||
private int damageToTarget;
|
||||
private int healSelf;
|
||||
private boolean defended;
|
||||
|
||||
public AttackResult(int damageToTarget, int healSelf, boolean defended) {
|
||||
this.damageToTarget = damageToTarget;
|
||||
this.healSelf = healSelf;
|
||||
this.defended = defended;
|
||||
}
|
||||
|
||||
public int getDamageToTarget() { return damageToTarget; }
|
||||
public int getHealSelf() { return healSelf; }
|
||||
public boolean isDefended() { return defended; }
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package org.project.combat;
|
||||
|
||||
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.managers.ActionDecisionManager;
|
||||
import org.project.managers.ManaCostManager;
|
||||
import org.project.managers.SpecialAbilityManager;
|
||||
import org.project.managers.StatusEffectManager;
|
||||
|
||||
public class TotalAttackCalculator {
|
||||
|
||||
private final StatusEffectManager statusEffectManager;
|
||||
private final SpecialAbilityManager specialAbilityManager;
|
||||
private final ManaCostManager manaCostManager;
|
||||
|
||||
private static final int HEAL_AMOUNT = 25;
|
||||
private static final int SHIELD_BASH_BASE_DAMAGE = 15;
|
||||
private static final int SHIELD_BASH_STUN_CHANCE = 30;
|
||||
|
||||
public TotalAttackCalculator(
|
||||
StatusEffectManager statusEffectManager,
|
||||
SpecialAbilityManager specialAbilityManager,
|
||||
ManaCostManager manaCostManager
|
||||
) {
|
||||
this.statusEffectManager = statusEffectManager;
|
||||
this.specialAbilityManager = specialAbilityManager;
|
||||
this.manaCostManager = manaCostManager;
|
||||
}
|
||||
|
||||
public AttackResult calculate(
|
||||
Entity attacker,
|
||||
Entity defender,
|
||||
ActionDecisionManager.actionsType action
|
||||
) {
|
||||
|
||||
switch (action) {
|
||||
|
||||
case lightAttack:
|
||||
return lightAttack(attacker, defender);
|
||||
|
||||
case heavyAttack:
|
||||
return heavyAttack(attacker, defender);
|
||||
|
||||
case defend:
|
||||
return defend(attacker);
|
||||
|
||||
case heal:
|
||||
return heal(attacker);
|
||||
|
||||
case ability:
|
||||
return ability(attacker, defender);
|
||||
|
||||
case shiedbash:
|
||||
return shieldBash(attacker, defender);
|
||||
}
|
||||
|
||||
return new AttackResult(0,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// LIGHT ATTACK
|
||||
// --------------------------------
|
||||
private AttackResult lightAttack(Entity attacker, Entity defender) {
|
||||
|
||||
int damage = attacker.getBaseDamage();
|
||||
|
||||
Weapon weapon = attacker.getWeapon();
|
||||
|
||||
if (weapon != null) {
|
||||
damage += weapon.getLightAttackDamage();
|
||||
|
||||
if (weapon.getEffect() != null)
|
||||
statusEffectManager.addEffect(weapon.getEffect(), defender);
|
||||
}
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (defender.isDefending())
|
||||
damage /= 2;
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// HEAVY ATTACK
|
||||
// --------------------------------
|
||||
private AttackResult heavyAttack(Entity attacker, Entity defender) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
int damage = attacker.getBaseDamage() * 2;
|
||||
|
||||
Weapon weapon = attacker.getWeapon();
|
||||
|
||||
if (weapon != null) {
|
||||
|
||||
damage += weapon.getHeavyAttackDamage();
|
||||
|
||||
if (weapon.getEffect() != null)
|
||||
statusEffectManager.addEffect(weapon.getEffect(), defender);
|
||||
}
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (defender.isDefending())
|
||||
damage /= 2;
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// DEFEND
|
||||
// --------------------------------
|
||||
private AttackResult defend(Entity attacker) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
return new AttackResult(0,0,true);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// HEAL
|
||||
// --------------------------------
|
||||
private AttackResult heal(Entity attacker) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
return new AttackResult(0,HEAL_AMOUNT,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// SPECIAL ABILITY
|
||||
// --------------------------------
|
||||
private AttackResult ability(Entity attacker, Entity defender) {
|
||||
|
||||
SpecialAbility ability = attacker.getSpacialAbility();
|
||||
|
||||
if (ability == null)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
if (attacker instanceof Player && !manaCostManager.useSpecialAbility((Player) attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
Entity target =
|
||||
ability.getTarget() == SpecialAbility.AbilityTarget.SELF
|
||||
? attacker
|
||||
: defender;
|
||||
|
||||
specialAbilityManager.addAbility(ability, target);
|
||||
|
||||
return new AttackResult(0,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// SHIELD BASH
|
||||
// --------------------------------
|
||||
private AttackResult shieldBash(Entity attacker, Entity defender) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
Armor armor = attacker.getArmor();
|
||||
|
||||
if (armor == null)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
if (armor.getType() != Armor.ArmorType.HEAVY)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
int damage = SHIELD_BASH_BASE_DAMAGE + armor.getDefense() / 2;
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (Math.random() * 100 < SHIELD_BASH_STUN_CHANCE)
|
||||
defender.stun();
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// ARMOR REDUCTION
|
||||
// --------------------------------
|
||||
private int applyArmor(Entity defender, int rawDamage) {
|
||||
|
||||
Armor armor = defender.getArmor();
|
||||
|
||||
if (armor == null)
|
||||
return rawDamage;
|
||||
|
||||
return armor.reduceDamage(rawDamage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user