forked from nkzw-tech/athena-crisis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessRewards.tsx
49 lines (47 loc) · 1.58 KB
/
processRewards.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import MapData from '@deities/athena/MapData.tsx';
import { WinCriteria } from '@deities/athena/WinConditions.tsx';
import isPresent from '@deities/hephaestus/isPresent.tsx';
import applyActionResponse from '../actions/applyActionResponse.tsx';
import {
GameEndActionResponse,
OptionalWinActionResponse,
} from '../GameOver.tsx';
import { GameState, MutableGameState } from '../Types.tsx';
import getWinningTeam from './getWinningTeam.tsx';
export function processRewards(
map: MapData,
actionResponse: GameEndActionResponse | OptionalWinActionResponse,
): [GameState, MapData] {
const gameState: MutableGameState = [];
const winningTeam = getWinningTeam(map, actionResponse);
if (winningTeam !== 'draw') {
const rewards = new Set(
[
'condition' in actionResponse ? actionResponse.condition?.reward : null,
map.config.winConditions.find(
(condition) => condition.type === WinCriteria.Default,
)?.reward,
].filter(isPresent),
);
if (rewards.size) {
for (const reward of rewards) {
for (const [, player] of map.getTeam(winningTeam).players) {
if (!player.skills.has(reward.skill)) {
const rewardActionResponse = {
player: player.id,
reward,
type: 'ReceiveReward',
} as const;
map = applyActionResponse(
map,
map.createVisionObject(player),
rewardActionResponse,
);
gameState.push([rewardActionResponse, map]);
}
}
}
}
}
return [gameState, map];
}