Skip to content

Commit

Permalink
fix(combat): ending combat should clear player buffs
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Mar 26, 2023
1 parent 73143d4 commit f8398f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app/helpers/combat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function handleCombatEnd(ctx: StateContext<IGameCombat>) {
}

} else if(hasEnemyWonCombat(ctx)) {

ctx.dispatch([
new AddCombatLogMessage('You have lost combat!'),
new PlaySFX('combat-lose'),
Expand Down
13 changes: 13 additions & 0 deletions src/stores/combat/combat.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,19 @@ export function tickPlayerEffects(ctx: StateContext<IGameCombat>) {
}));
}

/**
* Unapply all player status effects (when they die).
*/
export function unapplyAllEffectsForPlayer(ctx: StateContext<IGameCombat>) {
const currentPlayer = ctx.getState().currentPlayer;
if(!currentPlayer) {
return;
}

applyDeltas(ctx, currentPlayer, currentPlayer,
currentPlayer.statusEffects.map(effect => ({ target: 'source', attribute: '', delta: 0, unapplyStatusEffect: effect })));
}

/**
* Tick all of the enemy effects down by 1.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/stores/combat/combat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
import { attachments } from './combat.attachments';
import {
acquireItemDrops,
defaultCombat
defaultCombat,
unapplyAllEffectsForPlayer
} from './combat.functions';
import { EnterDungeon } from './dungeon.actions';

Expand Down Expand Up @@ -611,6 +612,7 @@ export class CombatState {

// check for combat ending and get out soon
if(state.currentEncounter.resetInSeconds === 0) {
unapplyAllEffectsForPlayer(ctx);
dispatchCorrectCombatEndEvent(ctx, state.currentEncounter);
return;
}
Expand Down

0 comments on commit f8398f7

Please sign in to comment.