added new auto keys, this and thisforeach, functionallity similair to aslongas and foreach, but for properties of the card as opposed to cards on the field. More details in first comment.

This commit is contained in:
salmelo16
2010-03-28 02:21:25 +00:00
parent a2987f7b0e
commit a06980a197
17 changed files with 728 additions and 13 deletions

View File

@@ -14,6 +14,7 @@
#include "WEvent.h"
#include "GuiStatic.h"
#include "GameObserver.h"
#include "ThisDescriptor.h"
#include <JGui.h>
#include <hge/hgeparticle.h>
@@ -1875,8 +1876,148 @@ class AForeach:public ListMaintainerAbility{
};
class AThis:public MTGAbility{
public:
MTGAbility * ability;
MTGAbility * a;
ThisDescriptor * td;
AThis(int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability):MTGAbility(_id, _source,_target),ability(ability){
td = _td;
ability->source = source;
ability->target = target;
a = NULL;
SAFE_DELETE(tc);
}
int removeFromGame(){
return removeAbilityFromGame();
}
int addToGame(){
return MTGAbility::addToGame();
}
void Update(float dt){
resolve();
}
int resolve(){
//TODO check if ability is oneShot ?
if (td->match(source) > 0){
addAbilityToGame();
}
if (ability->oneShot) a = NULL; //allows to call the effect several times
return 1;
}
int addAbilityToGame(){
if (a) return 0;
a = ability->clone();
if (a->oneShot){
a->resolve();
delete(a);
}else{
a->addToGame();
}
return 1;
}
int removeAbilityFromGame(){
if (!a) return 0;
game->removeObserver(a);
a = NULL;
return 1;
}
~AThis(){
if (!isClone) SAFE_DELETE(ability); SAFE_DELETE(td);
}
AThis * clone() const{
AThis * a = NEW AThis(*this);
a->isClone = 1;
return a;
}
};
class AThisForEach:public MTGAbility{
public:
MTGAbility * ability;
ThisDescriptor * td;
vector<MTGAbility *> abilities;
AThisForEach(int _id, MTGCardInstance * _source, Damageable * _target, ThisDescriptor * _td, MTGAbility * ability):MTGAbility(_id, _source,_target),ability(ability){
td = _td;
ability->source = source;
ability->target = target;
SAFE_DELETE(tc);
}
int removeFromGame(){
return removeAbilityFromGame();
}
int addToGame(){
return MTGAbility::addToGame();
}
void Update(float dt){
resolve();
}
int resolve(){
//TODO check if ability is oneShot ?
int matches = td->match(source);
if (matches > 0) {
if (abilities.size()){
removeAbilityFromGame();
}
for (int i = 0; i < matches; i++) {
addAbilityToGame();
}
}
return 1;
}
int addAbilityToGame(){
MTGAbility * a = ability->clone();
a->target = target;
if (a->oneShot){
a->resolve();
delete(a);
}else{
a->addToGame();
abilities.push_back(a);
//abilities[abilities.size()] = a;
}
return 1;
}
int removeAbilityFromGame(){
for (int i = abilities.size(); i > 0; i--){
game->removeObserver(abilities[i-1]);
}
abilities.clear();
return 1;
}
~AThisForEach(){
if (!isClone){
SAFE_DELETE(ability);
SAFE_DELETE(td);
}
if (abilities.size()){
removeAbilityFromGame();
}
}
AThisForEach * clone() const{
AThisForEach * a = NEW AThisForEach(*this);
a->isClone = 1;
return a;
}
};
class AADamager:public ActivatedAbilityTP{
public:

View File

@@ -0,0 +1,53 @@
/*
Filter-like system for determining if a card meats certain criteria, for this and thisforeach autos
*/
#ifndef _THISDESCRIPTOR_H_
#define _THISDESCRIPTOR_H_
#include "Counters.h"
#include "MTGGameZones.h"
#include "MTGCardInstance.h"
#include "CardDescriptor.h"
class ThisDescriptor{
public:
int comparisonMode;
int comparisonCriterion;
virtual int match(MTGCardInstance * card) = 0;
int matchValue(int value);
};
class ThisDescriptorFactory{
public:
ThisDescriptor * createThisDescriptor(string s);
};
class ThisCounter:public ThisDescriptor{
public:
Counter * counter;
virtual int match(MTGCardInstance * card);
ThisCounter(Counter * _counter);
ThisCounter(int power, int toughness, int nb, const char * name);
~ThisCounter();
};
class ThisCounterAny:public ThisDescriptor{
public:
virtual int match(MTGCardInstance *card);
ThisCounterAny(int nb);
};
class ThisPower:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisPower(int power);
};
class ThisToughness:public ThisDescriptor{
public:
virtual int match(MTGCardInstance * card);
ThisToughness(int toughness);
};
#endif