use logic_derive::Command; use titan::Payload; use crate::commands::command::{CommandOutcome, Execute}; use crate::commands::command_type; use crate::commands::header::LogicCommandHeader; use crate::data::LogicDataRef; use crate::home::LogicHomeMode; pub const WEEKDAY_MIN: i32 = 1; pub const WEEKDAY_MAX: i32 = 7; #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::BUY_CHEST)] pub struct LogicBuyChestCommand { pub header: LogicCommandHeader, #[codec(int)] pub unused: i32, pub chest: LogicDataRef, } impl Execute for LogicBuyChestCommand { fn execute(&self, mode: &mut LogicHomeMode) -> CommandOutcome { if self.chest.as_treasure_chest().is_none() { return CommandOutcome::Rejected("that is not a treasure chest"); } if mode.is_claiming_reward() { return CommandOutcome::Rejected("a reward claim is already in progress"); } mode.begin_claim(); CommandOutcome::PurchaseRequested { data: self.chest.clone(), count: 1, } } } #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::BUY_RESOURCE_PACK)] pub struct LogicBuyResourcePackCommand { pub header: LogicCommandHeader, pub pack: LogicDataRef, } impl Execute for LogicBuyResourcePackCommand { fn execute(&self, _mode: &mut LogicHomeMode) -> CommandOutcome { let Some(pack) = self.pack.as_resource_pack() else { return CommandOutcome::Rejected("that is not a resource pack"); }; let amount = pack.amount(); if amount < 1 { return CommandOutcome::Rejected("the resource pack is empty"); } CommandOutcome::PurchaseRequested { data: pack.resource(), count: amount, } } } #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::BUY_CARD)] pub struct LogicBuyCardCommand { pub header: LogicCommandHeader, #[codec(int)] pub unused: i32, pub card: LogicDataRef, } impl Execute for LogicBuyCardCommand { fn execute(&self, _mode: &mut LogicHomeMode) -> CommandOutcome { if self.card.as_spell().is_none() { return CommandOutcome::Rejected("that is not a card"); } CommandOutcome::PurchaseRequested { data: self.card.clone(), count: 1, } } } #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::SHOP_SEED_CHANGED)] pub struct LogicShopSeedChangedCommand { #[codec(vint)] pub shop_seed: i32, #[codec(vint)] pub seconds_to_cycle: i32, #[codec(vint)] pub weekday_index: i32, #[codec(vint)] pub server_command_id: i32, pub header: LogicCommandHeader, } impl LogicShopSeedChangedCommand { pub fn new(shop_seed: i32, seconds_to_cycle: i32, weekday_index: i32) -> Self { Self { shop_seed, seconds_to_cycle, weekday_index: weekday_index.clamp(WEEKDAY_MIN, WEEKDAY_MAX), server_command_id: 0, header: LogicCommandHeader::default(), } } } impl Execute for LogicShopSeedChangedCommand { fn execute(&self, _mode: &mut LogicHomeMode) -> CommandOutcome { CommandOutcome::Ignored } }