Conjured tokens xml attribute (#4646)

* Conjured xml attr

Add conjured attribute to related xml tags that makes those cards not be destroyed when they leave the battlefield.

* fix build errors, add sarkhan to test

* update oracle importer to support spellbooks from json

* debugging

* fix weird spacing

* fix oracle spacing too

* simplify if/else

Co-authored-by: Zach H <zahalpern+github@gmail.com>

* rename, remove oracle update

* remove extra linebreak

* run format.sh again
This commit is contained in:
cajun 2022-09-01 01:45:04 -05:00 committed by GitHub
parent 54b7943d17
commit 40c88fe385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 17 deletions

View file

@ -675,9 +675,10 @@ CardRelation::CardRelation(const QString &_name,
bool _doesAttach, bool _doesAttach,
bool _isCreateAllExclusion, bool _isCreateAllExclusion,
bool _isVariableCount, bool _isVariableCount,
int _defaultCount) int _defaultCount,
bool _isPersistent)
: name(_name), doesAttach(_doesAttach), isCreateAllExclusion(_isCreateAllExclusion), : name(_name), doesAttach(_doesAttach), isCreateAllExclusion(_isCreateAllExclusion),
isVariableCount(_isVariableCount), defaultCount(_defaultCount) isVariableCount(_isVariableCount), defaultCount(_defaultCount), isPersistent(_isPersistent)
{ {
} }

View file

@ -458,13 +458,15 @@ private:
bool isCreateAllExclusion; bool isCreateAllExclusion;
bool isVariableCount; bool isVariableCount;
int defaultCount; int defaultCount;
bool isPersistent;
public: public:
explicit CardRelation(const QString &_name = QString(), explicit CardRelation(const QString &_name = QString(),
bool _doesAttach = false, bool _doesAttach = false,
bool _isCreateAllExclusion = false, bool _isCreateAllExclusion = false,
bool _isVariableCount = false, bool _isVariableCount = false,
int _defaultCount = 1); int _defaultCount = 1,
bool _isPersistent = false);
inline const QString &getName() const inline const QString &getName() const
{ {
@ -490,5 +492,9 @@ public:
{ {
return defaultCount; return defaultCount;
} }
bool getIsPersistent() const
{
return isPersistent;
}
}; };
#endif #endif

View file

