mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2025-10-09 00:47:19 +08:00
Organize databases
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
use json::{array, object, JsonValue};
|
||||
use json::{array, object};
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::router::{global, userdata};
|
||||
use crate::router::{global, userdata, items, databases};
|
||||
use crate::encryption;
|
||||
use crate::router::items;
|
||||
|
||||
pub fn mission(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), "");
|
||||
@@ -22,17 +20,12 @@ pub fn mission(req: HttpRequest) -> HttpResponse {
|
||||
|
||||
pub fn clear(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), &body);
|
||||
|
||||
let mut missions = userdata::get_acc_missions(&key);
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
|
||||
for (_i, id) in body["master_mission_ids"].members().enumerate() {
|
||||
for (i, mission) in missions.members().enumerate() {
|
||||
if mission["master_mission_id"].to_string() == id.to_string() {
|
||||
//I think this is all?
|
||||
missions[i]["progress"] = (1).into();
|
||||
break;
|
||||
}
|
||||
}
|
||||
items::update_mission_status(id.as_i64().unwrap(), 0, true, true, 1, &mut missions);
|
||||
}
|
||||
|
||||
userdata::save_acc_missions(&key, missions);
|
||||
@@ -47,25 +40,6 @@ pub fn clear(req: HttpRequest, body: String) -> HttpResponse {
|
||||
global::send(resp, req)
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref MISSION_LIST: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = json::parse(include_str!("json/mission.json")).unwrap();
|
||||
for (_i, data) in items.members().enumerate() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
static ref MISSION_REWARD: JsonValue = {
|
||||
let mut info = object!{};
|
||||
let items = json::parse(include_str!("json/mission_reward.json")).unwrap();
|
||||
for (_i, data) in items.members().enumerate() {
|
||||
info[data["id"].to_string()] = data.clone();
|
||||
}
|
||||
info
|
||||
};
|
||||
}
|
||||
|
||||
pub fn receive(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), &body);
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
@@ -75,8 +49,8 @@ pub fn receive(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let mut rewards = array![];
|
||||
|
||||
for (_i, mission) in body["master_mission_ids"].members().enumerate() {
|
||||
let mission_info = MISSION_LIST[mission.to_string()].clone();
|
||||
let mut gift = MISSION_REWARD[mission_info["masterMissionRewardId"].to_string()].clone();
|
||||
let mission_info = databases::MISSION_LIST[mission.to_string()].clone();
|
||||
let mut gift = databases::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, &mut missions, &mut array![]);
|
||||
|
Reference in New Issue
Block a user