Skip to content

Boss Combat Outcomes

Phurin Vanasrivilai edited this page Oct 17, 2024 · 3 revisions

Overview

Handle the event triggers and event listeners after defeating or losing to the bosses in combat.

Implementation

In CombatManager, checking for combat ends to trigger the appropriate event

    /**
     * Checks if combat has ended by evaluating the health of both the player and the enemy.
     * Triggers events based on whether the player has won or lost the combat.
     */
    private void checkCombatEnd() {
        if (playerStats.getHealth() <= 0) {
            if (enemy.getComponent(CombatStatsComponent.class).isBoss()) {
                this.getEntity().getEvents().trigger("bossCombatLoss", enemy);
                GameState.resetState();
                SaveHandler.delete(GameState.class, "saves", FileLoader.Location.LOCAL);
            } else {
                this.getEntity().getEvents().trigger("combatLoss");
                //Clear inventory/other normal death events
            }
            // nullifyCombatDialogueListener(); // remove the listener added for animation syncing
        } else if (enemyStats.getHealth() <= 0) {
            if (enemy.getComponent(CombatStatsComponent.class).isBoss()) {
                entity.getEvents().trigger("bossCombatWin", enemy);
            } else {
                this.getEntity().getEvents().trigger("combatWin", enemy);
            }
            // nullifyCombatDialogueListener(); // remove the listener added for animation syncing
        }
    }

In 'CombatAction', listen to event bossCombatWin and bossCombatLoss

  public void create() {
      entity.getEvents().addListener("bossCombatWin", this::onBossCombatWin);
      entity.getEvents().addListener("bossCombatLoss", this::onBossCombatLoss);
  }

  private void onBossCombatWin(Entity bossEnemy) {
    logger.info("Switching back to main game after defeating kangaroo boss.");

    if (bossEnemy.getEnemyType() == Entity.EnemyType.KANGAROO) {
      entity.getEvents().trigger("landBossDefeated");
    } else if (bossEnemy.getEnemyType() == Entity.EnemyType.WATER_BOSS) {
      entity.getEvents().trigger("waterBossDefeated");
    } else if (bossEnemy.getEnemyType() == Entity.EnemyType.AIR_BOSS) {
      entity.getEvents().trigger("airBossDefeated");
    }

    // Reset player's stamina.
    manager.getPlayer().getComponent(CombatStatsComponent.class).setStamina(100);
    this.manager.getPlayer().getEvents().trigger("defeatedEnemy",this.manager.getEnemy());
    // For CombatStatsDisplay to update
    entity.getEvents().trigger("onCombatWin", manager.getPlayerStats());

    // For CombatButtonDisplay DialogueBox
    entity.getEvents().trigger("endOfBossCombatDialogue", bossEnemy, true);
    int enemyExp = bossEnemy.getComponent(CombatStatsComponent.class).getExperience();
    manager.getPlayer().getComponent(CombatStatsComponent.class).addExperience(enemyExp);
  }

  private void onBossCombatLoss(Entity enemy) {
    logger.info("Returning to main game screen after combat loss.");

    // For CombatButtonDisplay DialogueBox
    entity.getEvents().trigger("endOfBossCombatDialogue", enemy, false);
  }

Testing Plan

Visual testing, with captioning to explain: https://youtu.be/Ny-1nAlynto

AttackOnAnimals._.Sprint.4.Boss._.Team.9.mp4
Clone this wiki locally