feat(politics): update title eligibility messages and logic in PoliticsView
This commit is contained in:
@@ -7195,29 +7195,9 @@ class FalukantService extends BaseService {
|
||||
order: [['hierarchyLevel', 'ASC'], ['id', 'ASC']]
|
||||
});
|
||||
const nameToId = new Map(allTypes.map((t) => [t.name, t.id]));
|
||||
const titleId = character.titleOfNobility ?? character.nobleTitle?.id;
|
||||
const allowedOfficeNames = await getAllowedOfficeTypeNamesByTitle(titleId);
|
||||
const [titles, officeEligibilityBenefits] = await Promise.all([
|
||||
TitleOfNobility.findAll({ attributes: ['id', 'labelTr', 'level'] }),
|
||||
TitleBenefit.findAll({
|
||||
where: { benefitType: 'office_eligibility' },
|
||||
attributes: ['titleId', 'parameters']
|
||||
})
|
||||
]);
|
||||
const titleById = new Map(titles.map((title) => [Number(title.id), title]));
|
||||
const minimumTitleByOfficeName = new Map();
|
||||
for (const benefit of officeEligibilityBenefits) {
|
||||
const officeNames = benefit.parameters?.officeTypeNames;
|
||||
const title = titleById.get(Number(benefit.titleId));
|
||||
if (!Array.isArray(officeNames) || !title) continue;
|
||||
|
||||
for (const officeName of officeNames) {
|
||||
const currentMinimum = minimumTitleByOfficeName.get(officeName);
|
||||
if (!currentMinimum || title.level < currentMinimum.level) {
|
||||
minimumTitleByOfficeName.set(officeName, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
const titles = await TitleOfNobility.findAll({ attributes: ['labelTr', 'level'] });
|
||||
const titleByLabel = new Map(titles.map((title) => [title.labelTr, title]));
|
||||
const characterTitleLabel = character.nobleTitle?.labelTr;
|
||||
|
||||
return allTypes.map((typeRow) => {
|
||||
const type = typeRow.get({ plain: true });
|
||||
@@ -7225,6 +7205,9 @@ class FalukantService extends BaseService {
|
||||
const requiredOfficeNames = [...new Set(
|
||||
prereqRows.flatMap((pr) => Array.isArray(pr?.prerequisite?.jobs) ? pr.prerequisite.jobs : [])
|
||||
)];
|
||||
const requiredTitleLabels = [...new Set(
|
||||
prereqRows.flatMap((pr) => Array.isArray(pr?.prerequisite?.titles) ? pr.prerequisite.titles : [])
|
||||
)];
|
||||
|
||||
const matchedOfficeNames = requiredOfficeNames.filter((officeName) => {
|
||||
const reqId = nameToId.get(officeName);
|
||||
@@ -7232,9 +7215,12 @@ class FalukantService extends BaseService {
|
||||
});
|
||||
|
||||
const prerequisitesMet = requiredOfficeNames.length === 0 || matchedOfficeNames.length > 0;
|
||||
const titleEligible = allowedOfficeNames.size === 0 || allowedOfficeNames.has(type.name);
|
||||
const titleEligible = requiredTitleLabels.length === 0 || requiredTitleLabels.includes(characterTitleLabel);
|
||||
const canApplyNow = canApplyByAge && titleEligible && prerequisitesMet;
|
||||
const requiredTitle = minimumTitleByOfficeName.get(type.name);
|
||||
const requiredTitle = requiredTitleLabels
|
||||
.map((titleLabel) => titleByLabel.get(titleLabel))
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.level - b.level)[0];
|
||||
|
||||
return {
|
||||
officeTypeId: type.id,
|
||||
|
||||
@@ -1611,8 +1611,8 @@
|
||||
"yes": "Ja",
|
||||
"no": "Nein",
|
||||
"blockedByAge": "Mindestalter nicht erreicht",
|
||||
"blockedByTitle": "Benötigter Stand: mindestens {title}",
|
||||
"unknownRequiredTitle": "unbekannt",
|
||||
"blockedByTitle": "Standesvoraussetzung nicht erfüllt",
|
||||
"blockedByTitleMinimum": "Benötigter Stand: mindestens {title}",
|
||||
"blockedByPrerequisites": "Vorherige Ämter fehlen"
|
||||
},
|
||||
"too_young": "Dein Charakter ist noch zu jung. Eine Bewerbung ist erst ab 16 Jahren möglich.",
|
||||
|
||||
@@ -797,8 +797,8 @@
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"blockedByAge": "Minimum age not met",
|
||||
"blockedByTitle": "Required title: at least {title}",
|
||||
"unknownRequiredTitle": "unknown",
|
||||
"blockedByTitle": "Title requirement not met",
|
||||
"blockedByTitleMinimum": "Required title: at least {title}",
|
||||
"blockedByPrerequisites": "Required prior offices missing"
|
||||
},
|
||||
"too_young": "Your character is too young. Applications are only possible from age 16.",
|
||||
|
||||
@@ -180,11 +180,12 @@
|
||||
: $t('falukant.politics.officesTab.no') }}
|
||||
<template v-if="!office.canApplyNow">
|
||||
<span v-if="!office.canApplyByAge"> · {{ $t('falukant.politics.officesTab.blockedByAge') }}</span>
|
||||
<span v-if="!office.titleEligible">
|
||||
· {{ $t('falukant.politics.officesTab.blockedByTitle', {
|
||||
<span v-if="!office.titleEligible && office.requiredTitleLabelTr">
|
||||
· {{ $t('falukant.politics.officesTab.blockedByTitleMinimum', {
|
||||
title: formatRequiredTitle(office.requiredTitleLabelTr, office.characterGender)
|
||||
}) }}
|
||||
</span>
|
||||
<span v-else-if="!office.titleEligible"> · {{ $t('falukant.politics.officesTab.blockedByTitle') }}</span>
|
||||
<span v-if="!office.prerequisitesMet"> · {{ $t('falukant.politics.officesTab.blockedByPrerequisites') }}</span>
|
||||
</template>
|
||||
</span>
|
||||
@@ -369,7 +370,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
formatRequiredTitle(titleLabelTr, gender) {
|
||||
if (!titleLabelTr) return this.$t('falukant.politics.officesTab.unknownRequiredTitle');
|
||||
return this.$t(`falukant.titles.${gender === 'female' ? 'female' : 'male'}.${titleLabelTr}`);
|
||||
},
|
||||
formatPoliticalCharacterName(character) {
|
||||
|
||||
Reference in New Issue
Block a user