2024-09-08 10:11:24 -05:00
|
|
|
import { ConsumableEntry, ProvisionEntry } from '@blitzkit/core';
|
2024-01-25 11:50:43 -06:00
|
|
|
import { GunDefinition, TankDefinition } from './tankDefinitions';
|
|
|
|
|
|
2024-01-25 13:10:20 -06:00
|
|
|
export function checkConsumableProvisionInclusivity(
|
|
|
|
|
consumableProvision: ConsumableEntry | ProvisionEntry,
|
2024-01-25 11:50:43 -06:00
|
|
|
tank: TankDefinition,
|
|
|
|
|
gun: GunDefinition,
|
|
|
|
|
) {
|
2024-08-16 14:09:58 -05:00
|
|
|
const included =
|
|
|
|
|
!consumableProvision.gameMode &&
|
|
|
|
|
consumableProvision.include?.every((rule) => {
|
|
|
|
|
switch (rule.type) {
|
|
|
|
|
case 'tier':
|
|
|
|
|
return rule.min <= tank.tier && tank.tier <= rule.max;
|
2024-01-25 11:50:43 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'ids':
|
|
|
|
|
return rule.ids.includes(tank.id);
|
2024-01-25 11:50:43 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'nation':
|
|
|
|
|
return rule.nations.includes(tank.nation);
|
2024-01-25 13:51:30 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'category':
|
|
|
|
|
throw new SyntaxError('Category filtering found in include rule');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const excluded =
|
|
|
|
|
consumableProvision.gameMode ||
|
|
|
|
|
consumableProvision.exclude?.some((rule) => {
|
|
|
|
|
switch (rule.type) {
|
|
|
|
|
case 'tier':
|
|
|
|
|
return rule.min <= tank.tier && tank.tier <= rule.max;
|
2024-01-25 11:50:43 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'ids':
|
|
|
|
|
return rule.ids.includes(tank.id);
|
2024-01-25 11:50:43 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'nation':
|
|
|
|
|
return rule.nations.includes(tank.nation);
|
2024-01-25 13:51:30 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
case 'category':
|
|
|
|
|
return rule.categories.some((category) => {
|
|
|
|
|
switch (category) {
|
|
|
|
|
case 'clip':
|
|
|
|
|
return gun.type !== 'regular';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-01-25 11:50:43 -06:00
|
|
|
|
2024-08-16 14:09:58 -05:00
|
|
|
return (
|
|
|
|
|
!consumableProvision.gameMode &&
|
|
|
|
|
consumableProvision.include?.length > 0 &&
|
|
|
|
|
included &&
|
|
|
|
|
!excluded
|
|
|
|
|
);
|
2024-01-25 11:50:43 -06:00
|
|
|
}
|