Combat Moves - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

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.

Class Diagram

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()
    }
Loading

Sequence Diagram

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)
Loading

Key Components

CombatMove (Abstract Class)

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);
}

AttackMove

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
    }
}

GuardMove

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
    }
}

SleepMove

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()));
        }
    }
}

SpecialMove (Abstract Class)

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);
}

Usage

To use combat moves in your game:

  1. 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);
  1. 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));
  1. Execute moves during combat:
CombatMoveComponent movesComponent = entity.getComponent(CombatMoveComponent.class);
movesComponent.executeMove(CombatManager.Action.ATTACK, targetStats);

Extending the System

To create new types of moves:

  1. Extend the CombatMove class (or SpecialMove for unique abilities).
  2. Implement the execute methods to define the move's behavior.
  3. 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
    }
}
⚠️ **GitHub.com Fallback** ⚠️