mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2025-10-09 00:47:19 +08:00
Implement post-live rewards
This commit is contained in:
@@ -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<JsonValue> {
|
||||
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::<i64>().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": [],
|
||||
|
Reference in New Issue
Block a user