Skip to content

Commit

Permalink
Properly count buildings when capturing a HQ.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: d894ed850d78cd2d91b44f1f9437e491cc1bcd90
  • Loading branch information
cpojer committed Jan 24, 2025
1 parent e93809e commit b7a11d5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
9 changes: 9 additions & 0 deletions apollo/Objective.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,19 @@ export function applyObjectiveActionResponse(
case 'CaptureGameOver': {
const fromPlayer = map.getPlayer(actionResponse.fromPlayer);
const toPlayer = map.getPlayer(actionResponse.toPlayer);
const captured = map.buildings.filter((building) =>
map.matchesPlayer(building, fromPlayer),
).size;
return updateCapture(
removePlayer(
map.copy({
buildings: convertBuildings(map, fromPlayer, toPlayer.id),
teams: updatePlayer(
map.teams,
toPlayer.modifyStatistics({
captured,
}),
),
units: deleteUnits(map, fromPlayer),
}),
fromPlayer,
Expand Down
67 changes: 66 additions & 1 deletion tests/__tests__/Statistics.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import applyActionResponse from '@deities/apollo/actions/applyActionResponse.tsx';
import decodeGameActionResponse from '@deities/apollo/lib/decodeGameActionResponse.tsx';
import updateVisibleEntities from '@deities/apollo/lib/updateVisibleEntities.tsx';
import { Barracks, House } from '@deities/athena/info/Building.tsx';
import { Barracks, House, HQ } from '@deities/athena/info/Building.tsx';
import { Skill } from '@deities/athena/info/Skill.tsx';
import { ConstructionSite } from '@deities/athena/info/Tile.tsx';
import {
Expand Down Expand Up @@ -361,6 +361,71 @@ test('collects statistics on captures and creating units', async () => {
`);
});

test('capturing a HQ will add each captured building to the statistics', async () => {
const vecA = vec(1, 1);
const vecB = vec(2, 3);
const vecC = vec(3, 3);
const initialMap = map.copy({
buildings: map.buildings
.set(vecA, HQ.create(player2))
.set(vecB, Barracks.create(player2))
.set(vecC, House.create(player2)),
units: map.units.set(vecA, Pioneer.create(player1).capture()),
});

const [gameState] = await executeGameActions(initialMap, [
CaptureAction(vecA),
]);

const statsA = gameState.at(0)![1].getPlayer(player1.id).stats;
const statsB = gameState.at(1)![1].getPlayer(player1.id).stats;
const statsC = gameState.at(2)![1].getPlayer(player1.id).stats;
expect(statsA).toMatchInlineSnapshot(`
{
"captured": 1,
"createdBuildings": 0,
"createdUnits": 0,
"damage": 0,
"destroyedBuildings": 0,
"destroyedUnits": 0,
"lostBuildings": 0,
"lostUnits": 0,
"oneShots": 0,
"rescuedUnits": 0,
}
`);

expect(statsB).toMatchInlineSnapshot(`
{
"captured": 3,
"createdBuildings": 0,
"createdUnits": 0,
"damage": 0,
"destroyedBuildings": 0,
"destroyedUnits": 0,
"lostBuildings": 0,
"lostUnits": 0,
"oneShots": 0,
"rescuedUnits": 0,
}
`);

expect(statsC).toMatchInlineSnapshot(`
{
"captured": 3,
"createdBuildings": 0,
"createdUnits": 0,
"damage": 0,
"destroyedBuildings": 0,
"destroyedUnits": 0,
"lostBuildings": 0,
"lostUnits": 0,
"oneShots": 0,
"rescuedUnits": 0,
}
`);
});

test('tracks statistics for players of the same team in fog', async () => {
const vision = new Fog(player1.id);

Expand Down

0 comments on commit b7a11d5

Please sign in to comment.