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")

This commit is contained in:
wagic.jeck
2010-02-08 20:13:48 +00:00
parent 907c0b7b5d
commit 251f89d7b9
7 changed files with 23 additions and 18 deletions

View File

@@ -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();

View File

@@ -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,

View File

@@ -13,12 +13,16 @@ class PriceList{
MTGAllCards * collection;
string filename;
map<int,int> 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

View File

@@ -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();

View File

@@ -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");

View File

@@ -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());
}

View File

@@ -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;
}