Add a new command to reverse turn order (#3802)

This commit is contained in:
ctrlaltca 2019-08-28 02:04:27 +02:00 committed by Zach H
parent 013137c418
commit f54165025e
13 changed files with 113 additions and 7 deletions

View file

@ -530,6 +530,13 @@ void MessageLogWidget::logRevealCards(Player *player,
} }
} }
void MessageLogWidget::logReverseTurn(Player *player, bool reversed)
{
appendHtmlServerMessage(tr("%1 reversed turn order, now it's %2.")
.arg(sanitizeHtml(player->getName()))
.arg(reversed ? tr("reversed") : tr("normal")));
}
void MessageLogWidget::logRollDie(Player *player, int sides, int roll) void MessageLogWidget::logRollDie(Player *player, int sides, int roll)
{ {
if (sides == 2) { if (sides == 2) {

View file

@ -77,6 +77,7 @@ public slots:
Player *otherPlayer, Player *otherPlayer,
bool faceDown, bool faceDown,
int amount); int amount);
void logReverseTurn(Player *player, bool reversed);
void logRollDie(Player *player, int sides, int roll); void logRollDie(Player *player, int sides, int roll);
void logSay(Player *player, QString message); void logSay(Player *player, QString message);
void logSetActivePhase(int phase); void logSetActivePhase(int phase);

View file

@ -47,6 +47,7 @@
#include "pb/command_leave_game.pb.h" #include "pb/command_leave_game.pb.h"
#include "pb/command_next_turn.pb.h" #include "pb/command_next_turn.pb.h"
#include "pb/command_ready_start.pb.h" #include "pb/command_ready_start.pb.h"
#include "pb/command_reverse_turn.pb.h"
#include "pb/command_set_active_phase.pb.h" #include "pb/command_set_active_phase.pb.h"
#include "pb/command_set_sideboard_lock.pb.h" #include "pb/command_set_sideboard_lock.pb.h"
#include "pb/command_set_sideboard_plan.pb.h" #include "pb/command_set_sideboard_plan.pb.h"
@ -62,6 +63,7 @@
#include "pb/event_kicked.pb.h" #include "pb/event_kicked.pb.h"
#include "pb/event_leave.pb.h" #include "pb/event_leave.pb.h"
#include "pb/event_player_properties_changed.pb.h" #include "pb/event_player_properties_changed.pb.h"
#include "pb/event_reverse_turn.pb.h"
#include "pb/event_set_active_phase.pb.h" #include "pb/event_set_active_phase.pb.h"
#include "pb/event_set_active_player.pb.h" #include "pb/event_set_active_player.pb.h"
#include "pb/game_event_container.pb.h" #include "pb/game_event_container.pb.h"
@ -215,6 +217,9 @@ void TabGame::refreshShortcuts()
if (aNextTurn) { if (aNextTurn) {
aNextTurn->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aNextTurn")); aNextTurn->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aNextTurn"));
} }
if (aReverseTurn) {
aReverseTurn->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aReverseTurn"));
}
if (aRemoveLocalArrows) { if (aRemoveLocalArrows) {
aRemoveLocalArrows->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aRemoveLocalArrows")); aRemoveLocalArrows->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aRemoveLocalArrows"));
} }
@ -496,6 +501,9 @@ void TabGame::retranslateUi()
if (aNextTurn) { if (aNextTurn) {
aNextTurn->setText(tr("Next &turn")); aNextTurn->setText(tr("Next &turn"));
} }
if (aReverseTurn) {
aReverseTurn->setText(tr("Reverse turn order"));
}
if (aRemoveLocalArrows) { if (aRemoveLocalArrows) {
aRemoveLocalArrows->setText(tr("&Remove all local arrows")); aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
} }
@ -716,6 +724,11 @@ void TabGame::actNextTurn()
sendGameCommand(Command_NextTurn()); sendGameCommand(Command_NextTurn());
} }
void TabGame::actReverseTurn()
{
sendGameCommand(Command_ReverseTurn());
}
void TabGame::actRemoveLocalArrows() void TabGame::actRemoveLocalArrows()
{ {
QMapIterator<int, Player *> playerIterator(players); QMapIterator<int, Player *> playerIterator(players);
@ -847,6 +860,9 @@ void TabGame::processGameEventContainer(const GameEventContainer &cont, Abstract
case GameEvent::SET_ACTIVE_PHASE: case GameEvent::SET_ACTIVE_PHASE:
eventSetActivePhase(event.GetExtension(Event_SetActivePhase::ext), playerId, context); eventSetActivePhase(event.GetExtension(Event_SetActivePhase::ext), playerId, context);
break; break;
case GameEvent::REVERSE_TURN:
eventReverseTurn(event.GetExtension(Event_ReverseTurn::ext), playerId, context);
break;
default: { default: {
Player *player = players.value(playerId, 0); Player *player = players.value(playerId, 0);
@ -1209,6 +1225,15 @@ void TabGame::eventKicked(const Event_Kicked & /*event*/, int /*eventPlayerId*/,
emitUserEvent(); emitUserEvent();
} }
void TabGame::eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext & /*context*/)
{
Player *player = players.value(eventPlayerId, 0);
if (!player)
return;
messageLog->logReverseTurn(player, event.reversed());
}
void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/,
int eventPlayerId, int eventPlayerId,
const GameEventContext & /*context*/) const GameEventContext & /*context*/)
@ -1367,6 +1392,8 @@ void TabGame::createMenuItems()
connect(aNextPhaseAction, SIGNAL(triggered()), this, SLOT(actNextPhaseAction())); connect(aNextPhaseAction, SIGNAL(triggered()), this, SLOT(actNextPhaseAction()));
aNextTurn = new QAction(this); aNextTurn = new QAction(this);
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
aReverseTurn = new QAction(this);
connect(aReverseTurn, SIGNAL(triggered()), this, SLOT(actReverseTurn()));
aRemoveLocalArrows = new QAction(this); aRemoveLocalArrows = new QAction(this);
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
aRotateViewCW = new QAction(this); aRotateViewCW = new QAction(this);
@ -1399,6 +1426,7 @@ void TabGame::createMenuItems()
playersSeparator = gameMenu->addSeparator(); playersSeparator = gameMenu->addSeparator();
gameMenu->addMenu(phasesMenu); gameMenu->addMenu(phasesMenu);
gameMenu->addAction(aNextTurn); gameMenu->addAction(aNextTurn);
gameMenu->addAction(aReverseTurn);
gameMenu->addSeparator(); gameMenu->addSeparator();
gameMenu->addAction(aRemoveLocalArrows); gameMenu->addAction(aRemoveLocalArrows);
gameMenu->addAction(aRotateViewCW); gameMenu->addAction(aRotateViewCW);
@ -1415,6 +1443,7 @@ void TabGame::createReplayMenuItems()
aNextPhase = nullptr; aNextPhase = nullptr;
aNextPhaseAction = nullptr; aNextPhaseAction = nullptr;
aNextTurn = nullptr; aNextTurn = nullptr;
aReverseTurn = nullptr;
aRemoveLocalArrows = nullptr; aRemoveLocalArrows = nullptr;
aRotateViewCW = nullptr; aRotateViewCW = nullptr;
aRotateViewCCW = nullptr; aRotateViewCCW = nullptr;

View file

@ -45,6 +45,7 @@ class Event_SetActivePhase;
class Event_Ping; class Event_Ping;
class Event_GameSay; class Event_GameSay;
class Event_Kicked; class Event_Kicked;
class Event_ReverseTurn;
class Player; class Player;
class CardZone; class CardZone;
class AbstractCardItem; class AbstractCardItem;
@ -165,7 +166,7 @@ private:
QMenu *gameMenu, *phasesMenu, *viewMenu, *cardInfoDockMenu, *messageLayoutDockMenu, *playerListDockMenu, QMenu *gameMenu, *phasesMenu, *viewMenu, *cardInfoDockMenu, *messageLayoutDockMenu, *playerListDockMenu,
*replayDockMenu; *replayDockMenu;
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextPhaseAction, *aNextTurn, QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextPhaseAction, *aNextTurn,
*aRemoveLocalArrows, *aRotateViewCW, *aRotateViewCCW, *aResetLayout, *aResetReplayLayout; *aReverseTurn, *aRemoveLocalArrows, *aRotateViewCW, *aRotateViewCCW, *aResetLayout, *aResetReplayLayout;
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aMessageLayoutDockVisible, *aMessageLayoutDockFloating, QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aMessageLayoutDockVisible, *aMessageLayoutDockFloating,
*aPlayerListDockVisible, *aPlayerListDockFloating, *aReplayDockVisible, *aReplayDockFloating; *aPlayerListDockVisible, *aPlayerListDockFloating, *aReplayDockVisible, *aReplayDockFloating;
QList<QAction *> phaseActions; QList<QAction *> phaseActions;
@ -193,6 +194,7 @@ private:
void setActivePhase(int phase); void setActivePhase(int phase);
void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context); void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context);
void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context); void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context);
void eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext & /*context*/);
void emitUserEvent(); void emitUserEvent();
void createMenuItems(); void createMenuItems();
void createReplayMenuItems(); void createReplayMenuItems();
@ -236,6 +238,7 @@ private slots:
void actNextPhase(); void actNextPhase();
void actNextPhaseAction(); void actNextPhaseAction();
void actNextTurn(); void actNextTurn();
void actReverseTurn();
void addMentionTag(QString value); void addMentionTag(QString value);
void linkCardToChat(QString cardName); void linkCardToChat(QString cardName);

