Skip to content

Commit

Permalink
Revert "refactor(combat): remove CombatActionBehavior.select"
Browse files Browse the repository at this point in the history
- this change caused Guarding only to take effect when the players turn executed in order. So you could end up getting an unguarded hit after choosing guard if an enemy came before you in the turn order. I think this is unintuitive.

This reverts commit a64d827.
  • Loading branch information
justindujardin committed Nov 27, 2022
1 parent f05a120 commit 23b4510
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ describe('CombatGuardBehavior', () => {
expect(comp.canTarget()).toBe(false);
});
describe('act', () => {
it('rejects with invalid from player', async () => {
const { combat, machine } = testCombatCreateComponentFixture();
const fixture = TestBed.createComponent(CombatGuardBehavior);
const comp = fixture.componentInstance;
comp.combat = combat;
comp.from = null;
await expectAsync(comp.act()).toBeRejected();
});
it('transitions to end-turn state', async () => {
const { combat, machine } = testCombatCreateComponentFixture();
const fixture = TestBed.createComponent(CombatGuardBehavior);
Expand All @@ -57,6 +49,16 @@ describe('CombatGuardBehavior', () => {
await expectAsync(comp.act()).toBeResolved();
expect(machine.setCurrentState).toHaveBeenCalledOnceWith('end-turn');
});
});
describe('select', () => {
it('rejects with invalid from player', async () => {
const { combat, machine } = testCombatCreateComponentFixture();
const fixture = TestBed.createComponent(CombatGuardBehavior);
const comp = fixture.componentInstance;
comp.combat = combat;
comp.from = null;
await expect(() => comp.select()).toThrow();
});
it('sets "guarding" status on player until a target state is entered', async () => {
const { combat, machine } = testCombatCreateComponentFixture();
const fixture = TestBed.createComponent(CombatGuardBehavior);
Expand All @@ -65,7 +67,7 @@ describe('CombatGuardBehavior', () => {
spyOn(machine, 'setCurrentState').and.callThrough();
comp.combat = combat;
comp.from = players[0];
await expectAsync(comp.act()).toBeResolved();
await expect(() => comp.select()).not.toThrow();

// "guarding" status is added to player
const guardingPlayer = testCombatGetParty(comp.store)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ export class CombatGuardBehavior extends CombatActionBehavior {
return false;
}

async act(): Promise<boolean> {
this.combat.machine.setCurrentState('end-turn');
return true;
}

/**
* Until the end of the next turn, or combat end, increase the
* current players defense.
*/
async act(): Promise<boolean> {
select(): void {
const model: CombatantTypes = this.from?.model as CombatantTypes;
assertTrue(model, 'invalid guard behavior model');
assertTrue(this._subscription === null, 'subscription leak in guard behavior');
Expand All @@ -54,8 +59,6 @@ export class CombatGuardBehavior extends CombatActionBehavior {
this.store.dispatch(
new CombatSetStatusAction({ target: model, classes: ['guarding'] })
);
this.combat.machine.setCurrentState('end-turn');
return true;
}

enterStateHandler(change: IStateChange<CombatStateNames>) {
Expand Down
5 changes: 4 additions & 1 deletion src/app/routes/combat/behaviors/choose-action.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ export class ChooseActionTarget extends State<CombatChooseActionStateNames> {
selectTarget(click.hits[0]);
};

const beneficial: boolean = !!(machine.spell?.benefit || machine.item);
const beneficial: boolean = !!(
machine &&
((machine.spell && machine.spell.benefit) || machine.item)
);
const targets: GameEntityObject[] = beneficial ? machine.players : machine.enemies;
machine.parent.items = targets.map((a: GameEntityObject) => {
return {
Expand Down
7 changes: 7 additions & 0 deletions src/app/routes/combat/behaviors/combat-action.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export class CombatActionBehavior extends SceneObjectBehavior implements IPlayer
return Promise.reject('do not call super on .act()');
}

/**
* The action has been selected for the current turn.
*/
select() {
// nothing
}

/** Preload any sprites/sounds that the action requires */
async preload(): Promise<(AudioResource | ImageResource)[]> {
const spriteSheets = _.uniq(
Expand Down

0 comments on commit 23b4510

Please sign in to comment.