Enhance EventsWorker: Introduce EVENT_RATE_SCALE constant to adjust event frequency, improving control over event triggering rates.
This commit is contained in:
@@ -83,6 +83,9 @@ struct StorageDamageInfo {
|
||||
}
|
||||
|
||||
impl EventsWorker {
|
||||
// Globaler Skalierungsfaktor für Ereignisfrequenz (1.0 = unverändert).
|
||||
// Setze auf 0.05, um Ereignisse auf 1/20 der ursprünglichen Häufigkeit zu reduzieren.
|
||||
const EVENT_RATE_SCALE: f64 = 0.05;
|
||||
pub fn new(pool: ConnectionPool, broker: MessageBroker) -> Self {
|
||||
Self {
|
||||
base: BaseWorker::new("EventsWorker", pool, broker),
|
||||
@@ -367,6 +370,10 @@ impl EventsWorker {
|
||||
}
|
||||
}
|
||||
|
||||
// Globaler Skalierungsfaktor für Ereignisfrequenz (1.0 = unverändert).
|
||||
// Setze auf 0.05, um Ereignisse auf 1/20 der ursprünglichen Häufigkeit zu reduzieren.
|
||||
const EVENT_RATE_SCALE: f64 = 0.05;
|
||||
|
||||
fn check_and_trigger_events_inner(
|
||||
pool: &ConnectionPool,
|
||||
broker: &MessageBroker,
|
||||
@@ -377,12 +384,14 @@ impl EventsWorker {
|
||||
// Prüfe jedes mögliche Ereignis
|
||||
for event in events {
|
||||
// Zufällige Prüfung basierend auf Wahrscheinlichkeit
|
||||
let roll = rng.gen_range(0.0..=1.0);
|
||||
if roll < event.probability_per_minute {
|
||||
let roll = rng.gen_range(0.0..=1.0);
|
||||
let effective_prob = event.probability_per_minute * EVENT_RATE_SCALE;
|
||||
if roll < effective_prob {
|
||||
eprintln!(
|
||||
"[EventsWorker] Ereignis '{}' wurde ausgelöst (Wahrscheinlichkeit: {:.2}%)",
|
||||
event.id,
|
||||
event.probability_per_minute * 100.0
|
||||
"[EventsWorker] Ereignis '{}' wurde ausgelöst (Wahrscheinlichkeit: {:.4}% -> skaliert {:.4}%)",
|
||||
event.id,
|
||||
event.probability_per_minute * 100.0,
|
||||
effective_prob * 100.0
|
||||
);
|
||||
|
||||
match event.event_type {
|
||||
@@ -544,16 +553,26 @@ impl EventsWorker {
|
||||
}
|
||||
|
||||
// Schreibe Benachrichtigung in die Datenbank mit Event-Details
|
||||
let notification_json = serde_json::json!({
|
||||
// If any effect contains a character_id, include it at top-level for the notification
|
||||
let top_character_id = effect_results.iter().find_map(|eff| {
|
||||
eff.get("character_id").and_then(|v| v.as_i64()).map(|n| n as i32)
|
||||
});
|
||||
|
||||
let mut notification_json = serde_json::json!({
|
||||
"tr": format!("random_event.{}", event.id),
|
||||
"event_id": event.id,
|
||||
"event_type": "personal",
|
||||
"effects": effect_results
|
||||
});
|
||||
|
||||
if let Some(cid) = top_character_id {
|
||||
notification_json["character_id"] = serde_json::json!(cid);
|
||||
}
|
||||
|
||||
Self::notify_user(pool, broker, user_id, ¬ification_json.to_string())?;
|
||||
|
||||
// Sende Benachrichtigung über WebSocket
|
||||
let notification = json!({
|
||||
let mut notification = json!({
|
||||
"event": "random_event",
|
||||
"event_id": event.id,
|
||||
"event_type": "personal",
|
||||
@@ -563,6 +582,10 @@ impl EventsWorker {
|
||||
"effects": effect_results
|
||||
});
|
||||
|
||||
if let Some(cid) = top_character_id {
|
||||
notification["character_id"] = json!(cid);
|
||||
}
|
||||
|
||||
broker.publish(notification.to_string());
|
||||
eprintln!(
|
||||
"[EventsWorker] Persönliches Ereignis '{}' für Spieler {} verarbeitet",
|
||||
|
||||
Reference in New Issue
Block a user