-
Notifications
You must be signed in to change notification settings - Fork 1
Boss Combat Outcomes
Phurin Vanasrivilai edited this page Oct 17, 2024
·
3 revisions
Handle the event triggers and event listeners after defeating or losing to the bosses in combat.
/**
* 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
}
}
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);
}
Visual testing, with captioning to explain: https://youtu.be/Ny-1nAlynto