Refactor Falukant daemon logic for time-based processing: Updated the handling of monthly servant costs and lover installments to align with the new game time model, introducing a unified "Monatstick" concept for cost calculations. Enhanced SQL queries and worker logic to ensure accurate processing every 2 hours, improving financial interactions and family dynamics.
This commit is contained in:
@@ -34,8 +34,8 @@ use crate::message_broker::MessageBroker;
|
||||
|
||||
const DAILY_INTERVAL: Duration = Duration::from_secs(24 * 3600);
|
||||
const MONTHLY_INTERVAL: Duration = Duration::from_secs(30 * 24 * 3600);
|
||||
/// 12 Teilzahlungen pro Spieltag (24 h = 1 Spieljahr); 2 h = 1 Spielmonat.
|
||||
const LOVER_INSTALLMENT_INTERVAL: Duration = Duration::from_secs(2 * 3600);
|
||||
/// 12 Monatsticke pro Spieltag (24 h = 1 Spieljahr); 2 h = 1 Spielmonat (Liebschaft + Dienerschaft).
|
||||
const GAME_MONTH_SLICE_INTERVAL: Duration = Duration::from_secs(2 * 3600);
|
||||
|
||||
pub struct FalukantFamilyWorker {
|
||||
base: BaseWorker,
|
||||
@@ -43,7 +43,8 @@ pub struct FalukantFamilyWorker {
|
||||
dist: Uniform<f64>,
|
||||
last_daily: Option<Instant>,
|
||||
last_monthly: Option<Instant>,
|
||||
last_lover_installment: Option<Instant>,
|
||||
/// Gemeinsamer Tick für Liebschafts-Raten + Dienerschaft (Monatstick ≈ 2 h).
|
||||
last_game_month_slice: Option<Instant>,
|
||||
schema_ready: bool,
|
||||
/// Migration `004_falukant_servants_daemon.sql` (Dienerschaft-Ticks).
|
||||
servants_schema_ready: bool,
|
||||
@@ -59,7 +60,7 @@ impl FalukantFamilyWorker {
|
||||
dist: Uniform::from(0.0..1.0),
|
||||
last_daily: None,
|
||||
last_monthly: None,
|
||||
last_lover_installment: None,
|
||||
last_game_month_slice: None,
|
||||
schema_ready: false,
|
||||
servants_schema_ready: false,
|
||||
lover_installment_schema_ready: false,
|
||||
@@ -93,12 +94,21 @@ impl FalukantFamilyWorker {
|
||||
self.last_monthly = Some(now);
|
||||
}
|
||||
|
||||
if self.lover_installment_schema_ready {
|
||||
if Self::should_run(self.last_lover_installment, now, LOVER_INSTALLMENT_INTERVAL) {
|
||||
if let Err(e) = self.process_lover_installments() {
|
||||
eprintln!("[FalukantFamilyWorker] process_lover_installments: {e}");
|
||||
if self.servants_schema_ready || self.lover_installment_schema_ready {
|
||||
if Self::should_run(self.last_game_month_slice, now, GAME_MONTH_SLICE_INTERVAL) {
|
||||
if self.servants_schema_ready {
|
||||
if let Err(e) =
|
||||
super::falukant_servants::run_monthly(&self.base, &self.base.broker)
|
||||
{
|
||||
eprintln!("[FalukantFamilyWorker] falukant_servants::run_monthly: {e}");
|
||||
}
|
||||
}
|
||||
self.last_lover_installment = Some(now);
|
||||
if self.lover_installment_schema_ready {
|
||||
if let Err(e) = self.process_lover_installments() {
|
||||
eprintln!("[FalukantFamilyWorker] process_lover_installments: {e}");
|
||||
}
|
||||
}
|
||||
self.last_game_month_slice = Some(now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,10 +661,6 @@ impl FalukantFamilyWorker {
|
||||
}
|
||||
|
||||
fn process_monthly(&mut self) -> Result<(), DbError> {
|
||||
if self.servants_schema_ready {
|
||||
super::falukant_servants::run_monthly(&self.base, &self.base.broker)?;
|
||||
}
|
||||
|
||||
let mut conn = self
|
||||
.base
|
||||
.pool
|
||||
|
||||
Reference in New Issue
Block a user