fixed pw loyalty in oracle, PB code working

This commit is contained in:
Max-Wilhelm Bruker 2012-01-01 18:15:32 +01:00
parent d5c628966f
commit 6344b987de
8 changed files with 67 additions and 51 deletions

View file

@ -129,7 +129,7 @@ public:
const QString &_text = QString(),
const QStringList &_colors = QStringList(),
int _loyalty = 0,
bool cipt = false,
bool _cipt = false,
int _tableRow = 0,
const SetList &_sets = SetList(),
const QStringMap &_picURLs = QStringMap(),

View 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
View 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

View file

@ -9,13 +9,14 @@
#include <QPair>
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include "pb/server_message.pb.h"
class DeckList;
class GameEvent;
class GameEventContainer;
class GameEventContext;
#include <QDebug>
static const int protocolVersion = 13;
class GameEventStorageItem {
@ -23,21 +24,20 @@ public:
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
private:
::google::protobuf::Message *event;
int playerId;
GameEvent *event;
EventRecipients recipients;
public:
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()
{
delete event;
}
const ::google::protobuf::Message &getEvent() const { return *event; }
int getPlayerId() const { return playerId; }
const GameEvent &getGameEvent() const { return *event; }
EventRecipients getRecipients() const { return recipients; }
};
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
@ -59,9 +59,13 @@ public:
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; }
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
int getPrivatePlayerId() const { return privatePlayerId; }
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1)

View file

@ -419,7 +419,7 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, Server_Car
Event_DestroyCard event;
event.set_zone_name(startzone->getName().toStdString());
event.set_card_id(card->getId());
ges.setGameEventContext(new Context_MoveCard);
ges.setGameEventContext(Context_MoveCard());
ges.enqueueGameEvent(event, playerId);
card->deleteLater();
@ -561,7 +561,8 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, c
Event_SetCardAttr event;
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_value(result.toStdString());
ges.enqueueGameEvent(event, playerId);

View file

@ -345,35 +345,23 @@ Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const
if ((resp != Response::RespOk) && (resp != Response::RespNothing))
finalResponseCode = resp;
}
/*
* XXX konvertieren zu GameEventStorage (oben deklariert als "ges")
*
GameEventContainer *gQPublic = bla->getGameEventQueuePublic();
if (gQPublic) {
gameListMutex.lock();
QPair<Server_Game *, Server_Player *> gamePlayerPair = games.value(gQPublic->game_id());
if (gamePlayerPair.first) {
GameEventContainer *gQPrivate = bla->getGameEventQueuePrivate();
GameEventContainer *gQOmniscient = bla->getGameEventQueueOmniscient();
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();
GameEventContainer *contPrivate = new GameEventContainer;
GameEventContainer *contOthers = new GameEventContainer;
const QList<GameEventStorageItem *> &gameEventList = ges.getGameEventList();
for (int i = 0; i < gameEventList.size(); ++i) {
const GameEvent &event = gameEventList[i]->getGameEvent();
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
contPrivate->add_event_list()->CopyFrom(event);
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
contOthers->add_event_list()->CopyFrom(event);
}
*/
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;
}
@ -871,8 +859,8 @@ Response::ResponseCode Server_ProtocolHandler::cmdDeckSelect(const Command_DeckS
event.mutable_player_properties()->CopyFrom(player->getProperties());
ges.enqueueGameEvent(event, player->getPlayerId());
Context_DeckSelect *context = new Context_DeckSelect;
context->set_deck_hash(deck->getDeckHash().toStdString());
Context_DeckSelect context;
context.set_deck_hash(deck->getDeckHash().toStdString());
ges.setGameEventContext(context);
Response_DeckDownload *re = new Response_DeckDownload;
@ -921,7 +909,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdConcede(const Command_Concede
Event_PlayerPropertiesChanged event;
event.mutable_player_properties()->CopyFrom(player->getProperties());
ges.enqueueGameEvent(event, player->getPlayerId());
ges.setGameEventContext(new Context_Concede());
ges.setGameEventContext(Context_Concede());
game->stopGameIfFinished();
if (game->getGameStarted() && (game->getActivePlayer() == player->getPlayerId()))
@ -946,7 +934,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdReadyStart(const Command_Ready
Event_PlayerPropertiesChanged event;
event.mutable_player_properties()->CopyFrom(player->getProperties());
ges.enqueueGameEvent(event, player->getPlayerId());
ges.setGameEventContext(new Context_ReadyStart());
ges.setGameEventContext(Context_ReadyStart());
game->startGameIfReady();
return Response::RespOk;
@ -1012,8 +1000,8 @@ Response::ResponseCode Server_ProtocolHandler::cmdMulligan(const Command_Mulliga
if (number == player->getInitialCards())
number = -1;
Context_Mulligan *context = new Context_Mulligan;
context->set_number(number);
Context_Mulligan context;
context.set_number(number);
ges.setGameEventContext(context);
return Response::RespOk;

View file

@ -4,6 +4,7 @@ DEPENDPATH += . src
INCLUDEPATH += . src ../cockatrice/src
MOC_DIR = build
OBJECTS_DIR = build
QMAKE_CXXFLAGS_RELEASE += -O2
QT += network svg xml
HEADERS += src/oracleimporter.h src/window_main.h ../cockatrice/src/carddatabase.h ../cockatrice/src/settingscache.h

View file

@ -124,7 +124,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
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;
QString mainCardType = card->getMainCardType();
if ((mainCardType == "Land") || mArtifact)
@ -134,10 +134,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
else if (mainCardType == "Creature")
tableRow = 2;
card->setTableRow(tableRow);
if (mainCardType == "Planeswalker")
card->setLoyalty(cardLoyalty);
cardHash.insert(cardName, card);
}
card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName));