Skip to content

Commit

Permalink
feat: add difficulty parameter to roguelike preset (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Dec 24, 2024
1 parent 3629373 commit cbd714c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions maa-cli/src/run/preset/roguelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ pub struct RoguelikeParams {
#[arg(long)]
start_count: Option<i32>,

/// Difficulty, not valid for Phantom theme (no numerical difficulty)
///
/// If the given difficulty is larger than the maximum difficulty of the theme, it will be
/// capped to the maximum difficulty. If not given, 0 will be used.
#[arg(long)]
difficulty: Option<i32>,

// Investment related parameters
/// Disable investment
#[arg(long)]
Expand Down Expand Up @@ -154,6 +161,14 @@ impl TryFrom<RoguelikeParams> for MAAValue {

value.maybe_insert("start_count", params.start_count);

if matches!(theme, Theme::Phantom) {
if params.difficulty.is_some() {
log::warn!("Difficulty is not valid for Phantom theme, ignored");
}
} else {
value.maybe_insert("difficulty", params.difficulty);
}

if params.disable_investment {
value.insert("investment_enabled", false);
} else {
Expand Down Expand Up @@ -313,6 +328,12 @@ mod tests {
assert!(parse(["maa", "roguelike", "Phantom", "--mode", "5"]).is_err());
assert!(parse(["maa", "roguelike", "Phantom", "--mode", "7"]).is_err());

// Difficulty is ignored for Phantom theme
assert_eq!(
parse(["maa", "roguelike", "Phantom", "--difficulty", "15"]).unwrap(),
default_params.join(object!("theme" => "Phantom")),
);

assert_eq!(
parse([
"maa",
Expand All @@ -325,6 +346,7 @@ mod tests {
"--core-char",
"维什戴尔",
"--start-count=100",
"--difficulty=15",
])
.unwrap(),
default_params.join(object!(
Expand All @@ -333,6 +355,7 @@ mod tests {
"roles" => "取长补短",
"core_char" => "维什戴尔",
"start_count" => 100,
"difficulty" => 15,
)),
);

Expand Down

0 comments on commit cbd714c

Please sign in to comment.