diff --git a/src/router/card.rs b/src/router/card.rs index e36ca4f..f63a3f4 100644 --- a/src/router/card.rs +++ b/src/router/card.rs @@ -12,12 +12,7 @@ fn do_reinforce(user: &mut JsonValue, body: &JsonValue, exp_id: &str, money_mult let mut money: i64 = 0; for (_j, data2) in materials.members().enumerate() { - for (_k, data3) in user["item_list"].members_mut().enumerate() { - if data3["master_item_id"].to_string() == data2["master_item_id"].to_string() { - data3["amount"] = (data3["amount"].as_i64().unwrap() - data2["amount"].as_i64().unwrap()).into(); - break; - } - } + global::use_item(data2["master_item_id"].as_i64().unwrap(), data2["amount"].as_i64().unwrap(), user); let item = global::get_item_info(data2["master_item_id"].as_i64().unwrap()); if evolve { card["evolve"] = array![{type: 2,count: 1}]; diff --git a/src/router/clear_rate.rs b/src/router/clear_rate.rs index 37c4dba..28b695b 100644 --- a/src/router/clear_rate.rs +++ b/src/router/clear_rate.rs @@ -236,28 +236,21 @@ lazy_static! { static ref CACHED_DATA: Mutex> = Mutex::new(None); static ref LIVE_LIST: JsonValue = { let mut info = object!{}; - let mut info2 = object!{}; let items = json::parse(include_str!("json/live.json")).unwrap(); for (_i, data) in items.members().enumerate() { info[data["id"].to_string()] = data["masterMusicId"].clone(); } - for (_i, data) in items.members().enumerate() { - info2[data["masterMusicId"].to_string()] = data["id"].clone(); - } - object!{ - masterMusicId: info, - id: info2 - } + info }; } fn get_live_id(id: i64) -> i64 { - LIVE_LIST["masterMusicId"][id.to_string()].as_i64().unwrap() + LIVE_LIST[id.to_string()].as_i64().unwrap() } fn get_pass_percent(failed: i64, pass: i64) -> String { let total = (failed + pass) as f64; if failed + pass == 0 { - return String::from("--/--%"); + return String::from("--:--%"); } let pass = pass as f64; format!("{:.2}%", pass / total * 100.0) diff --git a/src/router/global.rs b/src/router/global.rs index 3ad41df..8b39c5c 100644 --- a/src/router/global.rs +++ b/src/router/global.rs @@ -174,6 +174,33 @@ pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool false } +pub fn give_gift(data: &JsonValue, user: &mut JsonValue) -> bool { + if data.is_empty() { + return false; + } + if data["reward_type"].to_string() == "1" { + // basically primogems!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + return !give_primogems(data["amount"].as_i64().unwrap(), user); + } else if data["reward_type"].to_string() == "2" { + //character + give_character(data["value"].to_string(), user); + return true; + } else if data["reward_type"].to_string() == "3" { + return !give_item(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user); + } else if data["reward_type"].to_string() == "4" { + // basically moraa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + return !give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user); + } + println!("Redeeming reward not implimented for reward type {}", data["reward_type"].to_string()); + return false; +} +pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i32, user: &mut JsonValue) -> bool { + give_gift(&object!{ + reward_type: ty_pe, + amount: amount, + value: id + }, user) +} pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool { let mut has = false; for (_j, dataa) in user["point_list"].members_mut().enumerate() { @@ -195,6 +222,16 @@ pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bo } false } +pub fn use_item(master_item_id: i64, amount: i64, user: &mut JsonValue) { + for (_j, dataa) in user["item_list"].members_mut().enumerate() { + if dataa["master_item_id"].as_i64().unwrap() == master_item_id { + if dataa["amount"].as_i64().unwrap() >= amount { + dataa["amount"] = (dataa["amount"].as_i64().unwrap() - amount).into(); + } + break; + } + } +} pub fn start_login_bonus(id: i64, bonus: &mut JsonValue) -> bool { if crate::router::login::get_login_bonus_info(id).is_empty() { diff --git a/src/router/live.rs b/src/router/live.rs index 4bb894a..4ed03a0 100644 --- a/src/router/live.rs +++ b/src/router/live.rs @@ -5,6 +5,7 @@ use actix_web::{HttpResponse, HttpRequest}; use crate::router::userdata; use rand::Rng; use crate::router::clear_rate::live_completed; +use lazy_static::lazy_static; pub fn retire(_req: HttpRequest, body: String) -> HttpResponse { let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); @@ -203,35 +204,37 @@ pub fn continuee(req: HttpRequest, body: String) -> HttpResponse { global::send(resp) } -pub fn update_live_data(user: &mut JsonValue, data: &JsonValue) -> JsonValue { +pub fn update_live_data(user: &mut JsonValue, data: &JsonValue, add: bool) -> JsonValue { if user["tutorial_step"].as_i32().unwrap() < 130 { return JsonValue::Null; } let mut rv = object!{ - "master_live_id": data["master_live_id"].as_i32().unwrap(), - "level": data["level"].as_i32().unwrap(), + "master_live_id": data["master_live_id"].as_i64().unwrap(), + "level": data["level"].as_i64().unwrap(), "clear_count": 1, - "high_score": data["live_score"]["score"].as_i32().unwrap(), - "max_combo": data["live_score"]["max_combo"].as_i32().unwrap(), + "high_score": data["live_score"]["score"].as_i64().unwrap(), + "max_combo": data["live_score"]["max_combo"].as_i64().unwrap(), "auto_enable": 1, //whats this? "updated_time": global::timestamp() }; let mut has = false; for (_i, current) in user["live_list"].members_mut().enumerate() { - if current["master_live_id"].to_string() == rv["master_live_id"].to_string() { + if current["master_live_id"].to_string() == rv["master_live_id"].to_string() && current["level"].to_string() == rv["level"].to_string() { has = true; - rv["clear_count"] = (current["clear_count"].as_i32().unwrap() + 1).into(); + if add { + rv["clear_count"] = (current["clear_count"].as_i64().unwrap() + 1).into(); + } current["clear_count"] = rv["clear_count"].clone(); - if rv["high_score"].as_i32().unwrap() > current["high_score"].as_i32().unwrap() { + if rv["high_score"].as_i64().unwrap() > current["high_score"].as_i64().unwrap() { current["high_score"] = rv["high_score"].clone(); } else { rv["high_score"] = current["high_score"].clone(); } - if rv["max_combo"].as_i32().unwrap() > current["max_combo"].as_i32().unwrap() { + if rv["max_combo"].as_i64().unwrap() > current["max_combo"].as_i64().unwrap() { current["max_combo"] = rv["max_combo"].clone(); } else { rv["max_combo"] = current["max_combo"].clone(); @@ -245,19 +248,172 @@ pub fn update_live_data(user: &mut JsonValue, data: &JsonValue) -> JsonValue { } rv } +pub fn update_live_mission_data(user: &mut JsonValue, data: &JsonValue) { + if user["tutorial_step"].as_i32().unwrap() < 130 { + return; + } + + let rv = object!{ + "master_live_id": data["master_live_id"].as_i64().unwrap(), + "clear_master_live_mission_ids": data["clear_master_live_mission_ids"].clone() + }; + + for (_i, current) in user["live_mission_list"].members_mut().enumerate() { + if current["master_live_id"].to_string() == rv["master_live_id"].to_string() { + current["clear_master_live_mission_ids"] = data["clear_master_live_mission_ids"].clone(); + return; + } + } + user["live_mission_list"].push(rv.clone()).unwrap(); +} + +lazy_static! { + static ref LIVE_LIST: JsonValue = { + let mut info = object!{}; + let items = json::parse(include_str!("json/live.json")).unwrap(); + for (_i, data) in items.members().enumerate() { + info[data["id"].to_string()] = data.clone(); + } + info + }; + static ref MISSION_DATA: JsonValue = { + json::parse(include_str!("json/live_mission.json")).unwrap() + }; + static ref MISSION_COMBO_DATA: JsonValue = { + let mut info = object!{}; + let items = json::parse(include_str!("json/live_mission_combo.json")).unwrap(); + for (_i, data) in items.members().enumerate() { + info[data["masterMusicId"].to_string()] = data.clone(); + } + info + }; + static ref MISSION_REWARD_DATA: JsonValue = { + let mut info = object!{}; + let items = json::parse(include_str!("json/live_mission_reward.json")).unwrap(); + for (_i, data) in items.members().enumerate() { + info[data["id"].to_string()] = data.clone(); + } + info + }; +} +fn get_live_info(id: i64) -> JsonValue { + LIVE_LIST[id.to_string()].clone() +} +fn get_live_combo_info(id: i64) -> JsonValue { + MISSION_COMBO_DATA[id.to_string()].clone() +} +fn get_live_mission_info(id: i64) -> JsonValue { + MISSION_REWARD_DATA[id.to_string()].clone() +} + +fn get_live_mission_completed_ids(live_id: i64, score: i64, combo: i64, clear_count: i64, level: String, full_combo: bool) -> Option { + let live_info = get_live_info(live_id); + let mut rv = array![]; + let combo_info = get_live_combo_info(live_info["masterMusicId"].as_i64()?); + + for (_i, data) in MISSION_DATA.members().enumerate() { + match data["type"].as_i32()? { + 1 => { + if live_info[&format!("score{}", data["value"].to_string())].as_i64()? <= score { + rv.push(data["id"].as_i32()?).ok()?; + } + }, + 2 => { + if full_combo && data["value"].to_string() == level { + rv.push(data["id"].as_i32()?).ok()?; + } + }, + 3 => { + if combo_info["valueList"][data["level"].as_usize()? - 1].as_i64()? <= combo { + rv.push(data["id"].as_i32()?).ok()?; + } + }, + 4 => { + if clear_count >= data["value"].to_string().parse::().ok()? { + rv.push(data["id"].as_i32()?).ok()?; + } + }, + _ => {} + } + } + Some(rv) +} + +fn give_mission_rewards(user: &mut JsonValue, missions: &JsonValue, multiplier: i64) -> JsonValue { + let mut rv = array![]; + for (_i, data) in MISSION_DATA.members().enumerate() { + if !missions.contains(data["id"].as_i32().unwrap()) { + continue; + } + let mut gift = get_live_mission_info(data["masterLiveMissionRewardId"].as_i64().unwrap()); + gift["reward_type"] = gift["type"].clone(); + gift["amount"] = (gift["amount"].as_i64().unwrap() * multiplier).into(); + global::give_gift(&gift, user); + } + if global::give_gift_basic(3, 16005001, 10, user) { + rv.push(object!{"type":3,"value":16005001,"level":0,"amount":10}).unwrap(); + } + if global::give_gift_basic(3, 17001001, 2, user) { + rv.push(object!{"type":3,"value":17001001,"level":0,"amount":2}).unwrap(); + } + rv +} + +pub fn end(req: HttpRequest, body: String) -> HttpResponse { + let key = global::get_login(req.headers(), &body); + let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); + let user2 = userdata::get_acc_home(&key); + let mut user = userdata::get_acc(&key); + let live = update_live_data(&mut user, &body, true); + + live_completed(body["master_live_id"].as_i64().unwrap(), body["level"].as_i32().unwrap(), false, body["live_score"]["score"].as_i64().unwrap(), user["user"]["id"].as_i64().unwrap()); + + let is_full_combo = (body["live_score"]["good"].as_i32().unwrap() + body["live_score"]["bad"].as_i32().unwrap() + body["live_score"]["miss"].as_i32().unwrap()) == 0; + let missions = get_live_mission_completed_ids(body["master_live_id"].as_i64().unwrap(), body["live_score"]["score"].as_i64().unwrap(), body["live_score"]["max_combo"].as_i64().unwrap(), live["clear_count"].as_i64().unwrap(), body["level"].to_string(), is_full_combo).unwrap_or(array![]); + + update_live_mission_data(&mut user, &object!{ + master_live_id: body["master_live_id"].as_i64().unwrap(), + clear_master_live_mission_ids: missions.clone() + }); + + let reward_list = give_mission_rewards(&mut user, &missions, 1); + + global::lp_modification(&mut user, body["use_lp"].as_u64().unwrap(), true); + + global::give_exp(body["use_lp"].as_i32().unwrap(), &mut user); + + userdata::save_acc(&key, user.clone()); + + let resp = object!{ + "code": 0, + "server_time": global::timestamp(), + "data": { + "gem": user["gem"].clone(), + "high_score": live["high_score"].clone(), + "item_list": user["item_list"].clone(), + "point_list": user["point_list"].clone(), + "live": live, + "clear_master_live_mission_ids": missions, + "user": user["user"].clone(), + "stamina": user["stamina"].clone(), + "character_list": user["character_list"].clone(), + "reward_list": reward_list, + "gift_list": user2["home"]["gift_list"].clone(), + "clear_mission_ids": user2["clear_mission_ids"].clone(), + "event_point_reward_list": [], + "ranking_change": [], + "event_member": [], + "event_ranking_data": [] + } + }; + global::send(resp) +} pub fn skip(req: HttpRequest, body: String) -> HttpResponse { let key = global::get_login(req.headers(), &body); let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); - let mut user2 = userdata::get_acc_home(&key); + let user2 = userdata::get_acc_home(&key); let mut user = userdata::get_acc(&key); - - global::gift_item_basic(1, 10000, 4, "You skipped a live!", &mut user2); - global::gift_item_basic(16005003, 10, 3, "You skipped a live!", &mut user2); - global::gift_item_basic(17001003, 2, 3, "You skipped a live!", &mut user2); - - global::give_exp(10, &mut user); - let live = update_live_data(&mut user, &object!{ master_live_id: body["master_live_id"].clone(), level: 1, @@ -265,10 +421,24 @@ pub fn skip(req: HttpRequest, body: String) -> HttpResponse { score: 1, max_combo: 1 } + }, false); + + let missions = get_live_mission_completed_ids(body["master_live_id"].as_i64().unwrap(), live["high_score"].as_i64().unwrap(), live["max_combo"].as_i64().unwrap(), live["clear_count"].as_i64().unwrap(), live["level"].to_string(), false).unwrap_or(array![]); + + update_live_mission_data(&mut user, &object!{ + master_live_id: body["master_live_id"].as_i64().unwrap(), + clear_master_live_mission_ids: missions.clone() }); + let reward_list = give_mission_rewards(&mut user, &missions, body["live_boost"].as_i64().unwrap()); + + global::lp_modification(&mut user, 10 * body["live_boost"].as_u64().unwrap(), true); + + global::give_exp(10 * body["live_boost"].as_i32().unwrap(), &mut user); + + global::use_item(21000001, body["live_boost"].as_i64().unwrap(), &mut user); + userdata::save_acc(&key, user.clone()); - userdata::save_acc_home(&key, user2.clone()); let resp = object!{ "code": 0, @@ -279,57 +449,11 @@ pub fn skip(req: HttpRequest, body: String) -> HttpResponse { "item_list": user["item_list"].clone(), "point_list": user["point_list"].clone(), "live": live, - "clear_master_live_mission_ids": [], + "clear_master_live_mission_ids": missions, "user": user["user"].clone(), "stamina": user["stamina"].clone(), "character_list": user["character_list"].clone(), - "reward_list": [], - "gift_list": user2["home"]["gift_list"].clone(), - "clear_mission_ids": user2["clear_mission_ids"].clone(), - "event_point_reward_list": [], - "ranking_change": [], - "event_member": [], - "event_ranking_data": [] - } - }; - global::send(resp) -} - -pub fn end(req: HttpRequest, body: String) -> HttpResponse { - let key = global::get_login(req.headers(), &body); - let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap(); - let mut user2 = userdata::get_acc_home(&key); - let mut user = userdata::get_acc(&key); - - live_completed(body["master_live_id"].as_i64().unwrap(), body["level"].as_i32().unwrap(), false, body["live_score"]["score"].as_i64().unwrap(), user["user"]["id"].as_i64().unwrap()); - - global::gift_item_basic(1, 10000, 4, "You completed a live!", &mut user2); - global::gift_item_basic(16005003, 10, 3, "You completed a live!", &mut user2); - global::gift_item_basic(17001003, 2, 3, "You completed a live!", &mut user2); - - global::lp_modification(&mut user, body["use_lp"].as_u64().unwrap(), true); - - global::give_exp(body["use_lp"].as_i32().unwrap(), &mut user); - - let live = update_live_data(&mut user, &body); - - userdata::save_acc(&key, user.clone()); - userdata::save_acc_home(&key, user2.clone()); - - let resp = object!{ - "code": 0, - "server_time": global::timestamp(), - "data": { - "gem": user["gem"].clone(), - "high_score": live["high_score"].clone(), - "item_list": user["item_list"].clone(), - "point_list": user["point_list"].clone(), - "live": live, - "clear_master_live_mission_ids": [], - "user": user["user"].clone(), - "stamina": user["stamina"].clone(), - "character_list": user["character_list"].clone(), - "reward_list": [], + "reward_list": reward_list, "gift_list": user2["home"]["gift_list"].clone(), "clear_mission_ids": user2["clear_mission_ids"].clone(), "event_point_reward_list": [], diff --git a/src/router/serial_code.rs b/src/router/serial_code.rs index 1495123..af83967 100644 --- a/src/router/serial_code.rs +++ b/src/router/serial_code.rs @@ -22,7 +22,7 @@ pub fn serial_code(req: HttpRequest, body: String) -> HttpResponse { let item; if body["input_code"].to_string() == "SIF2REVIVALREAL!" { - item = global::gift_item_basic(1, 10000, 4, "You typed in code!!!!!!!!!", &mut user); + item = global::gift_item_basic(1, 100000, 4, "You typed in code!!!!!!!!!", &mut user); } else { let resp = object!{ "code": 0, diff --git a/src/router/user.rs b/src/router/user.rs index 442e4bf..4f7fcd7 100644 --- a/src/router/user.rs +++ b/src/router/user.rs @@ -79,25 +79,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse { if data["id"].to_string() != gift_id.to_string() { continue; } - let limit_reached; - //println!("{}", json::stringify(data.clone())); - if data["reward_type"].to_string() == "1" { - // basically primogems!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - limit_reached = global::give_primogems(data["amount"].as_i64().unwrap(), &mut userr); - } else if data["reward_type"].to_string() == "2" { - //character - global::give_character(data["value"].to_string(), &mut userr); - limit_reached = false; - } else if data["reward_type"].to_string() == "3" { - limit_reached = global::give_item(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), &mut userr); - } else if data["reward_type"].to_string() == "4" { - // basically moraa!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - limit_reached = global::give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), &mut userr); - } else { - println!("Redeeming reward not implimented for reward type {}", data["reward_type"].to_string()); - limit_reached = true; - } - if limit_reached { + if !global::give_gift(&data, &mut userr) { failed.push(gift_id.clone()).unwrap(); break; }