mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-22 06:43:54 -07:00
[Game] [Arrows] Use arrowData/registry and generate unique server-side ids (#6973)
* [Game] [Arrows] Track creatorId, use arrowData in arrowItem, use registry, generate unique arrow id's on server side and delete-on-exist inserts. Took 2 minutes Took 1 minute * Fix emitting slot instead of signal. Took 15 minutes * Clear arrows locally in special circumstances i.e. teardown. Took 28 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
c14a008080
commit
23da49ee5b
19 changed files with 225 additions and 148 deletions
|
|
@ -81,17 +81,6 @@ int Server_AbstractPlayer::newCardId()
|
|||
return nextCardId++;
|
||||
}
|
||||
|
||||
int Server_AbstractPlayer::newArrowId() const
|
||||
{
|
||||
int id = 0;
|
||||
for (Server_Arrow *a : arrows) {
|
||||
if (a->getId() > id) {
|
||||
id = a->getId();
|
||||
}
|
||||
}
|
||||
return id + 1;
|
||||
}
|
||||
|
||||
void Server_AbstractPlayer::setupZones()
|
||||
{
|
||||
nextCardId = 0;
|
||||
|
|
@ -1144,7 +1133,7 @@ Server_AbstractPlayer::cmdCreateToken(const Command_CreateToken &cmd, ResponseCo
|
|||
|
||||
Event_CreateArrow createEvent;
|
||||
ServerInfo_Arrow *arrowInfo = createEvent.mutable_arrow_info();
|
||||
const int newId = player->newArrowId();
|
||||
const int newId = game->generateArrowId();
|
||||
arrow->setId(newId);
|
||||
arrowInfo->set_id(newId);
|
||||
arrowInfo->set_start_player_id(player->getPlayerId());
|
||||
|
|
@ -1267,7 +1256,8 @@ Server_AbstractPlayer::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseCo
|
|||
|
||||
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);
|
||||
auto arrow = new Server_Arrow(game->generateArrowId(), startCard, targetItem, cmd.arrow_color(), currentPhase,
|
||||
deletionPhase);
|
||||
addArrow(arrow);
|
||||
|
||||
Event_CreateArrow event;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ public:
|
|||
}
|
||||
|
||||
int newCardId();
|
||||
int newArrowId() const;
|
||||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
|
|
|
|||
|
|
@ -697,6 +697,11 @@ void Server_Game::setActivePhase(int newPhase)
|
|||
sendGameEventContainer(prepareGameEvent(event, -1));
|
||||
}
|
||||
|
||||
qint64 Server_Game::generateArrowId()
|
||||
{
|
||||
return nextArrowId++;
|
||||
}
|
||||
|
||||
void Server_Game::removeArrows(int newPhase, bool force)
|
||||
{
|
||||
QMutexLocker locker(&gameMutex);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class Server_Game : public QObject
|
|||
private:
|
||||
Server_Room *room;
|
||||
int nextPlayerId;
|
||||
std::atomic<qint64> nextArrowId = 1;
|
||||
int hostId;
|
||||
ServerInfo_User *creatorInfo;
|
||||
QMap<int, Server_AbstractParticipant *> participants;
|
||||
|
|
@ -196,6 +197,7 @@ public:
|
|||
}
|
||||
void setActivePlayer(int newPlayer);
|
||||
void setActivePhase(int newPhase);
|
||||
qint64 generateArrowId();
|
||||
void removeArrows(int newPhase, bool force = false);
|
||||
void nextTurn();
|
||||
int getSecondsElapsed() const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue