From 35e2a9d6f4e8a122f7b7a0fd5906a57d9ca7c7a1 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 13 Feb 2024 21:23:33 -0800 Subject: [PATCH] use quest extended rules if present --- README.md | 2 +- src/Episode3/Server.cc | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 078e4cb5..97745618 100644 --- a/README.md +++ b/README.md @@ -418,7 +418,7 @@ Some commands only work on the game server and not on the proxy server. The chat * Episode 3 commands (game server only) * `$spec`: Toggles the allow spectators flag for Episode 3 games. If any players are spectating when this flag is disabled, they will be sent back to the lobby. * `$inftime`: Toggles infinite-time mode. Must be used before starting a battle. If infinite-time mode is enabled, the overall and per-phase time limits will be disabled regardless of the values chosen during battle setup. After completing a battle, infinite-time mode is reset to the server's default value (which can be set in Episode3BehaviorFlags in config.json). - * `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Sets override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. + * `$dicerange [d:L-H] [1:L-H] [a1:L-H] [d1:L-H]`: Sets override dice ranges for the next battle. The min and max dice values from the rules setup menu always apply to the ATK dice, but you can specify a different range for the DEF dice with `d:2-4` (for example). The `1:` override applies to the 1-player team in a 2v1 game (so you would set the 2-player team's desired dice range in the rules menu). You can also specify the 1-player team's ATK and DEF ranges separately with the `a1:` and `d1:` overrides. Note that these ranges will only be used if the chosen map or quest does not override them. * `$stat `: Shows a statistic about your player or team in the current battle. `` can be `duration`, `fcs-destroyed`, `cards-destroyed`, `damage-given`, `damage-taken`, `opp-cards-destroyed`, `own-cards-destroyed`, `move-distance`, `cards-set`, `fcs-set`, `attack-actions-set`, `techs-set`, `assists-set`, `defenses-self`, `defenses-ally`, `cards-drawn`, `max-attack-damage`, `max-combo`, `attacks-given`, `attacks-taken`, `sc-damage`, `damage-defended`, or `rank`. * `$surrender`: Causes your team to immediately lose the current battle. * `$saverec `: Saves the recording of the last battle. diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 75e2de5a..84d2b52c 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -2603,12 +2603,30 @@ void Server::send_6xB6x41_to_all_clients() const { } } -void Server::handle_CAx41_map_request(shared_ptr, const string& data) { +void Server::handle_CAx41_map_request(shared_ptr c, const string& data) { const auto& cmd = check_size_t(data); - this->send_debug_command_received_message( - cmd.header.subsubcommand, "MAP DATA"); + this->send_debug_command_received_message(cmd.header.subsubcommand, "MAP DATA"); this->last_chosen_map = this->options.map_index->for_number(cmd.map_number); + + // We don't trust the extended rules fields from the client, and the client + // can't modify it anyway, so we always apply the map's extended rules here. + // This allows map creators to use newserv's extended rules in quests. + if (this->setup_phase == SetupPhase::REGISTRATION) { + auto mv = this->last_chosen_map->version(c->language()); + const auto& map_rules = mv->map->default_rules; + auto& server_rules = this->map_and_rules->rules; + if (map_rules.def_dice_value_range != 0xFF) { + server_rules.def_dice_value_range = map_rules.def_dice_value_range; + } + if (map_rules.atk_dice_value_range_2v1 != 0xFF) { + server_rules.atk_dice_value_range_2v1 = map_rules.atk_dice_value_range_2v1; + } + if (map_rules.def_dice_value_range_2v1 != 0xFF) { + server_rules.def_dice_value_range_2v1 = map_rules.def_dice_value_range_2v1; + } + } + this->send_6xB6x41_to_all_clients(); }