From 251f89d7b964806f707c7ebcb3fa5fd6cc6ed7fd Mon Sep 17 00:00:00 2001 From: "wagic.jeck" Date: Mon, 8 Feb 2010 20:13:48 +0000 Subject: [PATCH] Jeck - Consolidated card price functions from deckviewer/shop into PriceList. Also moved price discount hash variable. (As of around r1825, price discount has been based on (mtgid + static int randomKey) % 20. randomKey updates at the end of any won game, making prices for a given fixed between visits to the shop on the same "day") --- projects/mtg/include/GameStateShop.h | 5 ----- projects/mtg/include/MTGDefinitions.h | 4 ++++ projects/mtg/include/PriceList.h | 4 ++++ projects/mtg/src/Credits.cpp | 2 +- projects/mtg/src/GameStateDeckViewer.cpp | 4 +--- projects/mtg/src/GameStateShop.cpp | 8 +------- projects/mtg/src/PriceList.cpp | 14 ++++++++++++-- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/projects/mtg/include/GameStateShop.h b/projects/mtg/include/GameStateShop.h index 15d19f591..07e05bed6 100644 --- a/projects/mtg/include/GameStateShop.h +++ b/projects/mtg/include/GameStateShop.h @@ -80,14 +80,9 @@ class GameStateShop: public GameState, public JGuiListener void purchaseBooster(int controlId); int purchasePrice(int offset); string descPurchase(int controlId, bool tiny = false); - - - static int randomKey; public: GameStateShop(GameApp* parent); virtual ~GameStateShop(); - - static void passOneDay() {randomKey = rand();}; virtual void Start(); virtual void End(); virtual void Create(); diff --git a/projects/mtg/include/MTGDefinitions.h b/projects/mtg/include/MTGDefinitions.h index 9cae4f232..6563ce884 100644 --- a/projects/mtg/include/MTGDefinitions.h +++ b/projects/mtg/include/MTGDefinitions.h @@ -114,6 +114,10 @@ class Constants RARITY_L = 'L', //Lands RARITY_T = 'T', //Tokens + //Price flux + PRICE_FLUX_RANGE = 20, + PRICE_FLUX_MINUS = 10, + //Price for singles PRICE_1M = 3000, PRICE_1R = 500, diff --git a/projects/mtg/include/PriceList.h b/projects/mtg/include/PriceList.h index aa5a06c14..007f12796 100644 --- a/projects/mtg/include/PriceList.h +++ b/projects/mtg/include/PriceList.h @@ -13,12 +13,16 @@ class PriceList{ MTGAllCards * collection; string filename; map prices; + static int randomKey; public: PriceList(const char * file, MTGAllCards * _collection); ~PriceList(); int save(); + int getSellPrice(int cardid); + int getPurchasePrice(int cardid); int getPrice(int cardId); int setPrice(int cardId, int price); + static void updateKey() {randomKey = rand();}; }; #endif diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index f8fbb9d66..4003d4ace 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -151,7 +151,7 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){ playerdata->credits += value; - GameStateShop::passOneDay(); + PriceList::updateKey(); playerdata->taskList->passOneDay(); if (playerdata->taskList->getTaskCount() < 6) { playerdata->taskList->addRandomTask(); diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 5d7c74ffd..9eeff865b 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -327,9 +327,7 @@ void GameStateDeckViewer::Update(float dt) { MTGCard * card = cardIndex[2]; if (card && displayed_deck->count(card)){ - int rnd = (rand() % 20); - price = pricelist->getPrice(card->getMTGId()) / 2; - price = price - price * (rnd -10)/100; + int price = pricelist->getSellPrice(card->getMTGId()); sprintf(buffer,"%s : %i %s",_(card->data->getName()).c_str(),price,_("credits").c_str()); sellMenu = NEW SimpleMenu(2,this,Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); sellMenu->Add(20,"Yes"); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index 115a3b5fb..092240be2 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -22,8 +22,6 @@ float GameStateShop::_y3[] = {164,205,257,184,180,170,219,212,195,251,252}; float GameStateShop::_x4[] = { 76, 90, 65,131,171,221,123,187,225,141,237}; float GameStateShop::_y4[] = {169,188,250,182,182,168,220,208,198,259,245}; -int GameStateShop::randomKey = 0; - GameStateShop::GameStateShop(GameApp* parent): GameState(parent) { menu = NULL; for(int i=0;i<8;i++) @@ -48,8 +46,6 @@ GameStateShop::GameStateShop(GameApp* parent): GameState(parent) { mCounts[i] = 0; } mTouched = false; - if(randomKey == 0) - randomKey = rand(); } @@ -284,9 +280,7 @@ int GameStateShop::purchasePrice(int offset){ MTGCard * c = NULL; if(!pricelist || !srcCards || (c = srcCards->getCard(offset)) == NULL) return 0; - int rnd = abs(c->getMTGId() + randomKey) % 20; - float price = (float) pricelist->getPrice(c->getMTGId()); - price = price + price * (rnd -10)/100; + float price = (float) pricelist->getPurchasePrice(c->getMTGId()); return (int) (price + price * srcCards->filterFee()); } diff --git a/projects/mtg/src/PriceList.cpp b/projects/mtg/src/PriceList.cpp index e88063610..4fb952c8b 100644 --- a/projects/mtg/src/PriceList.cpp +++ b/projects/mtg/src/PriceList.cpp @@ -1,7 +1,7 @@ #include "../include/config.h" #include "../include/PriceList.h" - +int PriceList::randomKey = 0; PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){ filename = _filename; @@ -15,6 +15,8 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti } file.close(); } + if(randomKey == 0) + randomKey = rand(); } @@ -60,7 +62,6 @@ int PriceList::getPrice(int cardId){ default: return Constants::PRICE_1C; break; - } } @@ -69,3 +70,12 @@ int PriceList::setPrice(int cardId, int price){ prices[cardId] = price; return price; } +int PriceList::getSellPrice(int cardid){ + return getPurchasePrice(cardid) / 2; +} +int PriceList::getPurchasePrice(int cardid){ + float price = (float) getPrice(cardid); + int rnd = abs(cardid + randomKey) % (1+Constants::PRICE_FLUX_RANGE); + price += price * (float)(rnd - Constants::PRICE_FLUX_MINUS)/100.0f; + return price; +}