1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add warning when awarding XP via promo code or shop purchase to address #76

This commit is contained in:
NG (Graham)
2026-01-24 18:15:42 -05:00
parent edb5b2eba8
commit 753e9b0f51
2 changed files with 56 additions and 2 deletions

View File

@@ -59,6 +59,7 @@ impl CubeConfig {
let battle_res = self.battle.validate_in(&mut validation_info, self, "battle"); let battle_res = self.battle.validate_in(&mut validation_info, self, "battle");
let chat_res = self.chat.validate_in(&mut validation_info, self, "chat"); let chat_res = self.chat.validate_in(&mut validation_info, self, "chat");
let factory_res = self.factory.validate_in(&mut validation_info, self, "factory"); let factory_res = self.factory.validate_in(&mut validation_info, self, "factory");
let shop_res = self.shop.validate_in(&mut validation_info, self, "shop");
let settings_res = self.settings.validate_in(&mut validation_info, self, "settings"); let settings_res = self.settings.validate_in(&mut validation_info, self, "settings");
validation_info.info(super::ValidationMessage { validation_info.info(super::ValidationMessage {
@@ -70,6 +71,7 @@ impl CubeConfig {
battle_res battle_res
&& chat_res && chat_res
&& factory_res && factory_res
&& shop_res
&& settings_res && settings_res
&& validation_info.is_ok() && validation_info.is_ok()
} }

View File

@@ -10,7 +10,8 @@ pub struct ItemShopConfig {
impl super::config::SelfValidator for ItemShopConfig { impl super::config::SelfValidator for ItemShopConfig {
type Context = crate::ConfigImpl; type Context = crate::ConfigImpl;
fn validate(&self, info: &mut super::config::ValidationInfo, _ctx: &Self::Context) -> bool { fn validate(&self, info: &mut super::config::ValidationInfo, ctx: &Self::Context) -> bool {
let mut is_ok = true;
let daily_count = self.items.iter().filter(|x| matches!(x.recurrence, Recurrence::Daily)).count(); let daily_count = self.items.iter().filter(|x| matches!(x.recurrence, Recurrence::Daily)).count();
if daily_count < 6 { if daily_count < 6 {
info.warn(crate::persist::config::ValidationMessage { info.warn(crate::persist::config::ValidationMessage {
@@ -35,8 +36,14 @@ impl super::config::SelfValidator for ItemShopConfig {
message: "More than 3 weekly items in shop so some will never be shown".to_owned(), message: "More than 3 weekly items in shop so some will never be shown".to_owned(),
}); });
} }
for (i, item) in self.items.iter().enumerate() {
is_ok &= item.validate_in(info, ctx, &format!("items[{}]", i));
}
for (code_name, item_code) in self.promo_codes.iter() {
is_ok &= item_code.validate_in(info, ctx, &format!("promo_codes[\"{}\"]", code_name));
}
// TODO // TODO
true is_ok
} }
} }
@@ -85,6 +92,16 @@ impl ItemBundle {
} }
} }
impl super::config::SelfValidator for ItemBundle {
type Context = crate::ConfigImpl;
fn validate(&self, info: &mut super::config::ValidationInfo, ctx: &Self::Context) -> bool {
for (i, give) in self.gives.iter().enumerate() {
give.validate_in(info, ctx, &format!("gives[{}]", i));
}
true
}
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug)] #[derive(Serialize, Deserialize, Clone, Copy, Debug)]
pub enum ShopCategory { pub enum ShopCategory {
Cube, Cube,
@@ -174,6 +191,19 @@ impl std::convert::From<ItemPurchase> for crate::persist::config::ShopGain {
} }
} }
impl super::config::SelfValidator for ItemPurchase {
type Context = crate::ConfigImpl;
fn validate(&self, info: &mut super::config::ValidationInfo, _ctx: &Self::Context) -> bool {
if matches!(self, Self::Experience { xp: _ }) {
info.warn(crate::persist::config::ValidationMessage {
path: vec!["xp".to_owned()],
message: "Experience rewards cause (client-side only) UI desync of the XP bar".to_owned(),
});
}
true
}
}
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ItemCode { pub struct ItemCode {
#[serde(default)] #[serde(default)]
@@ -187,6 +217,16 @@ pub struct ItemCode {
pub gives: Vec<ItemPurchase>, pub gives: Vec<ItemPurchase>,
} }
impl super::config::SelfValidator for ItemCode {
type Context = crate::ConfigImpl;
fn validate(&self, info: &mut super::config::ValidationInfo, ctx: &Self::Context) -> bool {
for (i, give) in self.gives.iter().enumerate() {
give.validate_in(info, ctx, &format!("gives[{}]", i));
}
true
}
}
pub fn default_items() -> Vec<ItemBundle> { pub fn default_items() -> Vec<ItemBundle> {
vec![ vec![
// weekly (top row of 3) // weekly (top row of 3)
@@ -352,5 +392,17 @@ pub fn default_codes() -> std::collections::HashMap<String, ItemCode> {
value: 1.5, value: 1.5,
gives: vec![] gives: vec![]
}); });
map.insert("LEVEL10".to_owned(), ItemCode {
message: Some("Please re-log".to_owned()),
bundle_id: None,
promo_id: None,
is_serial: false,
value: 1.5,
gives: vec![
ItemPurchase::Experience {
xp: 10_000,
}
]
});
map map
} }