add phase to delete arrows in to protocol (#6159)

* protocol changes

* servatrice changes

* add new setting

* implement client side with static 4 phases

* reading the code explains the code

* add subphases to phase.cpp

* use new subphase definition
This commit is contained in:
ebbit1q 2025-11-26 15:16:10 +01:00 committed by GitHub
parent adee67115c
commit a21e45ed36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 133 additions and 39 deletions

View file

@ -1210,7 +1210,9 @@ Server_AbstractPlayer::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseCo
}
}
auto arrow = new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color());
int currentPhase = game->getActivePhase();
int deletionPhase = cmd.has_delete_in_phase() ? cmd.delete_in_phase() : currentPhase;
auto arrow = new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase, deletionPhase);
addArrow(arrow);
Event_CreateArrow event;

View file

@ -6,8 +6,14 @@
#include <libcockatrice/protocol/pb/serverinfo_arrow.pb.h>
Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor)
: id(_id), startCard(_startCard), targetItem(_targetItem), arrowColor(_arrowColor)
Server_Arrow::Server_Arrow(int _id,
Server_Card *_startCard,
Server_ArrowTarget *_targetItem,
const color &_arrowColor,
int _phaseCreated,
int _phaseDeleted)
: id(_id), startCard(_startCard), targetItem(_targetItem), arrowColor(_arrowColor), phaseCreated(_phaseCreated),
phaseDeleted(_phaseDeleted)
{
}

View file

@ -14,9 +14,15 @@ private:
Server_Card *startCard;
Server_ArrowTarget *targetItem;
color arrowColor;
int phaseCreated, phaseDeleted;
public:
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
Server_Arrow(int _id,
Server_Card *_startCard,
Server_ArrowTarget *_targetItem,
const color &_arrowColor,
int _phaseCreated,
int _phaseDeleted);
int getId() const
{
return id;
@ -45,6 +51,10 @@ public:
{
return arrowColor;
}
bool checkPhaseDeletion(int phase) const // returns true if the arrow should be deleted in this phase
{
return phase < phaseCreated || phase >= phaseDeleted;
}
void getInfo(ServerInfo_Arrow *info);
};

View file

@ -654,6 +654,8 @@ void Server_Game::setActivePlayer(int _activePlayer)
{
QMutexLocker locker(&gameMutex);
removeArrows(0, true);
activePlayer = _activePlayer;
Event_SetActivePlayer event;
@ -663,30 +665,35 @@ void Server_Game::setActivePlayer(int _activePlayer)
setActivePhase(0);
}
void Server_Game::setActivePhase(int _activePhase)
void Server_Game::setActivePhase(int newPhase)
{
QMutexLocker locker(&gameMutex);
for (auto *player : getPlayers().values()) {
QList<Server_Arrow *> toDelete = player->getArrows().values();
for (int i = 0; i < toDelete.size(); ++i) {
Server_Arrow *a = toDelete[i];
Event_DeleteArrow event;
event.set_arrow_id(a->getId());
sendGameEventContainer(prepareGameEvent(event, player->getPlayerId()));
player->deleteArrow(a->getId());
}
}
activePhase = _activePhase;
removeArrows(newPhase);
activePhase = newPhase;
Event_SetActivePhase event;
event.set_phase(activePhase);
sendGameEventContainer(prepareGameEvent(event, -1));
}
void Server_Game::removeArrows(int newPhase, bool force)
{
QMutexLocker locker(&gameMutex);
for (auto *anyPlayer : getPlayers().values()) {
for (auto *arrowToDelete : anyPlayer->getArrows().values()) { // values creates a copy
if (force || arrowToDelete->checkPhaseDeletion(newPhase)) {
Event_DeleteArrow event;
event.set_arrow_id(arrowToDelete->getId());
sendGameEventContainer(prepareGameEvent(event, anyPlayer->getPlayerId()));
anyPlayer->deleteArrow(arrowToDelete->getId());
}
}
}
}
void Server_Game::nextTurn()
{
QMutexLocker locker(&gameMutex);

View file

@ -198,8 +198,9 @@ public:
{
return activePhase;
}
void setActivePlayer(int _activePlayer);
void setActivePhase(int _activePhase);
void setActivePlayer(int newPlayer);
void setActivePhase(int newPhase);
void removeArrows(int newPhase, bool force = false);
void nextTurn();
int getSecondsElapsed() const
{