Enhance health management in FalukantService to improve user feedback and error handling
- Updated health deduction logic to clarify the distinction between health and monetary costs. - Added error handling for money update failures to ensure robust transaction processing. - Modified return value to include updated health status, providing clearer information for UI updates.
This commit is contained in:
@@ -4189,7 +4189,7 @@ class FalukantService extends BaseService {
|
||||
if (user.money - activityObject.cost < 0) {
|
||||
throw new Error('no money');
|
||||
}
|
||||
user.character.health -= activityObject.cost;
|
||||
// Hinweis: health ist ein Status (0..100) und darf nicht mit Geldkosten vermischt werden.
|
||||
const healthChange = await this[activityObject.method](user);
|
||||
await HealthActivity.create({
|
||||
characterId: user.character.id,
|
||||
@@ -4197,12 +4197,18 @@ class FalukantService extends BaseService {
|
||||
successPercentage: healthChange,
|
||||
cost: activityObject.cost
|
||||
});
|
||||
updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity);
|
||||
const moneyResult = await updateFalukantUserMoney(user.id, -activityObject.cost, 'health.' + activity, user.id);
|
||||
if (!moneyResult.success) throw new Error('Failed to update money');
|
||||
|
||||
// Status-Update Notification senden
|
||||
notifyUser(user.user.hashedId, 'falukantUpdateStatus', {});
|
||||
|
||||
return { success: true };
|
||||
// Give client enough info to update UI without ambiguity
|
||||
const updatedChar = await FalukantCharacter.findOne({
|
||||
where: { id: user.character.id },
|
||||
attributes: ['health']
|
||||
});
|
||||
return { success: true, delta: healthChange, health: updatedChar?.health ?? null };
|
||||
}
|
||||
|
||||
async healthChange(user, delta) {
|
||||
|
||||
Reference in New Issue
Block a user