Erwan
- reduced price of boosters - Sets need to be unlocked in order to be accessed from the shop - Added a "refresh" option in the shop
This commit is contained in:
BIN
projects/mtg/bin/Res/graphics/set_unlocked.png
Normal file
BIN
projects/mtg/bin/Res/graphics/set_unlocked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -26,6 +26,7 @@ private:
|
||||
int isMomirUnlocked();
|
||||
int isEvilTwinUnlocked();
|
||||
int isRandomDeckUnlocked();
|
||||
int unlockRandomSet();
|
||||
public:
|
||||
int value;
|
||||
Player * p1, *p2;
|
||||
@@ -34,6 +35,7 @@ public:
|
||||
int unlocked;
|
||||
JQuad * unlockedQuad;
|
||||
JTexture * unlockedTex;
|
||||
string unlockedString;
|
||||
vector<CreditBonus *> bonus;
|
||||
Credits();
|
||||
~Credits();
|
||||
|
||||
@@ -29,7 +29,7 @@ class GameStateShop: public GameState, public JGuiListener
|
||||
char starterBuffer[128], boosterBuffer[128];
|
||||
char setNames[SHOP_BOOSTERS][128];
|
||||
int setIds[SHOP_BOOSTERS];
|
||||
|
||||
void load();
|
||||
public:
|
||||
GameStateShop(GameApp* parent);
|
||||
virtual ~GameStateShop();
|
||||
|
||||
@@ -23,7 +23,7 @@ class GameApp;
|
||||
class MTGCard;
|
||||
|
||||
|
||||
#define MAX_SETS 50
|
||||
#define MAX_SETS 100
|
||||
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class MTGDeck{
|
||||
int totalCards();
|
||||
MTGDeck(TexturesCache * cache, MTGAllCards * _allcards);
|
||||
MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards, int meta_only = 0);
|
||||
int addRandomCards(int howmany, int setId = -1, int rarity = -1, const char * subtype = NULL, int * colors = NULL, int nbcolors = 0);
|
||||
int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const char * subtype = NULL, int * colors = NULL, int nbcolors = 0);
|
||||
int add(int cardid);
|
||||
int add(MTGDeck * deck); // adds the contents of "deck" into myself
|
||||
int remove(int cardid);
|
||||
|
||||
@@ -744,6 +744,10 @@ while( iter != mObjects.end() ){
|
||||
}
|
||||
|
||||
void ActionStack::Fizzle(Interruptible * action){
|
||||
if (!action){
|
||||
OutputDebugString("==ERROR==: action is NULL in ActionStack::Fizzle\n");
|
||||
return;
|
||||
}
|
||||
if (action->type == ACTION_SPELL){
|
||||
Spell * spell = (Spell *) action;
|
||||
spell->source->controller()->game->putInGraveyard(spell->source);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../include/PlayerData.h"
|
||||
#include "../include/DeckStats.h"
|
||||
#include "../include/Translate.h"
|
||||
#include "../include/MTGDeck.h"
|
||||
|
||||
CreditBonus::CreditBonus(int _value, string _text){
|
||||
value = _value;
|
||||
@@ -93,6 +94,14 @@ void Credits::compute(Player * _p1, Player * _p2, GameApp * _app){
|
||||
unlockedQuad = NEW JQuad(unlockedTex, 2, 2, 396, 96);
|
||||
GameOptions::GetInstance()->values[OPTIONS_RANDOMDECK_MODE_UNLOCKED] = GameOption(1);
|
||||
GameOptions::GetInstance()->save();
|
||||
}else if(unlocked = unlockRandomSet()) {
|
||||
unlockedTex = JRenderer::GetInstance()->LoadTexture("graphics/set_unlocked.png", TEX_TYPE_USE_VRAM);
|
||||
unlockedQuad = NEW JQuad(unlockedTex, 2, 2, 396, 96);
|
||||
char buffer[4096];
|
||||
unlockedString = MtgSets::SetsList->values[unlocked -1];
|
||||
sprintf(buffer,"unlocked_%s", unlockedString.c_str());
|
||||
GameOptions::GetInstance()->values[buffer] = GameOption(1);
|
||||
GameOptions::GetInstance()->save();
|
||||
}
|
||||
if (unlocked){
|
||||
JSample * sample = SampleCache::GetInstance()->getSample("sound/sfx/bonus.wav");
|
||||
@@ -138,6 +147,9 @@ void Credits::Render(){
|
||||
showMsg = 0;
|
||||
r->RenderQuad(unlockedQuad, 20, 20);
|
||||
}
|
||||
if(unlockedString.size()){
|
||||
f2->DrawString(unlockedString.c_str(),SCREEN_WIDTH/2, 80,JGETEXT_CENTER);
|
||||
}
|
||||
}else{
|
||||
sprintf (buffer, _("You have been defeated").c_str());
|
||||
}
|
||||
@@ -215,3 +227,13 @@ int Credits::isRandomDeckUnlocked(){
|
||||
if (p1->life >= 20 ) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Credits::unlockRandomSet(){
|
||||
if (rand() % 2) return 0;
|
||||
int setId = rand() % MtgSets::SetsList->nb_items;
|
||||
char buffer[4096];
|
||||
string s = MtgSets::SetsList->values[setId];
|
||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||
if (GameOptions::GetInstance()->values[buffer].getIntValue() == 1 ) return 0;
|
||||
return setId+1;
|
||||
}
|
||||
|
||||
@@ -119,15 +119,15 @@ void GameStateDuel::loadPlayerRandom(int playerId, int isAI, int mode){
|
||||
|
||||
|
||||
MTGDeck * tempDeck = NEW MTGDeck(NULL, mParent->collection);
|
||||
tempDeck->addRandomCards(9,-1,-1,lands[color1].c_str());
|
||||
tempDeck->addRandomCards(9,-1,-1,lands[color2].c_str());
|
||||
tempDeck->addRandomCards(1,-1,'U',"land",colors,nbcolors);
|
||||
tempDeck->addRandomCards(1,-1,'R',"land",colors,nbcolors);
|
||||
tempDeck->addRandomCards(12,-1,-1,"creature",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,-1,-1,"sorcery",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,-1,-1,"enchantment",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,-1,-1,"instant",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,-1,-1,"artifact",colors,nbcolors);
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color1].c_str());
|
||||
tempDeck->addRandomCards(9,0,0,-1,lands[color2].c_str());
|
||||
tempDeck->addRandomCards(1,0,0,'U',"land",colors,nbcolors);
|
||||
tempDeck->addRandomCards(1,0,0,'R',"land",colors,nbcolors);
|
||||
tempDeck->addRandomCards(12,0,0,-1,"creature",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"sorcery",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"enchantment",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"instant",colors,nbcolors);
|
||||
tempDeck->addRandomCards(2,0,0,-1,"artifact",colors,nbcolors);
|
||||
|
||||
char * deckFile = "random";
|
||||
string deckFileSmall = "random";
|
||||
|
||||
@@ -290,17 +290,24 @@ void GameStateMenu::Update(float dt)
|
||||
break;
|
||||
case MENU_STATE_MAJOR_FIRST_TIME :
|
||||
{
|
||||
//Give the player cards from the set for which we have the most variety
|
||||
int setId = 0;
|
||||
int maxcards = 0;
|
||||
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
|
||||
int value = mParent->collection->countBySet(i);
|
||||
if (value > maxcards){
|
||||
maxcards = value;
|
||||
setId = i;
|
||||
}
|
||||
}
|
||||
createUsersFirstDeck(setId);
|
||||
//Give the player cards from the set for which we have the most variety
|
||||
int setId = 0;
|
||||
int maxcards = 0;
|
||||
for (int i=0; i< MtgSets::SetsList->nb_items; i++){
|
||||
int value = mParent->collection->countBySet(i);
|
||||
if (value > maxcards){
|
||||
maxcards = value;
|
||||
setId = i;
|
||||
}
|
||||
}
|
||||
//Save this set as "unlocked"
|
||||
string s = MtgSets::SetsList->values[setId];
|
||||
char buffer[4096];
|
||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||
GameOptions::GetInstance()->values[buffer] = GameOption(1);
|
||||
GameOptions::GetInstance()->save();
|
||||
|
||||
createUsersFirstDeck(setId);
|
||||
}
|
||||
currentState = MENU_STATE_MAJOR_MAINMENU | MENU_STATE_MINOR_NONE;
|
||||
break;
|
||||
@@ -388,20 +395,21 @@ void GameStateMenu::createUsersFirstDeck(int setId){
|
||||
#endif
|
||||
MTGDeck *mCollection = NEW MTGDeck(RESPATH"/player/collection.dat", mParent->cache, mParent->collection);
|
||||
//10 lands of each
|
||||
if (!mCollection->addRandomCards(10, setId,Constants::RARITY_L,"Forest")){
|
||||
mCollection->addRandomCards(10, -1,Constants::RARITY_L,"Forest");
|
||||
int sets[] = {setId};
|
||||
if (!mCollection->addRandomCards(10, sets,1, Constants::RARITY_L,"Forest")){
|
||||
mCollection->addRandomCards(10, 0,0,Constants::RARITY_L,"Forest");
|
||||
}
|
||||
if (!mCollection->addRandomCards(10, setId,Constants::RARITY_L,"Plains")){
|
||||
mCollection->addRandomCards(10, -1,Constants::RARITY_L,"Plains");
|
||||
if (!mCollection->addRandomCards(10, sets,1,Constants::RARITY_L,"Plains")){
|
||||
mCollection->addRandomCards(10, 0,0,Constants::RARITY_L,"Plains");
|
||||
}
|
||||
if (!mCollection->addRandomCards(10, setId,Constants::RARITY_L,"Swamp")){
|
||||
mCollection->addRandomCards(10, -1,Constants::RARITY_L,"Swamp");
|
||||
if (!mCollection->addRandomCards(10, sets,1,Constants::RARITY_L,"Swamp")){
|
||||
mCollection->addRandomCards(10, 0,0,Constants::RARITY_L,"Swamp");
|
||||
}
|
||||
if (!mCollection->addRandomCards(10, setId,Constants::RARITY_L,"Mountain")){
|
||||
mCollection->addRandomCards(10, -1,Constants::RARITY_L,"Mountain");
|
||||
if (!mCollection->addRandomCards(10, sets,1,Constants::RARITY_L,"Mountain")){
|
||||
mCollection->addRandomCards(10, 0,0,Constants::RARITY_L,"Mountain");
|
||||
}
|
||||
if (!mCollection->addRandomCards(10, setId,Constants::RARITY_L,"Island")){
|
||||
mCollection->addRandomCards(10, -1,Constants::RARITY_L,"Island");
|
||||
if (!mCollection->addRandomCards(10, sets,1,Constants::RARITY_L,"Island")){
|
||||
mCollection->addRandomCards(10, 0,0,Constants::RARITY_L,"Island");
|
||||
}
|
||||
|
||||
|
||||
@@ -410,18 +418,18 @@ void GameStateMenu::createUsersFirstDeck(int setId){
|
||||
#endif
|
||||
|
||||
//Starter Deck
|
||||
mCollection->addRandomCards(3, setId,Constants::RARITY_R,NULL);
|
||||
mCollection->addRandomCards(9, setId,Constants::RARITY_U,NULL);
|
||||
mCollection->addRandomCards(48, setId,Constants::RARITY_C,NULL);
|
||||
mCollection->addRandomCards(3, sets,1,Constants::RARITY_R,NULL);
|
||||
mCollection->addRandomCards(9, sets,1,Constants::RARITY_U,NULL);
|
||||
mCollection->addRandomCards(48, sets,1,Constants::RARITY_C,NULL);
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
OutputDebugString("2\n");
|
||||
#endif
|
||||
//Boosters
|
||||
for (int i = 0; i< 2; i++){
|
||||
mCollection->addRandomCards(1, setId,Constants::RARITY_R);
|
||||
mCollection->addRandomCards(3, setId,Constants::RARITY_U);
|
||||
mCollection->addRandomCards(11, setId,Constants::RARITY_C);
|
||||
mCollection->addRandomCards(1, sets,1,Constants::RARITY_R);
|
||||
mCollection->addRandomCards(3, sets,1,Constants::RARITY_U);
|
||||
mCollection->addRandomCards(11, sets,1,Constants::RARITY_C);
|
||||
}
|
||||
mCollection->save();
|
||||
SAFE_DELETE(mCollection);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "../include/GameApp.h"
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/Translate.h"
|
||||
|
||||
#include "../include/GameOptions.h"
|
||||
|
||||
GameStateShop::GameStateShop(GameApp* parent): GameState(parent) {}
|
||||
|
||||
@@ -40,17 +40,55 @@ void GameStateShop::Start()
|
||||
JRenderer::GetInstance()->EnableVSync(true);
|
||||
|
||||
|
||||
shop = NULL;
|
||||
load();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GameStateShop::load(){
|
||||
SAFE_DELETE(shop);
|
||||
int sets[500];
|
||||
int boosterSets[500];
|
||||
int unlocked[500];
|
||||
int nbsets = 0;
|
||||
int nbboostersets = 0;
|
||||
|
||||
//Unlock a default set if no set is unlocked
|
||||
int ok = 0;
|
||||
int defaultSet = 0;
|
||||
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){
|
||||
if (mParent->collection->countBySet(i) > 80){ //Only sets with more than 80 cards can get boosters and starters
|
||||
sets[nbsets] = i;
|
||||
nbsets++;
|
||||
string s = MtgSets::SetsList->values[i];
|
||||
if (s.compare("10E") == 0) defaultSet = i;
|
||||
char buffer[4096];
|
||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||
unlocked[i] = GameOptions::GetInstance()->values[buffer].getIntValue();
|
||||
if ( unlocked[i] ){
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
if (nbsets){
|
||||
if (!ok){
|
||||
unlocked[defaultSet] = 1;
|
||||
string s = MtgSets::SetsList->values[defaultSet];
|
||||
char buffer[4096];
|
||||
sprintf(buffer,"unlocked_%s", s.c_str());
|
||||
GameOptions::GetInstance()->values[buffer] = GameOption(1);
|
||||
GameOptions::GetInstance()->save();
|
||||
}
|
||||
|
||||
for (int i = 0; i < MtgSets::SetsList->nb_items; i++){
|
||||
if (unlocked[i] ){
|
||||
sets[nbsets] = i;
|
||||
nbsets++;
|
||||
if (mParent->collection->countBySet(i) > 80){ //Only sets with more than 80 cards can get boosters and starters
|
||||
boosterSets[nbboostersets] = i;
|
||||
nbboostersets++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nbboostersets){
|
||||
for (int i = 0; i < SHOP_BOOSTERS; i++){
|
||||
setIds[i] = sets[(rand() % nbsets)];
|
||||
setIds[i] = boosterSets[(rand() % nbboostersets)];
|
||||
}
|
||||
}else{
|
||||
for (int i = 0; i < SHOP_BOOSTERS; i++){
|
||||
@@ -59,21 +97,24 @@ void GameStateShop::Start()
|
||||
}
|
||||
JQuad * mBackThumb = GameApp::CommonRes->GetQuad("back_thumb");
|
||||
|
||||
shop = NULL;
|
||||
|
||||
|
||||
shop = NEW ShopItems(10, this, itemFont, 10, 0, mParent->collection, setIds);
|
||||
for (int i = 0; i < SHOP_BOOSTERS; i++){
|
||||
sprintf(setNames[i], "%s Booster (15 %s)",MtgSets::SetsList->values[setIds[i]].c_str(), _("cards").c_str());
|
||||
shop->Add(setNames[i],mBack,mBackThumb, 1200);
|
||||
shop->Add(setNames[i],mBack,mBackThumb, 700);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++){
|
||||
shop->Add(mParent->collection->randomCardId());
|
||||
MTGDeck * tempDeck = NEW MTGDeck(NULL,mParent->collection);
|
||||
tempDeck->addRandomCards(8,sets,nbsets);
|
||||
for (map<int,int>::iterator it = tempDeck->cards.begin(); it!=tempDeck->cards.end(); it++){
|
||||
for (int j = 0; j < it->second; j++){
|
||||
shop->Add(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
delete tempDeck;
|
||||
}
|
||||
|
||||
|
||||
void GameStateShop::End()
|
||||
{
|
||||
JRenderer::GetInstance()->EnableVSync(false);
|
||||
@@ -103,6 +144,9 @@ void GameStateShop::Update(float dt)
|
||||
if (mEngine->GetButtonClick(PSP_CTRL_START)){
|
||||
mStage = STAGE_SHOP_MENU;
|
||||
}
|
||||
if (mEngine->GetButtonClick(PSP_CTRL_SQUARE)){
|
||||
load();
|
||||
}
|
||||
if (shop)
|
||||
shop->Update(dt);
|
||||
}
|
||||
@@ -112,10 +156,14 @@ void GameStateShop::Update(float dt)
|
||||
void GameStateShop::Render()
|
||||
{
|
||||
//Erase
|
||||
JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0));
|
||||
JRenderer * r = JRenderer::GetInstance();
|
||||
r->ClearScreen(ARGB(0,0,0,0));
|
||||
if (mBg)JRenderer::GetInstance()->RenderQuad(mBg,0,0);
|
||||
if (shop)
|
||||
shop->Render();
|
||||
|
||||
r->FillRect(5,SCREEN_HEIGHT-15,110,15,ARGB(200,0,0,0));
|
||||
itemFont->DrawString(_("press [] to refresh").c_str(),10,SCREEN_HEIGHT-12);
|
||||
if (mStage == STAGE_SHOP_MENU && menu){
|
||||
menu->Render();
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ int MTGCardInstance::reset(){
|
||||
Player * MTGCardInstance::controller(){
|
||||
GameObserver * game = GameObserver::GetInstance();
|
||||
if (!game) return NULL;
|
||||
for (int i = 0; i < 2; i++){
|
||||
for (int i = 0; i < 2; ++i){
|
||||
if (game->players[i]->game->inPlay->hasCard(this)) return game->players[i];
|
||||
if (game->players[i]->game->stack->hasCard(this)) return game->players[i];
|
||||
if (game->players[i]->game->graveyard->hasCard(this)) return game->players[i];
|
||||
|
||||
@@ -421,7 +421,7 @@ MTGCard * MTGDeck::getCardById(int mtgId){
|
||||
}
|
||||
|
||||
|
||||
int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _subtype, int * colors, int nbcolors){
|
||||
int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, const char * _subtype, int * colors, int nbcolors){
|
||||
int unallowedColors[Constants::MTG_NB_COLORS+1];
|
||||
for (int i=0; i < Constants::MTG_NB_COLORS; ++i){
|
||||
if (nbcolors) unallowedColors[i] = 1;
|
||||
@@ -433,7 +433,7 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su
|
||||
|
||||
int collectionTotal = database->totalCards();
|
||||
if (!collectionTotal) return 0;
|
||||
if (setId == -1 && rarity == -1 && !_subtype && !nbcolors){
|
||||
if (nbSets == 0 && rarity == -1 && !_subtype && !nbcolors){
|
||||
for (int i = 0; i < howmany; i++){
|
||||
add(database->randomCardId());
|
||||
}
|
||||
@@ -448,17 +448,28 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su
|
||||
int subtotal = 0;
|
||||
for (int i = 0; i < collectionTotal; i++){
|
||||
MTGCard * card = database->_(i);
|
||||
if ((setId == -1 || card->setId == setId) &&
|
||||
(rarity == -1 || card->getRarity()==rarity) &&
|
||||
if ((rarity == -1 || card->getRarity()==rarity) &&
|
||||
(!_subtype || card->hasSubtype(subtype))
|
||||
){
|
||||
int ok = 1;
|
||||
for (int j=0; j < Constants::MTG_NB_COLORS; ++j){
|
||||
if (unallowedColors[j] && card->hasColor(j)){
|
||||
ok = 0;
|
||||
int ok = 0;
|
||||
|
||||
if (!nbSets) ok = 1;
|
||||
for (int j=0; j < nbSets; ++j){
|
||||
if (card->setId == setIds[j]){
|
||||
ok = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok){
|
||||
for (int j=0; j < Constants::MTG_NB_COLORS; ++j){
|
||||
if (unallowedColors[j] && card->hasColor(j)){
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ok){
|
||||
subcollection.push_back(card->getId());
|
||||
subtotal++;
|
||||
@@ -466,7 +477,7 @@ int MTGDeck::addRandomCards(int howmany, int setId, int rarity, const char * _su
|
||||
}
|
||||
}
|
||||
if (subtotal == 0){
|
||||
if (rarity == Constants::RARITY_M) return addRandomCards(howmany, setId, Constants::RARITY_R, _subtype, colors, nbcolors);
|
||||
if (rarity == Constants::RARITY_M) return addRandomCards(howmany, setIds, nbSets, Constants::RARITY_R, _subtype, colors, nbcolors);
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < howmany; i++){
|
||||
|
||||
@@ -256,9 +256,10 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){
|
||||
int rare_or_mythic = Constants::RARITY_R;
|
||||
int rnd = rand() % 8;
|
||||
if (rnd == 0) rare_or_mythic = Constants::RARITY_M;
|
||||
tempDeck->addRandomCards(1, setIds[showPriceDialog],rare_or_mythic);
|
||||
tempDeck->addRandomCards(3, setIds[showPriceDialog],Constants::RARITY_U);
|
||||
tempDeck->addRandomCards(11, setIds[showPriceDialog],Constants::RARITY_C);
|
||||
int sets[] = {setIds[showPriceDialog]};
|
||||
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);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user