reimplemented mana color display for deck selection. This is now totally controlled by
stats generation. No data needs to be written to the deck master files themselves. Now the mana colors will only show if you have battled with a particular deck at least once. This is not retroactive, so you will need to battle the ai again. This can not be edited manually either to prevent tampering with the statistical data. Player deck mana color display is also covered this way. Decks will still be saved in the new layout if a disk write is necessary. So any changes via the deck editor will result in a deck file rewrite is was always the case.:)
This commit is contained in:
@@ -27,8 +27,6 @@ public:
|
||||
vector<DeckMetaData*> * getPlayerDeckOrderList();
|
||||
vector<DeckMetaData*> * getAIDeckOrderList();
|
||||
|
||||
void saveDeck ( const string& deckFilename, MTGAllCards *collection );
|
||||
void saveDeck ( MTGDeck *deck, MTGAllCards *collection );
|
||||
void AddMetaData( const std::string& filename, bool isAI);
|
||||
DeckMetaData* getDeckMetaDataById(int deckId, bool isAI);
|
||||
DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI);
|
||||
|
||||
@@ -15,10 +15,11 @@ class GameObserver;
|
||||
class DeckStat
|
||||
{
|
||||
public:
|
||||
DeckStat(int _nbgames = 0, int _victories = 0);
|
||||
DeckStat(int _nbgames = 0, int _victories = 0, string manaColorIndex = "");
|
||||
|
||||
int nbgames;
|
||||
int victories;
|
||||
string manaColorIndex;
|
||||
int percentVictories();
|
||||
};
|
||||
|
||||
@@ -27,9 +28,8 @@ class DeckStats
|
||||
protected:
|
||||
static DeckStats * mInstance;
|
||||
public:
|
||||
//map<string, DeckStat *> stats; // current set of statistics
|
||||
string currentDeck;
|
||||
map<string, map<string,DeckStat*> > masterDeckStats;
|
||||
map<string, map<string, DeckStat*> > masterDeckStats;
|
||||
|
||||
static DeckStats * GetInstance();
|
||||
static void EndInstance();
|
||||
@@ -94,7 +94,8 @@ public:
|
||||
int countNonLandProducersPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int totalCostPerColor[Constants::MTG_NB_COLORS + 1];
|
||||
int totalColoredSymbols;
|
||||
|
||||
|
||||
string getManaColorIndex();
|
||||
void updateStats(string filename, MTGAllCards * collection);
|
||||
void updateStats(DeckDataWrapper *mtgDeck);
|
||||
int countCardsByType(const char * _type, DeckDataWrapper * myDeck);
|
||||
|
||||
@@ -157,7 +157,6 @@ public:
|
||||
string meta_desc;
|
||||
string meta_name;
|
||||
int meta_id;
|
||||
string meta_deck_colors;
|
||||
int totalCards();
|
||||
int totalPrice();
|
||||
MTGDeck(MTGAllCards * _allcards);
|
||||
|
||||
@@ -105,42 +105,6 @@ DeckMetaData* DeckManager::getDeckMetaDataByFilename(const string& filename, boo
|
||||
return deck;
|
||||
}
|
||||
|
||||
void DeckManager::saveDeck( MTGDeck *deck, MTGAllCards *collection )
|
||||
{
|
||||
if ( deck->meta_deck_colors == "" )
|
||||
{
|
||||
bool isAI = deck->getFilename().find("baka") != string::npos;
|
||||
StatsWrapper *stats = getExtendedStatsForDeckId( deck->meta_id, collection, isAI );
|
||||
ostringstream manaColorIndex;
|
||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
||||
{
|
||||
if (stats->totalCostPerColor[i] != 0)
|
||||
manaColorIndex << "1";
|
||||
else
|
||||
manaColorIndex <<"0";
|
||||
}
|
||||
deck->meta_deck_colors = manaColorIndex.str();
|
||||
// save the deck to disk
|
||||
deck->save( deck->getFilename(), true, deck->meta_name, deck->meta_desc );
|
||||
// update DeckMetaData object
|
||||
DeckMetaData *meta = getDeckMetaDataByFilename(deck->getFilename(), isAI);
|
||||
meta->setColorIndex( deck->meta_deck_colors );
|
||||
}
|
||||
}
|
||||
|
||||
void DeckManager::saveDeck( const string& deckFilename, MTGAllCards *collection )
|
||||
{
|
||||
bool isAI = deckFilename.find("baka") != string::npos;
|
||||
DeckMetaData *metaData = getDeckMetaDataByFilename( deckFilename, isAI );
|
||||
if ( metaData->getColorIndex() == "" )
|
||||
{
|
||||
MTGDeck *tempDeck = NEW MTGDeck( deckFilename.c_str(), collection, 0 );
|
||||
saveDeck(tempDeck, collection);
|
||||
SAFE_DELETE( tempDeck );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DeckManager::AddMetaData( const string& filename, bool isAI )
|
||||
{
|
||||
if (isAI)
|
||||
|
||||
@@ -224,7 +224,6 @@ void DeckMenu::Render()
|
||||
{
|
||||
mSelectedDeckId = i;
|
||||
mSelectedDeck = currentMenuItem->meta;
|
||||
|
||||
WFont *mainFont = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
||||
|
||||
// display the "more info" button if special condition is met
|
||||
|
||||
@@ -34,6 +34,7 @@ void DeckMetaData::LoadStats()
|
||||
mPercentVictories = stats->percentVictories(mStatsFilename);
|
||||
mVictories = opponentDeckStats->victories;
|
||||
mGamesPlayed = opponentDeckStats->nbgames;
|
||||
mColorIndex = opponentDeckStats->manaColorIndex;
|
||||
ostringstream oss;
|
||||
int deckFilenameOffset = mStatsFilename.find("deck") + 4;
|
||||
int oppDeckId = atoi(mStatsFilename.substr(deckFilenameOffset, mStatsFilename.find_last_of(".")).c_str());
|
||||
@@ -65,7 +66,7 @@ void DeckMetaData::LoadStats()
|
||||
if (FileExists(mStatsFilename))
|
||||
{
|
||||
stats->load(mStatsFilename);
|
||||
mGamesPlayed = stats->nbGames();
|
||||
mGamesPlayed = stats->nbGames();
|
||||
mPercentVictories = stats->percentVictories();
|
||||
mVictories = static_cast<int>(mGamesPlayed * (mPercentVictories / 100.0f));
|
||||
}
|
||||
@@ -94,7 +95,6 @@ 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());
|
||||
mColorIndex = deck.meta_deck_colors;
|
||||
mDeckLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
DeckStats * DeckStats::mInstance = NULL;
|
||||
|
||||
DeckStat::DeckStat(int _nbgames, int _victories) : nbgames(_nbgames), victories(_victories)
|
||||
DeckStat::DeckStat(int nbgames, int victories, string manaColorIndex) : nbgames(nbgames), victories(victories), manaColorIndex( manaColorIndex)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -119,6 +119,22 @@ void DeckStats::load(const std::string& filename)
|
||||
|
||||
if (file)
|
||||
{
|
||||
// get the associated player deck file:
|
||||
int deckId = atoi(filename.substr(filename.find("_deck") + 5, filename.find(".txt")).c_str());
|
||||
char buffer[512];
|
||||
sprintf(buffer, "deck%i.txt", deckId);
|
||||
string playerDeckFilePath= options.profileFile( buffer);
|
||||
DeckMetaData *playerDeckMetaData = DeckManager::GetInstance()->getDeckMetaDataByFilename( playerDeckFilePath, false);
|
||||
// check if this player deck has already been profiled for manacolors
|
||||
char next = file.peek();
|
||||
string manaColorIndex = "";
|
||||
if ( next == 'M')
|
||||
{
|
||||
std::getline(file, s );
|
||||
manaColorIndex = s.substr( s.find(":") + 1);
|
||||
playerDeckMetaData->setColorIndex( manaColorIndex );
|
||||
}
|
||||
|
||||
while (std::getline(file, s))
|
||||
{
|
||||
string deckfile = s;
|
||||
@@ -126,11 +142,18 @@ void DeckStats::load(const std::string& filename)
|
||||
int games = atoi(s.c_str());
|
||||
std::getline(file, s);
|
||||
int victories = atoi(s.c_str());
|
||||
next = file.peek();
|
||||
|
||||
if ( next == 'M')
|
||||
{
|
||||
std::getline(file, s );
|
||||
manaColorIndex = s.substr( s.find(":") + 1);
|
||||
}
|
||||
if ( masterDeckStats[filename].find(deckfile) != masterDeckStats[filename].end())
|
||||
{
|
||||
SAFE_DELETE( masterDeckStats[filename][deckfile] );
|
||||
}
|
||||
DeckStat * newDeckStat = NEW DeckStat(games, victories);
|
||||
DeckStat * newDeckStat = NEW DeckStat(games, victories, manaColorIndex);
|
||||
(masterDeckStats[filename])[deckfile] = newDeckStat;
|
||||
}
|
||||
file.close();
|
||||
@@ -145,6 +168,20 @@ void DeckStats::save(const std::string& filename)
|
||||
{
|
||||
map<string, DeckStat *> stats = masterDeckStats[currentDeck];
|
||||
map<string, DeckStat *>::iterator it;
|
||||
string manaColorIndex = "";
|
||||
int deckId = atoi(filename.substr(filename.find("_deck") + 5, filename.find(".txt")).c_str());
|
||||
char buffer[512];
|
||||
sprintf(buffer, "deck%i.txt", deckId);
|
||||
string playerDeckFilePath= options.profileFile( buffer);
|
||||
DeckManager *deckManager = DeckManager::GetInstance();
|
||||
DeckMetaData *playerDeckMeta = deckManager->getDeckMetaDataByFilename(playerDeckFilePath, false);
|
||||
if ( playerDeckMeta->getColorIndex() == "" )
|
||||
{
|
||||
StatsWrapper *stw = deckManager->getExtendedDeckStats( playerDeckMeta, MTGAllCards::getInstance(), false);
|
||||
manaColorIndex = stw->getManaColorIndex();
|
||||
playerDeckMeta->setColorIndex( manaColorIndex );
|
||||
}
|
||||
file << "MANA:" << manaColorIndex << endl;
|
||||
for (it = stats.begin(); it != stats.end(); it++)
|
||||
{
|
||||
sprintf(writer, "%s\n", it->first.c_str());
|
||||
@@ -153,6 +190,7 @@ void DeckStats::save(const std::string& filename)
|
||||
file << writer;
|
||||
sprintf(writer, "%i\n", it->second->victories);
|
||||
file << writer;
|
||||
file << "MANA:" << it->second->manaColorIndex <<endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -173,14 +211,23 @@ void DeckStats::saveStats(Player *player, Player *opponent, GameObserver * game)
|
||||
load(currentDeck);
|
||||
map<string, DeckStat *> *stats = &masterDeckStats[currentDeck];
|
||||
map<string, DeckStat *>::iterator it = stats->find(opponent->deckFileSmall);
|
||||
string manaColorIndex = "";
|
||||
DeckManager *deckManager = DeckManager::GetInstance();
|
||||
DeckMetaData *aiDeckMeta = deckManager->getDeckMetaDataByFilename( opponent->deckFile, true);
|
||||
StatsWrapper *stw = deckManager->getExtendedDeckStats( aiDeckMeta, MTGAllCards::getInstance(), true);
|
||||
manaColorIndex = stw->getManaColorIndex();
|
||||
if (it == stats->end())
|
||||
{
|
||||
stats->insert( make_pair( opponent->deckFileSmall, NEW DeckStat(1, victory) ));
|
||||
stats->insert( make_pair( opponent->deckFileSmall, NEW DeckStat(1, victory, manaColorIndex) ));
|
||||
}
|
||||
else
|
||||
{
|
||||
it->second->victories += victory;
|
||||
it->second->nbgames += 1;
|
||||
if ( it->second->manaColorIndex == "" )
|
||||
{
|
||||
it->second->manaColorIndex = manaColorIndex;
|
||||
}
|
||||
}
|
||||
save(currentDeck);
|
||||
|
||||
@@ -300,6 +347,18 @@ void StatsWrapper::initStatistics(string deckstats)
|
||||
}
|
||||
}
|
||||
|
||||
string StatsWrapper::getManaColorIndex()
|
||||
{
|
||||
ostringstream oss;
|
||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
||||
if (totalCostPerColor[i] != 0)
|
||||
oss << "1";
|
||||
else
|
||||
oss <<"0";
|
||||
return oss.str();
|
||||
|
||||
}
|
||||
|
||||
void StatsWrapper::updateStats(string filename, MTGAllCards *collection)
|
||||
{
|
||||
if (FileExists(filename))
|
||||
|
||||
@@ -226,11 +226,6 @@ void GameStateDuel::End()
|
||||
if (!premadeDeck && mPlayers[0] && mPlayers[1])
|
||||
{ // save the stats for the game
|
||||
mPlayers[0]->End();
|
||||
if (mParent->players[1] != PLAYER_TYPE_TESTSUITE)
|
||||
{
|
||||
DeckManager::GetInstance()->saveDeck( mPlayers[1]->deckFile, MTGCollection());
|
||||
DeckManager::GetInstance()->saveDeck( mPlayers[0]->deckFile, MTGCollection());
|
||||
}
|
||||
}
|
||||
else if ( !mPlayers[1] && mPlayers[0] )
|
||||
// clean up player object
|
||||
|
||||
@@ -775,12 +775,6 @@ MTGDeck::MTGDeck(const char * config_file, MTGAllCards * _allcards, int meta_onl
|
||||
meta_desc.append(s.substr(found + 5));
|
||||
continue;
|
||||
}
|
||||
found = s.find("MANA:");
|
||||
if ( found != string::npos )
|
||||
{
|
||||
string colorIndex = s.substr(found + 5);
|
||||
meta_deck_colors = trim(colorIndex);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (meta_only) break;
|
||||
@@ -1042,26 +1036,7 @@ int MTGDeck::save(const string& destFileName, bool useExpandedDescriptions, cons
|
||||
|
||||
bool saveDetailedDeckInfo = options.get( Options::SAVEDETAILEDDECKINFO )->number == 1;
|
||||
|
||||
if ( filename.find("collection.dat") == string::npos )
|
||||
{
|
||||
// add in color information
|
||||
DeckManager *deckManager = DeckManager::GetInstance();
|
||||
file <<"#MANA:";
|
||||
|
||||
string deckId = filename.substr( filename.find("/deck")+5, filename.find(".txt") - (filename.find("/deck")+5) );
|
||||
bool isAI = filename.find("ai/baka") != string::npos;
|
||||
StatsWrapper *stats = deckManager->getExtendedStatsForDeckId( atoi(deckId.c_str()), this->database, isAI );
|
||||
|
||||
for (int i = Constants::MTG_COLOR_ARTIFACT; i < Constants::MTG_COLOR_LAND; ++i)
|
||||
{
|
||||
if (stats->totalCostPerColor[i] != 0)
|
||||
file << "1";
|
||||
else
|
||||
file <<"0";
|
||||
}
|
||||
file << endl;
|
||||
}
|
||||
else
|
||||
if ( filename.find("collection.dat") != string::npos )
|
||||
saveDetailedDeckInfo = false;
|
||||
|
||||
if (useExpandedDescriptions || saveDetailedDeckInfo)
|
||||
|
||||
Reference in New Issue
Block a user