Gacha thing

This commit is contained in:
Ethan O'Brien 2024-02-26 12:36:52 -06:00
parent 6f468029e6
commit d9a42f162c

View file

@ -1,5 +1,5 @@
use json;
use json::{array, object};
use json::{array, object, JsonValue};
use crate::router::global;
use crate::encryption;
use actix_web::{HttpResponse, HttpRequest, http::header::HeaderValue};
@ -20,7 +20,6 @@ pub fn tutorial(_req: HttpRequest, body: String) -> HttpResponse {
}
lotteryid += user;
let resp = object!{
"code": 0,
"server_time": global::timestamp(),
@ -40,6 +39,21 @@ pub fn tutorial(_req: HttpRequest, body: String) -> HttpResponse {
global::send(resp)
}
//todo - how to randomize?
fn get_random_cards(_count: i32) -> JsonValue {
return array![
{"id": 1, "master_card_id": 10010011, "master_lottery_item_id":100001, "master_lottery_item_number":138},
{"id": 2, "master_card_id": 10030008, "master_lottery_item_id":200001,"master_lottery_item_number":30},
{"id": 3, "master_card_id": 20010010, "master_lottery_item_id":100001,"master_lottery_item_number":178},
{"id": 4, "master_card_id": 20050004, "master_lottery_item_id":100001,"master_lottery_item_number":26},
{"id": 5, "master_card_id": 20090001, "master_lottery_item_id":100001,"master_lottery_item_number":113},
{"id": 6, "master_card_id": 30040001, "master_lottery_item_id":200001,"master_lottery_item_number":2},
{"id": 7, "master_card_id": 30090007, "master_lottery_item_id":200001,"master_lottery_item_number":83},
{"id": 8, "master_card_id": 30100005, "master_lottery_item_id":100001,"master_lottery_item_number":188},
{"id": 9, "master_card_id": 30120001, "master_lottery_item_id":100001,"master_lottery_item_number":154}
]
}
pub fn lottery(req: HttpRequest, body: String) -> HttpResponse {
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
println!("lottery: {}", body);
@ -49,19 +63,22 @@ pub fn lottery(req: HttpRequest, body: String) -> HttpResponse {
let mut user = userdata::get_acc(key, uid);
let user2 = userdata::get_acc(key, uid);
//todo - how to randomize?
let cardstogive = array![
{"id": 1, "master_card_id": 10010011, "master_lottery_item_id":100001, "master_lottery_item_number":138},
{"id": 2, "master_card_id": 10030008, "master_lottery_item_id":200001,"master_lottery_item_number":30},
{"id": 3, "master_card_id": 20010010, "master_lottery_item_id":100001,"master_lottery_item_number":178},
{"id": 4, "master_card_id": 20050004, "master_lottery_item_id":100001,"master_lottery_item_number":26},
{"id": 5, "master_card_id": 20090001, "master_lottery_item_id":100001,"master_lottery_item_number":113},
{"id": 6, "master_card_id": 30040001, "master_lottery_item_id":200001,"master_lottery_item_number":2},
{"id": 7, "master_card_id": 30090007, "master_lottery_item_id":200001,"master_lottery_item_number":83},
{"id": 8, "master_card_id": 30100005, "master_lottery_item_id":100001,"master_lottery_item_number":188},
{"id": 9, "master_card_id": 30120001, "master_lottery_item_id":100001,"master_lottery_item_number":154},
let mut cardstogive = get_random_cards(9);
/*let cardstogive = array![
//30110007
{"id": 10, "master_card_id": 40030002, "master_lottery_item_id":911002701,"master_lottery_item_number":1}
];
];*/
if body["master_lottery_id"].to_string().starts_with("9") {
//tutorial
let new_card = object!{
"id": 10,
"master_card_id": 40030002,//todo - what should this be??
"master_lottery_item_id": (body["master_lottery_id"].to_string().parse::<i32>().unwrap() * 100) + 1,
"master_lottery_item_number": 1
};
cardstogive.push(new_card).unwrap();
}
let mut new_cards = array![];
for (i, data) in cardstogive.members().enumerate() {