Adding a way to mark decks as "locked" based on options requirements (option on or off). Can be used for example to lock a deck until a specific set is not unlocked. Works for both player decks (could be used for premade?) and AI decks.
This commit is contained in:
@@ -20,6 +20,7 @@ private:
|
||||
string mFilename;
|
||||
string mDescription;
|
||||
string mName;
|
||||
vector<int> mUnlockRequirements;
|
||||
int mDeckId;
|
||||
string mAvatarFilename;
|
||||
string mColorIndex;
|
||||
@@ -44,6 +45,7 @@ public:
|
||||
string getAvatarFilename();
|
||||
string getColorIndex();
|
||||
string getStatsSummary();
|
||||
vector<int> getUnlockRequirements();
|
||||
|
||||
int getDeckId();
|
||||
int getGamesPlayed();
|
||||
|
||||
@@ -157,6 +157,7 @@ public:
|
||||
string meta_desc;
|
||||
string meta_name;
|
||||
vector<string> meta_AIHints;
|
||||
string meta_unlockRequirements;
|
||||
|
||||
int meta_id;
|
||||
int totalCards();
|
||||
|
||||
@@ -30,6 +30,13 @@ void DeckMetaData::LoadDeck()
|
||||
mName = trim(deck.meta_name);
|
||||
mDescription = trim(deck.meta_desc);
|
||||
mDeckId = atoi((mFilename.substr(mFilename.find("deck") + 4, mFilename.find(".txt"))).c_str());
|
||||
|
||||
vector<string> requirements = split(deck.meta_unlockRequirements, ',');
|
||||
for(size_t i = 0; i < requirements.size(); ++i)
|
||||
{
|
||||
mUnlockRequirements.push_back(Options::getID(requirements[i]));
|
||||
}
|
||||
|
||||
mDeckLoaded = true;
|
||||
if (!mIsAI)
|
||||
mAvatarFilename = "avatar.jpg";
|
||||
@@ -115,6 +122,12 @@ int DeckMetaData::getDeckId()
|
||||
return mDeckId;
|
||||
}
|
||||
|
||||
vector<int> DeckMetaData::getUnlockRequirements()
|
||||
{
|
||||
return mUnlockRequirements;
|
||||
}
|
||||
|
||||
|
||||
string DeckMetaData::getAvatarFilename()
|
||||
{
|
||||
return mAvatarFilename;
|
||||
|
||||
@@ -51,29 +51,44 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
|
||||
|
||||
if (meta)
|
||||
{
|
||||
found = 1;
|
||||
if (statsPlayer)
|
||||
//Check if the deck is unlocked based on sets etc...
|
||||
bool unlocked = true;
|
||||
vector<int> unlockRequirements = meta->getUnlockRequirements();
|
||||
for (size_t i = 0; i < unlockRequirements.size(); ++i)
|
||||
{
|
||||
std::ostringstream aiStatsDeckName;
|
||||
aiStatsDeckName << smallDeckPrefix << "_deck" << nbDecks;
|
||||
meta->mStatsFilename = aiStatsDeckName.str();
|
||||
meta->mIsAI = true;
|
||||
if (meta->mPlayerDeck != statsPlayer->GetCurrentDeckStatsFile())
|
||||
{
|
||||
meta->mPlayerDeck = statsPlayer->GetCurrentDeckStatsFile();
|
||||
meta->Invalidate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream playerStatsDeckName;
|
||||
playerStatsDeckName << "stats/player_deck" << nbDecks << ".txt";
|
||||
meta->mStatsFilename = options.profileFile(playerStatsDeckName.str());
|
||||
meta->mIsAI = false;
|
||||
if (! options[unlockRequirements[i]].number)
|
||||
{
|
||||
unlocked = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
retList.push_back(meta);
|
||||
nbDecks++;
|
||||
if (unlocked)
|
||||
{
|
||||
found = 1;
|
||||
if (statsPlayer)
|
||||
{
|
||||
std::ostringstream aiStatsDeckName;
|
||||
aiStatsDeckName << smallDeckPrefix << "_deck" << nbDecks;
|
||||
meta->mStatsFilename = aiStatsDeckName.str();
|
||||
meta->mIsAI = true;
|
||||
if (meta->mPlayerDeck != statsPlayer->GetCurrentDeckStatsFile())
|
||||
{
|
||||
meta->mPlayerDeck = statsPlayer->GetCurrentDeckStatsFile();
|
||||
meta->Invalidate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream playerStatsDeckName;
|
||||
playerStatsDeckName << "stats/player_deck" << nbDecks << ".txt";
|
||||
meta->mStatsFilename = options.profileFile(playerStatsDeckName.str());
|
||||
meta->mIsAI = false;
|
||||
}
|
||||
|
||||
retList.push_back(meta);
|
||||
nbDecks++;
|
||||
}
|
||||
}
|
||||
meta = NULL;
|
||||
}
|
||||
|
||||
@@ -698,7 +698,6 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
||||
meta_id = atoi(meta_name.substr(4).c_str());
|
||||
wagic::ifstream file(config_file);
|
||||
std::string s;
|
||||
|
||||
if (file)
|
||||
{
|
||||
while (std::getline(file, s))
|
||||
@@ -726,6 +725,12 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
||||
meta_AIHints.push_back(s.substr(found + 5));
|
||||
continue;
|
||||
}
|
||||
found = s.find("UNLOCK:");
|
||||
if (found != string::npos)
|
||||
{
|
||||
meta_unlockRequirements = s.substr(found + 7);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (meta_only) break;
|
||||
|
||||
Reference in New Issue
Block a user