mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { ConsumableEntry } from './consumableDefinitions';
|
|
import { ProvisionEntry } from './provisionDefinitions';
|
|
import { GunDefinition, TankDefinition } from './tankDefinitions';
|
|
|
|
export function checkConsumableProvisionInclusivity(
|
|
consumableProvision: ConsumableEntry | ProvisionEntry,
|
|
tank: TankDefinition,
|
|
gun: GunDefinition,
|
|
) {
|
|
const included = consumableProvision.include.every((rule) => {
|
|
switch (rule.type) {
|
|
case 'tier':
|
|
return rule.min <= tank.tier && tank.tier <= rule.max;
|
|
|
|
case 'ids':
|
|
return rule.ids.includes(tank.id);
|
|
|
|
case 'nation':
|
|
return rule.nations.includes(tank.nation);
|
|
|
|
case 'category':
|
|
throw new SyntaxError('Category filtering found in include rule');
|
|
}
|
|
});
|
|
const excluded = consumableProvision.exclude?.some((rule) => {
|
|
switch (rule.type) {
|
|
case 'tier':
|
|
return rule.min <= tank.tier && tank.tier <= rule.max;
|
|
|
|
case 'ids':
|
|
return rule.ids.includes(tank.id);
|
|
|
|
case 'nation':
|
|
return rule.nations.includes(tank.nation);
|
|
|
|
case 'category':
|
|
return rule.categories.some((category) => {
|
|
switch (category) {
|
|
case 'clip':
|
|
return gun.type !== 'regular';
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
return consumableProvision.include.length > 0 && included && !excluded;
|
|
}
|