Allow individual revived Fedaykin placement
This commit is contained in:
1 parent
6a0fba860d
commit
ff2826b980
25 files changed
+1301
-124
No files matched your search
@@ -37,29 +37,48 @@ export function homeworldRevivalDeploymentCanAct(g: GameView): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function deploymentQuantities(g: GameView): { amounts: number[]; blocked: string | null } {
|
||||
const offer = g.homeworldRevivalDeployment;
|
||||
if (!offer || !Number.isSafeInteger(offer.normal) || !Number.isSafeInteger(offer.elite) ||
|
||||
offer.normal < 0 || offer.elite < 0 || offer.normal + offer.elite <= 0 || offer.normal + offer.elite > 20)
|
||||
return { amounts: [], blocked: 'The revived group is no longer available.' };
|
||||
const allocation = offer.allocation;
|
||||
if (allocation === undefined) return { amounts: [offer.normal + offer.elite], blocked: null };
|
||||
if (!allocation || typeof allocation !== 'object' || Array.isArray(allocation) ||
|
||||
Object.keys(allocation).sort().join(',') !== 'kept,placed,remaining,total' || g.advanced || offer.kind !== 'fedaykin' || offer.normal !== 0 ||
|
||||
![allocation.total, allocation.remaining, allocation.placed, allocation.kept].every(value => Number.isSafeInteger(value) && value >= 0 && value <= 20) ||
|
||||
allocation.remaining <= 0 || allocation.total <= 0 || allocation.total !== allocation.remaining + allocation.placed + allocation.kept ||
|
||||
offer.elite !== allocation.remaining)
|
||||
return { amounts: [], blocked: 'The Southern revival allocation is no longer available.' };
|
||||
return { amounts: Array.from({ length: allocation.remaining }, (_, index) => index + 1), blocked: null };
|
||||
}
|
||||
|
||||
/** Only the stamped native Basic allocation allows a partial placement. */
|
||||
export function homeworldRevivalDeploymentQuantities(g: GameView): number[] {
|
||||
if (!homeworldRevivalDeploymentCanAct(g) || g.homeworldRevivalDeployment?.blocked) return [];
|
||||
return deploymentQuantities(g).amounts;
|
||||
}
|
||||
|
||||
export function homeworldRevivalDeploymentChoice(
|
||||
g: GameView,
|
||||
destination: string,
|
||||
amount?: number,
|
||||
): { blocked: string | null; action: Action | null } {
|
||||
const offer = g.homeworldRevivalDeployment;
|
||||
const target = offer?.destinations.find(
|
||||
(option) => option.id === destination,
|
||||
);
|
||||
const quantities = deploymentQuantities(g);
|
||||
const selected = amount === undefined ? quantities.amounts[0] : amount;
|
||||
let blocked: string | null = null;
|
||||
if (!homeworldRevivalDeploymentCanAct(g))
|
||||
blocked = 'Wait for the current choice to finish.';
|
||||
else if (offer!.blocked) blocked = offer!.blocked;
|
||||
else if (!target) blocked = 'Choose a current revival destination.';
|
||||
else if (target.blocked) blocked = target.blocked;
|
||||
else if (
|
||||
!Number.isSafeInteger(offer!.normal) ||
|
||||
!Number.isSafeInteger(offer!.elite) ||
|
||||
offer!.normal < 0 ||
|
||||
offer!.elite < 0 ||
|
||||
offer!.normal + offer!.elite <= 0 ||
|
||||
offer!.normal + offer!.elite > 20
|
||||
)
|
||||
blocked = 'The revived group is no longer available.';
|
||||
else if (quantities.blocked) blocked = quantities.blocked;
|
||||
else if (selected === undefined || !quantities.amounts.includes(selected))
|
||||
blocked = 'Choose a current revived quantity.';
|
||||
return {
|
||||
blocked,
|
||||
action: blocked
|
||||
@@ -68,7 +87,7 @@ export function homeworldRevivalDeploymentChoice(
|
||||
type: 'decision',
|
||||
event: offer!.event,
|
||||
destination,
|
||||
amount: offer!.normal + offer!.elite,
|
||||
amount: selected,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -89,11 +108,12 @@ export function homeworldRevivalDeploymentActions(g: GameView): Action[] {
|
||||
.filter(([, count]) => count > 0)
|
||||
.map(([key]) => splitLocation(key).territory),
|
||||
);
|
||||
const quantities = homeworldRevivalDeploymentQuantities(g);
|
||||
const choices = offer.destinations
|
||||
.map((target) => ({
|
||||
.flatMap((target) => quantities.map(amount => ({
|
||||
target,
|
||||
action: homeworldRevivalDeploymentChoice(g, target.id).action,
|
||||
}))
|
||||
action: homeworldRevivalDeploymentChoice(g, target.id, amount).action,
|
||||
})))
|
||||
.filter((choice) => choice.action);
|
||||
const preferred = choices.find(
|
||||
({ target }) =>
|
||||
@@ -102,5 +122,10 @@ export function homeworldRevivalDeploymentActions(g: GameView): Action[] {
|
||||
occupied.has(target.territory),
|
||||
);
|
||||
const action = preferred?.action ?? choices[0]?.action;
|
||||
if (offer.allocation !== undefined) {
|
||||
const ordered = preferred ? [preferred, ...choices.filter(choice => choice !== preferred && choice.target.id === preferred.target.id),
|
||||
...choices.filter(choice => choice.target.id !== preferred.target.id)] : choices;
|
||||
return [...ordered.flatMap(choice => choice.action ? [choice.action] : []), { type: 'decision', event: offer.event, decline: true }];
|
||||
}
|
||||
return [action ?? { type: 'decision', event: offer.event, decline: true }];
|
||||
}
|
||||
Reference in new issue
Block a user