mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 08:42:20 +08:00
Refactor lp_modification function
This commit is contained in:
@@ -267,31 +267,38 @@ pub fn gift_item_basic(id: i32, value: i64, ty_pe: i32, reason: &str, user: &mut
|
|||||||
}, reason, user)
|
}, reason, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) {
|
pub fn lp_modification(user: &mut JsonValue, change_amount: u64, remove: bool) -> bool {
|
||||||
|
let now = global::set_time(global::timestamp(), user["user"]["id"].as_i64().unwrap_or(0), false);
|
||||||
let max = get_user_rank_data(user["user"]["exp"].as_i64().unwrap())["maxLp"].as_u64().unwrap();
|
let max = get_user_rank_data(user["user"]["exp"].as_i64().unwrap())["maxLp"].as_u64().unwrap();
|
||||||
|
|
||||||
let speed = 285; //4 mins, 45 sec
|
let orig_stamina = user["stamina"]["stamina"].as_u64().unwrap();
|
||||||
let since_last = global::timestamp() - user["stamina"]["last_updated_time"].as_u64().unwrap();
|
let orig_anchor = user["stamina"]["last_updated_time"].as_u64().unwrap();
|
||||||
|
|
||||||
let diff = since_last % speed;
|
let mut stamina = orig_stamina;
|
||||||
let restored = (since_last - diff) / speed;
|
let mut anchor = orig_anchor;
|
||||||
user["stamina"]["last_updated_time"] = (global::timestamp() - diff).into();
|
|
||||||
|
if stamina < max && now > anchor {
|
||||||
let mut stamina = user["stamina"]["stamina"].as_u64().unwrap();
|
let restored = (now - anchor) / 300;
|
||||||
if stamina < max {
|
stamina = (stamina + restored).min(max);
|
||||||
stamina += restored;
|
anchor += restored * 300;
|
||||||
if stamina > max {
|
}
|
||||||
stamina = max;
|
|
||||||
|
if change_amount > 0 {
|
||||||
|
if remove {
|
||||||
|
let was_full = stamina >= max;
|
||||||
|
stamina -= change_amount;
|
||||||
|
if was_full {
|
||||||
|
anchor = now;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stamina += change_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if remove {
|
|
||||||
stamina -= change_amount;
|
|
||||||
} else {
|
|
||||||
stamina += change_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
user["stamina"]["stamina"] = stamina.into();
|
user["stamina"]["stamina"] = stamina.into();
|
||||||
|
user["stamina"]["last_updated_time"] = anchor.into();
|
||||||
|
|
||||||
|
stamina != orig_stamina || anchor != orig_anchor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rarity(id: i64) -> i32 {
|
pub fn get_rarity(id: i64) -> i32 {
|
||||||
@@ -360,8 +367,7 @@ pub fn give_exp(amount: i32, user: &mut JsonValue, mission: &mut JsonValue, rv:
|
|||||||
let new_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
let new_rank = get_user_rank_data(user["user"]["exp"].as_i64().unwrap());
|
||||||
if current_rank["rank"] != new_rank["rank"] {
|
if current_rank["rank"] != new_rank["rank"] {
|
||||||
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i64().unwrap() + new_rank["maxLp"].as_i64().unwrap()).into();
|
user["stamina"]["stamina"] = (user["stamina"]["stamina"].as_i64().unwrap() + new_rank["maxLp"].as_i64().unwrap()).into();
|
||||||
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
|
||||||
|
|
||||||
let status = get_mission_status(get_variable_mission_num(1101001, 1101030, mission), mission);
|
let status = get_mission_status(get_variable_mission_num(1101001, 1101030, mission), mission);
|
||||||
if status.is_empty() {
|
if status.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ async fn tutorial(req: HttpRequest, body: String) -> impl Responder {
|
|||||||
if user["tutorial_step"].as_i32().unwrap() < 130 {
|
if user["tutorial_step"].as_i32().unwrap() < 130 {
|
||||||
user["tutorial_step"] = body["step"].clone();
|
user["tutorial_step"] = body["step"].clone();
|
||||||
user["stamina"]["stamina"] = (100).into();
|
user["stamina"]["stamina"] = (100).into();
|
||||||
user["stamina"]["last_updated_time"] = global::timestamp().into();
|
user["stamina"]["last_updated_time"] = global::set_time(global::timestamp(), user["user"]["id"].as_i64().unwrap(), false).into();
|
||||||
userdata::save_acc(&key, user);
|
userdata::save_acc(&key, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,11 +268,14 @@ fn remove_deleted_custom_songs(user: &mut JsonValue) -> bool {
|
|||||||
pub fn get_acc(auth_key: &str) -> JsonValue {
|
pub fn get_acc(auth_key: &str) -> JsonValue {
|
||||||
let mut user = get_data(auth_key, "userdata");
|
let mut user = get_data(auth_key, "userdata");
|
||||||
cleanup_account(&mut user);
|
cleanup_account(&mut user);
|
||||||
if remove_deleted_custom_songs(&mut user) {
|
let mut changed = remove_deleted_custom_songs(&mut user);
|
||||||
|
|
||||||
|
if items::lp_modification(&mut user, 0, false) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if changed {
|
||||||
save_data(auth_key, "userdata", user.clone());
|
save_data(auth_key, "userdata", user.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
items::lp_modification(&mut user, 0, false);
|
|
||||||
user
|
user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user