Refactor constraints and action definitions for improved clarity and functionality
- Renamed `requireMinimumTerm` to `reqMinimumTreatyTerm` for consistency in naming conventions. - Introduced `battleGroundCity` constraint to encapsulate logic for checking if a city is in a war zone. - Added `hasRouteToDestCity` constraint to validate city accessibility based on distance and resource requirements. - Replaced `alwaysFail` with `denyWithReason` for better error handling in action definitions. - Implemented `reqEnvValue` for environment value checks with comparison operators. - Enhanced nation constraints with `reqNationValue` and `reqDestNationValue` for flexible value comparisons. - Added `wanderingNation` constraint to check if a nation is classified as wandering. - Improved general constraints with `reqGeneralValue` for dynamic value checks. - Updated various action definitions to utilize new constraints for better maintainability and readability.
This commit is contained in:
@@ -120,3 +120,28 @@ export const parsePercent = (value: string): number | null => {
|
||||
}
|
||||
return Number(match[1]) / 100;
|
||||
};
|
||||
|
||||
export type CompareOperator = '>' | '>=' | '==' | '<=' | '<' | '!=' | '===' | '!==';
|
||||
|
||||
export const compareValues = (target: unknown, op: CompareOperator, source: unknown): boolean => {
|
||||
const lhs = target as any;
|
||||
const rhs = source as any;
|
||||
switch (op) {
|
||||
case '<':
|
||||
return lhs < rhs;
|
||||
case '<=':
|
||||
return lhs <= rhs;
|
||||
case '==':
|
||||
return lhs == rhs;
|
||||
case '!=':
|
||||
return lhs != rhs;
|
||||
case '===':
|
||||
return lhs === rhs;
|
||||
case '!==':
|
||||
return lhs !== rhs;
|
||||
case '>=':
|
||||
return lhs >= rhs;
|
||||
case '>':
|
||||
return lhs > rhs;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user