View file

@ -38,6 +38,7 @@ SET(PROTO_FILES
command_replay_download.proto command_replay_download.proto
command_replay_modify_match.proto command_replay_modify_match.proto
command_reveal_cards.proto command_reveal_cards.proto
command_reverse_turn.proto
command_roll_die.proto command_roll_die.proto
command_set_active_phase.proto command_set_active_phase.proto
command_set_card_attr.proto command_set_card_attr.proto
@ -88,6 +89,7 @@ SET(PROTO_FILES
event_remove_from_list.proto event_remove_from_list.proto
event_replay_added.proto event_replay_added.proto
event_reveal_cards.proto event_reveal_cards.proto
event_reverse_turn.proto
event_roll_die.proto event_roll_die.proto
event_room_say.proto event_room_say.proto
event_server_complete_list.proto event_server_complete_list.proto

View file

@ -0,0 +1,8 @@
syntax = "proto2";
import "game_commands.proto";
message Command_ReverseTurn {
extend GameCommand {
optional Command_ReverseTurn ext = 1034;
}
}

View file

@ -0,0 +1,9 @@
syntax = "proto2";
import "game_event.proto";
message Event_ReverseTurn {
extend GameEvent {
optional Event_ReverseTurn ext = 2021;
}
optional bool reversed = 1;
}

View file

@ -35,6 +35,7 @@ message GameCommand {
CHANGE_ZONE_PROPERTIES = 1031; CHANGE_ZONE_PROPERTIES = 1031;
UNCONCEDE = 1032; UNCONCEDE = 1032;
JUDGE = 1033; JUDGE = 1033;
REVERSE_TURN = 1034;
} }
extensions 100 to max; extensions 100 to max;
} }

