mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 21:04:07 -07:00
servatrice changes
This commit is contained in:
parent
8a7ba430ea
commit
9dabc3a02f
5 changed files with 47 additions and 21 deletions
|
|
@ -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);
|
addArrow(arrow);
|
||||||
|
|
||||||
Event_CreateArrow event;
|
Event_CreateArrow event;
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,14 @@
|
||||||
|
|
||||||
#include <libcockatrice/protocol/pb/serverinfo_arrow.pb.h>
|
#include <libcockatrice/protocol/pb/serverinfo_arrow.pb.h>
|
||||||
|
|
||||||
Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor)
|
Server_Arrow::Server_Arrow(int _id,
|
||||||
: id(_id), startCard(_startCard), targetItem(_targetItem), arrowColor(_arrowColor)
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,15 @@ private:
|
||||||
Server_Card *startCard;
|
Server_Card *startCard;
|
||||||
Server_ArrowTarget *targetItem;
|
Server_ArrowTarget *targetItem;
|
||||||
color arrowColor;
|
color arrowColor;
|
||||||
|
int phaseCreated, phaseDeleted;
|
||||||
|
|
||||||
public:
|
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
|
int getId() const
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
|
|
@ -45,6 +51,10 @@ public:
|
||||||
{
|
{
|
||||||
return arrowColor;
|
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);
|
void getInfo(ServerInfo_Arrow *info);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -654,6 +654,8 @@ void Server_Game::setActivePlayer(int _activePlayer)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
||||||
|
removeArrows(0, true);
|
||||||
|
|
||||||
activePlayer = _activePlayer;
|
activePlayer = _activePlayer;
|
||||||
|
|
||||||
Event_SetActivePlayer event;
|
Event_SetActivePlayer event;
|
||||||
|
|
@ -663,30 +665,35 @@ void Server_Game::setActivePlayer(int _activePlayer)
|
||||||
setActivePhase(0);
|
setActivePhase(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::setActivePhase(int _activePhase)
|
void Server_Game::setActivePhase(int newPhase)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
||||||
for (auto *player : getPlayers().values()) {
|
removeArrows(newPhase);
|
||||||
QList<Server_Arrow *> toDelete = player->getArrows().values();
|
activePhase = newPhase;
|
||||||
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;
|
|
||||||
|
|
||||||
Event_SetActivePhase event;
|
Event_SetActivePhase event;
|
||||||
event.set_phase(activePhase);
|
event.set_phase(activePhase);
|
||||||
sendGameEventContainer(prepareGameEvent(event, -1));
|
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()
|
void Server_Game::nextTurn()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
|
||||||
|
|
@ -198,8 +198,9 @@ public:
|
||||||
{
|
{
|
||||||
return activePhase;
|
return activePhase;
|
||||||
}
|
}
|
||||||
void setActivePlayer(int _activePlayer);
|
void setActivePlayer(int newPlayer);
|
||||||
void setActivePhase(int _activePhase);
|
void setActivePhase(int newPhase);
|
||||||
|
void removeArrows(int newPhase, bool force = false);
|
||||||
void nextTurn();
|
void nextTurn();
|
||||||
int getSecondsElapsed() const
|
int getSecondsElapsed() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue