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:
parent
54b7943d17
commit
40c88fe385
5 changed files with 38 additions and 17 deletions
|
@ -675,9 +675,10 @@ CardRelation::CardRelation(const QString &_name,
|
|||
bool _doesAttach,
|
||||
bool _isCreateAllExclusion,
|
||||
bool _isVariableCount,
|
||||
int _defaultCount)
|
||||
int _defaultCount,
|
||||
bool _isPersistent)
|
||||
: name(_name), doesAttach(_doesAttach), isCreateAllExclusion(_isCreateAllExclusion),
|
||||
isVariableCount(_isVariableCount), defaultCount(_defaultCount)
|
||||
isVariableCount(_isVariableCount), defaultCount(_defaultCount), isPersistent(_isPersistent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -458,13 +458,15 @@ private:
|
|||
bool isCreateAllExclusion;
|
||||
bool isVariableCount;
|
||||
int defaultCount;
|
||||
bool isPersistent;
|
||||
|
||||
public:
|
||||
explicit CardRelation(const QString &_name = QString(),
|
||||
bool _doesAttach = false,
|
||||
bool _isCreateAllExclusion = false,
|
||||
bool _isVariableCount = false,
|
||||
int _defaultCount = 1);
|
||||
int _defaultCount = 1,
|
||||
bool _isPersistent = false);
|
||||
|
||||
inline const QString &getName() const
|
||||
{
|
||||
|
@ -490,5 +492,9 @@ public:
|
|||
{
|
||||
return defaultCount;
|
||||
}
|
||||
bool getIsPersistent() const
|
||||
{
|
||||
return isPersistent;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -185,6 +185,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
bool attach = false;
|
||||
bool exclude = false;
|
||||
bool variable = false;
|
||||
bool persistent = false;
|
||||
int count = 1;
|
||||
QXmlStreamAttributes attrs = xml.attributes();
|
||||
QString cardName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
||||
|
@ -211,7 +212,11 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
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") {
|
||||
reverseRelatedCards << relation;
|
||||
} else {
|
||||
|
@ -294,7 +299,9 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
if (i->getIsCreateAllExclusion()) {
|
||||
xml.writeAttribute("exclude", "exclude");
|
||||
}
|
||||
|
||||
if (i->getIsPersistent()) {
|
||||
xml.writeAttribute("persistent", "persistent");
|
||||
}
|
||||
if (i->getIsVariable()) {
|
||||
if (1 == i->getDefaultCount()) {
|
||||
xml.writeAttribute("count", "x");
|
||||
|
@ -318,6 +325,9 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
xml.writeAttribute("exclude", "exclude");
|
||||
}
|
||||
|
||||
if (i->getIsPersistent()) {
|
||||
xml.writeAttribute("persistent", "persistent");
|
||||
}
|
||||
if (i->getIsVariable()) {
|
||||
if (1 == i->getDefaultCount()) {
|
||||
xml.writeAttribute("count", "x");
|
||||
|
|
|
@ -1655,8 +1655,9 @@ void Player::actCreateAllRelatedCards()
|
|||
for (CardRelation *cardRelationAll : relatedCards) {
|
||||
if (!cardRelationAll->getDoesAttach() && !cardRelationAll->getIsVariable()) {
|
||||
dbName = cardRelationAll->getName();
|
||||
bool persistent = cardRelationAll->getIsPersistent();
|
||||
for (int i = 0; i < cardRelationAll->getDefaultCount(); ++i) {
|
||||
createCard(sourceCard, dbName);
|
||||
createCard(sourceCard, dbName, false, persistent);
|
||||
}
|
||||
++tokensTypesCreated;
|
||||
if (tokensTypesCreated == 1) {
|
||||
|
@ -1669,8 +1670,9 @@ void Player::actCreateAllRelatedCards()
|
|||
for (CardRelation *cardRelationNotExcluded : nonExcludedRelatedCards) {
|
||||
if (!cardRelationNotExcluded->getDoesAttach() && !cardRelationNotExcluded->getIsVariable()) {
|
||||
dbName = cardRelationNotExcluded->getName();
|
||||
bool persistent = cardRelationNotExcluded->getIsPersistent();
|
||||
for (int i = 0; i < cardRelationNotExcluded->getDefaultCount(); ++i) {
|
||||
createCard(sourceCard, dbName);
|
||||
createCard(sourceCard, dbName, false, persistent);
|
||||
}
|
||||
++tokensTypesCreated;
|
||||
if (tokensTypesCreated == 1) {
|
||||
|
@ -1698,6 +1700,7 @@ bool Player::createRelatedFromRelation(const CardItem *sourceCard, const CardRel
|
|||
return false;
|
||||
}
|
||||
QString dbName = cardRelation->getName();
|
||||
bool persistent = cardRelation->getIsPersistent();
|
||||
if (cardRelation->getIsVariable()) {
|
||||
bool ok;
|
||||
dialogSemaphore = true;
|
||||
|
@ -1708,23 +1711,23 @@ bool Player::createRelatedFromRelation(const CardItem *sourceCard, const CardRel
|
|||
return false;
|
||||
}
|
||||
for (int i = 0; i < count; ++i) {
|
||||
createCard(sourceCard, dbName);
|
||||
createCard(sourceCard, dbName, false, persistent);
|
||||
}
|
||||
} else if (cardRelation->getDefaultCount() > 1) {
|
||||
for (int i = 0; i < cardRelation->getDefaultCount(); ++i) {
|
||||
createCard(sourceCard, dbName);
|
||||
createCard(sourceCard, dbName, false, persistent);
|
||||
}
|
||||
} else {
|
||||
if (cardRelation->getDoesAttach()) {
|
||||
createAttachedCard(sourceCard, dbName);
|
||||
createAttachedCard(sourceCard, dbName, persistent);
|
||||
} else {
|
||||
createCard(sourceCard, dbName);
|
||||
createCard(sourceCard, dbName, false, persistent);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
|
@ -1758,7 +1761,7 @@ void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, b
|
|||
} else {
|
||||
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_x(gridPoint.x());
|
||||
cmd.set_y(gridPoint.y());
|
||||
|
@ -1770,9 +1773,9 @@ void Player::createCard(const CardItem *sourceCard, const QString &dbCardName, b
|
|||
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()
|
||||
|
|
|
@ -285,8 +285,9 @@ private:
|
|||
bool allCards);
|
||||
void addRelatedCardActions(const CardItem *card, QMenu *cardMenu);
|
||||
void addRelatedCardView(const CardItem *card, QMenu *cardMenu);
|
||||
void createCard(const CardItem *sourceCard, const QString &dbCardName, bool attach = false);
|
||||
void createAttachedCard(const CardItem *sourceCard, const QString &dbCardName);
|
||||
void
|
||||
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);
|
||||
|
||||
QRectF bRect;
|
||||
|
|
Loading…
Reference in a new issue