View file

@ -30,6 +30,7 @@ message GameEvent {
DUMP_ZONE = 2018; DUMP_ZONE = 2018;
STOP_DUMP_ZONE = 2019; STOP_DUMP_ZONE = 2019;
CHANGE_ZONE_PROPERTIES = 2020; CHANGE_ZONE_PROPERTIES = 2020;
REVERSE_TURN = 2021;
} }
optional sint32 player_id = 1 [default = -1]; optional sint32 player_id = 1 [default = -1];
extensions 100 to max; extensions 100 to max;

View file

@ -66,7 +66,8 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo,
onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed), onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed),
spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk),
spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), startTimeOfThisGame(0), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), startTimeOfThisGame(0),
secondsElapsed(0), firstGameStarted(false), startTime(QDateTime::currentDateTime()), gameMutex(QMutex::Recursive) secondsElapsed(0), firstGameStarted(false), turnOrderReversed(false), startTime(QDateTime::currentDateTime()),
gameMutex(QMutex::Recursive)
{ {
currentReplay = new GameReplay; currentReplay = new GameReplay;
currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId()); currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId());
@ -657,9 +658,17 @@ void Server_Game::nextTurn()
if (activePlayer != -1) if (activePlayer != -1)
listPos = keys.indexOf(activePlayer); listPos = keys.indexOf(activePlayer);
do { do {
if (turnOrderReversed) {
--listPos;
if (listPos < 0) {
listPos = keys.size() - 1;
}
} else {
++listPos; ++listPos;
if (listPos == keys.size()) if (listPos == keys.size()) {
listPos = 0; listPos = 0;
}
}
} while (players.value(keys[listPos])->getSpectator() || players.value(keys[listPos])->getConceded()); } while (players.value(keys[listPos])->getSpectator() || players.value(keys[listPos])->getConceded());
setActivePlayer(keys[listPos]); setActivePlayer(keys[listPos]);

