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:
@@ -720,13 +720,35 @@ impl FalukantFamilyWorker {
|
||||
conn.prepare("mar_sub", QUERY_MARRIAGE_SUBTRACT_SATISFACTION)?;
|
||||
conn.prepare("mark_inst", QUERY_MARK_LOVER_INSTALLMENT_AT)?;
|
||||
|
||||
let mut notify: HashSet<i32> = HashSet::new();
|
||||
struct LoverInst {
|
||||
rel_id: i32,
|
||||
c1: i32,
|
||||
c2: i32,
|
||||
lover_role: String,
|
||||
maintenance_level: i32,
|
||||
status_fit: i32,
|
||||
base: i32,
|
||||
title1: String,
|
||||
title2: String,
|
||||
u1: Option<i32>,
|
||||
u2: Option<i32>,
|
||||
affection: i32,
|
||||
visibility: i32,
|
||||
discretion: i32,
|
||||
consec: i32,
|
||||
scandal_extra: i32,
|
||||
payer_cid: Option<i32>,
|
||||
free_political_slot: bool,
|
||||
}
|
||||
|
||||
let mut items: Vec<LoverInst> = Vec::new();
|
||||
for r in lover_rows {
|
||||
let rel_id = parse_i32(&r, "rel_id", -1);
|
||||
if rel_id < 0 {
|
||||
continue;
|
||||
}
|
||||
let c1 = parse_i32(&r, "c1", -1);
|
||||
let c2 = parse_i32(&r, "c2", -1);
|
||||
let lover_role = r.get("lover_role").cloned().unwrap_or_default();
|
||||
let maintenance_level = parse_i32(&r, "maintenance_level", 50);
|
||||
let status_fit = parse_i32(&r, "status_fit", 0);
|
||||
@@ -741,6 +763,83 @@ impl FalukantFamilyWorker {
|
||||
}
|
||||
let title1 = r.get("title1_tr").cloned().unwrap_or_default();
|
||||
let title2 = r.get("title2_tr").cloned().unwrap_or_default();
|
||||
let u1 = parse_opt_i32(&r, "user1_id");
|
||||
let u2 = parse_opt_i32(&r, "user2_id");
|
||||
let payer = u1.or(u2).filter(|x| *x > 0);
|
||||
let payer_cid = match (u1, u2, payer) {
|
||||
(Some(a), _, Some(p)) if p == a => Some(c1),
|
||||
(_, Some(b), Some(p)) if p == b => Some(c2),
|
||||
_ => None,
|
||||
};
|
||||
items.push(LoverInst {
|
||||
rel_id,
|
||||
c1,
|
||||
c2,
|
||||
lover_role,
|
||||
maintenance_level,
|
||||
status_fit,
|
||||
base,
|
||||
title1,
|
||||
title2,
|
||||
u1,
|
||||
u2,
|
||||
affection: parse_i32(&r, "affection", 50),
|
||||
visibility: parse_i32(&r, "visibility", 0),
|
||||
discretion: parse_i32(&r, "discretion", 50),
|
||||
consec: parse_i32(&r, "months_underfunded", 0),
|
||||
scandal_extra: parse_i32(&r, "scandal_extra_daily_pct", 0),
|
||||
payer_cid,
|
||||
free_political_slot: false,
|
||||
});
|
||||
}
|
||||
|
||||
items.sort_by_key(|x| (x.payer_cid.unwrap_or(-1), x.rel_id));
|
||||
|
||||
let mut free_slots_by_char: HashMap<i32, i32> = HashMap::new();
|
||||
let mut seen_payer: HashSet<i32> = HashSet::new();
|
||||
for it in &items {
|
||||
if let Some(cid) = it.payer_cid {
|
||||
if seen_payer.insert(cid) {
|
||||
if let Ok(n) = super::political_benefits::sum_free_lover_slots(&mut conn, cid) {
|
||||
free_slots_by_char.insert(cid, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut cur_group = -2i32;
|
||||
let mut eligible_ix: usize = 0;
|
||||
for it in &mut items {
|
||||
let gk = it.payer_cid.unwrap_or(-1);
|
||||
if gk != cur_group {
|
||||
cur_group = gk;
|
||||
eligible_ix = 0;
|
||||
}
|
||||
let free_n = it
|
||||
.payer_cid
|
||||
.and_then(|c| free_slots_by_char.get(&c).copied())
|
||||
.unwrap_or(0);
|
||||
let role_ok = matches!(
|
||||
it.lover_role.as_str(),
|
||||
"lover" | "mistress_or_favorite"
|
||||
);
|
||||
if role_ok && it.payer_cid.is_some() {
|
||||
if eligible_ix < free_n as usize {
|
||||
it.free_political_slot = true;
|
||||
}
|
||||
eligible_ix += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut notify: HashSet<i32> = HashSet::new();
|
||||
|
||||
for it in items {
|
||||
let rel_id = it.rel_id;
|
||||
let maintenance_level = it.maintenance_level;
|
||||
let status_fit = it.status_fit;
|
||||
let base = it.base;
|
||||
let title1 = it.title1.clone();
|
||||
let title2 = it.title2.clone();
|
||||
let g = pair_rank_group(&title1, &title2);
|
||||
let rank_m = rank_cost_multiplier(g);
|
||||
let maint_f = 0.6 + (maintenance_level as f64 / 100.0) * 1.2;
|
||||
@@ -750,17 +849,20 @@ impl FalukantFamilyWorker {
|
||||
_ => 1.0,
|
||||
};
|
||||
let cost = ((base as f64) * rank_m * maint_f * sf_m).round() as i32;
|
||||
let installment = ((cost as f64) / 12.0 * 100.0).round() / 100.0;
|
||||
let mut installment = ((cost as f64) / 12.0 * 100.0).round() / 100.0;
|
||||
if it.free_political_slot {
|
||||
installment = 0.0;
|
||||
}
|
||||
|
||||
let u1 = parse_opt_i32(&r, "user1_id");
|
||||
let u2 = parse_opt_i32(&r, "user2_id");
|
||||
let u1 = it.u1;
|
||||
let u2 = it.u2;
|
||||
let payer = u1.or(u2).filter(|x| *x > 0);
|
||||
|
||||
let affection = parse_i32(&r, "affection", 50);
|
||||
let visibility = parse_i32(&r, "visibility", 0);
|
||||
let discretion = parse_i32(&r, "discretion", 50);
|
||||
let mut consec = parse_i32(&r, "months_underfunded", 0);
|
||||
let mut scandal_extra = parse_i32(&r, "scandal_extra_daily_pct", 0);
|
||||
let affection = it.affection;
|
||||
let visibility = it.visibility;
|
||||
let discretion = it.discretion;
|
||||
let mut consec = it.consec;
|
||||
let mut scandal_extra = it.scandal_extra;
|
||||
|
||||
if let Some(uid) = payer {
|
||||
if installment <= 0.0 {
|
||||
@@ -795,7 +897,7 @@ impl FalukantFamilyWorker {
|
||||
],
|
||||
)?;
|
||||
|
||||
for cid in [parse_i32(&r, "c1", 0), parse_i32(&r, "c2", 0)] {
|
||||
for cid in [it.c1, it.c2] {
|
||||
if cid <= 0 {
|
||||
continue;
|
||||
}
|
||||
@@ -805,7 +907,7 @@ impl FalukantFamilyWorker {
|
||||
}
|
||||
|
||||
if visibility >= 40 {
|
||||
for cid in [parse_i32(&r, "c1", 0), parse_i32(&r, "c2", 0)] {
|
||||
for cid in [it.c1, it.c2] {
|
||||
if cid > 0 {
|
||||
let cur = fetch_reputation(&mut conn, cid)?;
|
||||
let s = format!("{:.2}", (cur - 1.0).max(0.0));
|
||||
|
||||
Reference in New Issue
Block a user