-fixed shop refresh method problem (would not save correctly)
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-07-26 06:08:39 +00:00
parent ada385d358
commit 129334b93f
10 changed files with 41 additions and 22 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 981 B

View File

@@ -1154,8 +1154,7 @@ toughness=1
[card]
text=When Highway Robber comes into play, target opponent loses 2 life and you gain 2 life.
id=129564
target=player
auto=damage:2
auto=life:-2 opponent
auto=life:2 controller
name=Highway Robber
rarity=C

View File

@@ -33,6 +33,7 @@ class DeckDataWrapper{
~DeckDataWrapper();
int Add(MTGCard * card, int quantity = 1);
int Add(MTGDeck * deck);
int Remove(MTGCard * card);
MTGCard * getNext(MTGCard * previous = NULL, int color = -1);
MTGCard * getPrevious(MTGCard * next = NULL, int color = -1);

View File

@@ -777,7 +777,7 @@ class GameStateDeckViewer: public GameState, public JGuiListener
{
MTGCard * card = cardIndex[2];
if (card){
int rnd = (rand() % 20);
int rnd = (rand() % 25);
playerdata->credits += price;
price = price - (rnd * price)/100;
pricelist->setPrice(card->getMTGId(),price*2);

View File

@@ -26,7 +26,6 @@ class ShopItem:public JGuiObject{
JQuad * thumb;
float mScale;
float mTargetScale;
DeckDataWrapper * mDDW;
public:
@@ -37,6 +36,7 @@ class ShopItem:public JGuiObject{
ShopItem(int id, JLBFont * font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw);
ShopItem(int id, JLBFont * font, char* text, JQuad * _quad, JQuad * _thumb,int x, int y, bool hasFocus, int _price);
~ShopItem();
int updateCount(DeckDataWrapper * ddw);
virtual void Render();
virtual void Update(float dt);

View File

@@ -8,12 +8,18 @@ DeckDataWrapper::DeckDataWrapper(MTGDeck * deck){
for (int i = 0; i <= Constants::MTG_NB_COLORS; i++){
colors[i] = 0;
}
Add(deck);
currentColor = -1;
}
int DeckDataWrapper::Add(MTGDeck * deck){
map<int,int>::iterator it;
for (it = deck->cards.begin(); it!=deck->cards.end(); it++){
MTGCard * card = deck->getCardById(it->first);
Add(card,it->second);
}
currentColor = -1;
return 1;
}
void DeckDataWrapper::save(){

View File

@@ -47,6 +47,7 @@ void GameStateShop::Start()
void GameStateShop::load(){
if (shop) shop->saveAll();
SAFE_DELETE(shop);
int sets[500];
int boosterSets[500];

View File

@@ -530,6 +530,7 @@ int MTGDeck::remove(int cardid){
return 1;
}
int MTGDeck::remove(MTGCard * card){
if (!card) return 0;
return (remove(card->getId()));

View File

@@ -20,7 +20,6 @@ ShopItem::ShopItem(int id, JLBFont *font, char* text, JQuad * _quad,JQuad * _thu
ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFocus, MTGAllCards * collection, int _price, DeckDataWrapper * ddw): JGuiObject(id), mFont(font), mX(x), mY(y), price(_price){
mHasFocus = hasFocus;
mDDW = ddw;
mScale = 1.0f;
mTargetScale = 1.0f;
@@ -28,7 +27,7 @@ ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFoc
Entering();
card = collection->getCardById(_cardid);
nameCount = mDDW->countByName(card);
updateCount(ddw);
quantity = 1 + (rand() % 4);
if (card->getRarity() == Constants::RARITY_L) quantity = 50;
@@ -37,6 +36,12 @@ ShopItem::ShopItem(int id, JLBFont *font, int _cardid, int x, int y, bool hasFoc
}
int ShopItem::updateCount(DeckDataWrapper * ddw){
if (!card) return 0;
nameCount = ddw->countByName(card);
return nameCount;
}
ShopItem::~ShopItem(){
}
@@ -242,13 +247,15 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
if (playerdata->credits >= price){
playerdata->credits -= price;
if (item->card){
int rnd = (rand() % 5);
price = price + (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
playerdata->collection->add(item->card);
item->quantity--;
item->nameCount++;
}else{
int rnd = (rand() % 25);
price = price + (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
playerdata->collection->add(item->card);
item->quantity--;
myCollection->Add(item->card);
item->nameCount++;
item->price = price;
}else{
safeDeleteDisplay();
display = NEW CardDisplay(12,NULL, SCREEN_WIDTH - 200, SCREEN_HEIGHT/2,this,NULL,5);
@@ -257,10 +264,20 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
int rnd = rand() % 8;
if (rnd == 0) rare_or_mythic = Constants::RARITY_M;
int sets[] = {setIds[showPriceDialog]};
//for (int i= 0; i <15; i++){
// tempDeck->add(136218);
//}
tempDeck->addRandomCards(1, sets,1,rare_or_mythic);
tempDeck->addRandomCards(3, sets,1,Constants::RARITY_U);
tempDeck->addRandomCards(11, sets,1,Constants::RARITY_C);
playerdata->collection->add(tempDeck);
myCollection->Add(tempDeck);
for (int j = 0; j < mCount; j++){
ShopItem * si = ((ShopItem *)mObjects[j]);
si->updateCount(myCollection);
}
int i = 0;
@@ -272,12 +289,6 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
display->AddCard(card);
i++;
}
for (int j = 0; j < mCount; j++){
ShopItem * si = ((ShopItem *)mObjects[j]);
if (si->card && si->card->name.compare(c->name) == 0){
si->nameCount+= it->second;
}
}
}
delete tempDeck;
}
@@ -289,9 +300,10 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
break;
case 2:
if (item->card){
int rnd = (rand() % 5);
int rnd = (rand() % 25);
price = price - (rnd * price)/100;
pricelist->setPrice(item->card->getMTGId(),price);
item->price = price;
}
showPriceDialog = -1;
break;
@@ -334,7 +346,6 @@ ostream& ShopItem::toString(ostream& out) const
<< " ; thumb : " << thumb
<< " ; mScale : " << mScale
<< " ; mTargetScale : " << mTargetScale
<< " ; mDDW : " << mDDW
<< " ; nameCount : " << nameCount
<< " ; quantity : " << quantity
<< " ; card : " << card