mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 11:01:29 -07:00
[Server][Game][Arrows] Properly notify clients when deleting arrows on card move and transform into (#6936)
* [Server][Game][Arrows] Properly notify clients when deleting arrows on card move and transform into Took 15 minutes * Observe "not found" response Took 18 minutes Took 4 seconds --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
@@ -217,7 +217,20 @@ void GameEventHandler::handleArrowDeletion(int arrowId)
|
||||
{
|
||||
Command_DeleteArrow cmd;
|
||||
cmd.set_arrow_id(arrowId);
|
||||
sendGameCommand(cmd);
|
||||
|
||||
auto preparedCommand = prepareGameCommand(cmd);
|
||||
|
||||
connect(preparedCommand, &PendingCommand::finished, this,
|
||||
[arrowId, this](const Response &response) { handleArrowDeletionFinished(response, arrowId); });
|
||||
|
||||
sendGameCommand(preparedCommand);
|
||||
}
|
||||
|
||||
void GameEventHandler::handleArrowDeletionFinished(const Response &response, int arrowId)
|
||||
{
|
||||
if (response.response_code() == Response::RespNameNotFound) {
|
||||
emit arrowDeleted(arrowId);
|
||||
}
|
||||
}
|
||||
|
||||
void GameEventHandler::eventSpectatorSay(const Event_GameSay &event,
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
void handleGameLeft();
|
||||
void handleChatMessageSent(const QString &chatMessage);
|
||||
void handleArrowDeletion(int arrowId);
|
||||
void handleArrowDeletionFinished(const Response &response, int arrowId);
|
||||
|
||||
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
|
||||
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
|
||||
@@ -112,6 +113,7 @@ signals:
|
||||
void containerProcessingStarted(GameEventContext context);
|
||||
void setContextJudgeName(QString judgeName);
|
||||
void containerProcessingDone();
|
||||
void arrowDeleted(int arrowId);
|
||||
void logSpectatorSay(ServerInfo_User userInfo, QString message);
|
||||
void logSpectatorLeave(QString name, QString reason);
|
||||
void logGameStart();
|
||||
|
||||
@@ -1147,6 +1147,7 @@ void TabGame::createPlayAreaWidget(bool bReplay)
|
||||
connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange);
|
||||
connect(scene, &GameScene::requestArrowDeletion, game->getGameEventHandler(),
|
||||
&GameEventHandler::handleArrowDeletion);
|
||||
connect(game->getGameEventHandler(), &GameEventHandler::arrowDeleted, scene, &GameScene::onArrowDeleted);
|
||||
gameView = new GameView(scene);
|
||||
|
||||
auto gamePlayAreaVBox = new QVBoxLayout;
|
||||
|
||||
+16
-7
@@ -397,6 +397,9 @@ void Server_AbstractPlayer::processMoveCard(GameEventStorage &ges,
|
||||
}
|
||||
}
|
||||
for (int j : arrowsToDelete) {
|
||||
Event_DeleteArrow event;
|
||||
event.set_arrow_id(j);
|
||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||
player->deleteArrow(j);
|
||||
}
|
||||
}
|
||||
@@ -1132,12 +1135,18 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
||||
targetItem = card;
|
||||
}
|
||||
if (sendGameEvent) {
|
||||
Event_CreateArrow _event;
|
||||
ServerInfo_Arrow *arrowInfo = _event.mutable_arrow_info();
|
||||
changedArrowIds.append(arrow->getId());
|
||||
int id = player->newArrowId();
|
||||
arrow->setId(id);
|
||||
arrowInfo->set_id(id);
|
||||
const int oldId = arrow->getId();
|
||||
changedArrowIds.append(oldId);
|
||||
|
||||
Event_DeleteArrow deleteEvent;
|
||||
deleteEvent.set_arrow_id(oldId);
|
||||
ges.enqueueGameEvent(deleteEvent, player->getPlayerId());
|
||||
|
||||
Event_CreateArrow createEvent;
|
||||
ServerInfo_Arrow *arrowInfo = createEvent.mutable_arrow_info();
|
||||
const int newId = player->newArrowId();
|
||||
arrow->setId(newId);
|
||||
arrowInfo->set_id(newId);
|
||||
arrowInfo->set_start_player_id(player->getPlayerId());
|
||||
arrowInfo->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||
arrowInfo->set_start_card_id(startCard->getId());
|
||||
@@ -1151,7 +1160,7 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
||||
arrowInfo->set_target_card_id(arrowTargetCard->getId());
|
||||
}
|
||||
arrowInfo->mutable_arrow_color()->CopyFrom(arrow->getColor());
|
||||
ges.enqueueGameEvent(_event, player->getPlayerId());
|
||||
ges.enqueueGameEvent(createEvent, player->getPlayerId());
|
||||
}
|
||||
}
|
||||
for (int id : changedArrowIds) {
|
||||
|
||||
Reference in New Issue
Block a user