add $surrender command

This commit is contained in:
Martin Michelsen
2023-09-03 22:44:36 -07:00
parent c3edb93248
commit 9f943cf5d8
4 changed files with 50 additions and 6 deletions
+27
View File
@@ -1259,6 +1259,32 @@ static void server_command_enable_ep3_battle_debug_menu(
}
}
static void server_command_surrender(
shared_ptr<ServerState>, shared_ptr<Lobby> l, shared_ptr<Client> c, const std::u16string&) {
check_is_game(l, true);
check_is_ep3(c, true);
if (l->episode != Episode::EP3) {
throw logic_error("non-Ep3 client in Ep3 game");
}
auto base = l->ep3_server_base;
if (!base) {
send_text_message(c, u"$C6Episode 3 server\nis not initialized");
return;
}
auto server = base->server;
if (!server) {
send_text_message(c, u"$C6Episode 3 server\nis not initialized");
return;
}
if (server->setup_phase != Episode3::SetupPhase::MAIN_BATTLE) {
send_text_message(c, u"$C6Battle has not\nyet started");
return;
}
string name = encode_sjis(c->game_data.player()->disp.name);
send_text_message_printf(l, "$C6%s has\nsurrendered", name.c_str());
server->force_battle_result(c->lobby_client_id, false);
}
////////////////////////////////////////////////////////////////////////////////
typedef void (*server_handler_t)(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
@@ -1307,6 +1333,7 @@ static const unordered_map<u16string, ChatCommandDefinition> chat_commands({
{u"$song", {server_command_song, proxy_command_song}},
{u"$spec", {server_command_spec, nullptr}},
{u"$ss", {nullptr, proxy_command_send_server}},
{u"$surrender", {server_command_surrender, nullptr}},
{u"$swa", {server_command_switch_assist, proxy_command_switch_assist}},
{u"$type", {server_command_lobby_type, nullptr}},
{u"$warp", {server_command_warpme, proxy_command_warpme}},
+18 -3
View File
@@ -524,6 +524,21 @@ bool Server::check_for_battle_end() {
return ret;
}
void Server::force_battle_result(uint8_t specified_client_id, bool set_winner) {
auto specified_ps = this->player_states[specified_client_id];
for (size_t z = 0; z < 4; z++) {
auto ps = this->player_states[z];
if (ps) {
ps->assist_flags &= 0xFFFFB7FB;
if ((ps->get_team_id() == specified_ps->get_team_id()) == set_winner) {
ps->assist_flags |= 4;
}
ps->update_hand_and_equip_state_and_send_6xB4x02_if_needed(true);
}
}
this->set_battle_ended();
}
void Server::check_for_destroyed_cards_and_send_6xB4x05_6xB4x02() {
for (size_t z = 0; z < 4; z++) {
if (this->player_states[z]) {
@@ -706,15 +721,15 @@ void Server::draw_phase_after() {
}
if (this->overall_time_expired || (this->round_num >= 1000)) {
bool unknown_v1 = true;
bool no_winner_specified = true;
for (size_t z = 0; z < 4; z++) {
auto ps = this->player_states[z];
if (ps && (ps->assist_flags & 4)) {
unknown_v1 = false;
no_winner_specified = false;
break;
}
}
if (unknown_v1) {
if (no_winner_specified) {
this->compute_losing_team_id_and_add_winner_flags(0);
}
this->round_num--;
+1
View File
@@ -145,6 +145,7 @@ public:
uint16_t card_id_for_card_ref(uint16_t card_ref) const;
bool card_ref_is_empty_or_has_valid_card_id(uint16_t card_ref) const;
bool check_for_battle_end();
void force_battle_result(uint8_t surrendered_client_id, bool set_winner);
void check_for_destroyed_cards_and_send_6xB4x05_6xB4x02();
bool check_presence_entry(uint8_t client_id) const;
void clear_player_flags_after_dice_phase();