- 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]
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
id=139691
name=Hearthcage Giant

View File

@@ -66,7 +66,7 @@ hannas_custody.txt
hymn_of_rebirth.txt
icatian_priest.txt
keldon_warlord.txt
keldon_warlord_2.txt
keldon_warlord2.txt
kird_ape.txt
kudzu.txt
kudzu2.txt
@@ -104,4 +104,8 @@ tranquil_domain.txt
volcanic_island.txt
white_knight1.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:
Targetable * menuObject;
SimpleMenu * abilitiesMenu;
int stuffHappened;
virtual void Render();
virtual void Update(float dt);
int unstopableRenderInProgress();
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();
int isWaitingForAnswer();
int isReactingToTargetClick(Targetable * card);
@@ -32,6 +33,8 @@ class ActionLayer: public GuiLayer, public JGuiListener{
int reactToTargetClick(Targetable * card);
int isReactingToClick(MTGCardInstance * card);
int reactToClick(MTGCardInstance * card);
int reactToClick(ActionElement * ability,MTGCardInstance * card);
int reactToTargetClick(ActionElement * ability,Targetable * card);
int stillInUse(MTGCardInstance * card);
void setMenuObject(Targetable * object);
void ButtonPressed(int controllerid, int controlid);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -175,13 +175,21 @@ int MTGMomirRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana){
}
int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard){
if (!isReactingToClick(card_to_discard)) return 0;
Player * player = game->currentlyActing();
ManaCost * cost = player->getManaPool();
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);
MTGCardInstance * card = genCreature(cardId);
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);
Spell * spell = NEW Spell(card);
spell->resolve();
@@ -191,7 +199,14 @@ int MTGMomirRule::reactToClick(MTGCardInstance * card_to_discard){
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();
int total_cards = collection->totalCards();
int start = (rand() % total_cards);
@@ -199,13 +214,13 @@ MTGCardInstance * MTGMomirRule::genRandomCreature(int convertedCost){
while (id2 < total_cards){
MTGCard * card = collection->collection[id2];
if (card->isACreature() && card->getManaCost()->getConvertedCost() == convertedCost){
return NEW MTGCardInstance(card,p->game);
return card->getMTGId();
}
id2++;
if (id2 == start) return NULL;
if (id2 == start) return 0;
if (id2 == total_cards) id2 = 0;
}
return NULL;
return 0;
}
//The Momir rule is never destroyed

View File

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