Skip to content

Commit

Permalink
* Awakening of Vitu-Ghazi - fixed that it creates non legendary tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
JayDi85 committed Apr 30, 2019
1 parent 67f02ec commit f7622d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@

package mage.abilities.effects.common.continuous;

import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.constants.*;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.TokenImpl;
import mage.game.permanent.token.Token;

import java.util.HashSet;
import java.util.Set;

/**
* @author LevelX2
*
*/
public class BecomesCreatureAllEffect extends ContinuousEffectImpl {

protected Token token;
protected String theyAreStillType;
private final FilterPermanent filter;
private boolean loseColor = true;
protected boolean loseName = false;

public BecomesCreatureAllEffect(Token token, String theyAreStillType, FilterPermanent filter, Duration duration, boolean loseColor) {
this(token, theyAreStillType, filter, duration, loseColor, false);
}

public BecomesCreatureAllEffect(Token token, String theyAreStillType, FilterPermanent filter, Duration duration, boolean loseColor, boolean loseName) {
super(duration, Outcome.BecomeCreature);
this.token = token;
this.theyAreStillType = theyAreStillType;
this.filter = filter;
this.loseColor = loseColor;
this.loseName = loseName;
}

public BecomesCreatureAllEffect(final BecomesCreatureAllEffect effect) {
Expand All @@ -44,6 +43,7 @@ public BecomesCreatureAllEffect(final BecomesCreatureAllEffect effect) {
this.theyAreStillType = effect.theyAreStillType;
this.filter = effect.filter.copy();
this.loseColor = effect.loseColor;
this.loseName = effect.loseName;
}

@Override
Expand All @@ -65,30 +65,47 @@ public BecomesCreatureAllEffect copy() {
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Set<Permanent> affectedPermanents = new HashSet<>();
if (this.affectedObjectsSet) {
for(MageObjectReference ref : affectedObjectList) {
for (MageObjectReference ref : affectedObjectList) {
affectedPermanents.add(ref.getPermanent(game));
}
} else {
affectedPermanents = new HashSet<>(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game));
}

for(Permanent permanent : affectedPermanents) {
for (Permanent permanent : affectedPermanents) {
if (permanent != null) {
switch (layer) {
case TextChangingEffects_3:
if (sublayer == SubLayer.NA) {
if (loseName) {
permanent.setName(token.getName());
}
}
break;

case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
if (!token.getCardType().isEmpty()) {
for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) {
permanent.addCardType(t);
if (theyAreStillType != null) {
permanent.getSubtype(game).retainAll(SubType.getLandTypes());
permanent.getSubtype(game).addAll(token.getSubtype(game));
} else {
for (SubType t : token.getSubtype(game)) {
if (!permanent.hasSubtype(t, game)) {
permanent.getSubtype(game).add(t);
}
}
}
if (theyAreStillType == null) {
permanent.getSubtype(game).clear();

for (SuperType t : token.getSuperType()) {
if (!permanent.getSuperType().contains(t)) {
permanent.addSuperType(t);
}
}
if (!token.getSubtype(game).isEmpty()) {
permanent.getSubtype(game).addAll(token.getSubtype(game));

for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) {
permanent.addCardType(t);
}
}
}
break;
Expand Down Expand Up @@ -141,7 +158,11 @@ public boolean apply(Game game, Ability source) {

@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == Layer.TypeChangingEffects_4;
return layer == Layer.PTChangingEffects_7
|| layer == Layer.AbilityAddingRemovingEffects_6
|| layer == Layer.ColorChangingEffects_5
|| layer == Layer.TypeChangingEffects_4
|| layer == Layer.TextChangingEffects_3;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,34 @@ public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game)
}
}
break;

case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
if (loseAllAbilities) {
permanent.getSubtype(game).retainAll(SubType.getLandTypes());
permanent.getSubtype(game).addAll(token.getSubtype(game));
} else {
if (!token.getSubtype(game).isEmpty()) {
for (SubType subtype : token.getSubtype(game)) {
if (!permanent.hasSubtype(subtype, game)) {
permanent.getSubtype(game).add(subtype);
}
for (SubType t : token.getSubtype(game)) {
if (!permanent.hasSubtype(t, game)) {
permanent.getSubtype(game).add(t);
}
}
}

for (SuperType t : token.getSuperType()) {
if (!permanent.getSuperType().contains(t)) {
permanent.addSuperType(t);
}
}
if (!token.getCardType().isEmpty()) {
for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) {
permanent.addCardType(t);
}

for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) {
permanent.addCardType(t);
}
}
}
break;

case ColorChangingEffects_5:
if (sublayer == SubLayer.NA) {
if (loseAllAbilities) {
Expand All @@ -107,6 +111,7 @@ public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game)
}
}
break;

case AbilityAddingRemovingEffects_6:
if (loseAllAbilities) {
permanent.removeAllAbilities(source.getSourceId(), game);
Expand Down

0 comments on commit f7622d3

Please sign in to comment.