mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Add obtain gold mission
This commit is contained in:
parent
0ee281895e
commit
f3d045649c
7 changed files with 47 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
|||
use json::{JsonValue, object};
|
||||
use json::{JsonValue, object, array};
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
|
@ -37,6 +37,8 @@ pub fn exchange_post(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 user = userdata::get_acc(&key);
|
||||
let mut missions = userdata::get_acc_missions(&key);
|
||||
let mut cleared_missions = array![];
|
||||
|
||||
let item = &EXCHANGE_LIST[body["master_exchange_item_id"].to_string()];
|
||||
|
||||
|
@ -49,9 +51,10 @@ pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
let mut gift = EXCHANGE_REWARD[item["masterExchangeItemRewardId"].to_string()].clone();
|
||||
gift["reward_type"] = gift["type"].clone();
|
||||
gift["amount"] = (gift["amount"].as_i64().unwrap() * body["count"].as_i64().unwrap()).into();
|
||||
items::give_gift(&gift, &mut user);
|
||||
items::give_gift(&gift, &mut user, &mut missions, &mut cleared_missions);
|
||||
|
||||
userdata::save_acc(&key, user.clone());
|
||||
userdata::save_acc_missions(&key, missions);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
|
@ -63,7 +66,7 @@ pub fn exchange_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
"item_list": user["item_list"].clone(),
|
||||
"point_list": user["point_list"].clone()
|
||||
},
|
||||
"clear_mission_ids": []
|
||||
"clear_mission_ids": cleared_missions
|
||||
}
|
||||
};
|
||||
global::send(resp, req)
|
||||
|
|
|
@ -84,6 +84,9 @@ lazy_static! {
|
|||
for i in 1158001..=1158082 {
|
||||
missions.push(i).unwrap();
|
||||
}
|
||||
for i in 1121001..=1121019 {
|
||||
missions.push(i).unwrap();
|
||||
}
|
||||
missions
|
||||
};
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ 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 {
|
||||
pub fn give_gift(data: &JsonValue, user: &mut JsonValue, missions: &mut JsonValue, clear_missions: &mut JsonValue) -> bool {
|
||||
if data.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ pub fn give_gift(data: &JsonValue, user: &mut JsonValue) -> bool {
|
|||
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);
|
||||
return !give_points(data["value"].as_i64().unwrap(), data["amount"].as_i64().unwrap(), user, missions, clear_missions);
|
||||
} else if data["reward_type"].to_string() == "8" {
|
||||
// title
|
||||
let title = data["value"].as_i64().unwrap();
|
||||
|
@ -120,23 +120,29 @@ pub fn give_gift(data: &JsonValue, user: &mut JsonValue) -> bool {
|
|||
println!("Redeeming reward not implemented for reward type {}", data["reward_type"].to_string());
|
||||
return false;
|
||||
}
|
||||
pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||
pub fn give_gift_basic(ty_pe: i32, id: i64, amount: i64, user: &mut JsonValue, missions: &mut JsonValue, clear_missions: &mut JsonValue) -> bool {
|
||||
give_gift(&object!{
|
||||
reward_type: ty_pe,
|
||||
amount: amount,
|
||||
value: id
|
||||
}, user)
|
||||
}, user, missions, clear_missions)
|
||||
}
|
||||
pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||
pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue, missions: &mut JsonValue, clear_missions: &mut JsonValue) -> bool {
|
||||
if master_item_id == 1 {
|
||||
let cleared = advance_variable_mission(1121001, 1121019, amount, missions);
|
||||
for (_i, data) in cleared.members().enumerate() {
|
||||
clear_missions.push(data.clone()).unwrap();
|
||||
}
|
||||
}
|
||||
let mut has = false;
|
||||
for (_j, dataa) in user["point_list"].members_mut().enumerate() {
|
||||
if dataa["type"].as_i64().unwrap() == master_item_id {
|
||||
for (_j, data) in user["point_list"].members_mut().enumerate() {
|
||||
if data["type"].as_i64().unwrap() == master_item_id {
|
||||
has = true;
|
||||
let new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
||||
let new_amount = data["amount"].as_i64().unwrap() + amount;
|
||||
if new_amount > LIMIT_COINS {
|
||||
return true;
|
||||
}
|
||||
dataa["amount"] = new_amount.into();
|
||||
data["amount"] = new_amount.into();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -150,12 +156,12 @@ pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bo
|
|||
}
|
||||
|
||||
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();
|
||||
for (_j, data) in user["item_list"].members_mut().enumerate() {
|
||||
if data["master_item_id"].as_i64().unwrap() == master_item_id {
|
||||
if data["amount"].as_i64().unwrap() >= amount {
|
||||
data["amount"] = (data["amount"].as_i64().unwrap() - amount).into();
|
||||
} else {
|
||||
dataa["amount"] = (0).into();
|
||||
data["amount"] = (0).into();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -376,7 +376,7 @@ fn get_live_mission_completed_ids(user: &JsonValue, live_id: i64, score: i64, co
|
|||
Some(out)
|
||||
}
|
||||
|
||||
fn give_mission_rewards(user: &mut JsonValue, missions: &JsonValue, multiplier: i64) -> JsonValue {
|
||||
fn give_mission_rewards(user: &mut JsonValue, missions: &mut JsonValue, cleared_missions: &mut JsonValue, multiplier: i64) -> JsonValue {
|
||||
let mut rv = array![];
|
||||
for (_i, data) in MISSION_DATA.members().enumerate() {
|
||||
if !missions.contains(data["id"].as_i32().unwrap()) {
|
||||
|
@ -388,12 +388,12 @@ fn give_mission_rewards(user: &mut JsonValue, missions: &JsonValue, multiplier:
|
|||
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();
|
||||
items::give_gift(&gift, user);
|
||||
items::give_gift(&gift, user, missions, cleared_missions);
|
||||
}
|
||||
if items::give_gift_basic(3, 16005001, 10 * multiplier, user) {
|
||||
if items::give_gift_basic(3, 16005001, 10 * multiplier, user, missions, cleared_missions) {
|
||||
rv.push(object!{"type":3,"value":16005001,"level":0,"amount":10}).unwrap();
|
||||
}
|
||||
if items::give_gift_basic(3, 17001001, 2 * multiplier, user) {
|
||||
if items::give_gift_basic(3, 17001001, 2 * multiplier, user, missions, cleared_missions) {
|
||||
rv.push(object!{"type":3,"value":17001001,"level":0,"amount":2}).unwrap();
|
||||
}
|
||||
rv
|
||||
|
@ -507,7 +507,7 @@ fn live_end(req: &HttpRequest, body: &String, skipped: bool) -> JsonValue {
|
|||
clear_master_live_mission_ids: missions.clone()
|
||||
});
|
||||
|
||||
let reward_list = give_mission_rewards(&mut user, &missions, body["live_boost"].as_i64().unwrap_or(1));
|
||||
let reward_list = give_mission_rewards(&mut user, &mut user_missions, &mut cleared_missions, body["live_boost"].as_i64().unwrap_or(1));
|
||||
|
||||
let lp_used: i32 = body["use_lp"].as_i32().unwrap_or(10 * body["live_boost"].as_i32().unwrap_or(0));
|
||||
|
||||
|
|
|
@ -153,6 +153,8 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
println!("lottery: {}", body);
|
||||
let mut user = userdata::get_acc(&key);
|
||||
let user2 = userdata::get_acc(&key);
|
||||
let mut missions = userdata::get_acc_missions(&key);
|
||||
let mut cleared_missions = array![];
|
||||
|
||||
let mut cardstogive;
|
||||
|
||||
|
@ -212,11 +214,11 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
}
|
||||
lottery_list.push(to_push).unwrap();
|
||||
}
|
||||
items::give_gift_basic(3, 15540034, 10, &mut user);
|
||||
items::give_gift_basic(3, 15540034, 10, &mut user, &mut missions, &mut cleared_missions);
|
||||
} else if lottery_type == 2 {
|
||||
for (_i, data) in cardstogive.members().enumerate() {
|
||||
let info = get_card(data["master_lottery_item_id"].to_string(), data["master_lottery_item_number"].to_string());
|
||||
items::give_gift_basic(info["type"].as_i32().unwrap(), info["value"].as_i64().unwrap(), info["amount"].as_i64().unwrap(), &mut user);
|
||||
items::give_gift_basic(info["type"].as_i32().unwrap(), info["value"].as_i64().unwrap(), info["amount"].as_i64().unwrap(), &mut user, &mut missions, &mut cleared_missions);
|
||||
let to_push = object!{
|
||||
"master_lottery_item_id": data["master_lottery_item_id"].clone(),
|
||||
"master_lottery_item_number": data["master_lottery_item_number"].clone(),
|
||||
|
@ -227,8 +229,8 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
}
|
||||
|
||||
userdata::save_acc(&key, user.clone());
|
||||
userdata::save_acc_missions(&key, missions);
|
||||
|
||||
//todo
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
|
@ -239,7 +241,7 @@ pub fn lottery_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
"item_list": user["item_list"].clone()
|
||||
},
|
||||
"gift_list": user2["home"]["gift_list"].clone(),
|
||||
"clear_mission_ids": [],
|
||||
"clear_mission_ids": cleared_missions,
|
||||
"draw_count_list": []
|
||||
}
|
||||
};
|
||||
|
|
|
@ -79,10 +79,10 @@ pub fn receive(req: HttpRequest, body: String) -> HttpResponse {
|
|||
let mut gift = MISSION_REWARD[mission_info["masterMissionRewardId"].to_string()].clone();
|
||||
gift["reward_type"] = gift["type"].clone();
|
||||
gift["amount"] = gift["amount"].as_i64().unwrap().into();
|
||||
items::give_gift(&gift, &mut user);
|
||||
items::give_gift(&gift, &mut user, &mut missions, &mut array![]);
|
||||
rewards.push(gift).unwrap();
|
||||
|
||||
let variable_missions = array![[1153001, 1153019], [1105001, 1105017], [1101001, 1101030]];
|
||||
let variable_missions = array![[1153001, 1153019], [1105001, 1105017], [1101001, 1101030], [1121001, 1121019]];
|
||||
let mut variable = false;
|
||||
for (_i, id) in variable_missions.members().enumerate() {
|
||||
if mission.as_i64().unwrap() >= id[0].as_i64().unwrap() && mission.as_i64().unwrap() < id[1].as_i64().unwrap() {
|
||||
|
@ -116,7 +116,6 @@ pub fn receive(req: HttpRequest, body: String) -> HttpResponse {
|
|||
"point_list": user["point_list"].clone()
|
||||
},
|
||||
"mission_list": missions
|
||||
|
||||
}
|
||||
};
|
||||
global::send(resp, req)
|
||||
|
|
|
@ -78,7 +78,9 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
|
|||
|
||||
let mut user = userdata::get_acc_home(&key);
|
||||
let mut userr = userdata::get_acc(&key);
|
||||
let mut missions = userdata::get_acc_missions(&key);
|
||||
|
||||
let mut cleared_missions = array![];
|
||||
let mut rewards = array![];
|
||||
let mut failed = array![];
|
||||
|
||||
|
@ -88,7 +90,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
|
|||
if data["id"].to_string() != gift_id.to_string() {
|
||||
continue;
|
||||
}
|
||||
if !items::give_gift(&data, &mut userr) {
|
||||
if !items::give_gift(&data, &mut userr, &mut missions, &mut cleared_missions) {
|
||||
failed.push(gift_id.clone()).unwrap();
|
||||
break;
|
||||
}
|
||||
|
@ -108,6 +110,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
|
|||
}
|
||||
}
|
||||
|
||||
userdata::save_acc_missions(&key, missions);
|
||||
userdata::save_acc_home(&key, user);
|
||||
userdata::save_acc(&key, userr.clone());
|
||||
let userr = userdata::get_acc(&key);
|
||||
|
@ -122,7 +125,7 @@ pub fn gift(req: HttpRequest, body: String) -> HttpResponse {
|
|||
"item_list": userr["item_list"].clone(),
|
||||
"point_list": userr["point_list"].clone()
|
||||
},
|
||||
"clear_mission_ids": [],
|
||||
"clear_mission_ids": cleared_missions,
|
||||
"reward_list": rewards
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue