Files
blitzkit/packages/core/src/blitzkit/checkConsumableProvisionInclusivity.ts
T

57 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-10-05 23:20:04 -05:00
import {
Consumable,
ConsumableTankCategoryFilterCategory,
GunDefinition,
Provision,
TankDefinition,
2025-12-31 14:41:13 -06:00
} from "../protos";
2024-01-25 11:50:43 -06:00
2024-01-25 13:10:20 -06:00
export function checkConsumableProvisionInclusivity(
2024-10-05 23:20:04 -05:00
consumableProvision: Consumable | Provision,
2024-01-25 11:50:43 -06:00
tank: TankDefinition,
2025-12-31 14:41:13 -06:00
gun: GunDefinition
2024-01-25 11:50:43 -06:00
) {
2026-01-02 11:32:27 -06:00
const included = consumableProvision.include?.every((rule) => {
switch (rule.filter_type!.$case) {
case "tiers":
return (
rule.filter_type!.value.min <= tank.tier &&
tank.tier <= rule.filter_type!.value.max
);
2024-01-25 11:50:43 -06:00
2026-01-02 11:32:27 -06:00
case "ids":
return rule.filter_type!.value.ids.includes(tank.id);
2024-01-25 11:50:43 -06:00
2026-01-02 11:32:27 -06:00
case "nations":
return rule.filter_type!.value.nations.includes(tank.nation);
2024-01-25 13:51:30 -06:00
2026-01-02 11:32:27 -06:00
case "categories":
throw new SyntaxError("Category filtering found in include rule");
}
});
const excluded = consumableProvision.exclude?.some((rule) => {
switch (rule.filter_type!.$case) {
case "tiers":
return (
rule.filter_type!.value.min <= tank.tier &&
tank.tier <= rule.filter_type!.value.max
);
2024-01-25 11:50:43 -06:00
2026-01-02 11:32:27 -06:00
case "ids":
return rule.filter_type!.value.ids.includes(tank.id);
2024-01-25 11:50:43 -06:00
2026-01-02 11:32:27 -06:00
case "nations":
return rule.filter_type!.value.nations.includes(tank.nation);
2024-01-25 13:51:30 -06:00
2026-01-02 11:32:27 -06:00
case "categories":
return rule.filter_type!.value.categories.some((category) => {
switch (category) {
case ConsumableTankCategoryFilterCategory.CLIP:
return gun.gun_type!.$case !== "regular";
}
});
}
});
2024-01-25 11:50:43 -06:00
2026-01-02 11:32:27 -06:00
return consumableProvision.include?.length > 0 && included && !excluded;
2024-01-25 11:50:43 -06:00
}