@ -185,6 +185,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
bool attach = false; bool attach = false;
bool exclude = false; bool exclude = false;
bool variable = false; bool variable = false;
bool persistent = false;
int count = 1; int count = 1;
QXmlStreamAttributes attrs = xml.attributes(); QXmlStreamAttributes attrs = xml.attributes();
QString cardName = xml.readElementText(QXmlStreamReader::IncludeChildElements); QString cardName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
@ -211,7 +212,11 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
exclude = true; exclude = true;
} }
auto *relation = new CardRelation(cardName, attach, exclude, variable, count); if (attrs.hasAttribute("persistent")) {
persistent = true;
}
auto *relation = new CardRelation(cardName, attach, exclude, variable, count, persistent);
if (xmlName == "reverse-related") { if (xmlName == "reverse-related") {
reverseRelatedCards << relation; reverseRelatedCards << relation;
} else { } else {
@ -294,7 +299,9 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
if (i->getIsCreateAllExclusion()) { if (i->getIsCreateAllExclusion()) {
xml.writeAttribute("exclude", "exclude"); xml.writeAttribute("exclude", "exclude");
} }
if (i->getIsPersistent()) {
xml.writeAttribute("persistent", "persistent");
}
if (i->getIsVariable()) { if (i->getIsVariable()) {
if (1 == i->getDefaultCount()) { if (1 == i->getDefaultCount()) {
xml.writeAttribute("count", "x"); xml.writeAttribute("count", "x");
@ -318,6 +325,9 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
xml.writeAttribute("exclude", "exclude"); xml.writeAttribute("exclude", "exclude");
} }
if (i->getIsPersistent()) {
xml.writeAttribute("persistent", "persistent");
}
if (i->getIsVariable()) { if (i->getIsVariable()) {
if (1 == i->getDefaultCount()) { if (1 == i->getDefaultCount()) {
xml.writeAttribute("count", "x"); xml.writeAttribute("count", "x");

View file

@ -1655,8 +1655,9 @@ void Player::actCreateAllRelatedCards()
for (CardRelation *cardRelationAll : relatedCards) { for (CardRelation *cardRelationAll : relatedCards) {
if (!cardRelationAll->getDoesAttach() && !cardRelationAll->getIsVariable()) { if (!cardRelationAll->getDoesAttach() && !cardRelationAll->getIsVariable()) {
dbName = cardRelationAll->getName(); dbName = cardRelationAll->getName();
bool persistent = cardRelationAll->getIsPersistent();
for (int i = 0; i < cardRelationAll->getDefaultCount(); ++i) { for (int i = 0; i < cardRelationAll->getDefaultCount(); ++i) {
createCard(sourceCard, dbName); createCard(sourceCard, dbName, false, persistent);
} }
++tokensTypesCreated; ++tokensTypesCreated;
if (tokensTypesCreated == 1) { if (tokensTypesCreated == 1) {
@ -1669,8 +1670,9 @@ void Player::actCreateAllRelatedCards()
for (CardRelation *cardRelationNotExcluded : nonExcludedRelatedCards) { for (CardRelation *cardRelationNotExcluded : nonExcludedRelatedCards) {
if (!cardRelationNotExcluded->getDoesAttach() && !cardRelationNotExcluded->getIsVariable()) { if (!cardRelationNotExcluded->getDoesAttach() && !cardRelationNotExcluded->getIsVariable()) {
dbName = cardRelationNotExcluded->getName(); dbName = cardRelationNotExcluded->getName();
bool persistent = cardRelationNotExcluded->getIsPersistent();
for (int i = 0; i < cardRelationNotExcluded->getDefaultCount(); ++i) { for (int i = 0; i < cardRelationNotExcluded->getDefaultCount(); ++i) {
createCard(sourceCard, dbName); createCard(sourceCard, dbName, false, persistent);
} }
++tokensTypesCreated; ++tokensTypesCreated;
if (tokensTypesCreated == 1) { if (tokensTypesCreated == 1) {
@ -1698,6 +1700,7 @@ bool Player::createRelatedFromRelation(const CardItem *sourceCard, const CardRel
return false; return false;
} }
QString dbName = cardRelation->getName(); QString dbName = cardRelation->getName();
bool persistent = cardRelation->getIsPersistent();
if (cardRelation->getIsVariable()) { if (cardRelation->getIsVariable()) {
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
@ -1708,23 +1711,23 @@ bool Player::createRelatedFromRelation(const CardItem *sourceCard, const CardRel
return false; return false;
} }
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
createCard(sourceCard, dbName); createCard(sourceCard, dbName, false, persistent);
} }
} else if (cardRelation->getDefaultCount() > 1) { } else if (cardRelation->getDefaultCount() > 1) {
for (int i = 0; i < cardRelation->getDefaultCount(); ++i) { for (int i = 0; i < cardRelation->getDefaultCount(); ++i) {
createCard(sourceCard, dbName); createCard(sourceCard, dbName, false, persistent);
} }
} else { } else {
if (cardRelation->getDoesAttach()) { if (cardRelation->getDoesAttach()) {
createAttachedCard(sourceCard, dbName); createAttachedCard(sourceCard, dbName, persistent);
} else { } else {
createCard(sourceCard, dbName); createCard(sourceCard, dbName, false, persistent);
} }
} }
return true; return true;
} }
void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, bool attach) void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, bool attach, bool persistent)
{ {
CardInfoPtr cardInfo = db->getCard(dbCardName); CardInfoPtr cardInfo = db->getCard(dbCardName);
@ -1758,7 +1761,7 @@ void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, b
} else { } else {
cmd.set_annotation(""); cmd.set_annotation("");
} }
cmd.set_destroy_on_zone_change(true); cmd.set_destroy_on_zone_change(!persistent);
cmd.set_target_zone(sourceCard->getZone()->getName().toStdString()); cmd.set_target_zone(sourceCard->getZone()->getName().toStdString());
cmd.set_x(gridPoint.x()); cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y()); cmd.set_y(gridPoint.y());
@ -1770,9 +1773,9 @@ void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, b
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::createAttachedCard(const CardItem *sourceCard, const QString &dbCardName) void Player::createAttachedCard(const CardItem *sourceCard, const QString &dbCardName, bool persistent)
{ {
createCard(sourceCard, dbCardName, true); createCard(sourceCard, dbCardName, true, persistent);
} }
void Player::actSayMessage() void Player::actSayMessage()

View file

@ -285,8 +285,9 @@ private:
bool allCards); bool allCards);
void addRelatedCardActions(const CardItem *card, QMenu *cardMenu); void addRelatedCardActions(const CardItem *card, QMenu *cardMenu);
void addRelatedCardView(const CardItem *card, QMenu *cardMenu); void addRelatedCardView(const CardItem *card, QMenu *cardMenu);
void createCard(const CardItem *sourceCard, const QString &dbCardName, bool attach = false); void
void createAttachedCard(const CardItem *sourceCard, const QString &dbCardName); createCard(const CardItem *sourceCard, const QString &dbCardName, bool attach = false, bool persistent = false);
void createAttachedCard(const CardItem *sourceCard, const QString &dbCardName, bool persistent = false);
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation);
QRectF bRect; QRectF bRect;