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::home::LogicHomeMode; #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::UPDATE_LAST_SHOWN_LEVEL_UP)] pub struct LogicUpdateLastShownLevelUpCommand { pub header: LogicCommandHeader, } impl Execute for LogicUpdateLastShownLevelUpCommand { fn execute(&self, mode: &mut LogicHomeMode) -> CommandOutcome { let level = mode.avatar().exp_level; let shown = mode.home().last_shown_level_up; if level <= shown { return CommandOutcome::Rejected("that level up was already shown"); } mode.home_mut().last_shown_level_up = if shown > 1 { shown + 1 } else { 2 }; CommandOutcome::Applied } } #[derive(Debug, Default, Payload, Command)] #[command(id = command_type::START_MATCHMAKE)] pub struct LogicStartMatchmakeCommand { pub header: LogicCommandHeader, #[codec(vint)] pub matchmake_slot: i32, #[codec(bool)] pub notify: bool, } impl Execute for LogicStartMatchmakeCommand { fn execute(&self, mode: &mut LogicHomeMode) -> CommandOutcome { if mode .avatar() .arena .as_arena() .map(|arena| arena.is_training_camp()) .unwrap_or(true) { return CommandOutcome::Rejected("the training camp cannot matchmake"); } if mode.is_claiming_reward() { return CommandOutcome::Rejected("a reward claim is in progress"); } CommandOutcome::MatchmakeStarted } }