diff --git a/projects/mtg/bin/Res/sets/10E/_cards.dat b/projects/mtg/bin/Res/sets/10E/_cards.dat index 05e56c576..76486cf6c 100644 --- a/projects/mtg/bin/Res/sets/10E/_cards.dat +++ b/projects/mtg/bin/Res/sets/10E/_cards.dat @@ -486,6 +486,16 @@ type=Sorcery mana={B} [/card] [card] +text=Tap all creatures without flying. +id=135223 +name=Deluge +auto=tap all(creature[-flying]) +rarity=U +color=Blue +type=Instant +mana={2}{U} +[/card] +[card] text=Destroy target artifact or land. target=artifact,land auto=destroy diff --git a/projects/mtg/bin/Res/sets/10E/todo.dat b/projects/mtg/bin/Res/sets/10E/todo.dat index f758dfa2b..3a2ff743a 100644 --- a/projects/mtg/bin/Res/sets/10E/todo.dat +++ b/projects/mtg/bin/Res/sets/10E/todo.dat @@ -311,15 +311,6 @@ mana={3}{U} subtype=Aura [/card] [card] -text=Tap all creatures without flying. -id=135223 -name=Deluge -rarity=U -color=Blue -type=Instant -mana={2}{U} -[/card] -[card] text=When Denizen of the Deep comes into play, return each other creature you control to its owner's hand. id=135250 name=Denizen of the Deep diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 2e09c43d6..d7babb576 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -1,269 +1,270 @@ -#ifndef _MTGABILITY_H_ -#define _MTGABILITY_H_ - - - -class MTGCardInstance; -class GameObserver; -class Spell; -class Damageable; -class PlayGuiObject; -class TargetChooser; -class ManaCost; -class MTGGameZone; -class Player; -class AManaProducer; -class WEvent; - -#include "ActionElement.h" -#include -#include -#include -using std::string; -using std::map; - - -//Two stupid variables used to give a hint to the AI: -// Should I cast a spell on an enemy or friendly unit ? -#define BAKA_EFFECT_GOOD 1 -#define BAKA_EFFECT_BAD -1 -#define BAKA_EFFECT_DONTKNOW 0 - -#define COUNT_POWER 1 - -#define PARSER_LORD 1 -#define PARSER_FOREACH 2 -#define PARSER_ASLONGAS 3 - -class MTGAbility: public ActionElement{ - protected: - char menuText[25]; - - GameObserver * game; - public: - int forceDestroy; - ManaCost * cost; - Damageable * target; - int aType; - MTGCardInstance * source; - MTGAbility(int id, MTGCardInstance * card); - MTGAbility(int id, MTGCardInstance * _source, Damageable * _target); - virtual int testDestroy(); - virtual ~MTGAbility(); - virtual void Render(){}; - virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL){return 0;}; - virtual int reactToClick(MTGCardInstance * card){return 0;}; - virtual int receiveEvent(WEvent * event){return 0;}; - virtual void Update(float dt){}; - virtual int fireAbility(); - virtual int stillInUse(MTGCardInstance * card){if (card==source) return 1; return 0;}; - virtual int resolve(){return 0;}; - virtual ostream& toString(ostream& out) const; - - /*Poor man's casting */ - /* Todo replace that crap with dynamic casting */ - enum { - UNKNOWN = 0, - MANA_PRODUCER = 1, - MTG_ATTACK_RULE = 2, - DAMAGER = 3, - STANDARD_REGENERATE = 4, - PUT_INTO_PLAY = 5, - MOMIR = 6, - MTG_BLOCK_RULE = 7, - }; -}; - - -class TriggeredAbility:public MTGAbility{ - public: - TriggeredAbility(int id, MTGCardInstance * card); - TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target); - virtual void Update(float dt); - virtual void Render(){}; - virtual int trigger()=0; - virtual int resolve() = 0; - virtual ostream& toString(ostream& out) const; -}; - - -class ActivatedAbility:public MTGAbility{ - public: - int playerturnonly; - int needsTapping; - ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); - virtual int reactToClick(MTGCardInstance * card); - virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); - virtual int reactToTargetClick(Targetable * object); - virtual int resolve() = 0; - virtual ostream& toString(ostream& out) const; -}; - -class TargetAbility:public ActivatedAbility{ - public: - TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); - TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); - virtual void Update(float dt); - virtual int reactToClick(MTGCardInstance * card); - virtual int reactToTargetClick(Targetable * object); - virtual void Render(); - virtual ostream& toString(ostream& out) const; -}; - -class InstantAbility:public MTGAbility{ - public: - int init; - virtual void Update(float dt); - virtual int testDestroy(); - InstantAbility(int _id, MTGCardInstance * source); - InstantAbility(int _id, MTGCardInstance * source,Damageable * _target); - virtual int resolve(){return 0;}; - virtual ostream& toString(ostream& out) const; -}; - -/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */ -class ListMaintainerAbility:public MTGAbility{ - public: - map cards; - ListMaintainerAbility(int _id):MTGAbility(_id,NULL){}; - ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){}; - ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){}; - virtual void Update(float dt); - virtual int canBeInList(MTGCardInstance * card) = 0; - virtual int added(MTGCardInstance * card) = 0; - virtual int removed(MTGCardInstance * card) = 0; - virtual int destroy(); - virtual ostream& toString(ostream& out) const; -}; - -/* An attempt to globalize triggered abilities as much as possible */ -class MTGAbilityBasicFeatures{ - public: - Damageable * target; - GameObserver * game; - MTGCardInstance * source; - MTGAbilityBasicFeatures(); - MTGAbilityBasicFeatures(MTGCardInstance * _source, Damageable * _target = NULL); - void init(MTGCardInstance * _source, Damageable * _target = NULL); -}; - -class Trigger:public MTGAbilityBasicFeatures{ - public: - virtual int trigger()=0; - virtual int testDestroy(){return 0;}; -}; - - -class TriggerAtPhase:public Trigger{ - public: - int currentPhase, newPhase; - int phaseId; - - TriggerAtPhase(int _phaseId); - - virtual int trigger(); -}; - -class TriggerNextPhase:public TriggerAtPhase{ - public: - int destroyActivated; - TriggerNextPhase(int _phaseId); - - virtual int testDestroy(); - -}; - -class TriggeredEvent:public MTGAbilityBasicFeatures{ - public: - TriggeredEvent(); - TriggeredEvent(MTGCardInstance * source, Damageable * target = NULL); - virtual int resolve()=0; -}; - -class DrawEvent:public TriggeredEvent{ - public: - Player * player; - int nbcards; - DrawEvent(Player * _player, int _nbcards); - int resolve(); -}; - -class BuryEvent: public TriggeredEvent{ - public: - int resolve(); -}; - -class DamageEvent:public TriggeredEvent{ - public: - int damage; - DamageEvent(MTGCardInstance * _source, Damageable * _target, int _damage); - int resolve(); -}; - - - -class DestroyCondition:public MTGAbilityBasicFeatures{ - public: - virtual int testDestroy(); -}; - - -class GenericTriggeredAbility:public TriggeredAbility{ - public: - Trigger * t; - TriggeredEvent * te; - DestroyCondition * dc; - GenericTriggeredAbility(int id, MTGCardInstance * _source, Trigger * _t, TriggeredEvent * _te, DestroyCondition * _dc = NULL, Damageable * _target = NULL); - virtual int trigger(); - virtual int resolve(); - virtual int testDestroy(); - ~GenericTriggeredAbility(); -}; - -/* Ability Factory */ -class AbilityFactory{ - private: - int countCards(TargetChooser * tc, Player * player = NULL, int option = 0); - int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p); - int parsePowerToughness(string s, int *power, int *toughness); - Trigger * parseTrigger(string magicText); - Damageable * parseCollateralTarget(MTGCardInstance * card, string s); - public: - int magicText(int id, Spell * spell, MTGCardInstance * card = NULL); - int destroyAllInPlay(TargetChooser * tc, int bury = 0); - int moveAll(TargetChooser * tc, string destinationZone); - int damageAll(TargetChooser * tc, int damage); - void addAbilities(int _id, Spell * spell); -}; - - -class AManaProducer: public MTGAbility{ - protected: - - ManaCost * cost; - ManaCost * output; - string menutext; - float x0,y0,x1,y1,x,y; - float animation; - Player * controller; - int tap; - - hgeParticleSystem * mParticleSys; - public: - static int currentlyTapping; - AManaProducer(int id, MTGCardInstance * card, ManaCost * _output, ManaCost * _cost = NULL, int doTap = 1 ); - void Update(float dt); - void Render(); - int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL); - int resolve(); - int reactToClick(MTGCardInstance * _card); - const char * getMenuText(); - int testDestroy(); - ~AManaProducer(); - virtual ostream& toString(ostream& out) const; -}; - -#include "MTGCardInstance.h" - -#endif - +#ifndef _MTGABILITY_H_ +#define _MTGABILITY_H_ + + + +class MTGCardInstance; +class GameObserver; +class Spell; +class Damageable; +class PlayGuiObject; +class TargetChooser; +class ManaCost; +class MTGGameZone; +class Player; +class AManaProducer; +class WEvent; + +#include "ActionElement.h" +#include +#include +#include +using std::string; +using std::map; + + +//Two stupid variables used to give a hint to the AI: +// Should I cast a spell on an enemy or friendly unit ? +#define BAKA_EFFECT_GOOD 1 +#define BAKA_EFFECT_BAD -1 +#define BAKA_EFFECT_DONTKNOW 0 + +#define COUNT_POWER 1 + +#define PARSER_LORD 1 +#define PARSER_FOREACH 2 +#define PARSER_ASLONGAS 3 + +class MTGAbility: public ActionElement{ + protected: + char menuText[25]; + + GameObserver * game; + public: + int forceDestroy; + ManaCost * cost; + Damageable * target; + int aType; + MTGCardInstance * source; + MTGAbility(int id, MTGCardInstance * card); + MTGAbility(int id, MTGCardInstance * _source, Damageable * _target); + virtual int testDestroy(); + virtual ~MTGAbility(); + virtual void Render(){}; + virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL){return 0;}; + virtual int reactToClick(MTGCardInstance * card){return 0;}; + virtual int receiveEvent(WEvent * event){return 0;}; + virtual void Update(float dt){}; + virtual int fireAbility(); + virtual int stillInUse(MTGCardInstance * card){if (card==source) return 1; return 0;}; + virtual int resolve(){return 0;}; + virtual ostream& toString(ostream& out) const; + + /*Poor man's casting */ + /* Todo replace that crap with dynamic casting */ + enum { + UNKNOWN = 0, + MANA_PRODUCER = 1, + MTG_ATTACK_RULE = 2, + DAMAGER = 3, + STANDARD_REGENERATE = 4, + PUT_INTO_PLAY = 5, + MOMIR = 6, + MTG_BLOCK_RULE = 7, + }; +}; + + +class TriggeredAbility:public MTGAbility{ + public: + TriggeredAbility(int id, MTGCardInstance * card); + TriggeredAbility(int id, MTGCardInstance * _source, Damageable * _target); + virtual void Update(float dt); + virtual void Render(){}; + virtual int trigger()=0; + virtual int resolve() = 0; + virtual ostream& toString(ostream& out) const; +}; + + +class ActivatedAbility:public MTGAbility{ + public: + int playerturnonly; + int needsTapping; + ActivatedAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); + virtual int reactToClick(MTGCardInstance * card); + virtual int isReactingToClick(MTGCardInstance * card, ManaCost * mana = NULL); + virtual int reactToTargetClick(Targetable * object); + virtual int resolve() = 0; + virtual ostream& toString(ostream& out) const; +}; + +class TargetAbility:public ActivatedAbility{ + public: + TargetAbility(int id, MTGCardInstance * card, TargetChooser * _tc,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); + TargetAbility(int id, MTGCardInstance * card,ManaCost * _cost = NULL, int _playerturnonly = 0,int tap = 1); + virtual void Update(float dt); + virtual int reactToClick(MTGCardInstance * card); + virtual int reactToTargetClick(Targetable * object); + virtual void Render(); + virtual ostream& toString(ostream& out) const; +}; + +class InstantAbility:public MTGAbility{ + public: + int init; + virtual void Update(float dt); + virtual int testDestroy(); + InstantAbility(int _id, MTGCardInstance * source); + InstantAbility(int _id, MTGCardInstance * source,Damageable * _target); + virtual int resolve(){return 0;}; + virtual ostream& toString(ostream& out) const; +}; + +/* State based effects. This class works ONLY for InPlay and needs to be extended for other areas of the game !!! */ +class ListMaintainerAbility:public MTGAbility{ + public: + map cards; + ListMaintainerAbility(int _id):MTGAbility(_id,NULL){}; + ListMaintainerAbility(int _id, MTGCardInstance *_source):MTGAbility(_id, _source){}; + ListMaintainerAbility(int _id, MTGCardInstance *_source,Damageable * _target):MTGAbility(_id, _source, _target){}; + virtual void Update(float dt); + virtual int canBeInList(MTGCardInstance * card) = 0; + virtual int added(MTGCardInstance * card) = 0; + virtual int removed(MTGCardInstance * card) = 0; + virtual int destroy(); + virtual ostream& toString(ostream& out) const; +}; + +/* An attempt to globalize triggered abilities as much as possible */ +class MTGAbilityBasicFeatures{ + public: + Damageable * target; + GameObserver * game; + MTGCardInstance * source; + MTGAbilityBasicFeatures(); + MTGAbilityBasicFeatures(MTGCardInstance * _source, Damageable * _target = NULL); + void init(MTGCardInstance * _source, Damageable * _target = NULL); +}; + +class Trigger:public MTGAbilityBasicFeatures{ + public: + virtual int trigger()=0; + virtual int testDestroy(){return 0;}; +}; + + +class TriggerAtPhase:public Trigger{ + public: + int currentPhase, newPhase; + int phaseId; + + TriggerAtPhase(int _phaseId); + + virtual int trigger(); +}; + +class TriggerNextPhase:public TriggerAtPhase{ + public: + int destroyActivated; + TriggerNextPhase(int _phaseId); + + virtual int testDestroy(); + +}; + +class TriggeredEvent:public MTGAbilityBasicFeatures{ + public: + TriggeredEvent(); + TriggeredEvent(MTGCardInstance * source, Damageable * target = NULL); + virtual int resolve()=0; +}; + +class DrawEvent:public TriggeredEvent{ + public: + Player * player; + int nbcards; + DrawEvent(Player * _player, int _nbcards); + int resolve(); +}; + +class BuryEvent: public TriggeredEvent{ + public: + int resolve(); +}; + +class DamageEvent:public TriggeredEvent{ + public: + int damage; + DamageEvent(MTGCardInstance * _source, Damageable * _target, int _damage); + int resolve(); +}; + + + +class DestroyCondition:public MTGAbilityBasicFeatures{ + public: + virtual int testDestroy(); +}; + + +class GenericTriggeredAbility:public TriggeredAbility{ + public: + Trigger * t; + TriggeredEvent * te; + DestroyCondition * dc; + GenericTriggeredAbility(int id, MTGCardInstance * _source, Trigger * _t, TriggeredEvent * _te, DestroyCondition * _dc = NULL, Damageable * _target = NULL); + virtual int trigger(); + virtual int resolve(); + virtual int testDestroy(); + ~GenericTriggeredAbility(); +}; + +/* Ability Factory */ +class AbilityFactory{ + private: + int countCards(TargetChooser * tc, Player * player = NULL, int option = 0); + int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p); + int parsePowerToughness(string s, int *power, int *toughness); + Trigger * parseTrigger(string magicText); + Damageable * parseCollateralTarget(MTGCardInstance * card, string s); + public: + int magicText(int id, Spell * spell, MTGCardInstance * card = NULL); + int destroyAllInPlay(TargetChooser * tc, int bury = 0); + int moveAll(TargetChooser * tc, string destinationZone); + int damageAll(TargetChooser * tc, int damage); + int TapAll(TargetChooser * tc); + void addAbilities(int _id, Spell * spell); +}; + + +class AManaProducer: public MTGAbility{ + protected: + + ManaCost * cost; + ManaCost * output; + string menutext; + float x0,y0,x1,y1,x,y; + float animation; + Player * controller; + int tap; + + hgeParticleSystem * mParticleSys; + public: + static int currentlyTapping; + AManaProducer(int id, MTGCardInstance * card, ManaCost * _output, ManaCost * _cost = NULL, int doTap = 1 ); + void Update(float dt); + void Render(); + int isReactingToClick(MTGCardInstance * _card, ManaCost * mana = NULL); + int resolve(); + int reactToClick(MTGCardInstance * _card); + const char * getMenuText(); + int testDestroy(); + ~AManaProducer(); + virtual ostream& toString(ostream& out) const; +}; + +#include "MTGCardInstance.h" + +#endif + diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 4d0a1f34a..63da15366 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -87,6 +87,21 @@ int AbilityFactory::moveAll(TargetChooser * tc, string destinationZone){ } +int AbilityFactory::TapAll(TargetChooser * tc){ + MTGCardInstance * source = tc->source; + tc->source = NULL; // This is to prevent protection from... + GameObserver * g = GameObserver::GetInstance(); + for (int i = 0; i < 2 ; i++){ + for (int j = g->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){ + MTGCardInstance * current = g->players[i]->game->inPlay->cards[j]; + if (tc->canTarget(current)){ + current->tapped = 1; + } + } + } + tc->source = source; //restore source + return 1; +} int AbilityFactory::putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p){ @@ -931,10 +946,14 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ break; } if (tc){ - game->addObserver(NEW ATapper(id, card, cost, tc)); - }else{ - target->tapped = 1; - } + if (all){ + TapAll(tc); + }else{ + game->addObserver(NEW ATapper(id, card, cost, tc)); + } + }else{ + target->tapped = 1; + } result++; continue; }