Create global::give_points tool

This commit is contained in:
Ethan O'Brien
2024-04-25 14:59:38 -05:00
parent 8056f0e5d5
commit 4b73cbdb85
2 changed files with 21 additions and 17 deletions

View File

@@ -135,6 +135,26 @@ pub fn give_item(master_item_id: i64, amount: i64, user: &mut JsonValue) {
}
}
pub fn give_points(master_item_id: i64, amount: i64, user: &mut JsonValue) {
let mut has = false;
for (_j, dataa) in user["point_list"].members_mut().enumerate() {
if dataa["type"].as_i64().unwrap() == master_item_id {
has = true;
dataa["amount"] = (dataa["amount"].as_i64().unwrap() + amount).into();
if dataa["amount"].as_i64().unwrap() > 2000000000 {
dataa["amount"] = (2000000000).into();
}
}
break;
}
if !has {
user["point_list"].push(object!{
type: master_item_id,
amount: amount
}).unwrap();
}
}
// true - added
// false - already has
pub fn give_character(id: String, user: &mut JsonValue) -> bool {