fixed pw loyalty in oracle, PB code working
This commit is contained in:
parent
d5c628966f
commit
6344b987de
8 changed files with 67 additions and 51 deletions
|
@ -129,7 +129,7 @@ public:
|
||||||
const QString &_text = QString(),
|
const QString &_text = QString(),
|
||||||
const QStringList &_colors = QStringList(),
|
const QStringList &_colors = QStringList(),
|
||||||
int _loyalty = 0,
|
int _loyalty = 0,
|
||||||
bool cipt = false,
|
bool _cipt = false,
|
||||||
int _tableRow = 0,
|
int _tableRow = 0,
|
||||||
const SetList &_sets = SetList(),
|
const SetList &_sets = SetList(),
|
||||||
const QStringMap &_picURLs = QStringMap(),
|
const QStringMap &_picURLs = QStringMap(),
|
||||||
|
|
13
common/get_pb_extension.cpp
Normal file
13
common/get_pb_extension.cpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#include "get_pb_extension.h"
|
||||||
|
#include <google/protobuf/message.h>
|
||||||
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
|
int getPbExtension(const ::google::protobuf::Message &message)
|
||||||
|
{
|
||||||
|
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
|
||||||
|
message.GetReflection()->ListFields(message, &fieldList);
|
||||||
|
for (unsigned int j = 0; j < fieldList.size(); ++j)
|
||||||
|
if (fieldList[j]->is_extension())
|
||||||
|
return fieldList[j]->number();
|
||||||
|
return -1;
|
||||||
|
}
|
12
common/get_pb_extension.h
Normal file
12
common/get_pb_extension.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef GET_PB_EXTENSION_H
|
||||||
|
#define GET_PB_EXTENSION_H
|
||||||
|
|
||||||
|
namespace google {
|
||||||
|
namespace protobuf {
|
||||||
|
class Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getPbExtension(const ::google::protobuf::Message &message);
|
||||||
|
|
||||||
|
#endif
|
|
@ -9,13 +9,14 @@
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
|
|
||||||
#include <google/protobuf/message.h>
|
#include <google/protobuf/message.h>
|
||||||
|
#include <google/protobuf/descriptor.h>
|
||||||
#include "pb/server_message.pb.h"
|
#include "pb/server_message.pb.h"
|
||||||
|
|
||||||
class DeckList;
|
class DeckList;
|
||||||
class GameEvent;
|
class GameEvent;
|
||||||
class GameEventContainer;
|
class GameEventContainer;
|
||||||
class GameEventContext;
|
class GameEventContext;
|
||||||
|
#include <QDebug>
|
||||||
static const int protocolVersion = 13;
|
static const int protocolVersion = 13;
|
||||||
|
|
||||||
class GameEventStorageItem {
|
class GameEventStorageItem {
|
||||||
|
@ -23,21 +24,20 @@ public:
|
||||||
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
||||||
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
||||||
private:
|
private:
|
||||||
::google::protobuf::Message *event;
|
GameEvent *event;
|
||||||
int playerId;
|
|
||||||
EventRecipients recipients;
|
EventRecipients recipients;
|
||||||
public:
|
public:
|
||||||
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients)
|
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients)
|
||||||
: event(_event.New()), playerId(_playerId), recipients(_recipients)
|
: event(new GameEvent), recipients(_recipients)
|
||||||
{
|
{
|
||||||
event->CopyFrom(_event);
|
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
||||||
|
event->set_player_id(_playerId);
|
||||||
}
|
}
|
||||||
~GameEventStorageItem()
|
~GameEventStorageItem()
|
||||||
{
|
{
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
const ::google::protobuf::Message &getEvent() const { return *event; }
|
const GameEvent &getGameEvent() const { return *event; }
|
||||||
int getPlayerId() const { return playerId; }
|
|
||||||
EventRecipients getRecipients() const { return recipients; }
|
EventRecipients getRecipients() const { return recipients; }
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
|
||||||
|
@ -59,9 +59,13 @@ public:
|
||||||
delete gameEventList[i];
|
delete gameEventList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGameEventContext(::google::protobuf::Message *_gameEventContext) { gameEventContext = _gameEventContext; }
|
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext) {
|
||||||
|
delete gameEventContext;
|
||||||
|
gameEventContext = new GameEventContext;
|
||||||
|
gameEventContext->GetReflection()->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_gameEventContext);
|
||||||
|
}
|
||||||
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
||||||
|
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
|
||||||
int getPrivatePlayerId() const { return privatePlayerId; }
|
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||||
|
|
||||||
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1)
|
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1)
|
||||||
|
|
|
@ -419,7 +419,7 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, Server_Car
|
||||||
Event_DestroyCard event;
|
Event_DestroyCard event;
|
||||||
event.set_zone_name(startzone->getName().toStdString());
|
event.set_zone_name(startzone->getName().toStdString());
|
||||||
event.set_card_id(card->getId());
|
event.set_card_id(card->getId());
|
||||||
ges.setGameEventContext(new Context_MoveCard);
|
ges.setGameEventContext(Context_MoveCard());
|
||||||
ges.enqueueGameEvent(event, playerId);
|
ges.enqueueGameEvent(event, playerId);
|
||||||
|
|
||||||
card->deleteLater();
|
card->deleteLater();
|
||||||
|
@ -561,7 +561,8 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, c
|
||||||
|
|
||||||
Event_SetCardAttr event;
|
Event_SetCardAttr event;
|
||||||
event.set_zone_name(zone->getName().toStdString());
|
event.set_zone_name(zone->getName().toStdString());
|
||||||
event.set_card_id(cardId);
|
if (cardId != -1)
|
||||||
|
event.set_card_id(cardId);
|
||||||
event.set_attr_name(attrName.toStdString());
|
event.set_attr_name(attrName.toStdString());
|
||||||
event.set_attr_value(result.toStdString());
|
event.set_attr_value(result.toStdString());
|
||||||
ges.enqueueGameEvent(event, playerId);
|
ges.enqueueGameEvent(event, playerId);
|
||||||
|
|
|
@ -345,35 +345,23 @@ Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const
|
||||||
if ((resp != Response::RespOk) && (resp != Response::RespNothing))
|
if ((resp != Response::RespOk) && (resp != Response::RespNothing))
|
||||||
finalResponseCode = resp;
|
finalResponseCode = resp;
|
||||||
}
|
}
|
||||||
/*
|
GameEventContainer *contPrivate = new GameEventContainer;
|
||||||
* XXX konvertieren zu GameEventStorage (oben deklariert als "ges")
|
GameEventContainer *contOthers = new GameEventContainer;
|
||||||
*
|
const QList<GameEventStorageItem *> &gameEventList = ges.getGameEventList();
|
||||||
GameEventContainer *gQPublic = bla->getGameEventQueuePublic();
|
for (int i = 0; i < gameEventList.size(); ++i) {
|
||||||
if (gQPublic) {
|
const GameEvent &event = gameEventList[i]->getGameEvent();
|
||||||
gameListMutex.lock();
|
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
|
||||||
QPair<Server_Game *, Server_Player *> gamePlayerPair = games.value(gQPublic->game_id());
|
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
||||||
if (gamePlayerPair.first) {
|
contPrivate->add_event_list()->CopyFrom(event);
|
||||||
GameEventContainer *gQPrivate = bla->getGameEventQueuePrivate();
|
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
||||||
GameEventContainer *gQOmniscient = bla->getGameEventQueueOmniscient();
|
contOthers->add_event_list()->CopyFrom(event);
|
||||||
if (gQPrivate) {
|
|
||||||
int privatePlayerId = bla->getPrivatePlayerId();
|
|
||||||
Server_Player *privatePlayer;
|
|
||||||
if (privatePlayerId == -1)
|
|
||||||
privatePlayer = gamePlayerPair.second;
|
|
||||||
else
|
|
||||||
privatePlayer = gamePlayerPair.first->getPlayer(privatePlayerId);
|
|
||||||
if (gQOmniscient) {
|
|
||||||
gamePlayerPair.first->sendGameEventContainer(gQPublic, privatePlayer, true);
|
|
||||||
gamePlayerPair.first->sendGameEventContainerOmniscient(gQOmniscient, privatePlayer);
|
|
||||||
} else
|
|
||||||
gamePlayerPair.first->sendGameEventContainer(gQPublic, privatePlayer);
|
|
||||||
privatePlayer->sendProtocolItem(gQPrivate);
|
|
||||||
} else
|
|
||||||
gamePlayerPair.first->sendGameEventContainer(gQPublic);
|
|
||||||
}
|
|
||||||
gameListMutex.unlock();
|
|
||||||
}
|
}
|
||||||
*/
|
if (ges.getGameEventContext()) {
|
||||||
|
contPrivate->mutable_context()->CopyFrom(*ges.getGameEventContext());
|
||||||
|
contOthers->mutable_context()->CopyFrom(*ges.getGameEventContext());
|
||||||
|
}
|
||||||
|
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, ges.getPrivatePlayerId());
|
||||||
|
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, ges.getPrivatePlayerId());
|
||||||
return finalResponseCode;
|
return finalResponseCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,8 +859,8 @@ Response::ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckS
|
||||||
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
||||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||||
|
|
||||||
Context_DeckSelect *context = new Context_DeckSelect;
|
Context_DeckSelect context;
|
||||||
context->set_deck_hash(deck->getDeckHash().toStdString());
|
context.set_deck_hash(deck->getDeckHash().toStdString());
|
||||||
ges.setGameEventContext(context);
|
ges.setGameEventContext(context);
|
||||||
|
|
||||||
Response_DeckDownload *re = new Response_DeckDownload;
|
Response_DeckDownload *re = new Response_DeckDownload;
|
||||||
|
@ -921,7 +909,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede
|
||||||
Event_PlayerPropertiesChanged event;
|
Event_PlayerPropertiesChanged event;
|
||||||
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
||||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||||
ges.setGameEventContext(new Context_Concede());
|
ges.setGameEventContext(Context_Concede());
|
||||||
|
|
||||||
game->stopGameIfFinished();
|
game->stopGameIfFinished();
|
||||||
if (game->getGameStarted() && (game->getActivePlayer() == player->getPlayerId()))
|
if (game->getGameStarted() && (game->getActivePlayer() == player->getPlayerId()))
|
||||||
|
@ -946,7 +934,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_Ready
|
||||||
Event_PlayerPropertiesChanged event;
|
Event_PlayerPropertiesChanged event;
|
||||||
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
event.mutable_player_properties()->CopyFrom(player->getProperties());
|
||||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
ges.enqueueGameEvent(event, player->getPlayerId());
|
||||||
ges.setGameEventContext(new Context_ReadyStart());
|
ges.setGameEventContext(Context_ReadyStart());
|
||||||
|
|
||||||
game->startGameIfReady();
|
game->startGameIfReady();
|
||||||
return Response::RespOk;
|
return Response::RespOk;
|
||||||
|
@ -1012,8 +1000,8 @@ Response::ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulliga
|
||||||
if (number == player->getInitialCards())
|
if (number == player->getInitialCards())
|
||||||
number = -1;
|
number = -1;
|
||||||
|
|
||||||
Context_Mulligan *context = new Context_Mulligan;
|
Context_Mulligan context;
|
||||||
context->set_number(number);
|
context.set_number(number);
|
||||||
ges.setGameEventContext(context);
|
ges.setGameEventContext(context);
|
||||||
|
|
||||||
return Response::RespOk;
|
return Response::RespOk;
|
||||||
|
|
|
@ -4,6 +4,7 @@ DEPENDPATH += . src
|
||||||
INCLUDEPATH += . src ../cockatrice/src
|
INCLUDEPATH += . src ../cockatrice/src
|
||||||
MOC_DIR = build
|
MOC_DIR = build
|
||||||
OBJECTS_DIR = build
|
OBJECTS_DIR = build
|
||||||
|
QMAKE_CXXFLAGS_RELEASE += -O2
|
||||||
QT += network svg xml
|
QT += network svg xml
|
||||||
|
|
||||||
HEADERS += src/oracleimporter.h src/window_main.h ../cockatrice/src/carddatabase.h ../cockatrice/src/settingscache.h
|
HEADERS += src/oracleimporter.h src/window_main.h ../cockatrice/src/carddatabase.h ../cockatrice/src/settingscache.h
|
||||||
|
|
|
@ -124,7 +124,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
||||||
|
|
||||||
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped."));
|
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped."));
|
||||||
|
|
||||||
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors, cipt);
|
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors, cardLoyalty, cipt);
|
||||||
int tableRow = 1;
|
int tableRow = 1;
|
||||||
QString mainCardType = card->getMainCardType();
|
QString mainCardType = card->getMainCardType();
|
||||||
if ((mainCardType == "Land") || mArtifact)
|
if ((mainCardType == "Land") || mArtifact)
|
||||||
|
@ -134,10 +134,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
||||||
else if (mainCardType == "Creature")
|
else if (mainCardType == "Creature")
|
||||||
tableRow = 2;
|
tableRow = 2;
|
||||||
card->setTableRow(tableRow);
|
card->setTableRow(tableRow);
|
||||||
|
|
||||||
if (mainCardType == "Planeswalker")
|
|
||||||
card->setLoyalty(cardLoyalty);
|
|
||||||
|
|
||||||
cardHash.insert(cardName, card);
|
cardHash.insert(cardName, card);
|
||||||
}
|
}
|
||||||
card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName));
|
card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName));
|
||||||
|
|
Loading…
Reference in a new issue