Implement political benefits management in FalukantFamilyWorker and SQL: Introduced a new structure for handling lover relationships, including political slots and reputation ticks. Updated SQL queries to support political benefits, ensuring proper handling of appointments and reputation gains. Enhanced the FalukantFamilyWorker logic to manage free political slots and maintain relationships effectively. Improved documentation for clarity on the new political benefits features and their integration into the existing system.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 2m55s
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 2m55s
This commit is contained in:
@@ -1289,6 +1289,102 @@ SELECT elig.user_id,
|
||||
ORDER BY elig.election_id, elig.user_id;
|
||||
"#;
|
||||
|
||||
// --- Politische Amtsvorteile (reputation_periodic, free_lover_slots, Ernennungs-Ablauf) ---
|
||||
|
||||
/// `political_benefit_last_tick` + `falukant_predefine.political_office_benefit` vorhanden.
|
||||
pub const QUERY_POLITICAL_BENEFIT_DAEMON_SCHEMA_READY: &str = r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'political_benefit_last_tick'
|
||||
) AND EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'falukant_predefine'
|
||||
AND table_name = 'political_office_benefit'
|
||||
) AS ready;
|
||||
"#;
|
||||
|
||||
/// Spieler mit aktivem Amt + `reputation_periodic` (JSON `tr` oder `benefitType`); Kalendertage seit `last_tick_at`.
|
||||
pub const QUERY_POLITICAL_REPUTATION_TICK_ROWS: &str = r#"
|
||||
SELECT
|
||||
pob.id AS benefit_id,
|
||||
po.character_id AS character_id,
|
||||
GREATEST(1, COALESCE(NULLIF((pob.value::jsonb->>'intervalDays'), '')::int, 7)) AS interval_days,
|
||||
COALESCE(NULLIF((pob.value::jsonb->>'gain'), '')::numeric, 0::numeric) AS gain,
|
||||
ch.user_id AS falukant_user_id
|
||||
FROM falukant_data.political_office po
|
||||
JOIN falukant_predefine.political_office_benefit pob
|
||||
ON pob.political_office_type_id = po.office_type_id
|
||||
JOIN falukant_data.character ch ON ch.id = po.character_id
|
||||
LEFT JOIN falukant_data.political_benefit_last_tick btl
|
||||
ON btl.character_id = po.character_id
|
||||
AND btl.political_office_benefit_id = pob.id
|
||||
WHERE po.character_id IS NOT NULL
|
||||
AND ch.user_id IS NOT NULL
|
||||
AND COALESCE(pob.value::jsonb->>'tr', pob.value::jsonb->>'benefitType') = 'reputation_periodic'
|
||||
AND COALESCE(NULLIF((pob.value::jsonb->>'gain'), '')::numeric, 0::numeric) > 0
|
||||
AND (
|
||||
btl.last_tick_at IS NULL
|
||||
OR (CURRENT_DATE - (btl.last_tick_at::date))
|
||||
>= GREATEST(1, COALESCE(NULLIF((pob.value::jsonb->>'intervalDays'), '')::int, 7))
|
||||
);
|
||||
"#;
|
||||
|
||||
pub const QUERY_POLITICAL_REPUTATION_TICK_UPSERT: &str = r#"
|
||||
INSERT INTO falukant_data.political_benefit_last_tick
|
||||
(character_id, political_office_benefit_id, last_tick_at, ticks_count)
|
||||
VALUES ($1::int, $2::int, NOW(), 1)
|
||||
ON CONFLICT (character_id, political_office_benefit_id)
|
||||
DO UPDATE SET
|
||||
last_tick_at = EXCLUDED.last_tick_at,
|
||||
ticks_count = falukant_data.political_benefit_last_tick.ticks_count + 1;
|
||||
"#;
|
||||
|
||||
pub const QUERY_POLITICAL_REPUTATION_APPLY_GAIN: &str = r#"
|
||||
UPDATE falukant_data.character c
|
||||
SET reputation = LEAST(
|
||||
100::numeric,
|
||||
GREATEST(0::numeric, COALESCE(c.reputation, 50::numeric) + $gain::numeric)
|
||||
),
|
||||
updated_at = NOW()
|
||||
WHERE c.id = $1::int;
|
||||
"#;
|
||||
|
||||
pub const QUERY_POLITICAL_APPOINTMENT_SCHEMA_READY: &str = r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'political_appointment'
|
||||
) AS ready;
|
||||
"#;
|
||||
|
||||
pub const QUERY_POLITICAL_APPOINTMENT_EXPIRE_PENDING: &str = r#"
|
||||
UPDATE falukant_data.political_appointment
|
||||
SET status = 'expired',
|
||||
updated_at = NOW()
|
||||
WHERE status = 'pending'
|
||||
AND expires_at IS NOT NULL
|
||||
AND expires_at < NOW();
|
||||
"#;
|
||||
|
||||
/// Summe `count` aus `free_lover_slots`-Benefits (JSON `tr`/`benefitType`), gedeckelt.
|
||||
pub const QUERY_SUM_FREE_LOVER_SLOTS_FOR_CHARACTER: &str = r#"
|
||||
SELECT LEAST(
|
||||
5,
|
||||
COALESCE(SUM(
|
||||
GREATEST(0, COALESCE(NULLIF((pob.value::jsonb->>'count'), '')::int, 0))
|
||||
), 0)
|
||||
)::int AS free_slots
|
||||
FROM falukant_data.political_office po
|
||||
JOIN falukant_predefine.political_office_benefit pob
|
||||
ON pob.political_office_type_id = po.office_type_id
|
||||
WHERE po.character_id = $1::int
|
||||
AND COALESCE(pob.value::jsonb->>'tr', pob.value::jsonb->>'benefitType') = 'free_lover_slots';
|
||||
"#;
|
||||
|
||||
pub const QUERY_TRIM_EXCESS_OFFICES_GLOBAL: &str = r#"
|
||||
WITH seats AS (
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user