- fix issue 304 (Momir + persist)
- some minor cleanup
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-09-25 09:13:30 +00:00
parent f3cc20eb31
commit a6e4fba26b
8 changed files with 82 additions and 38 deletions

View File

@@ -504,9 +504,10 @@ Zombie_Infestation.txt
zombie_master.txt zombie_master.txt
zombify.txt zombify.txt
######################## ########################
#Momir Basic Tests #Momir Tests
######################## ########################
momir/keldon_warlord.txt momir/keldon_warlord.txt
momir/persist_i304.txt
momir/overcost.txt momir/overcost.txt
######################## ########################
#AI Tests #AI Tests

View File

@@ -0,0 +1,37 @@
#Creatures with persist shouldn't go back from the graveyard if they are tokens
MOMIR
[INIT]
SECONDMAIN
[PLAYER1]
hand:plains
manapool:{3}
[PLAYER2]
inplay:Rock Badger
[DO]
plains -momir- Rendclaw Trow
eot
next
#upkeep
next
#draw
next
#main
next
#combat begins
next
#attackers
Rock Badger
next
#blockers
Rendclaw Trow
next
#damage
next
#end combat
[ASSERT]
COMBATEND
[PLAYER1]
graveyard:plains
[PLAYER2]
inplay:rock badger
[END]

View File

