feat: add non-aggression cancel actions and related diplomacy constraints
This commit is contained in:
@@ -63,3 +63,58 @@ export const disallowDiplomacyBetweenStatus = (
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
export const allowDiplomacyBetweenStatus = (
|
||||
allowList: number[],
|
||||
reason: string
|
||||
): Constraint => ({
|
||||
name: 'AllowDiplomacyBetweenStatus',
|
||||
requires: (ctx) => {
|
||||
const reqs: RequirementKey[] = [];
|
||||
if (ctx.nationId !== undefined) {
|
||||
reqs.push({ kind: 'nation', id: ctx.nationId });
|
||||
}
|
||||
const destNationId = resolveDestNationId(ctx);
|
||||
if (destNationId !== undefined) {
|
||||
reqs.push({ kind: 'destNation', id: destNationId });
|
||||
if (ctx.nationId !== undefined) {
|
||||
reqs.push({
|
||||
kind: 'diplomacy',
|
||||
srcNationId: ctx.nationId,
|
||||
destNationId,
|
||||
});
|
||||
}
|
||||
}
|
||||
const destCityId = resolveDestCityId(ctx);
|
||||
if (destCityId !== undefined) {
|
||||
reqs.push({ kind: 'destCity', id: destCityId });
|
||||
}
|
||||
return reqs;
|
||||
},
|
||||
test: (ctx, view) => {
|
||||
const general = readGeneral(ctx, view);
|
||||
const baseNationId = ctx.nationId ?? general?.nationId;
|
||||
if (baseNationId === undefined) {
|
||||
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
|
||||
}
|
||||
const destCity = readDestCity(ctx, view);
|
||||
const destNationId =
|
||||
resolveDestNationId(ctx) ?? destCity?.nationId;
|
||||
if (destNationId === undefined) {
|
||||
return unknownOrDeny(ctx, [], '상대 국가 정보가 없습니다.');
|
||||
}
|
||||
const state = readDiplomacyState(view, baseNationId, destNationId);
|
||||
if (state === null) {
|
||||
const req: RequirementKey = {
|
||||
kind: 'diplomacy',
|
||||
srcNationId: baseNationId,
|
||||
destNationId,
|
||||
};
|
||||
return unknownOrDeny(ctx, [req], '외교 정보가 없습니다.');
|
||||
}
|
||||
if (!allowList.includes(state)) {
|
||||
return { kind: 'deny', reason };
|
||||
}
|
||||
return allow();
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user