View file

@ -68,6 +68,7 @@ private:
int inactivityCounter; int inactivityCounter;
int startTimeOfThisGame, secondsElapsed; int startTimeOfThisGame, secondsElapsed;
bool firstGameStarted; bool firstGameStarted;
bool turnOrderReversed;
QDateTime startTime; QDateTime startTime;
QTimer *pingClock; QTimer *pingClock;
QList<GameReplay *> replayList; QList<GameReplay *> replayList;
@ -185,6 +186,10 @@ public:
{ {
return secondsElapsed; return secondsElapsed;
} }
bool reverseTurnOrder()
{
return turnOrderReversed = !turnOrderReversed;
}
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming); void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);

View file

@ -35,6 +35,7 @@
#include "pb/command_next_turn.pb.h" #include "pb/command_next_turn.pb.h"
#include "pb/command_ready_start.pb.h" #include "pb/command_ready_start.pb.h"
#include "pb/command_reveal_cards.pb.h" #include "pb/command_reveal_cards.pb.h"
#include "pb/command_reverse_turn.pb.h"
#include "pb/command_roll_die.pb.h" #include "pb/command_roll_die.pb.h"
#include "pb/command_set_active_phase.pb.h" #include "pb/command_set_active_phase.pb.h"
#include "pb/command_set_card_attr.pb.h" #include "pb/command_set_card_attr.pb.h"
@ -60,6 +61,7 @@
#include "pb/event_move_card.pb.h" #include "pb/event_move_card.pb.h"
#include "pb/event_player_properties_changed.pb.h" #include "pb/event_player_properties_changed.pb.h"
#include "pb/event_reveal_cards.pb.h" #include "pb/event_reveal_cards.pb.h"
#include "pb/event_reverse_turn.pb.h"
#include "pb/event_roll_die.pb.h" #include "pb/event_roll_die.pb.h"
#include "pb/event_set_card_attr.pb.h" #include "pb/event_set_card_attr.pb.h"
#include "pb/event_set_card_counter.pb.h" #include "pb/event_set_card_counter.pb.h"
@ -1990,6 +1992,30 @@ Response::ResponseCode Server_Player::cmdChangeZoneProperties(const Command_Chan
} }
} }
Response::ResponseCode
Server_Player::cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges)
{
if (spectator) {
return Response::RespFunctionNotAllowed;
}
if (!game->getGameStarted()) {
return Response::RespGameNotStarted;
}
if (conceded) {
return Response::RespContextError;
}
bool reversedTurn = game->reverseTurnOrder();
Event_ReverseTurn event;
event.set_reversed(reversedTurn);
ges.enqueueGameEvent(event, playerId);
return Response::RespOk;
}
Response::ResponseCode Response::ResponseCode
Server_Player::processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges) Server_Player::processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges)
{ {
@ -2096,7 +2122,9 @@ Server_Player::processGameCommand(const GameCommand &command, ResponseContainer
case GameCommand::JUDGE: case GameCommand::JUDGE:
return cmdJudge(command.GetExtension(Command_Judge::ext), rc, ges); return cmdJudge(command.GetExtension(Command_Judge::ext), rc, ges);
break; break;
case GameCommand::REVERSE_TURN:
return cmdReverseTurn(command.GetExtension(Command_ReverseTurn::ext), rc, ges);
break;
default: default:
return Response::RespInvalidCommand; return Response::RespInvalidCommand;
} }

View file

@ -57,6 +57,7 @@ class Command_SetActivePhase;
class Command_DumpZone; class Command_DumpZone;
class Command_StopDumpZone; class Command_StopDumpZone;
class Command_RevealCards; class Command_RevealCards;
class Command_ReverseTurn;
class Command_MoveCard; class Command_MoveCard;
class Command_SetSideboardPlan; class Command_SetSideboardPlan;
class Command_DeckSelect; class Command_DeckSelect;
@ -228,6 +229,8 @@ public:
cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges); cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges); Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode Response::ResponseCode
cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges);
Response::ResponseCode
cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges); cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges); Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);