mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-10-11 17:14:30 +08:00
Redo story stuff
This commit is contained in:
@@ -60,6 +60,7 @@ pub fn add_chat_from_chapter_id(chapter_id: i64, chats: &mut JsonValue) -> bool
|
||||
}
|
||||
|
||||
async fn home(Login(key): Login) -> impl Responder {
|
||||
refresh_birthday(&key, &userdata::get_acc(&key));
|
||||
let chats = userdata::get_acc_chats(&key);
|
||||
|
||||
let mut rooms = array![];
|
||||
@@ -75,6 +76,54 @@ async fn home(Login(key): Login) -> impl Responder {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn refresh_birthday(key: &str, user: &JsonValue) {
|
||||
if !super::user::valid_birthday(user["user"]["birthday"].as_str().unwrap_or("")) { return; }
|
||||
let now = global::set_time(global::timestamp(), user["user"]["id"].as_i64().unwrap(), true);
|
||||
if !is_birthday(user, now) { return; }
|
||||
let mut chats = userdata::get_acc_chats(key);
|
||||
let mut missions = userdata::get_acc_missions(key);
|
||||
if grant_birthday_chats(user, &mut chats, &mut missions, now) {
|
||||
userdata::save_acc_chats(key, chats);
|
||||
userdata::save_acc_missions(key, missions);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_birthday(user: &JsonValue, now: u64) -> bool {
|
||||
let date = global::format_datetime(now);
|
||||
let birthday = user["user"]["birthday"].as_str().unwrap_or("");
|
||||
birthday == format!("{}{}", &date[5..7], &date[8..10])
|
||||
}
|
||||
|
||||
fn grant_birthday_chats(user: &JsonValue, chats: &mut JsonValue, missions: &mut JsonValue, now: u64) -> bool {
|
||||
if !is_birthday(user, now) { return false; }
|
||||
let mut changed = false;
|
||||
for (_, master) in databases::MISSION_LIST.entries() {
|
||||
if master["conditionType"] != 75 { continue; }
|
||||
let character = &master["conditionValues"][0];
|
||||
let target = master["conditionNumber"].as_i64().unwrap();
|
||||
if !user["character_list"].members().any(|c|
|
||||
c["master_character_id"] == *character && c["exp"].as_i64().unwrap_or(0) >= target) { continue; }
|
||||
let id = master["id"].as_i64().unwrap();
|
||||
if items::get_mission_status(id, missions)["status"] == 3 { continue; }
|
||||
for reward in databases::MISSION_REWARDS[master["masterMissionRewardId"].to_string()].members().filter(|r| r["type"] == 16) {
|
||||
for (_, by_room) in databases::CHATS.entries() {
|
||||
for (_, room) in by_room.entries().filter(|(_, r)| r["id"] == reward["value"]) {
|
||||
add_chat(room["masterChatId"].as_i64().unwrap(), room["roomId"].as_i64().unwrap(), chats);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !missions.members().any(|m| m["master_mission_id"] == id) {
|
||||
missions.push(object! {master_mission_id: id, status: 1, progress: 0, expire_date_time: 0, not_visible: 0}).unwrap();
|
||||
}
|
||||
for mission in missions.members_mut().filter(|m| m["master_mission_id"] == id) {
|
||||
mission["status"] = 3.into();
|
||||
mission["progress"] = target.into();
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
async fn start() -> impl Responder {
|
||||
Api(Some(object!{"select_talk_id_list":[],"get_item_list":[],"is_read":0}))
|
||||
}
|
||||
@@ -102,6 +151,25 @@ async fn end(Session { key, body }: Session) -> impl Responder {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn birthday_chats_require_the_date_and_bond_and_are_not_duplicated() {
|
||||
let _test = crate::runtime::lock_test_data_path();
|
||||
let user = object! { user: {birthday: "0531"}, character_list: [
|
||||
{master_character_id: 1001, exp: 50}, {master_character_id: 1002, exp: 49}
|
||||
]};
|
||||
let mut chats = array![];
|
||||
let mut missions = array![];
|
||||
let day = global::parse_datetime("2024/05/31 12:00:00").unwrap();
|
||||
assert!(!grant_birthday_chats(&user, &mut chats, &mut missions, day - 86400));
|
||||
assert!(grant_birthday_chats(&user, &mut chats, &mut missions, day));
|
||||
assert_eq!(chats.len(), 1);
|
||||
assert_eq!(chats[0]["chapter_id"], 100100301);
|
||||
assert_eq!(missions[0]["status"], 3);
|
||||
assert_eq!(missions[0]["progress"], 50);
|
||||
assert!(!grant_birthday_chats(&user, &mut chats, &mut missions, day));
|
||||
assert_eq!(chats.len(), 1);
|
||||
}
|
||||
|
||||
// Verbatim from an official /api/chat/home capture (JP log, the 65-occurrence
|
||||
// baseline seen on accounts that had earned no extra stamps yet). Both the JP and EN
|
||||
// chat_stamp tables reproduce it exactly from _initialStamp, which is what lets
|
||||
|
||||
Reference in New Issue
Block a user