From 6de55e90968f2c51f411a8682d0647c547a1706b Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Thu, 28 May 2026 23:51:12 -0700 Subject: [PATCH] [Game][Arrow] Correctly call clear all arrows for player (#6951) --- cockatrice/src/game/game_scene.cpp | 21 ++++++++++++++++++--- cockatrice/src/game/game_scene.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/game/game_scene.cpp b/cockatrice/src/game/game_scene.cpp index d9ffe3443..1b4f0d461 100644 --- a/cockatrice/src/game/game_scene.cpp +++ b/cockatrice/src/game/game_scene.cpp @@ -88,7 +88,7 @@ void GameScene::addPlayer(PlayerLogic *player) connect(player, &PlayerLogic::concededChanged, this, [this](int id, bool conceded) { if (conceded) { - requestClearArrowsForPlayer(id); + clearArrowsForPlayer(id); } rearrange(); }); @@ -97,7 +97,7 @@ void GameScene::addPlayer(PlayerLogic *player) connect(player, &PlayerLogic::arrowCreateRequested, this, &GameScene::addArrow); connect(player, &PlayerLogic::arrowDeleteRequested, this, &GameScene::requestArrowDeletion); connect(player, &PlayerLogic::arrowsCleared, this, - [this, id = player->getPlayerInfo()->getId()]() { requestClearArrowsForPlayer(id); }); + [this, id = player->getPlayerInfo()->getId()]() { clearArrowsForPlayer(id); }); connect(player->getPlayerEventHandler(), &PlayerEventHandler::cardZoneChanged, this, &GameScene::onCardZoneChanged); @@ -114,7 +114,7 @@ void GameScene::removePlayer(PlayerLogic *player) { qCInfo(GameScenePlayerAdditionRemovalLog) << "GameScene::removePlayer name=" << player->getPlayerInfo()->getName(); - requestClearArrowsForPlayer(player->getPlayerInfo()->getId()); + clearArrowsForPlayer(player->getPlayerInfo()->getId()); for (ZoneViewWidget *zone : zoneViews) { if (zone->getPlayer() == player) { @@ -412,6 +412,21 @@ void GameScene::deleteArrow(int arrowId) } } +void GameScene::clearArrowsForPlayer(int playerId) +{ + QList toDelete; + for (auto i = arrowRegistry.cbegin(); i != arrowRegistry.cend(); ++i) { + auto *arrow = i.value(); + if (arrow->getPlayer()->getPlayerInfo()->getId() == playerId) { + toDelete.append(i.key()); + } + } + + for (int arrowId : toDelete) { + arrowRegistry.take(arrowId)->delArrow(); + } +} + void GameScene::requestArrowDeletion(int arrowId) { if (arrowRegistry.contains(arrowId)) { diff --git a/cockatrice/src/game/game_scene.h b/cockatrice/src/game/game_scene.h index 70dbfb3d9..1551c8365 100644 --- a/cockatrice/src/game/game_scene.h +++ b/cockatrice/src/game/game_scene.h @@ -204,6 +204,7 @@ public slots: /// Directly modifies the scene void addArrow(const ArrowData &data); void deleteArrow(int arrowId); + void clearArrowsForPlayer(int playerId); /// Queues up arrow deletion but doesn't directly modify the scene void requestArrowDeletion(int arrowId);