use of mage.game.permanent.token.Token in project mage by magefree.
the class SarpadianEmpiresCreateSelectedTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
String tokenType = game.getState().getValue(source.getSourceId().toString() + "_SarpadianEmpiresVolVii").toString();
Token token;
switch(tokenType) {
case "White Citizen":
token = new CitizenToken();
break;
case "Blue Camarid":
token = new CamaridToken();
break;
case "Black Thrull":
token = new ThrullToken();
break;
case "Red Goblin":
token = new GoblinToken();
break;
default:
token = new SaprolingToken();
break;
}
token.putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class SaprolingBurstDestroyEffect method apply.
@Override
@SuppressWarnings("unchecked")
public boolean apply(Game game, Ability source) {
Token token = new SaprolingBurstToken(new MageObjectReference(source.getSourceObject(game), game));
token.putOntoBattlefield(1, game, source, source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game));
Set<UUID> tokensCreated;
if (object != null) {
tokensCreated = (Set<UUID>) object;
} else {
tokensCreated = new HashSet<>();
}
for (UUID tokenId : token.getLastAddedTokenIds()) {
tokensCreated.add(tokenId);
}
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
}
return true;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class SarkhanTheMadDragonDamageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
Token dragonToken = new DragonToken2();
dragonToken.putOntoBattlefield(1, game, source, player.getId());
}
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class TheBookOfVileDarknessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Set<MageObjectReference> morSet = (Set<MageObjectReference>) getValue("BookEyeHand");
if (morSet == null) {
return false;
}
Token token = new VecnaToken();
for (MageObjectReference mor : morSet) {
// the card object in the mor doesn't work, so the permanent object is used
Permanent card = mor.getPermanentOrLKIBattlefield(game);
if (card == null) {
continue;
}
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof TriggeredAbility) {
Ability copyAbility = ability.copy();
copyAbility.newId();
copyAbility.setControllerId(source.getControllerId());
token.addAbility(copyAbility);
}
}
}
return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class MageBook method loadTokens.
public List<Object> loadTokens() {
List<Object> res = new ArrayList<>();
// tokens
List<CardDownloadData> allTokens = getTokenCardUrls();
for (CardDownloadData token : allTokens) {
if (token.getSet().equals(currentSet)) {
try {
String className = token.getName();
className = className.replaceAll("[^a-zA-Z0-9]", "");
className = "mage.game.permanent.token." + className + "Token";
if (token.getTokenClassName() != null && token.getTokenClassName().length() > 0) {
if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*token.*")) {
className = token.getTokenClassName();
className = "mage.game.permanent.token." + className;
} else if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
continue;
}
}
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newToken = cons.newInstance();
if (newToken instanceof Token) {
((Token) newToken).setOriginalExpansionSetCode(currentSet);
((Token) newToken).setExpansionSetCodeForImage(currentSet);
((Token) newToken).setTokenType(token.getType());
res.add(newToken);
}
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
// Swallow exception
}
}
}
// emblems
List<CardDownloadData> allEmblems = getTokenCardUrls();
for (CardDownloadData emblem : allEmblems) {
if (emblem.getSet().equals(currentSet)) {
try {
String className = emblem.getName();
if (emblem.getTokenClassName() != null && emblem.getTokenClassName().length() > 0) {
if (emblem.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
className = emblem.getTokenClassName();
className = "mage.game.command.emblems." + className;
}
} else {
continue;
}
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newEmblem = cons.newInstance();
if (newEmblem instanceof Emblem) {
((Emblem) newEmblem).setExpansionSetCodeForImage(currentSet);
res.add(newEmblem);
}
} catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
// Swallow exception
}
}
}
// planes
List<CardDownloadData> allPlanes = getTokenCardUrls();
for (CardDownloadData plane : allPlanes) {
if (plane.getSet().equals(currentSet)) {
try {
String className = plane.getName();
if (plane.getTokenClassName() != null && plane.getTokenClassName().length() > 0) {
if (plane.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*plane.*")) {
className = plane.getTokenClassName();
className = "mage.game.command.planes." + className;
}
} else {
continue;
}
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newPlane = cons.newInstance();
if (newPlane instanceof Plane) {
((Plane) newPlane).setExpansionSetCodeForImage(currentSet);
res.add(newPlane);
}
} catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
// Swallow exception
}
}
}
// dungeons
List<CardDownloadData> allDungeons = getTokenCardUrls();
for (CardDownloadData dungeon : allDungeons) {
if (dungeon.getSet().equals(currentSet)) {
try {
String className = dungeon.getName();
if (dungeon.getTokenClassName() != null && dungeon.getTokenClassName().length() > 0) {
if (dungeon.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*dungeon.*")) {
className = dungeon.getTokenClassName();
className = "mage.game.command.dungeons." + className;
}
} else {
continue;
}
Class<?> c = Class.forName(className);
Constructor<?> cons = c.getConstructor();
Object newDungeon = cons.newInstance();
if (newDungeon instanceof Dungeon) {
((Dungeon) newDungeon).setExpansionSetCodeForImage(currentSet);
res.add(newDungeon);
}
} catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
// Swallow exception
}
}
}
return res;
}
Aggregations