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:
@@ -80,14 +80,9 @@ class GameStateShop: public GameState, public JGuiListener
|
|||||||
void purchaseBooster(int controlId);
|
void purchaseBooster(int controlId);
|
||||||
int purchasePrice(int offset);
|
int purchasePrice(int offset);
|
||||||
string descPurchase(int controlId, bool tiny = false);
|
string descPurchase(int controlId, bool tiny = false);
|
||||||
|
|
||||||
|
|
||||||
static int randomKey;
|
|
||||||
public:
|
public:
|
||||||
GameStateShop(GameApp* parent);
|
GameStateShop(GameApp* parent);
|
||||||
virtual ~GameStateShop();
|
virtual ~GameStateShop();
|
||||||
|
|
||||||
static void passOneDay() {randomKey = rand();};
|
|
||||||
virtual void Start();
|
virtual void Start();
|
||||||
virtual void End();
|
virtual void End();
|
||||||
virtual void Create();
|
virtual void Create();
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ class Constants
|
|||||||
RARITY_L = 'L', //Lands
|
RARITY_L = 'L', //Lands
|
||||||
RARITY_T = 'T', //Tokens
|
RARITY_T = 'T', //Tokens
|
||||||
|
|
||||||
|
//Price flux
|
||||||
|
PRICE_FLUX_RANGE = 20,
|
||||||
|
PRICE_FLUX_MINUS = 10,
|
||||||
|
|
||||||
//Price for singles
|
//Price for singles
|
||||||
PRICE_1M = 3000,
|
PRICE_1M = 3000,
|
||||||
PRICE_1R = 500,
|
PRICE_1R = 500,
|
||||||
|
|||||||
@@ -13,12 +13,16 @@ class PriceList{
|
|||||||
MTGAllCards * collection;
|
MTGAllCards * collection;
|
||||||
string filename;
|
string filename;
|
||||||
map<int,int> prices;
|
map<int,int> prices;
|
||||||
|
static int randomKey;
|
||||||
public:
|
public:
|
||||||
PriceList(const char * file, MTGAllCards * _collection);
|
PriceList(const char * file, MTGAllCards * _collection);
|
||||||
~PriceList();
|
~PriceList();
|
||||||
int save();
|
int save();
|
||||||
|
int getSellPrice(int cardid);
|
||||||
|
int getPurchasePrice(int cardid);
|
||||||
int getPrice(int cardId);
|
int getPrice(int cardId);
|
||||||
int setPrice(int cardId, int price);
|
int setPrice(int cardId, int price);
|
||||||
|
static void updateKey() {randomKey = rand();};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
|||||||
|
|
||||||
|
|
||||||
playerdata->credits += value;
|
playerdata->credits += value;
|
||||||
GameStateShop::passOneDay();
|
PriceList::updateKey();
|
||||||
playerdata->taskList->passOneDay();
|
playerdata->taskList->passOneDay();
|
||||||
if (playerdata->taskList->getTaskCount() < 6) {
|
if (playerdata->taskList->getTaskCount() < 6) {
|
||||||
playerdata->taskList->addRandomTask();
|
playerdata->taskList->addRandomTask();
|
||||||
|
|||||||
@@ -327,9 +327,7 @@ void GameStateDeckViewer::Update(float dt)
|
|||||||
{
|
{
|
||||||
MTGCard * card = cardIndex[2];
|
MTGCard * card = cardIndex[2];
|
||||||
if (card && displayed_deck->count(card)){
|
if (card && displayed_deck->count(card)){
|
||||||
int rnd = (rand() % 20);
|
int price = pricelist->getSellPrice(card->getMTGId());
|
||||||
price = pricelist->getPrice(card->getMTGId()) / 2;
|
|
||||||
price = price - price * (rnd -10)/100;
|
|
||||||
sprintf(buffer,"%s : %i %s",_(card->data->getName()).c_str(),price,_("credits").c_str());
|
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 = NEW SimpleMenu(2,this,Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
|
||||||
sellMenu->Add(20,"Yes");
|
sellMenu->Add(20,"Yes");
|
||||||
|
|||||||
@@ -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::_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};
|
float GameStateShop::_y4[] = {169,188,250,182,182,168,220,208,198,259,245};
|
||||||
|
|
||||||
int GameStateShop::randomKey = 0;
|
|
||||||
|
|
||||||
GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {
|
GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {
|
||||||
menu = NULL;
|
menu = NULL;
|
||||||
for(int i=0;i<8;i++)
|
for(int i=0;i<8;i++)
|
||||||
@@ -48,8 +46,6 @@ GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {
|
|||||||
mCounts[i] = 0;
|
mCounts[i] = 0;
|
||||||
}
|
}
|
||||||
mTouched = false;
|
mTouched = false;
|
||||||
if(randomKey == 0)
|
|
||||||
randomKey = rand();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -284,9 +280,7 @@ int GameStateShop::purchasePrice(int offset){
|
|||||||
MTGCard * c = NULL;
|
MTGCard * c = NULL;
|
||||||
if(!pricelist || !srcCards || (c = srcCards->getCard(offset)) == NULL)
|
if(!pricelist || !srcCards || (c = srcCards->getCard(offset)) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
int rnd = abs(c->getMTGId() + randomKey) % 20;
|
float price = (float) pricelist->getPurchasePrice(c->getMTGId());
|
||||||
float price = (float) pricelist->getPrice(c->getMTGId());
|
|
||||||
price = price + price * (rnd -10)/100;
|
|
||||||
return (int) (price + price * srcCards->filterFee());
|
return (int) (price + price * srcCards->filterFee());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "../include/config.h"
|
#include "../include/config.h"
|
||||||
#include "../include/PriceList.h"
|
#include "../include/PriceList.h"
|
||||||
|
|
||||||
|
int PriceList::randomKey = 0;
|
||||||
|
|
||||||
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collection(_collection){
|
||||||
filename = _filename;
|
filename = _filename;
|
||||||
@@ -15,6 +15,8 @@ PriceList::PriceList(const char * _filename, MTGAllCards * _collection):collecti
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
if(randomKey == 0)
|
||||||
|
randomKey = rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +62,6 @@ int PriceList::getPrice(int cardId){
|
|||||||
default:
|
default:
|
||||||
return Constants::PRICE_1C;
|
return Constants::PRICE_1C;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,3 +70,12 @@ int PriceList::setPrice(int cardId, int price){
|
|||||||
prices[cardId] = price;
|
prices[cardId] = price;
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user