Commit 6fa513fe authored by Michael Kamensky's avatar Michael Kamensky

Merge branch 'gainControlRework' into 'master'

ControlGain: without addExtrinsicKeyword

See merge request !1988
parents 6f52632c 6cf5a08b
......@@ -290,7 +290,6 @@ public class GameCopier {
// TODO: Is this correct? Does it not duplicate keywords from enchantments and such?
for (KeywordInterface kw : c.getHiddenExtrinsicKeywords())
newCard.addHiddenExtrinsicKeyword(kw);
newCard.setExtrinsicKeyword(Lists.newArrayList(c.getExtrinsicKeyword()));
if (c.isTapped()) {
newCard.setTapped(true);
}
......
......@@ -3,6 +3,8 @@ package forge.game.ability.effects;
import java.util.Arrays;
import java.util.List;
import com.google.common.collect.Lists;
import forge.GameCommand;
import forge.card.mana.ManaCost;
import forge.game.Game;
......@@ -11,6 +13,7 @@ import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
import forge.game.card.CardCollectionView;
import forge.game.card.CardLists;
import forge.game.event.GameEventCardStatsChanged;
import forge.game.player.Player;
import forge.game.spellability.Ability;
import forge.game.spellability.SpellAbility;
......@@ -35,23 +38,26 @@ public class ControlGainEffect extends SpellAbilityEffect {
if (tgts.isEmpty()) {
sb.append(" (nothing)");
} else {
for (final Card c : getDefinedCards(sa)) {
sb.append(" ");
if (c.isFaceDown()) {
sb.append("Face-down creature (").append(c.getId()).append(')');
} else {
sb.append(c);
}
}
for (final Card c : tgts) {
sb.append(" ");
if (c.isFaceDown()) {
sb.append("Face-down creature (").append(c.getId()).append(')');
} else {
sb.append(c);
}
}
}
sb.append(".");
if (sa.hasParam("Untap")) {
sb.append(" Untap it.");
}
return sb.toString();
}
private static void doLoseControl(final Card c, final Card host,
final boolean tapOnLose, final List<String> addedKeywords,
final long tStamp) {
final boolean tapOnLose, final long tStamp) {
if (null == c || c.hasKeyword("Other players can't gain control of CARDNAME.")) {
return;
}
......@@ -61,12 +67,6 @@ public class ControlGainEffect extends SpellAbilityEffect {
if (tapOnLose) {
c.tap();
}
if (null != addedKeywords) {
for (final String kw : addedKeywords) {
c.removeExtrinsicKeyword(kw);
}
}
} // if
host.removeGainControlTargets(c);
......@@ -82,7 +82,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
final boolean remember = sa.hasParam("RememberControlled");
final boolean forget = sa.hasParam("ForgetControlled");
final List<String> destroyOn = sa.hasParam("DestroyTgt") ? Arrays.asList(sa.getParam("DestroyTgt").split(",")) : null;
final List<String> kws = sa.hasParam("AddKWs") ? Arrays.asList(sa.getParam("AddKWs").split(" & ")) : null;
final List<String> keywords = sa.hasParam("AddKWs") ? Arrays.asList(sa.getParam("AddKWs").split(" & ")) : null;
final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null;
final List<Player> controllers = getDefinedPlayersOrTargeted(sa, "NewController");
......@@ -125,15 +125,22 @@ public class ControlGainEffect extends SpellAbilityEffect {
tgtC.untap();
}
if (null != kws) {
for (final String kw : kws) {
tgtC.addExtrinsicKeyword(kw);
if (kw.equals("Haste")) {
tgtC.updateStateForView(); // ensure that summoning sickness icon is removed
final List<String> kws = Lists.newArrayList();
if (null != keywords) {
for (final String kw : keywords) {
if (kw.startsWith("HIDDEN")) {
tgtC.addHiddenExtrinsicKeyword(kw);
} else {
kws.add(kw);
}
}
}
if (!kws.isEmpty()) {
tgtC.addChangedCardKeywords(kws, Lists.<String>newArrayList(), false, false, tStamp);
game.fireEvent(new GameEventCardStatsChanged(tgtC));
}
if (remember && !sa.getHostCard().isRemembered(tgtC)) {
sa.getHostCard().addRemembered(tgtC);
}
......@@ -143,7 +150,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
}
if (lose != null) {
final GameCommand loseControl = getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws);
final GameCommand loseControl = getLoseControlCommand(tgtC, tStamp, bTapOnLose, source);
if (lose.contains("LeavesPlay")) {
sa.getHostCard().addLeavesPlayCommand(loseControl);
}
......@@ -183,6 +190,26 @@ public class ControlGainEffect extends SpellAbilityEffect {
}
}
if (keywords != null) {
// Add keywords only until end of turn
final GameCommand untilKeywordEOT = new GameCommand() {
private static final long serialVersionUID = -42244224L;
@Override
public void run() {
if (keywords.size() > 0) {
for (String kw : keywords) {
if (kw.startsWith("HIDDEN")) {
tgtC.removeHiddenExtrinsicKeyword(kw);
}
}
tgtC.removeChangedCardKeywords(tStamp);
}
}
};
game.getEndOfTurn().addUntil(untilKeywordEOT);
}
game.getAction().controllerChangeZoneCorrection(tgtC);
} // end foreach target
}
......@@ -236,14 +263,13 @@ public class ControlGainEffect extends SpellAbilityEffect {
* @return a {@link forge.GameCommand} object.
*/
private static GameCommand getLoseControlCommand(final Card c,
final long tStamp, final boolean bTapOnLose, final Card hostCard,
final List<String> kws) {
final long tStamp, final boolean bTapOnLose, final Card hostCard) {
final GameCommand loseControl = new GameCommand() {
private static final long serialVersionUID = 878543373519872418L;
@Override
public void run() {
doLoseControl(c, hostCard, bTapOnLose, kws, tStamp);
doLoseControl(c, hostCard, bTapOnLose, tStamp);
c.getSVars().remove("SacMe");
}
};
......
......@@ -94,7 +94,6 @@ public class Card extends GameEntity implements Comparable<Card> {
private final CardDamageHistory damageHistory = new CardDamageHistory();
private Map<Card, Map<CounterType, Integer>> countersAddedBy = Maps.newTreeMap();
private KeywordCollection extrinsicKeyword = new KeywordCollection();
// Hidden keywords won't be displayed on the card
private final KeywordCollection hiddenExtrinsicKeyword = new KeywordCollection();
......@@ -3727,7 +3726,6 @@ public class Card extends GameEntity implements Comparable<Card> {
if (!removeIntrinsic) {
keywords.insertAll(state.getIntrinsicKeywords());
}
keywords.insertAll(extrinsicKeyword.getValues());
// see if keyword changes are in effect
for (final KeywordsChange ck : changedCardKeywords.values()) {
......@@ -3755,11 +3753,6 @@ public class Card extends GameEntity implements Comparable<Card> {
return;
}
}
for (KeywordInterface kw : extrinsicKeyword.getValues()) {
if (!visitor.visit(kw)) {
return;
}
}
} else {
for (KeywordInterface kw : getUnhiddenKeywords(state)) {
if (!visitor.visit(kw)) {
......@@ -3927,53 +3920,6 @@ public class Card extends GameEntity implements Comparable<Card> {
}
}
public Collection<KeywordInterface> getExtrinsicKeyword() {
return extrinsicKeyword.getValues();
}
public final void setExtrinsicKeyword(final List<String> a) {
extrinsicKeyword.clear();
extrinsicKeyword.addAll(a);
}
public void setExtrinsicKeyword(Collection<KeywordInterface> extrinsicKeyword2) {
extrinsicKeyword.clear();
extrinsicKeyword.insertAll(extrinsicKeyword2);
}
public void addExtrinsicKeyword(final String s) {
if (s.startsWith("HIDDEN")) {
addHiddenExtrinsicKeyword(s);
}
else {
extrinsicKeyword.add(s);
}
}
public void removeExtrinsicKeyword(final String s) {
if (s.startsWith("HIDDEN")) {
removeHiddenExtrinsicKeyword(s);
}
else if (extrinsicKeyword.remove(s)) {
currentState.getView().updateKeywords(this, currentState);
}
}
public void removeAllExtrinsicKeyword(final String s) {
final List<String> strings = Lists.newArrayList();
strings.add(s);
boolean needKeywordUpdate = false;
if (extrinsicKeyword.removeAll(strings)) {
needKeywordUpdate = true;
}
strings.add("HIDDEN " + s);
if (hiddenExtrinsicKeyword.removeAll(strings)) {
view.updateNonAbilityText(this);
needKeywordUpdate = true;
}
if (needKeywordUpdate) {
currentState.getView().updateKeywords(this, currentState);
}
}
// Hidden Keywords will be returned without the indicator HIDDEN
public final List<KeywordInterface> getHiddenExtrinsicKeywords() {
ListKeywordVisitor visitor = new ListKeywordVisitor();
......
......@@ -255,7 +255,6 @@ public final class CardUtil {
newCopy.setBaseToughness(in.getCurrentToughness() + in.getTempToughnessBoost() + in.getSemiPermanentToughnessBoost());
newCopy.setCounters(Maps.newEnumMap(in.getCounters()));
newCopy.setExtrinsicKeyword(in.getExtrinsicKeyword());
newCopy.setColor(in.determineColor().getColor());
newCopy.setReceivedDamageFromThisTurn(in.getReceivedDamageFromThisTurn());
......
......@@ -209,11 +209,10 @@ public class Untap extends Phase {
// Remove temporary keywords
for (final Card c : player.getCardsIn(ZoneType.Battlefield)) {
c.removeAllExtrinsicKeyword("This card doesn't untap during your next untap step.");
c.removeAllExtrinsicKeyword("HIDDEN This card doesn't untap during your next untap step.");
c.removeHiddenExtrinsicKeyword("This card doesn't untap during your next untap step.");
if (c.hasKeyword("This card doesn't untap during your next two untap steps.")) {
c.removeAllExtrinsicKeyword("HIDDEN This card doesn't untap during your next two untap steps.");
c.addHiddenExtrinsicKeyword("HIDDEN This card doesn't untap during your next untap step.");
c.removeHiddenExtrinsicKeyword("This card doesn't untap during your next two untap steps.");
c.addHiddenExtrinsicKeyword("This card doesn't untap during your next untap step.");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment