From 129334b93f09f1b22e972fba872f04e634ecd092 Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Sun, 26 Jul 2009 06:08:39 +0000 Subject: [PATCH] Erwan -fixed shop refresh method problem (would not save correctly) --- projects/mtg/bin/Res/graphics/smallface.dat | Bin 0 -> 2048 bytes projects/mtg/bin/Res/graphics/smallface.png | Bin 0 -> 981 bytes projects/mtg/bin/Res/sets/10E/_cards.dat | 3 +- projects/mtg/include/DeckDataWrapper.h | 1 + projects/mtg/include/GameStateDeckViewer.h | 2 +- projects/mtg/include/ShopItem.h | 2 +- projects/mtg/src/DeckDataWrapper.cpp | 8 +++- projects/mtg/src/GameStateShop.cpp | 1 + projects/mtg/src/MTGDeck.cpp | 1 + projects/mtg/src/ShopItem.cpp | 45 ++++++++++++-------- 10 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 projects/mtg/bin/Res/graphics/smallface.dat create mode 100644 projects/mtg/bin/Res/graphics/smallface.png diff --git a/projects/mtg/bin/Res/graphics/smallface.dat b/projects/mtg/bin/Res/graphics/smallface.dat new file mode 100644 index 0000000000000000000000000000000000000000..adddccfd289797433874235192d163d84631d00a GIT binary patch literal 2048 zcmeIxOG^S#6ae6xnpviqW?E|YqOb=f^dbr~NZS+y(V`YXyZ-+lDCd4Ozo1pl=HndB z%)R%VJ0ax4V<>c8@-wW9!K4xG2rTQCnx8i&8gE%lk44ofy`glX(f`uqAoByDx`7I;J!Gca%qgD@k*tT_@uLG}_)Usv`UJTiQe22lrFtAIk1C9V-A&iT2y zsd*&~&PAz-C8;S2<(VZJ3hti10pX2&;tUMT2A(dCAr-gY&c5BZ+JMJ(`HKJlPuu!W zUBq#_+WJ6a*4pVag@h(a+@JK}JNy3Q&p-b>^S}T4s@KMmbNBw<^jx!c=IQ=ZzyAIGXCF7eb6x-W*|#OS z(aMT$VhXQ6`_H&>!YAxmkm2>NpQn7bD?eC1>)cbn`EQwJ9e3LmJdI>vNK=@=sxonA z$e+t`v8qcueicu-S#tJwZi_hQBH<2;(p_&?)`qY?U|+SK_w-Cy)o-)X$LS?b)oJ&At zch2;?GJURHuygs=Go40LPZ(OUY&&%OinhDZ=CT-br!0mK9#-tLuKcz-t{uk5TCRM2)xG3>y(`2b z@BW^$bmvd$F73Fm=OzcX*O!YtT4r@#hb8`Mf%^JaUoQHp&r7j2H?8VoTh6oN^FuH7 zUBRpyHr@Wn!I)MV@>Om3{PNPG<$hWlc2#^Rj@Mv3Fmd9{s$Y?Num9Y0hV%bivpG|q zzI*BPl6kSoK~K$1>nql)dHddZT`up2`dh5{n)v9!eIQ*IvpbdBNcT gI}FVdQ&MBb@0E#ubxBvhE literal 0 HcmV?d00001 diff --git a/projects/mtg/bin/Res/sets/10E/_cards.dat b/projects/mtg/bin/Res/sets/10E/_cards.dat index d3f88ecb0..9e5648523 100644 --- a/projects/mtg/bin/Res/sets/10E/_cards.dat +++ b/projects/mtg/bin/Res/sets/10E/_cards.dat @@ -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 diff --git a/projects/mtg/include/DeckDataWrapper.h b/projects/mtg/include/DeckDataWrapper.h index b469f2986..abd00c9c2 100644 --- a/projects/mtg/include/DeckDataWrapper.h +++ b/projects/mtg/include/DeckDataWrapper.h @@ -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); diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 96eaab305..9377f111b 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -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); diff --git a/projects/mtg/include/ShopItem.h b/projects/mtg/include/ShopItem.h index 52500e199..10e7b8b36 100644 --- a/projects/mtg/include/ShopItem.h +++ b/projects/mtg/include/ShopItem.h @@ -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); diff --git a/projects/mtg/src/DeckDataWrapper.cpp b/projects/mtg/src/DeckDataWrapper.cpp index 9fd4e4fcb..aeba86f9f 100644 --- a/projects/mtg/src/DeckDataWrapper.cpp +++ b/projects/mtg/src/DeckDataWrapper.cpp @@ -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::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(){ diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index 345e4ef0f..3ef6f6062 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -47,6 +47,7 @@ void GameStateShop::Start() void GameStateShop::load(){ + if (shop) shop->saveAll(); SAFE_DELETE(shop); int sets[500]; int boosterSets[500]; diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index f9ed81ba7..c4653965e 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -530,6 +530,7 @@ int MTGDeck::remove(int cardid){ return 1; } + int MTGDeck::remove(MTGCard * card){ if (!card) return 0; return (remove(card->getId())); diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index 3370b19af..33422a2de 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -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