@@ -116,10 +116,10 @@ public:
// Triggers When a card gets added to a zone (@movedTo) // Triggers When a card gets added to a zone (@movedTo)
class TrCardAddedToZone:public TriggeredAbility{ class TrCardAddedToZone:public TriggeredAbility{
public: public:
TargetChooser * toTc; TargetZoneChooser * toTcZone, * fromTcZone;
TargetZoneChooser * fromTcZone; TargetChooser * toTcCard, * fromTcCard;
TargetChooser * fromTcCard; TrCardAddedToZone(int id, MTGCardInstance * source, TargetZoneChooser * toTcZone, TargetChooser * toTcCard , TargetZoneChooser * fromTcZone = NULL,TargetChooser * fromTcCard = NULL)
TrCardAddedToZone(int id, MTGCardInstance * source, TargetChooser * toTc, TargetZoneChooser * fromTcZone = NULL,TargetChooser * fromTcCard = NULL):TriggeredAbility(id,source), toTc(toTc), fromTcZone(fromTcZone), fromTcCard(fromTcCard){} :TriggeredAbility(id,source), toTcZone(toTcZone), fromTcZone(fromTcZone), toTcCard(toTcCard), fromTcCard(fromTcCard){};
int resolve(){ int resolve(){
return 0; //This is a trigger, this function should not be called return 0; //This is a trigger, this function should not be called
@@ -129,7 +129,8 @@ public:
WEventZoneChange * e = dynamic_cast<WEventZoneChange*>(event); WEventZoneChange * e = dynamic_cast<WEventZoneChange*>(event);
if (!e) return 0; if (!e) return 0;
if (!toTc->canTarget(e->card)) return 0; if (!toTcZone->targetsZone(e->to)) return 0;
if (!toTcCard->canTarget(e->card)) return 0;
if (fromTcZone && !fromTcZone->targetsZone(e->from)) return 0; if (fromTcZone && !fromTcZone->targetsZone(e->from)) return 0;
if (fromTcCard && !fromTcCard->canTarget(e->card->previous)) return 0; if (fromTcCard && !fromTcCard->canTarget(e->card->previous)) return 0;
@@ -143,7 +144,8 @@ public:
} }
~TrCardAddedToZone(){ ~TrCardAddedToZone(){
SAFE_DELETE(toTc); SAFE_DELETE(toTcZone);
SAFE_DELETE(toTcCard);
SAFE_DELETE(fromTcZone); SAFE_DELETE(fromTcZone);
SAFE_DELETE(fromTcCard); SAFE_DELETE(fromTcCard);
} }

View File

@@ -305,9 +305,8 @@ int AIPlayer::interruptIfICan(){
int AIPlayer::effectBadOrGood(MTGCardInstance * card, int mode, TargetChooser * tc){ int AIPlayer::effectBadOrGood(MTGCardInstance * card, int mode, TargetChooser * tc){
int id = card->getMTGId(); int id = card->getMTGId();
AbilityFactory * af = NEW AbilityFactory(); AbilityFactory af;
int autoGuess = af->magicText(id,NULL,card, mode, tc); int autoGuess = af.magicText(id,NULL,card, mode, tc);
delete af;
if (autoGuess) return autoGuess; if (autoGuess) return autoGuess;
return BAKA_EFFECT_DONTKNOW; return BAKA_EFFECT_DONTKNOW;
} }
@@ -632,9 +631,8 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
int currentCost = card->getManaCost()->getConvertedCost(); int currentCost = card->getManaCost()->getConvertedCost();
int hasX = card->getManaCost()->hasX(); int hasX = card->getManaCost()->hasX();
if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost())){ if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost())){
TargetChooserFactory * tcf = NEW TargetChooserFactory(); TargetChooserFactory tcf;
TargetChooser * tc = tcf->createTargetChooser(card); TargetChooser * tc = tcf.createTargetChooser(card);
delete tcf;
int shouldPlayPercentage = 10; int shouldPlayPercentage = 10;
if (tc){ if (tc){
int hasTarget = (chooseTarget(tc)); int hasTarget = (chooseTarget(tc));
@@ -653,7 +651,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
if (hasX){ if (hasX){
int xDiff = pMana->getConvertedCost() - currentCost; int xDiff = pMana->getConvertedCost() - currentCost;
if (xDiff < 0) xDiff = 0; if (xDiff < 0) xDiff = 0;
shouldPlayPercentage = shouldPlayPercentage - ((shouldPlayPercentage * 1.9) / (1 + xDiff)); shouldPlayPercentage = shouldPlayPercentage - ((shouldPlayPercentage * 1.9f) / (1 + xDiff));
} }
if (WRand() % 100 > shouldPlayPercentage) continue; if (WRand() % 100 > shouldPlayPercentage) continue;
@@ -682,7 +680,7 @@ AIPlayerBaka::AIPlayerBaka(MTGPlayerCards * deck, string file, string fileSmall,
} }
void AIPlayerBaka::initTimer(){ void AIPlayerBaka::initTimer(){
timer = 0.1; timer = 0.1f;
} }
int AIPlayerBaka::computeActions(){ int AIPlayerBaka::computeActions(){

View File

@@ -38,9 +38,9 @@ void CardSelector::Add(CardSelector::Target* target)
if (NULL == limitor || limitor->select(active)) if (NULL == limitor || limitor->select(active))
active = target; active = target;
CardView* c = dynamic_cast<CardView*>(target); CardView* c = dynamic_cast<CardView*>(target);
if (c) c->zoom = 1.0; if (c) c->zoom = 1.0f;
c = dynamic_cast<CardView*>(active); c = dynamic_cast<CardView*>(active);
if (c) c->zoom = 1.4; if (c) c->zoom = 1.4f;
cards.push_back(target); cards.push_back(target);
} }
template<> template<>
@@ -51,9 +51,9 @@ void CardSelector::Remove(CardSelector::Target* card)
{ {
if (active == *it) if (active == *it)
{ {
CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.0; CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.0f;
active = closest<Diff>(cards, limitor, active); active = closest<Diff>(cards, limitor, active);
c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f;
} }
if (active == *it) active = NULL; if (active == *it) active = NULL;
cards.erase(it); cards.erase(it);
@@ -89,8 +89,8 @@ void CardSelector::Pop() {
if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive); if (nullZone != oldowner) lasts[oldowner] = SelectorMemory(oldactive);
} }
if (active != oldactive) { if (active != oldactive) {
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } //Is this needed, I think it is one in Leaving(0) ? { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; } //Is this needed, I think it is one in Leaving(0) ?
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } //Is this needed, I think it is one in Entering() ? { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; } //Is this needed, I think it is one in Entering() ?
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
if (active) active->Entering(); if (active) active->Entering();
} }
@@ -159,8 +159,8 @@ bool CardSelector::CheckUserInput(JButton key)
} }
} }
if (active != oldactive) { if (active != oldactive) {
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; }
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; }
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
if (active) active->Entering(); if (active) active->Entering();
} }
@@ -223,8 +223,8 @@ void CardSelector::Limit(LimitorFunctor<Target>* limitor, SelectorZone destzone)
} }
if (active != oldactive) { if (active != oldactive) {
{ CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0; } { CardView* c = dynamic_cast<CardView*>(oldactive); if (c) c->zoom = 1.0f; }
{ CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4; } { CardView* c = dynamic_cast<CardView*>(active); if (c) c->zoom = 1.4f; }
if (oldactive) oldactive->Leaving(JGE_BTN_NONE); if (oldactive) oldactive->Leaving(JGE_BTN_NONE);
if (active) active->Entering(); if (active) active->Entering();
} }

View File

