- fix with Momir+ */* creatures
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-04-06 12:19:18 +00:00
parent a8942331eb
commit e9190ff19f
16 changed files with 110 additions and 40 deletions

View File

@@ -220,7 +220,7 @@ toughness=5
[/card] [/card]
[card] [card]
text=When Hearthcage Giant comes into play, put two 3/1 red Elemental Shaman creature tokens into play. Sacrifice an Elemental: Target Giant creature gets +3/+1 until end of turn. text=When Hearthcage Giant comes into play, put two 3/1 red Elemental Shaman creature tokens into play. Sacrifice an Elemental: Target Giant creature gets +3/+1 until end of turn.
auto=token(Elemental Shaman,creature Elemental Shaman,3/1,red)*3 auto=token(Elemental Shaman,creature Elemental Shaman,3/1,red)*2
auto={G}{S(elemental|myinplay)}:3/1 auto={G}{S(elemental|myinplay)}:3/1
id=139691 id=139691
name=Hearthcage Giant name=Hearthcage Giant

View File

@@ -66,7 +66,7 @@ hannas_custody.txt
hymn_of_rebirth.txt hymn_of_rebirth.txt
icatian_priest.txt icatian_priest.txt
keldon_warlord.txt keldon_warlord.txt
keldon_warlord_2.txt keldon_warlord2.txt
kird_ape.txt kird_ape.txt
kudzu.txt kudzu.txt
kudzu2.txt kudzu2.txt
@@ -104,4 +104,8 @@ tranquil_domain.txt
volcanic_island.txt volcanic_island.txt
white_knight1.txt white_knight1.txt
wrath_of_god.txt wrath_of_god.txt
zombie_master.txt zombie_master.txt
########################
#Momir Basic Tests
########################
momir/keldon_warlord.txt

View File

@@ -20,11 +20,12 @@ class ActionLayer: public GuiLayer, public JGuiListener{
public: public:
Targetable * menuObject; Targetable * menuObject;
SimpleMenu * abilitiesMenu; SimpleMenu * abilitiesMenu;
int stuffHappened;
virtual void Render(); virtual void Render();
virtual void Update(float dt); virtual void Update(float dt);
int unstopableRenderInProgress(); int unstopableRenderInProgress();
bool CheckUserInput(u32 key); bool CheckUserInput(u32 key);
ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL;}; ActionLayer(int id, GameObserver* _game):GuiLayer(id, _game){ menuObject = NULL; abilitiesMenu = NULL; stuffHappened = 0;};
~ActionLayer(); ~ActionLayer();
int isWaitingForAnswer(); int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card); int isReactingToTargetClick(Targetable * card);
@@ -32,6 +33,8 @@ class ActionLayer: public GuiLayer, public JGuiListener{
int reactToTargetClick(Targetable * card); int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card); int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int reactToClick(ActionElement * ability,MTGCardInstance * card);
int reactToTargetClick(ActionElement * ability,Targetable * card);
int stillInUse(MTGCardInstance * card); int stillInUse(MTGCardInstance * card);
void setMenuObject(Targetable * object); void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid); void ButtonPressed(int controllerid, int controlid);

View File

@@ -44,7 +44,7 @@ class GuiLayers{
GuiLayer * objects[MAX_GUI_LAYERS]; GuiLayer * objects[MAX_GUI_LAYERS];
public: public:
GuiLayers(); GuiLayers();
void Update(float dt, Player * player); virtual void Update(float dt, Player * player);
void Render(); void Render();
void Add(GuiLayer * layer); void Add(GuiLayer * layer);
void Remove(); void Remove();

View File

@@ -99,8 +99,9 @@ class Constants
CLOUD = 38, CLOUD = 38,
CANTATTACK = 39, CANTATTACK = 39,
MUSTATTACK = 40, MUSTATTACK = 40,
CANTBLOCK = 41,
NB_BASIC_ABILITIES = 41, NB_BASIC_ABILITIES = 42,
RARITY_M = 'M', RARITY_M = 'M',

View File

@@ -123,15 +123,18 @@ class MTGLegendRule:public ListMaintainerAbility{
class MTGMomirRule:public MTGAbility{ class MTGMomirRule:public MTGAbility{
private:
int genRandomCreatureId(int convertedCost);
public: public:
int alreadyplayed; int alreadyplayed;
MTGAllCards * collection; MTGAllCards * collection;
MTGCardInstance * genRandomCreature(int convertedCost); MTGCardInstance * genCreature(int id);
int testDestroy(); int testDestroy();
void Update(float dt); void Update(float dt);
MTGMomirRule(int _id, MTGAllCards * _collection); MTGMomirRule(int _id, MTGAllCards * _collection);
int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL);
int reactToClick(MTGCardInstance * card); int reactToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card, int id);
const char * getMenuText(){return "Momir";} const char * getMenuText(){return "Momir";}
}; };

View File

@@ -51,6 +51,7 @@ class TestSuite{
public: public:
MTGAllCards* collection; MTGAllCards* collection;
int summoningSickness; int summoningSickness;
int gameType;
float timerLimit; float timerLimit;
int currentAction; int currentAction;
TestSuiteState initState; TestSuiteState initState;

View File

@@ -15,7 +15,7 @@ int AIAction::Act(){
return 1; return 1;
} }
if (ability){ if (ability){
ability->reactToClick(click); g->mLayers->actionLayer()->reactToClick(ability,click);
if (target) g->cardClick(target); if (target) g->cardClick(target);
return 1; return 1;
}else if (click){ //Shouldn't be used, really... }else if (click){ //Shouldn't be used, really...

View File

@@ -14,6 +14,19 @@ MTGAbility* ActionLayer::getAbility(int type){
return NULL; return NULL;
} }
int ActionLayer::reactToClick(ActionElement * ability, MTGCardInstance * card){
int result = ability->reactToClick(card);
if (result) stuffHappened = 1;
return result;
}
int ActionLayer::reactToTargetClick(ActionElement* ability, Targetable * card){
int result = ability->reactToTargetClick(card);
if (result) stuffHappened = 1;
return result;
}
int ActionLayer::unstopableRenderInProgress(){ int ActionLayer::unstopableRenderInProgress(){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
@@ -43,6 +56,7 @@ bool ActionLayer::CheckUserInput(u32 key){
void ActionLayer::Update(float dt){ void ActionLayer::Update(float dt){
stuffHappened = 0;
if (menuObject){ if (menuObject){
abilitiesMenu->Update(dt); abilitiesMenu->Update(dt);
return; return;
@@ -139,7 +153,7 @@ int ActionLayer::reactToTargetClick(Targetable * card){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){ if(currentAction->waitingForAnswer){
return currentAction->reactToTargetClick(card); return reactToTargetClick(currentAction,card);
} }
} }
@@ -171,14 +185,14 @@ int ActionLayer::reactToClick(MTGCardInstance * card){
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){ if(currentAction->waitingForAnswer){
return currentAction->reactToClick(card); return reactToClick(currentAction,card);
} }
} }
for (int i=0;i<mCount;i++){ for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i]; ActionElement * currentAction = (ActionElement *)mObjects[i];
OutputDebugString(currentAction->getMenuText()); OutputDebugString(currentAction->getMenuText());
result += currentAction->reactToClick(card); result += reactToClick(currentAction,card);
if (result) return result; if (result) return result;
} }
return result; return result;

View File

@@ -217,6 +217,9 @@ void GameObserver::Update(float dt){
currentActionPlayer = player; currentActionPlayer = player;
if (isInterrupting) player = isInterrupting; if (isInterrupting) player = isInterrupting;
mLayers->Update(dt,player); mLayers->Update(dt,player);
while (mLayers->actionLayer()->stuffHappened){
mLayers->actionLayer()->Update(0);
}
stateEffects(); stateEffects();
oldGamePhase = currentGamePhase; oldGamePhase = currentGamePhase;
@@ -225,6 +228,7 @@ void GameObserver::Update(float dt){
//applies damage to creatures after updates //applies damage to creatures after updates
//Players life test //Players life test
void GameObserver::stateEffects(){ void GameObserver::stateEffects(){
if (mLayers->stackLayer()->count(0,NOT_RESOLVED) != 0) return; if (mLayers->stackLayer()->count(0,NOT_RESOLVED) != 0) return;
if (mLayers->actionLayer()->menuObject) return; if (mLayers->actionLayer()->menuObject) return;
if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()) return; if (targetChooser || mLayers->actionLayer()->isWaitingForAnswer()) return;
@@ -333,7 +337,7 @@ void GameObserver::cardClick (MTGCardInstance * card, Targetable * object){
waitForExtraPayment->tryToSetPayment(card); waitForExtraPayment->tryToSetPayment(card);
} }
if (waitForExtraPayment->isPaymentSet()){ if (waitForExtraPayment->isPaymentSet()){
waitForExtraPayment->action->reactToClick(waitForExtraPayment->source); mLayers->actionLayer()->reactToClick(waitForExtraPayment->action, waitForExtraPayment->source);
waitForExtraPayment = NULL; waitForExtraPayment = NULL;
} }
return; return;

View File

@@ -161,7 +161,7 @@ void GameStateDuel::loadTestSuitePlayers(){
OutputDebugString ("loading suite 2\n"); OutputDebugString ("loading suite 2\n");
deck[i] = mPlayers[i]->game; deck[i] = mPlayers[i]->game;
} }
mParent->gameType = testSuite->gameType;
if (game) delete game; if (game) delete game;
game = NULL; game = NULL;
if (!game){ if (!game){
@@ -171,6 +171,13 @@ void GameStateDuel::loadTestSuitePlayers(){
OutputDebugString ("loading suite 4\n"); OutputDebugString ("loading suite 4\n");
game->startGame(0,0); game->startGame(0,0);
OutputDebugString ("loading suite 5\n"); OutputDebugString ("loading suite 5\n");
if (mParent->gameType == GAME_TYPE_MOMIR){
game->addObserver(NEW MTGMomirRule(-1, mParent->collection));
for (int i = 0; i < 2; i++){
game->players[i]->life+=4;
}
}
} }
} }
#endif #endif
@@ -223,7 +230,9 @@ void GameStateDuel::Update(float dt)
#ifdef TESTSUITE #ifdef TESTSUITE
else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){ else if (mParent->players[1] == PLAYER_TYPE_TESTSUITE){
if (testSuite && testSuite->loadNext()){ if (testSuite && testSuite->loadNext()){
loadTestSuitePlayers(); loadTestSuitePlayers();
mGamePhase = DUEL_STATE_PLAY; mGamePhase = DUEL_STATE_PLAY;
testSuite->initGame(); testSuite->initGame();
char buf[4096]; char buf[4096];

View File

@@ -110,29 +110,27 @@ void GuiLayers::Remove(){
} }
void GuiLayers::Update(float dt, Player * currentPlayer){ void GuiLayers::Update(float dt, Player * currentPlayer){
int i;
int isAI = currentPlayer->isAI(); for (int i=0; i<nbitems; i++){
for (i=0; i<nbitems; i++){
objects[i]->Update(dt); objects[i]->Update(dt);
} }
int isAI = currentPlayer->isAI();
u32 key; u32 key;
while ((key = JGE::GetInstance()->ReadButton())) while ((key = JGE::GetInstance()->ReadButton())){
{ GameObserver * game = GameObserver::GetInstance();
GameObserver * game = GameObserver::GetInstance(); if (game->waitForExtraPayment && key == PSP_CTRL_CROSS){
if (game->waitForExtraPayment && key == PSP_CTRL_CROSS){ game->waitForExtraPayment = NULL;
game->waitForExtraPayment = NULL; continue;
continue;
}
for (i=0; i<nbitems; i++){
if (!isAI){
if (0 != key)
if (objects[i]->CheckUserInput(key))
break;
}
}
} }
if (isAI) for (int i=0; i<nbitems; i++){
currentPlayer->Act(dt); if (!isAI){
if (0 != key)
if (objects[i]->CheckUserInput(key)) break;
}
}
}
if (isAI) currentPlayer->Act(dt);
} }
void GuiLayers::Render(){ void GuiLayers::Render(){

View File

@@ -295,8 +295,10 @@ int MTGCardInstance::setToughness(int value){
} }
int MTGCardInstance::canBlock(){ int MTGCardInstance::canBlock(){
if (!tapped && isACreature())return 1; if (tapped) return 0;
return 0; if (basicAbilities[Constants::CANTBLOCK]) return 0;
if (!isACreature())return 0;
return 1;
} }
int MTGCardInstance::canBlock(MTGCardInstance * opponent){ int MTGCardInstance::canBlock(MTGCardInstance * opponent){

View File

@@ -49,6 +49,7 @@ const char* Constants::MTGBasicAbilities[] = {
"cloud", "cloud",
"cantattack", "cantattack",
"mustattack", "mustattack",
"cantblock",
}; };
const char* Constants::MTGPhaseNames[] = const char* Constants::MTGPhaseNames[] =

View File

@@ -175,13 +175,21 @@ int MTGMomirRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana){
} }
int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard){ int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard){
if (!isReactingToClick(card_to_discard)) return 0;
Player * player = game->currentlyActing(); Player * player = game->currentlyActing();
ManaCost * cost = player->getManaPool(); ManaCost * cost = player->getManaPool();
int converted = cost->getConvertedCost(); int converted = cost->getConvertedCost();
int id = genRandomCreatureId(converted);
return reactToClick(card_to_discard, id);
}
int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard, int cardId){
if (!isReactingToClick(card_to_discard)) return 0;
Player * player = game->currentlyActing();
ManaCost * cost = player->getManaPool();
player->getManaPool()->pay(cost); player->getManaPool()->pay(cost);
MTGCardInstance * card = genCreature(cardId);
player->game->putInZone(card_to_discard, player->game->hand, player->game->graveyard); player->game->putInZone(card_to_discard, player->game->hand, player->game->graveyard);
MTGCardInstance * card = genRandomCreature(converted); //TODO code this function
player->game->stack->addCard(card); player->game->stack->addCard(card);
Spell * spell = NEW Spell(card); Spell * spell = NEW Spell(card);
spell->resolve(); spell->resolve();
@@ -191,7 +199,14 @@ int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard){
return 1; return 1;
} }
MTGCardInstance * MTGMomirRule::genRandomCreature(int convertedCost){ MTGCardInstance * MTGMomirRule::genCreature( int id){
if (!id) return NULL;
Player * p = game->currentlyActing();
MTGCard * card = collection->getCardById(id);
return NEW MTGCardInstance(card,p->game);
}
int MTGMomirRule::genRandomCreatureId(int convertedCost){
Player * p = game->currentlyActing(); Player * p = game->currentlyActing();
int total_cards = collection->totalCards(); int total_cards = collection->totalCards();
int start = (rand() % total_cards); int start = (rand() % total_cards);
@@ -199,13 +214,13 @@ MTGCardInstance * MTGMomirRule::genRandomCreature(int convertedCost){
while (id2 < total_cards){ while (id2 < total_cards){
MTGCard * card = collection->collection[id2]; MTGCard * card = collection->collection[id2];
if (card->isACreature() && card->getManaCost()->getConvertedCost() == convertedCost){ if (card->isACreature() && card->getManaCost()->getConvertedCost() == convertedCost){
return NEW MTGCardInstance(card,p->game); return card->getMTGId();
} }
id2++; id2++;
if (id2 == start) return NULL; if (id2 == start) return 0;
if (id2 == total_cards) id2 = 0; if (id2 == total_cards) id2 = 0;
} }
return NULL; return 0;
} }
//The Momir rule is never destroyed //The Momir rule is never destroyed

View File

@@ -1,6 +1,8 @@
#include "../include/TestSuiteAI.h" #include "../include/TestSuiteAI.h"
#include "../include/config.h" #include "../include/config.h"
#include "../include/MTGAbility.h" #include "../include/MTGAbility.h"
#include "../include/MTGRules.h"
#include "../include/ActionLayer.h"
#include <string> #include <string>
using std::string; using std::string;
@@ -97,6 +99,13 @@ int TestSuiteAI::Act(float dt){
OutputDebugString("choice !!!\n"); OutputDebugString("choice !!!\n");
int choice = atoi(action.substr(action.find("choice ") + 7).c_str()); int choice = atoi(action.substr(action.find("choice ") + 7).c_str());
g->mLayers->actionLayer()->doReactTo(choice); g->mLayers->actionLayer()->doReactTo(choice);
}else if(action.find(" -momir- ")!=string::npos){
int start = action.find(" -momir- ");
int cardId = suite->getMTGId(action.substr(start + 9).c_str());
int cardIdHand = suite->getMTGId(action.substr(0,start).c_str());
MTGMomirRule * a = ((MTGMomirRule *)g->mLayers->actionLayer()->getAbility(MTGAbility::MOMIR));
a->reactToClick(suite->getCardByMTGId(cardIdHand), cardId);
g->mLayers->actionLayer()->stuffHappened = 1;
}else{ }else{
int mtgid = suite->getMTGId(action); int mtgid = suite->getMTGId(action);
if (mtgid){ if (mtgid){
@@ -428,6 +437,8 @@ void TestSuite::cleanup(){
} }
int TestSuite::load(const char * _filename){ int TestSuite::load(const char * _filename){
summoningSickness = 0;
gameType = GAME_TYPE_CLASSIC;
char filename[4096]; char filename[4096];
sprintf(filename, RESPATH"/test/%s", _filename); sprintf(filename, RESPATH"/test/%s", _filename);
std::ifstream file(filename); std::ifstream file(filename);
@@ -447,6 +458,10 @@ int TestSuite::load(const char * _filename){
summoningSickness = 1; summoningSickness = 1;
continue; continue;
} }
if (s.compare("momir") == 0) {
gameType = GAME_TYPE_MOMIR;
continue;
}
switch(state){ switch(state){
case -1: case -1:
if (s.compare("[init]") == 0) state++; if (s.compare("[init]") == 0) state++;