수정
This commit is contained in:
@@ -113,11 +113,11 @@ export const suppliedDestCity = (): Constraint => ({
|
|||||||
requires: (ctx) =>
|
requires: (ctx) =>
|
||||||
resolveDestCityId(ctx) !== undefined
|
resolveDestCityId(ctx) !== undefined
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
kind: 'destCity',
|
kind: 'destCity',
|
||||||
id: resolveDestCityId(ctx) ?? 0,
|
id: resolveDestCityId(ctx) ?? 0,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
test: (ctx, view) => {
|
test: (ctx, view) => {
|
||||||
const destCity = readDestCity(ctx, view);
|
const destCity = readDestCity(ctx, view);
|
||||||
@@ -249,11 +249,11 @@ export const existsDestCity = (): Constraint => ({
|
|||||||
requires: (ctx) =>
|
requires: (ctx) =>
|
||||||
resolveDestCityId(ctx) !== undefined
|
resolveDestCityId(ctx) !== undefined
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
kind: 'destCity',
|
kind: 'destCity',
|
||||||
id: resolveDestCityId(ctx) ?? 0,
|
id: resolveDestCityId(ctx) ?? 0,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
test: (ctx, view) => {
|
test: (ctx, view) => {
|
||||||
const destCityId = resolveDestCityId(ctx);
|
const destCityId = resolveDestCityId(ctx);
|
||||||
@@ -315,11 +315,11 @@ export const notNeutralDestCity = (): Constraint => ({
|
|||||||
requires: (ctx) =>
|
requires: (ctx) =>
|
||||||
resolveDestCityId(ctx) !== undefined
|
resolveDestCityId(ctx) !== undefined
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
kind: 'destCity',
|
kind: 'destCity',
|
||||||
id: resolveDestCityId(ctx) ?? 0,
|
id: resolveDestCityId(ctx) ?? 0,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
test: (ctx, view) => {
|
test: (ctx, view) => {
|
||||||
const destCity = readDestCity(ctx, view);
|
const destCity = readDestCity(ctx, view);
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ const readDiplomacyEntry = (
|
|||||||
typeof record.state === 'number'
|
typeof record.state === 'number'
|
||||||
? record.state
|
? record.state
|
||||||
: typeof record.stateCode === 'number'
|
: typeof record.stateCode === 'number'
|
||||||
? record.stateCode
|
? record.stateCode
|
||||||
: null;
|
: null;
|
||||||
const term = typeof record.term === 'number' ? record.term : null;
|
const term = typeof record.term === 'number' ? record.term : null;
|
||||||
return { state, term };
|
return { state, term };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,3 +31,17 @@ export const collectRequirements = (constraints: Constraint[], ctx: ConstraintCo
|
|||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface ActionWithConstraints {
|
||||||
|
buildConstraints(ctx: ConstraintContext, args: unknown): Constraint[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const evaluateActionConstraints = <Args>(
|
||||||
|
action: ActionWithConstraints,
|
||||||
|
ctx: ConstraintContext,
|
||||||
|
view: StateView,
|
||||||
|
args: Args
|
||||||
|
): ConstraintResult => {
|
||||||
|
const constraints = action.buildConstraints(ctx, args);
|
||||||
|
return evaluateConstraints(constraints, ctx, view);
|
||||||
|
};
|
||||||
|
|||||||
@@ -181,11 +181,11 @@ export const existsDestGeneral = (): Constraint => ({
|
|||||||
requires: (ctx) =>
|
requires: (ctx) =>
|
||||||
resolveDestGeneralId(ctx) !== undefined
|
resolveDestGeneralId(ctx) !== undefined
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
kind: 'destGeneral',
|
kind: 'destGeneral',
|
||||||
id: resolveDestGeneralId(ctx) ?? 0,
|
id: resolveDestGeneralId(ctx) ?? 0,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
test: (ctx, view) => {
|
test: (ctx, view) => {
|
||||||
const destGeneralId = resolveDestGeneralId(ctx);
|
const destGeneralId = resolveDestGeneralId(ctx);
|
||||||
|
|||||||
@@ -21,21 +21,25 @@ export const notOpeningPart = (relYear: number, openingPartYear: number): Constr
|
|||||||
export const beOpeningPart = (): Constraint => ({
|
export const beOpeningPart = (): Constraint => ({
|
||||||
name: 'beOpeningPart',
|
name: 'beOpeningPart',
|
||||||
requires: () => [
|
requires: () => [
|
||||||
{ kind: 'env', key: 'year' },
|
{ kind: 'env', key: 'relYear' },
|
||||||
{ kind: 'env', key: 'openingPartYear' },
|
{ kind: 'env', key: 'openingPartYear' },
|
||||||
],
|
],
|
||||||
test: (_ctx, view) => {
|
test: (_ctx, view) => {
|
||||||
const year = view.get({ kind: 'env', key: 'year' }) as number | undefined;
|
const relYear = view.get({ kind: 'env', key: 'relYear' }) as number | undefined;
|
||||||
const openingPartYear = view.get({ kind: 'env', key: 'openingPartYear' }) as number | undefined;
|
const openingPartYear = view.get({ kind: 'env', key: 'openingPartYear' }) as number | undefined;
|
||||||
|
|
||||||
if (year === undefined || openingPartYear === undefined) {
|
if (openingPartYear === undefined) {
|
||||||
// 정보가 없으면 제약을 무시하거나 알림
|
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relYear === undefined) {
|
||||||
|
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relYear + 1 <= openingPartYear) {
|
||||||
return allow();
|
return allow();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (year <= openingPartYear) {
|
return { kind: 'deny', reason: '초반 제한 중에는 불가능합니다.' };
|
||||||
return allow();
|
|
||||||
}
|
|
||||||
return { kind: 'deny', reason: '초반이 지났습니다.' };
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -154,11 +154,11 @@ export const existsDestNation = (): Constraint => ({
|
|||||||
requires: (ctx) =>
|
requires: (ctx) =>
|
||||||
resolveDestNationId(ctx) !== undefined
|
resolveDestNationId(ctx) !== undefined
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
kind: 'destNation',
|
kind: 'destNation',
|
||||||
id: resolveDestNationId(ctx) ?? 0,
|
id: resolveDestNationId(ctx) ?? 0,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
test: (ctx, view) => {
|
test: (ctx, view) => {
|
||||||
const destNationId = resolveDestNationId(ctx);
|
const destNationId = resolveDestNationId(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user