@@ -28,6 +28,7 @@ void DuelLayers::init(){
action->Add(NEW MTGAttackRule(-1)); action->Add(NEW MTGAttackRule(-1));
action->Add(NEW MTGBlockRule(-1)); action->Add(NEW MTGBlockRule(-1));
action->Add(NEW MTGLegendRule(-1)); action->Add(NEW MTGLegendRule(-1));
action->Add(NEW MTGTokensCleanup(-1)); // needs to be before persist
action->Add(NEW MTGPersistRule(-1)); action->Add(NEW MTGPersistRule(-1));
action->Add(NEW MTGAffinityRule(-1)); action->Add(NEW MTGAffinityRule(-1));
action->Add(NEW MTGUnearthRule(-1)); action->Add(NEW MTGUnearthRule(-1));
@@ -36,7 +37,7 @@ void DuelLayers::init(){
action->Add(NEW MTGLifelinkRule(-1)); action->Add(NEW MTGLifelinkRule(-1));
action->Add(NEW MTGDeathtouchRule(-1)); action->Add(NEW MTGDeathtouchRule(-1));
action->Add(NEW OtherAbilitiesEventReceiver(-1)); action->Add(NEW OtherAbilitiesEventReceiver(-1));
action->Add(NEW MTGTokensCleanup(-1));
//Other display elements //Other display elements
action->Add(NEW HUDDisplay(-1)); action->Add(NEW HUDDisplay(-1));

View File

@@ -100,9 +100,21 @@ TriggeredAbility * AbilityFactory::parseTrigger(string magicText, int id, Spell
if (found != string::npos){ if (found != string::npos){
size_t end = s.find (")"); size_t end = s.find (")");
string starget = s.substr(found+8,end - found - 8); string starget = s.substr(found+8,end - found - 8);
if (starget.find("|") == string::npos) starget.insert(0,"*|");
TargetChooserFactory tcf; TargetChooserFactory tcf;
TargetChooser *toTc = tcf.createTargetChooser(starget,card);
TargetChooser *toTc = NULL;
TargetChooser *toTcCard = NULL;
end = starget.find ("|");
if (end == string::npos) {
toTcCard = tcf.createTargetChooser("*",card);
found = 0;
}else{
toTcCard = tcf.createTargetChooser(starget.substr(0, end).append("|*"),card);
found = end + 1;
}
toTcCard->setAllZones();
starget = starget.substr(found,end - found).insert(0,"*|");
toTc = tcf.createTargetChooser(starget,card);
toTc->targetter = NULL; toTc->targetter = NULL;
TargetChooser *fromTc = NULL; TargetChooser *fromTc = NULL;
@@ -123,7 +135,7 @@ TriggeredAbility * AbilityFactory::parseTrigger(string magicText, int id, Spell
fromTc = tcf.createTargetChooser(starget,card); fromTc = tcf.createTargetChooser(starget,card);
fromTc->targetter = NULL; fromTc->targetter = NULL;
} }
return NEW TrCardAddedToZone(id,card,toTc,(TargetZoneChooser *)fromTc,fromTcCard); return NEW TrCardAddedToZone(id,card,(TargetZoneChooser *)toTc, toTcCard,(TargetZoneChooser *)fromTc,fromTcCard);
} }
//Card Tapped //Card Tapped

View File

@@ -1398,7 +1398,8 @@ int MTGTokensCleanup::receiveEvent(WEvent * e){
if (!event->card->isToken) return 0; if (!event->card->isToken) return 0;
if (event->to == game->players[0]->game->inPlay || event->to == game->players[1]->game->inPlay) return 0; if (event->to == game->players[0]->game->inPlay || event->to == game->players[1]->game->inPlay) return 0;
if (event->to == game->players[0]->game->garbage || event->to == game->players[1]->game->garbage) return 0; if (event->to == game->players[0]->game->garbage || event->to == game->players[1]->game->garbage) return 0;
list.push_back(event->card); MTGCardInstance * c = event->card;
c->controller()->game->putInZone(c,c->currentZone, c->controller()->game->garbage);
return 1; return 1;
} }
return 0; return 0;
@@ -1406,14 +1407,6 @@ int MTGTokensCleanup::receiveEvent(WEvent * e){
int MTGTokensCleanup::testDestroy(){return 0;} int MTGTokensCleanup::testDestroy(){return 0;}
void MTGTokensCleanup::Update(float dt){
MTGAbility::Update(dt);
for(size_t i= 0; i < list.size(); ++i){
MTGCardInstance * c = list[i];
c->controller()->game->putInZone(c,c->currentZone, c->controller()->game->garbage);
}
list.clear();
}
MTGTokensCleanup * MTGTokensCleanup::clone() const{ MTGTokensCleanup * MTGTokensCleanup::clone() const{
MTGTokensCleanup * a = NEW MTGTokensCleanup(*this); MTGTokensCleanup * a = NEW MTGTokensCleanup(*this);