feat(falukant): add improve lover affection feature and localization updates
All checks were successful
Deploy to production / deploy (push) Successful in 2m49s
All checks were successful
Deploy to production / deploy (push) Successful in 2m49s
- Introduced the `improveLoverAffection` method in FalukantService to enhance relationship dynamics by allowing users to boost affection at a cost. - Updated FalukantController and FalukantRouter to include the new endpoint for improving lover affection. - Enhanced FamilyView component to provide a button for users to trigger the affection improvement action. - Added localization entries for the new feature in multiple languages, ensuring clarity in user interactions regarding affection improvements.
This commit is contained in:
@@ -119,6 +119,8 @@ class FalukantController {
|
||||
});
|
||||
this.setLoverMaintenance = this._wrapWithUser((userId, req) =>
|
||||
this.service.setLoverMaintenance(userId, req.params.relationshipId, req.body?.maintenanceLevel), { blockInDebtorsPrison: true });
|
||||
this.improveLoverAffection = this._wrapWithUser((userId, req) =>
|
||||
this.service.improveLoverAffection(userId, req.params.relationshipId), { blockInDebtorsPrison: true });
|
||||
this.createLoverRelationship = this._wrapWithUser((userId, req) =>
|
||||
this.service.createLoverRelationship(userId, req.body?.targetCharacterId, req.body?.loverRole), { successStatus: 201, blockInDebtorsPrison: true });
|
||||
this.spendTimeWithSpouse = this._wrapWithUser((userId) =>
|
||||
|
||||
@@ -54,6 +54,7 @@ router.post('/family/marriage/spend-time', falukantController.spendTimeWithSpous
|
||||
router.post('/family/marriage/gift', falukantController.giftToSpouse);
|
||||
router.post('/family/marriage/reconcile', falukantController.reconcileMarriage);
|
||||
router.post('/family/lover/:relationshipId/maintenance', falukantController.setLoverMaintenance);
|
||||
router.post('/family/lover/:relationshipId/improve-affection', falukantController.improveLoverAffection);
|
||||
router.post('/family/lover/:relationshipId/acknowledge', falukantController.acknowledgeLover);
|
||||
router.post('/family/lover/:relationshipId/end', falukantController.endLoverRelationship);
|
||||
router.get('/heirs/potential', falukantController.getPotentialHeirs);
|
||||
|
||||
@@ -3880,6 +3880,91 @@ class FalukantService extends BaseService {
|
||||
};
|
||||
}
|
||||
|
||||
async improveLoverAffection(hashedUserId, relationshipId) {
|
||||
const parsedRelationshipId = Number.parseInt(relationshipId, 10);
|
||||
if (Number.isNaN(parsedRelationshipId)) {
|
||||
throw { status: 400, message: 'relationshipId is required' };
|
||||
}
|
||||
|
||||
const action = {
|
||||
cost: 60,
|
||||
affectionDelta: 6,
|
||||
visibilityDelta: 3,
|
||||
discretionDelta: -2,
|
||||
householdOrderDelta: -3,
|
||||
marriageSatisfactionDelta: -1
|
||||
};
|
||||
|
||||
const { user, state } = await this.getOwnedLoverRelationState(hashedUserId, parsedRelationshipId);
|
||||
if (Number(user.money || 0) < action.cost) {
|
||||
throw new Error('notenoughmoney.');
|
||||
}
|
||||
|
||||
const userHouse = await UserHouse.findOne({
|
||||
where: { userId: user.id },
|
||||
attributes: ['householdOrder']
|
||||
});
|
||||
|
||||
const marriage = await Relationship.findOne({
|
||||
where: { character1Id: user.character.id },
|
||||
include: [
|
||||
{ model: RelationshipType, as: 'relationshipType', where: { tr: 'married' } },
|
||||
{ model: RelationshipState, as: 'state', required: false }
|
||||
]
|
||||
});
|
||||
|
||||
let marriageState = marriage?.state || null;
|
||||
if (marriage && !marriageState) {
|
||||
marriageState = await RelationshipState.create({
|
||||
relationshipId: marriage.id,
|
||||
...this.buildDefaultRelationshipState('married')
|
||||
});
|
||||
}
|
||||
|
||||
const nextAffection = this.clampScore((state.affection ?? 50) + action.affectionDelta);
|
||||
const nextVisibility = this.clampScore((state.visibility ?? 15) + action.visibilityDelta);
|
||||
const nextDiscretion = this.clampScore((state.discretion ?? 50) + action.discretionDelta);
|
||||
const nextHouseholdOrder = userHouse
|
||||
? this.clampScore((userHouse.householdOrder ?? 55) + action.householdOrderDelta)
|
||||
: null;
|
||||
const nextMarriageSatisfaction = marriageState
|
||||
? this.clampScore((marriageState.marriageSatisfaction ?? 55) + action.marriageSatisfactionDelta)
|
||||
: null;
|
||||
|
||||
await sequelize.transaction(async (t) => {
|
||||
await state.update(
|
||||
{
|
||||
affection: nextAffection,
|
||||
visibility: nextVisibility,
|
||||
discretion: nextDiscretion,
|
||||
},
|
||||
{ transaction: t }
|
||||
);
|
||||
if (userHouse && nextHouseholdOrder != null) {
|
||||
await userHouse.update({ householdOrder: nextHouseholdOrder }, { transaction: t });
|
||||
}
|
||||
if (marriageState && nextMarriageSatisfaction != null) {
|
||||
await marriageState.update({ marriageSatisfaction: nextMarriageSatisfaction }, { transaction: t });
|
||||
}
|
||||
await updateFalukantUserMoney(user.id, -action.cost, 'lover_affection_boost', user.id);
|
||||
});
|
||||
|
||||
await this.refreshHouseholdTensionState(user, user.character);
|
||||
await notifyUser(hashedUserId, 'falukantUpdateFamily', { reason: 'daily' });
|
||||
await notifyUser(hashedUserId, 'falukantUpdateStatus', {});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
relationshipId: parsedRelationshipId,
|
||||
cost: action.cost,
|
||||
affection: nextAffection,
|
||||
visibility: nextVisibility,
|
||||
discretion: nextDiscretion,
|
||||
householdOrder: nextHouseholdOrder,
|
||||
marriageSatisfaction: nextMarriageSatisfaction,
|
||||
};
|
||||
}
|
||||
|
||||
async spendTimeWithSpouse(hashedUserId) {
|
||||
const user = await this.getFalukantUserByHashedId(hashedUserId);
|
||||
if (!user?.character?.id) throw new Error('User or character not found');
|
||||
|
||||
Reference in New Issue
Block a user