From 2f82f1888cd5e7c7d0fdf5cde637ea1784bfdf8c Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Tue, 5 Apr 2011 16:03:19 +0000 Subject: [PATCH] couple things, first i goofed up in 2 spots, the equipment check for legality, yes shroud isnt a case, but it is also not a case of why you shouldnt remove it from a card which is illegal, so reworked it to find that the items i was looking to exclude( the protections) were all in a single spot :) yay to good programing!...so i pass a bool now with cantarget "withoutProtections" defaults to false so protections are always accounted for unless you specify not to include them, which is what ive done....now if only auras had a nice little spot to add such coding we can correct this rule on auras... 2nd, fixed a misunderstood line i added, i was aiming for the tc that triggered the event in trtargted....all tested passed, and i didn't manually test that change (SHAME ON ME!!!)...corrected it in the correct place now, where the event is sent. 3rd, trying to fix a broken alias class, this is a work in progress, i intend to fix this and then convert it to a keyword for draw replacement effects for 16.1(?) anyways, only thing ive left to figure out is telling it how to determine that the last stack ability is a "draw" ability. this class quit working ALONG time ago when the "addDraw" object was no longer used. the methods for card drawing changed and no one updated the alias class to use the new method, i imagine this is also what broke aladdins lamp originally(which the change of draw events and how card display is set up) --- projects/mtg/include/AllAbilities.h | 33 +++++++++++++++++------- projects/mtg/include/TargetChooser.h | 34 ++++++++++++++++--------- projects/mtg/src/MTGAbility.cpp | 3 +++ projects/mtg/src/TargetChooser.cpp | 38 ++++++++++++++-------------- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index f485601ae..ef7c147c6 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -911,7 +911,6 @@ public: if(source->isPhased) return 0; WEventTarget * e = dynamic_cast (event); if (!e) return 0; - if (!tc->targetter) return 0;//notatarget case. if (!tc->canTarget(e->card)) return 0; if (fromTc && !fromTc->canTarget(e->source)) return 0; return 1; @@ -2884,8 +2883,10 @@ public: int testDestroy() { - if (source->target && !game->isInPlay(source->target)) unequip(); - if (source->target && !source->target->has(Constants::SHROUD) && TargetAbility::tc && !TargetAbility::tc->canTarget((Targetable *)source->target)) unequip(); + if (source->target && !game->isInPlay(source->target)) + unequip(); + if (source->target && TargetAbility::tc && !TargetAbility::tc->canTarget((Targetable *)source->target,true)) + unequip(); return TargetAbility::testDestroy(); } @@ -5103,6 +5104,7 @@ class AIslandSanctuary: public MTGAbility { public: int initThisTurn; + vector effectedCards; AIslandSanctuary(int _id, MTGCardInstance * _source) : MTGAbility(_id, _source) { @@ -5111,25 +5113,38 @@ public: void Update(float dt) { - if (currentPhase == Constants::MTG_PHASE_UNTAP && game->currentPlayer == source->controller()) initThisTurn = 0; - - if (initThisTurn && currentPhase == Constants::MTG_PHASE_COMBATATTACKERS && game->currentPlayer != source->controller()) + if (currentPhase == Constants::MTG_PHASE_UNTAP && game->currentPlayer == source->controller()) + { + initThisTurn = 0; + for(unsigned int i = 0; i < effectedCards.size(); i++) + effectedCards.at(i)->basicAbilities[Constants::CANTATTACK] = 0; + effectedCards.clear(); + } + if (initThisTurn && currentPhase == Constants::MTG_PHASE_COMBATBEGIN && game->currentPlayer != source->controller()) { MTGGameZone * zone = game->currentPlayer->game->inPlay; for (int i = 0; i < zone->nb_cards; i++) { MTGCardInstance * card = zone->cards[i]; - if (card->isAttacker() && !card->basicAbilities[Constants::FLYING] && !card->basicAbilities[Constants::ISLANDWALK]) source->toggleAttacker(); + if (!card->has(Constants::FLYING) && !card->has(Constants::ISLANDWALK) && !card->has(Constants::CANTATTACK)) + { + card->basicAbilities[Constants::CANTATTACK] = 1; + effectedCards.push_back(card); + } } } } int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL) { - if (card == source && game->currentPlayer == card->controller() && currentPhase == Constants::MTG_PHASE_DRAW) + if (card == source && game->currentPlayer == card->controller()) { + Interruptible * action = game->mLayers->stackLayer()->getAt(-1); - if (action->type == ACTION_DRAW) return 1; + Spell * spell = (Spell *) action; + AADrawer * draw = dynamic_cast (action); + if (draw && draw->aType == MTGAbility::STANDARD_DRAW) + return 1; } return 0; } diff --git a/projects/mtg/include/TargetChooser.h b/projects/mtg/include/TargetChooser.h index 08c5b02ff..d293c64cb 100644 --- a/projects/mtg/include/TargetChooser.h +++ b/projects/mtg/include/TargetChooser.h @@ -35,7 +35,7 @@ public: OWNER = 3 }; bool other; - + bool withoutProtections; TargetChooser(MTGCardInstance * card = NULL, int _maxtargets = -1, bool other = false); MTGCardInstance * source; @@ -55,7 +55,7 @@ public: int ForceTargetListReady(); int targetsReadyCheck(); virtual int addTarget(Targetable * target); - virtual bool canTarget(Targetable * _target); + virtual bool canTarget(Targetable * _target,bool withoutProtections = false); //returns true if tc is equivalent to this TargetChooser //Two targetchoosers are equivalent if they target exactly the same cards @@ -100,9 +100,10 @@ public: int nbzones; int init(int * _zones, int _nbzones); bool targetsZone(MTGGameZone * z); + bool withoutProtections; TargetZoneChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); TargetZoneChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); - virtual bool canTarget(Targetable * _card); + virtual bool canTarget(Targetable * _card,bool withoutProtections = false); int setAllZones(); virtual TargetZoneChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -113,8 +114,9 @@ class CardTargetChooser: public TargetZoneChooser protected: MTGCardInstance * validTarget; public: + bool withoutProtections; CardTargetChooser(MTGCardInstance * card, MTGCardInstance * source, int * zones = NULL, int nbzones = 0); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual CardTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -124,11 +126,12 @@ class TypeTargetChooser: public TargetZoneChooser public: int nbtypes; int types[10]; + bool withoutProtections; TypeTargetChooser(const char * _type, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); TypeTargetChooser(const char * _type, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); void addType(int type); void addType(const char * type); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual TypeTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -136,6 +139,7 @@ public: class DamageableTargetChooser: public TypeTargetChooser { public: + bool withoutProtections; DamageableTargetChooser(int * _zones, int _nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false) : TypeTargetChooser("creature",_zones, _nbzones, card, _maxtargets, other) { @@ -146,7 +150,7 @@ public: { } ; - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual DamageableTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -156,8 +160,9 @@ class PlayerTargetChooser: public TargetChooser protected: Player * p; //In Case we can only target a specific player public: + bool withoutProtections; PlayerTargetChooser(MTGCardInstance * card = NULL, int _maxtargets = 1, Player *_p = NULL); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual PlayerTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -166,9 +171,10 @@ class DescriptorTargetChooser: public TargetZoneChooser { public: CardDescriptor * cd; + bool withoutProtections; DescriptorTargetChooser(CardDescriptor * _cd, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); DescriptorTargetChooser(CardDescriptor * _cd, int * _zones, int nbzones, MTGCardInstance * card = NULL, int _maxtargets = 1, bool other = false); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); ~DescriptorTargetChooser(); virtual DescriptorTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); @@ -178,8 +184,9 @@ class SpellTargetChooser: public TargetChooser { public: int color; + bool withoutProtections; SpellTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual SpellTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -188,8 +195,9 @@ class SpellOrPermanentTargetChooser: public TargetZoneChooser { public: int color; + bool withoutProtections; SpellOrPermanentTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, bool other = false); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual SpellOrPermanentTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -199,8 +207,9 @@ class DamageTargetChooser: public TargetChooser public: int color; int state; + bool withoutProtections; DamageTargetChooser(MTGCardInstance * card = NULL, int _color = -1, int _maxtargets = 1, int state = NOT_RESOLVED); - virtual bool canTarget(Targetable * target); + virtual bool canTarget(Targetable * target,bool withoutProtections = false); virtual DamageTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; @@ -211,9 +220,10 @@ class TriggerTargetChooser: public TargetChooser public: Targetable * target; int triggerTarget; + bool withoutProtections; TriggerTargetChooser(int _triggerTarget); virtual bool targetsZone(MTGGameZone * z); - virtual bool canTarget(Targetable * _target); + virtual bool canTarget(Targetable * _target,bool withoutProtections = false); virtual TriggerTargetChooser * clone() const; virtual bool equals(TargetChooser * tc); }; diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index e5e8ee1a0..b011d4ea8 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -4163,8 +4163,11 @@ int TargetAbility::reactToClick(MTGCardInstance * card) { waitingForAnswer = 0; game->mLayers->actionLayer()->setCurrentWaitingAction(NULL); + if(tc->targetter) + { WEvent * e = NEW WEventTarget(card,source); game->receiveEvent(e); + } } return result; } diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index 656cca0cf..67c8b7eee 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -739,7 +739,7 @@ TargetChooser::TargetChooser(MTGCardInstance * card, int _maxtargets, bool _othe //Default targetter : every card can be targetted, unless it is protected from the targetter card // For spells that do not "target" a specific card, set targetter to NULL -bool TargetChooser::canTarget(Targetable * target) +bool TargetChooser::canTarget(Targetable * target,bool withoutProtections) { if (!target) return false; if (target->typeAsTarget() == TARGET_CARD) @@ -759,7 +759,7 @@ bool TargetChooser::canTarget(Targetable * target) //this is kinda cheating but by default we let auras and equipments always continue to target a phased creature. else if(card->isPhased) return false; - if (source && targetter && card->isInPlay()) + if (source && targetter && card->isInPlay() && !withoutProtections) { if (card->has(Constants::SHROUD)) return false; if (card->protectedAgainst(targetter)) return false; @@ -858,12 +858,12 @@ CardTargetChooser::CardTargetChooser(MTGCardInstance * _card, MTGCardInstance * validTarget = _card; } -bool CardTargetChooser::canTarget(Targetable * target) +bool CardTargetChooser::canTarget(Targetable * target,bool withoutProtections) { if (!target) return false; if (target->typeAsTarget() != TARGET_CARD) return false; - if (!nbzones && !TargetChooser::canTarget(target)) return false; - if (nbzones && !TargetZoneChooser::canTarget(target)) return false; + if (!nbzones && !TargetChooser::canTarget(target,withoutProtections)) return false; + if (nbzones && !TargetZoneChooser::canTarget(target,withoutProtections)) return false; MTGCardInstance * card = (MTGCardInstance *) target; while (card) { @@ -936,9 +936,9 @@ void TypeTargetChooser::addType(int type) nbtypes++; } -bool TypeTargetChooser::canTarget(Targetable * target) +bool TypeTargetChooser::canTarget(Targetable * target,bool withoutProtections) { - if (!TargetZoneChooser::canTarget(target)) return false; + if (!TargetZoneChooser::canTarget(target,withoutProtections)) return false; if (target->typeAsTarget() == TARGET_CARD) { MTGCardInstance * card = (MTGCardInstance *) target; @@ -1028,9 +1028,9 @@ DescriptorTargetChooser::DescriptorTargetChooser(CardDescriptor * _cd, int * _zo cd = _cd; } -bool DescriptorTargetChooser::canTarget(Targetable * target) +bool DescriptorTargetChooser::canTarget(Targetable * target,bool withoutProtections) { - if (!TargetZoneChooser::canTarget(target)) return false; + if (!TargetZoneChooser::canTarget(target,withoutProtections)) return false; if (target->typeAsTarget() == TARGET_CARD) { MTGCardInstance * _target = (MTGCardInstance *) target; @@ -1105,9 +1105,9 @@ int TargetZoneChooser::setAllZones() return 1; } -bool TargetZoneChooser::canTarget(Targetable * target) +bool TargetZoneChooser::canTarget(Targetable * target,bool withoutProtections) { - if (!TargetChooser::canTarget(target)) return false; + if (!TargetChooser::canTarget(target,withoutProtections)) return false; if (target->typeAsTarget() == TARGET_CARD) { MTGCardInstance * card = (MTGCardInstance *) target; @@ -1180,7 +1180,7 @@ PlayerTargetChooser::PlayerTargetChooser(MTGCardInstance * card, int _maxtargets { } -bool PlayerTargetChooser::canTarget(Targetable * target) +bool PlayerTargetChooser::canTarget(Targetable * target,bool withoutProtections) { if (source && targetter && (targetter->controller() != targetter->controller()->opponent()) && (targetter->controller()->opponent()->game->inPlay->hasAbility(Constants::CONTROLLERSHROUD)) @@ -1214,7 +1214,7 @@ bool PlayerTargetChooser::equals(TargetChooser * tc) } /*Damageable Target */ -bool DamageableTargetChooser::canTarget(Targetable * target) +bool DamageableTargetChooser::canTarget(Targetable * target,bool withoutProtections) { if (source && targetter && (targetter->controller() != targetter->controller()->opponent()) && (targetter->controller()->opponent()->game->inPlay->hasAbility(Constants::CONTROLLERSHROUD)) @@ -1229,7 +1229,7 @@ bool DamageableTargetChooser::canTarget(Targetable * target) { return true; } - return TypeTargetChooser::canTarget(target); + return TypeTargetChooser::canTarget(target,withoutProtections); } DamageableTargetChooser* DamageableTargetChooser::clone() const @@ -1256,7 +1256,7 @@ SpellTargetChooser::SpellTargetChooser(MTGCardInstance * card, int _color, int _ color = _color; } -bool SpellTargetChooser::canTarget(Targetable * target) +bool SpellTargetChooser::canTarget(Targetable * target,bool withoutProtections) { MTGCardInstance * card = NULL; if (target->typeAsTarget() == TARGET_STACKACTION) @@ -1301,13 +1301,13 @@ SpellOrPermanentTargetChooser::SpellOrPermanentTargetChooser(MTGCardInstance * c color = _color; } -bool SpellOrPermanentTargetChooser::canTarget(Targetable * target) +bool SpellOrPermanentTargetChooser::canTarget(Targetable * target,bool withoutProtections) { MTGCardInstance * card = NULL; if (target->typeAsTarget() == TARGET_CARD) { card = (MTGCardInstance *) target; - if (color == -1 || card->hasColor(color)) return TargetZoneChooser::canTarget(target); + if (color == -1 || card->hasColor(color)) return TargetZoneChooser::canTarget(target,withoutProtections); } else if (target->typeAsTarget() == TARGET_STACKACTION) { @@ -1349,7 +1349,7 @@ DamageTargetChooser::DamageTargetChooser(MTGCardInstance * card, int _color, int state = _state; } -bool DamageTargetChooser::canTarget(Targetable * target) +bool DamageTargetChooser::canTarget(Targetable * target,bool withoutProtections) { MTGCardInstance * card = NULL; if (target->typeAsTarget() == TARGET_STACKACTION) @@ -1395,7 +1395,7 @@ bool TriggerTargetChooser::targetsZone(MTGGameZone * z) return true; } -bool TriggerTargetChooser::canTarget(Targetable * _target) +bool TriggerTargetChooser::canTarget(Targetable * _target,bool withoutProtections) { if (_target == target) return true; return false;