Enhance Falukant family and production dynamics: Updated FalukantFamilyWorker to include public stability and household tension calculations, integrating new SQL queries for managing marriage states and household attributes. Added FalukantCertificateWorker for production certificate management, enhancing overall family interaction and production tracking.
This commit is contained in:
@@ -2162,6 +2162,7 @@ pub const QUERY_GET_ACTIVE_LOVER_ROWS_FOR_DAILY: &str = r#"
|
||||
rs.monthly_base_cost,
|
||||
rs.scandal_extra_daily_pct,
|
||||
rs.months_underfunded,
|
||||
COALESCE(rs.acknowledged, false) AS acknowledged,
|
||||
c1.gender AS g1,
|
||||
c2.gender AS g2,
|
||||
COALESCE(t1.tr, '') AS title1_tr,
|
||||
@@ -2267,6 +2268,7 @@ pub const QUERY_GET_MARRIAGE_ROWS: &str = r#"
|
||||
r.character1_id AS m1,
|
||||
r.character2_id AS m2,
|
||||
r.marriage_satisfaction,
|
||||
COALESCE(r.marriage_public_stability, 55)::int AS marriage_public_stability,
|
||||
r.marriage_drift_high,
|
||||
r.marriage_drift_low,
|
||||
COALESCE(t1.tr, '') AS title1_tr,
|
||||
@@ -2276,7 +2278,23 @@ pub const QUERY_GET_MARRIAGE_ROWS: &str = r#"
|
||||
COALESCE(r.marriage_gift_buff_days_remaining, 0)::int AS marriage_gift_buff_days_remaining,
|
||||
COALESCE(r.marriage_pending_feast_bonus, 0)::int AS marriage_pending_feast_bonus,
|
||||
COALESCE(r.marriage_house_supply, 50)::int AS marriage_house_supply,
|
||||
COALESCE(r.marriage_no_lover_bonus_counter, 0)::int AS marriage_no_lover_bonus_counter
|
||||
COALESCE(r.marriage_no_lover_bonus_counter, 0)::int AS marriage_no_lover_bonus_counter,
|
||||
COALESCE((
|
||||
SELECT uh.household_order FROM falukant_data.user_house uh
|
||||
WHERE uh.user_id = c1.user_id ORDER BY uh.id LIMIT 1
|
||||
), 55)::int AS household_order_1,
|
||||
COALESCE((
|
||||
SELECT uh.household_order FROM falukant_data.user_house uh
|
||||
WHERE uh.user_id = c2.user_id ORDER BY uh.id LIMIT 1
|
||||
), 55)::int AS household_order_2,
|
||||
COALESCE((
|
||||
SELECT uh.servant_quality FROM falukant_data.user_house uh
|
||||
WHERE uh.user_id = c1.user_id ORDER BY uh.id LIMIT 1
|
||||
), 50)::int AS servant_quality_1,
|
||||
COALESCE((
|
||||
SELECT uh.servant_quality FROM falukant_data.user_house uh
|
||||
WHERE uh.user_id = c2.user_id ORDER BY uh.id LIMIT 1
|
||||
), 50)::int AS servant_quality_2
|
||||
FROM falukant_data.relationship r
|
||||
JOIN falukant_type.relationship rt ON rt.id = r.relationship_type_id
|
||||
AND rt.tr IN ('married', 'engaged', 'wooing')
|
||||
@@ -2298,6 +2316,7 @@ pub const QUERY_UPDATE_MARRIAGE_STATE: &str = r#"
|
||||
"#;
|
||||
|
||||
/// Inkl. Geschenk-/Fest-/Haus-Zähler (Migration `003_falukant_family_marriage_buffs.sql`).
|
||||
/// `marriage_public_stability`: Migration `005_falukant_marriage_housepeace.sql`.
|
||||
pub const QUERY_UPDATE_MARRIAGE_STATE_AND_BUFFS: &str = r#"
|
||||
UPDATE falukant_data.relationship
|
||||
SET marriage_satisfaction = $1::smallint,
|
||||
@@ -2305,8 +2324,48 @@ pub const QUERY_UPDATE_MARRIAGE_STATE_AND_BUFFS: &str = r#"
|
||||
marriage_drift_low = $3::smallint,
|
||||
marriage_gift_buff_days_remaining = $4::smallint,
|
||||
marriage_pending_feast_bonus = $5::smallint,
|
||||
marriage_no_lover_bonus_counter = $6::smallint
|
||||
WHERE id = $7::int;
|
||||
marriage_no_lover_bonus_counter = $6::smallint,
|
||||
marriage_public_stability = $7::smallint
|
||||
WHERE id = $8::int;
|
||||
"#;
|
||||
|
||||
/// Persistiert berechneten Hausfrieden (0..100), Migration `005_falukant_marriage_housepeace.sql`.
|
||||
pub const QUERY_UPDATE_USER_HOUSE_TENSION_BY_USER: &str = r#"
|
||||
UPDATE falukant_data.user_house
|
||||
SET household_tension_score = $1::smallint
|
||||
WHERE user_id = $2::int;
|
||||
"#;
|
||||
|
||||
/// Kinder aus Liebschaften, die einen Charakter dieses Falukant-Users betreffen.
|
||||
pub const QUERY_COUNT_LOVER_CHILDREN_FOR_USER: &str = r#"
|
||||
SELECT COUNT(*)::int AS cnt
|
||||
FROM falukant_data.child_relation cr
|
||||
WHERE cr.birth_context = 'lover'
|
||||
AND (
|
||||
EXISTS (
|
||||
SELECT 1 FROM falukant_data.character c
|
||||
WHERE c.id = cr.father_character_id AND c.user_id = $1::int
|
||||
)
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM falukant_data.character c
|
||||
WHERE c.id = cr.mother_character_id AND c.user_id = $1::int
|
||||
)
|
||||
);
|
||||
"#;
|
||||
|
||||
/// Haushalt für Spannungsberechnung (ein Eintrag pro Zeile; typisch eine Zeile pro User).
|
||||
pub const QUERY_GET_USER_HOUSE_ROW_BY_USER: &str = r#"
|
||||
SELECT uh.id AS user_house_id,
|
||||
uh.user_id AS falukant_user_id,
|
||||
COALESCE(uh.household_order, 55)::int AS household_order,
|
||||
COALESCE(uh.servant_count, 0)::int AS servant_count,
|
||||
COALESCE(uh.servant_quality, 50)::int AS servant_quality,
|
||||
COALESCE(NULLIF(TRIM(uh.servant_pay_level), ''), 'normal') AS servant_pay_level,
|
||||
COALESCE(uh.household_tension_score, 0)::int AS prev_tension_score
|
||||
FROM falukant_data.user_house uh
|
||||
WHERE uh.user_id = $1::int
|
||||
ORDER BY uh.id
|
||||
LIMIT 1;
|
||||
"#;
|
||||
|
||||
pub const QUERY_MARRIAGE_SUBTRACT_SATISFACTION: &str = r#"
|
||||
@@ -2438,3 +2497,57 @@ pub const QUERY_INSERT_CHILD_RELATION_LOVER: &str = r#"
|
||||
);
|
||||
"#;
|
||||
|
||||
// --- Produktionszertifikat (Daemon Daily, Spec: Produktionszertifikate) ---
|
||||
|
||||
/// Ein Spielercharakter pro Falukant-User (niedrigste character.id bei mehreren lebenden).
|
||||
pub const QUERY_GET_PRODUCTION_CERTIFICATE_INPUT_ROWS: &str = r#"
|
||||
SELECT DISTINCT ON (fu.id)
|
||||
fu.id AS falukant_user_id,
|
||||
COALESCE(fu.certificate, 1)::int AS certificate,
|
||||
COALESCE(fu.money, 0)::float8 AS money,
|
||||
c.id AS character_id,
|
||||
COALESCE(c.reputation, 50)::float8 AS reputation,
|
||||
COALESCE(t.level, 0)::int AS title_level,
|
||||
COALESCE((
|
||||
SELECT AVG(k.knowledge)::float8
|
||||
FROM falukant_data.knowledge k
|
||||
WHERE k.character_id = c.id
|
||||
), 0.0) AS avg_knowledge,
|
||||
COALESCE((
|
||||
SELECT COUNT(*)::bigint
|
||||
FROM falukant_log.production pl
|
||||
WHERE pl.producer_id = fu.id
|
||||
), 0) AS completed_production_count,
|
||||
COALESCE((
|
||||
SELECT MAX(cot.hierarchy_level)::int
|
||||
FROM falukant_data.church_office co
|
||||
JOIN falukant_type.church_office_type cot ON cot.id = co.office_type_id
|
||||
WHERE co.character_id = c.id
|
||||
), 0) AS max_church_hierarchy,
|
||||
COALESCE((
|
||||
SELECT STRING_AGG(DISTINCT pot.name, '|')
|
||||
FROM falukant_data.political_office po
|
||||
JOIN falukant_type.political_office_type pot ON pot.id = po.office_type_id
|
||||
WHERE po.character_id = c.id
|
||||
AND (po.created_at + (pot.term_length * INTERVAL '1 day')) > NOW()
|
||||
), '') AS political_office_names,
|
||||
COALESCE((
|
||||
SELECT h.position::int
|
||||
FROM falukant_data.user_house uh
|
||||
JOIN falukant_type.house h ON h.id = uh.house_type_id
|
||||
WHERE uh.user_id = fu.id
|
||||
ORDER BY uh.id
|
||||
LIMIT 1
|
||||
), 0) AS house_position
|
||||
FROM falukant_data.falukant_user fu
|
||||
JOIN falukant_data.character c ON c.user_id = fu.id AND c.health > 0
|
||||
LEFT JOIN falukant_type.title t ON t.id = c.title_of_nobility
|
||||
ORDER BY fu.id, c.id;
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_FALUKANT_USER_CERTIFICATE: &str = r#"
|
||||
UPDATE falukant_data.falukant_user
|
||||
SET certificate = $1::int
|
||||
WHERE id = $2::int;
|
||||
"#;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user