Combat Moves - UQcsse3200/2024-studio-2 GitHub Wiki
The combat moves are implemented using a hierarchy of classes, with CombatMove
as the base abstract class. Specific move types (Attack, Guard, Sleep, and Special) extend this base class to provide unique behaviors.
classDiagram
CombatMove <|-- AttackMove
CombatMove <|-- GuardMove
CombatMove <|-- SleepMove
CombatMove <|-- SpecialMove
CombatMove : +String moveName
CombatMove : +int hungerCost
CombatMove : +execute(CombatStatsComponent)
CombatMove : +execute(CombatStatsComponent, CombatStatsComponent)
CombatMove : +execute(CombatStatsComponent, CombatStatsComponent, boolean)
CombatMove : +execute(CombatStatsComponent, CombatStatsComponent, boolean, int)
class AttackMove {
+execute()
-calculateDamage()
}
class GuardMove {
+execute()
}
class SleepMove {
+execute()
}
class SpecialMove {
+execute()
#applyDebuffs()
#applyBuffs()
}
sequenceDiagram
participant CM as CombatManager
participant CMC as CombatMoveComponent
participant AM as AttackMove
participant CS as CombatStatsComponent
CM->>CMC: executeMove(ATTACK)
CMC->>AM: execute(attackerStats, targetStats)
AM->>AM: calculateDamage()
AM->>CS: setHealth(newHealth)
AM->>CS: addHunger(-hungerCost)
The base class for all combat moves. It defines the common properties and methods that all moves share.
public abstract class CombatMove {
protected String moveName;
protected int hungerCost;
// Constructor and getter methods...
public abstract void execute(CombatStatsComponent attackerStats);
public abstract void execute(CombatStatsComponent attackerStats, CombatStatsComponent targetStats);
public abstract void execute(CombatStatsComponent attackerStats, CombatStatsComponent targetStats, boolean targetIsGuarded);
public abstract void execute(CombatStatsComponent attackerStats, CombatStatsComponent targetStats, boolean targetIsGuarded, int numHitsLanded);
}
Represents an offensive move that deals damage to the target.
public class AttackMove extends CombatMove {
@Override
public void execute(CombatStatsComponent attackerStats, CombatStatsComponent targetStats, boolean targetIsGuarded, int numHitsLanded) {
// Implementation of attack logic
int damage = calculateDamage(attackerStats, targetStats, targetIsGuarded, numHitsLanded);
targetStats.setHealth(targetStats.getHealth() - damage);
attackerStats.addHunger(-(this.getHungerCost()));
}
private int calculateDamage(/* parameters */) {
// Damage calculation logic
}
}
A defensive move that reduces incoming damage.
public class GuardMove extends CombatMove {
@Override
public void execute(CombatStatsComponent attackerStats) {
attackerStats.addHunger(-(this.getHungerCost()));
// Additional guard logic can be implemented here
}
}
A recovery move that restores health and hunger.
public class SleepMove extends CombatMove {
@Override
public void execute(CombatStatsComponent attackerStats) {
attackerStats.addHunger((int) (0.25 * attackerStats.getMaxHunger()));
if (!attackerStats.hasStatusEffect(CombatStatsComponent.StatusEffect.POISONED)) {
attackerStats.addHealth((int) (0.1 * attackerStats.getMaxHealth()));
}
}
}
Base class for unique, powerful moves typically used by bosses or special characters.
public abstract class SpecialMove extends CombatMove {
@Override
public void execute(CombatStatsComponent attackerStats, CombatStatsComponent targetStats, boolean targetIsGuarded) {
if (!targetIsGuarded) {
applyDebuffs(targetStats);
}
applyBuffs(attackerStats);
attackerStats.addHunger(-getHungerCost());
}
protected abstract void applyDebuffs(CombatStatsComponent targetStats);
protected abstract void applyBuffs(CombatStatsComponent attackerStats);
}
To use combat moves in your game:
- Create instances of the desired move types:
AttackMove punch = new AttackMove("Punch", 10);
GuardMove defend = new GuardMove("Defend", 5);
SleepMove rest = new SleepMove("Rest", 0);
- Add these moves to an entity's
CombatMoveComponent
:
List<CombatMove> moveSet = new ArrayList<>();
moveSet.add(punch);
moveSet.add(defend);
moveSet.add(rest);
entity.addComponent(new CombatMoveComponent(moveSet));
- Execute moves during combat:
CombatMoveComponent movesComponent = entity.getComponent(CombatMoveComponent.class);
movesComponent.executeMove(CombatManager.Action.ATTACK, targetStats);
To create new types of moves:
- Extend the
CombatMove
class (orSpecialMove
for unique abilities). - Implement the
execute
methods to define the move's behavior. - Add the new move type to entities' movesets as needed.
Example of a custom special move:
public class FireballMove extends SpecialMove {
public FireballMove(String moveName, int hungerCost) {
super(moveName, hungerCost);
}
@Override
protected void applyDebuffs(CombatStatsComponent targetStats) {
targetStats.addStatusEffect(CombatStatsComponent.StatusEffect.BURNING);
}
@Override
protected void applyBuffs(CombatStatsComponent attackerStats) {
attackerStats.addStrength(5); // Temporary strength boost
}
}