mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-07-12 00:32:20 +08:00
Remove duplicated logic
This commit is contained in:
@@ -71,48 +71,54 @@ const LIMIT_ITEMS: i64 = 200000000;
|
|||||||
const LIMIT_COINS: i64 = 2000000000;
|
const LIMIT_COINS: i64 = 2000000000;
|
||||||
const LIMIT_PRIMOGEMS: i64 = 1000000;
|
const LIMIT_PRIMOGEMS: i64 = 1000000;
|
||||||
|
|
||||||
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
fn give(array: &mut JsonValue, shop_id: &str, master_item_id: i64, limit: i64, count_id: &str, count: i64, default_push: JsonValue) -> bool {
|
||||||
for dataa in user["shop_list"].members_mut() {
|
for data in array.members_mut() {
|
||||||
if dataa["master_shop_item_id"].as_i64().unwrap() == master_item_id {
|
if data[shop_id].as_i64().unwrap() == master_item_id {
|
||||||
if dataa["count"].as_i64().unwrap() >= LIMIT_ITEMS {
|
if data[count_id].as_i64().unwrap() >= limit {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let mut new_amount = dataa["count"].as_i64().unwrap() + count;
|
let mut new_amount = data[count_id].as_i64().unwrap() + count;
|
||||||
if new_amount > LIMIT_ITEMS {
|
if new_amount > limit {
|
||||||
new_amount = LIMIT_ITEMS;
|
new_amount = limit;
|
||||||
}
|
}
|
||||||
dataa["count"] = new_amount.into();
|
data[count_id] = new_amount.into();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user["shop_list"].push(object!{
|
array.push(default_push).unwrap();
|
||||||
master_shop_item_id: master_item_id,
|
|
||||||
count: count
|
|
||||||
}).unwrap();
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
pub fn give_shop(master_item_id: i64, count: i64, user: &mut JsonValue) -> bool {
|
||||||
for dataa in user["item_list"].members_mut() {
|
give(
|
||||||
if dataa["master_item_id"].as_i64().unwrap() == master_item_id {
|
&mut user["shop_list"],
|
||||||
if dataa["amount"].as_i64().unwrap() >= LIMIT_ITEMS {
|
"master_shop_item_id",
|
||||||
return true;
|
master_item_id,
|
||||||
}
|
LIMIT_ITEMS,
|
||||||
let mut new_amount = dataa["amount"].as_i64().unwrap() + amount;
|
"count",
|
||||||
if new_amount > LIMIT_ITEMS {
|
count,
|
||||||
new_amount = LIMIT_ITEMS;
|
object!{
|
||||||
}
|
master_shop_item_id: master_item_id,
|
||||||
dataa["amount"] = new_amount.into();
|
count: count
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
user["item_list"].push(object!{
|
}
|
||||||
id: master_item_id,
|
|
||||||
master_item_id: master_item_id,
|
pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) -> bool {
|
||||||
amount: amount,
|
give(
|
||||||
expire_date_time: null
|
&mut user["item_list"],
|
||||||
}).unwrap();
|
"master_item_id",
|
||||||
false
|
master_item_id,
|
||||||
|
LIMIT_ITEMS,
|
||||||
|
"amount",
|
||||||
|
amount,
|
||||||
|
object!{
|
||||||
|
id: master_item_id,
|
||||||
|
master_item_id: master_item_id,
|
||||||
|
amount: amount,
|
||||||
|
expire_date_time: null
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_item(item: &JsonValue, multiplier: i64, user: &mut JsonValue) {
|
pub fn use_item(item: &JsonValue, multiplier: i64, user: &mut JsonValue) {
|
||||||
@@ -173,24 +179,18 @@ pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue, missi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for data in user["point_list"].members_mut() {
|
give(
|
||||||
if data["type"].as_i64().unwrap() == master_item_id {
|
&mut user["point_list"],
|
||||||
if data["amount"].as_i64().unwrap() >= LIMIT_COINS {
|
"type",
|
||||||
return true;
|
master_item_id,
|
||||||
}
|
LIMIT_COINS,
|
||||||
let mut new_amount = data["amount"].as_i64().unwrap() + amount;
|
"amount",
|
||||||
if new_amount > LIMIT_COINS {
|
amount,
|
||||||
new_amount = LIMIT_COINS;
|
object!{
|
||||||
}
|
type: master_item_id,
|
||||||
data["amount"] = new_amount.into();
|
amount: amount
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
user["point_list"].push(object!{
|
|
||||||
type: master_item_id,
|
|
||||||
amount: amount
|
|
||||||
}).unwrap();
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
pub fn use_itemm(master_item_id: i64, amount: i64, user: &mut JsonValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user