Skip to content

Commit

Permalink
Do not activate powers for story based crystal activations.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 7ff1b86ad97601a6d781158b6dfcdecd42542015
  • Loading branch information
cpojer committed Oct 29, 2024
1 parent 6b1b94e commit 5c8c5db
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 11 deletions.
19 changes: 9 additions & 10 deletions apollo/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -964,16 +964,15 @@ function activateCrystal(
{ biome, crystal }: ActivateCrystalAction,
isEffect: boolean,
) {
if (
isEffect &&
Crystals.includes(crystal) &&
(!biome || (Biomes.includes(biome) && biome !== Biome.Spaceship))
) {
return {
biome,
crystal,
type: 'ActivateCrystal',
} as const;
if (isEffect) {
return Crystals.includes(crystal) &&
(!biome || (Biomes.includes(biome) && biome !== Biome.Spaceship))
? ({
biome,
crystal,
type: 'ActivateCrystal',
} as const)
: null;
}

const player = map.getCurrentPlayer();
Expand Down
5 changes: 4 additions & 1 deletion apollo/Effects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ const handleDefaultEffects = (
let gameState: GameStateWithEffects = [];
if (actionResponse.type === 'Start') {
return [[{ type: 'BeginGame' }, activeMap, effects]];
} else if (actionResponse.type === 'ActivateCrystal') {
} else if (
actionResponse.type === 'ActivateCrystal' &&
actionResponse.player
) {
const currentPlayer = activeMap.getCurrentPlayer();
for (const skill of currentPlayer.skills) {
const { activateOnInvasion } = getSkillConfig(skill);
Expand Down
67 changes: 67 additions & 0 deletions tests/__tests__/Power.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {
ActivateCrystalAction,
ActivatePowerAction,
AttackUnitAction,
EndTurnAction,
StartAction,
} from '@deities/apollo/action-mutators/ActionMutators.tsx';
import { Effect, Effects } from '@deities/apollo/Effects.tsx';
import { Skill } from '@deities/athena/info/Skill.tsx';
import { SmallTank } from '@deities/athena/info/Unit.tsx';
import { Crystal } from '@deities/athena/invasions/Crystal.tsx';
import updatePlayer from '@deities/athena/lib/updatePlayer.tsx';
import withModifiers from '@deities/athena/lib/withModifiers.tsx';
import { Biome } from '@deities/athena/map/Biome.tsx';
import { Charge, MaxCharges } from '@deities/athena/map/Configuration.tsx';
import vec from '@deities/athena/map/vec.tsx';
import MapData from '@deities/athena/MapData.tsx';
Expand Down Expand Up @@ -86,3 +91,65 @@ test('skills are active until the beginning of the next turn', async () => {
EndTurn { current: { funds: 500, player: 2 }, next: { funds: 500, player: 1 }, round: 3, rotatePlayers: false, supply: null, miss: false }"
`);
});

test('crystals activate powers', async () => {
const skills = new Set([Skill.Shield]);
const vecA = vec(1, 1);
const vecB = vec(1, 2);
const mapA = initialMap.copy({
teams: updatePlayer(
initialMap.teams,
initialMap.getPlayer(1).copy({
skills,
}),
),
units: initialMap.units
.set(vecA, SmallTank.create(1))
.set(vecB, SmallTank.create(2)),
});

const [gameStateA, gameActionResponseA] = await executeGameActions(mapA, [
ActivateCrystalAction(Crystal.Power),
]);

expect(snapshotEncodedActionResponse(gameActionResponseA))
.toMatchInlineSnapshot(`
"ActivateCrystal { crystal: 0, player: 1, biome: null, hq: null }
ActivatePower { skill: 38, units: null, free: true }"
`);

expect(gameStateA.at(-1)?.[1].units.get(vecA)?.shield).toBe(true);

// Powers are not activated when it is a regular crystal effect:
const effects: Effects = new Map([
[
'Start',
new Set<Effect>([
{
actions: [
{
biome: Biome.Swamp,
crystal: Crystal.Memory,
type: 'ActivateCrystal',
},
],
},
]),
],
]);

const [gameStateB, gameActionResponseB] = await executeGameActions(
mapA,
[StartAction()],
effects,
);

expect(snapshotEncodedActionResponse(gameActionResponseB))
.toMatchInlineSnapshot(`
"Start
ActivateCrystal { crystal: 4, player: null, biome: 3, hq: null }
BeginGame"
`);

expect(gameStateB.at(-1)?.[1].units.get(vecA)?.shield).toBe(null);
});

0 comments on commit 5c8c5db

Please sign in to comment.