Skip to content

Commit

Permalink
Card: add Suspected Flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanmac committed Jan 21, 2024
1 parent b274ead commit 3dd7a6a
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 8 deletions.
7 changes: 7 additions & 0 deletions forge-ai/src/main/java/forge/ai/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ private void addCard(ZoneType zoneType, Map<ZoneType, String> cardTexts, Card c)
if (c.isSolved()) {
newText.append("|Solved");
}
if (c.isSuspected()) {
newText.append("|Suspected");
}
if (c.isMonstrous()) {
newText.append("|Monstrous");
}
Expand Down Expand Up @@ -1259,6 +1262,10 @@ private CardCollectionView processCardsForZone(final String[] data, final Player
c.tap(false, null, null);
} else if (info.startsWith("Renowned")) {
c.setRenowned(true);
} else if (info.startsWith("Solved")) {
c.setSolved(true);
} else if (info.startsWith("Suspected")) {
c.setSuspected(true);
} else if (info.startsWith("Monstrous")) {
c.setMonstrous(true);
} else if (info.startsWith("PhasedOut")) {
Expand Down
3 changes: 3 additions & 0 deletions forge-ai/src/main/java/forge/ai/simulation/GameCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ private void addCard(Game newGame, ZoneType zone, Card c, Player aiPlayer) {
if (c.isSolved()) {
newCard.setSolved(true);
}
if (c.isSuspected()) {
newCard.setSuspected(true);
}
if (c.isPlaneswalker()) {
for (SpellAbility sa : c.getAllSpellAbilities()) {
int active = sa.getActivationsThisTurn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import forge.game.card.Card;
import forge.game.card.CardCollection;
import forge.game.spellability.SpellAbility;
import forge.util.Lang;
import forge.util.TextUtil;

import java.util.ArrayList;

Expand All @@ -15,15 +17,30 @@ public void resolve(SpellAbility sa) {
ArrayList<String> attributes = Lists.newArrayList(sa.getParam("Attributes").split(","));
CardCollection defined = getDefinedCardsOrTargeted(sa, "Defined");

if (sa.hasParam("Optional")) {
final String targets = Lang.joinHomogenous(defined);
final String message = sa.hasParam("OptionQuestion")
? TextUtil.fastReplace(sa.getParam("OptionQuestion"), "TARGETS", targets)
: getStackDescription(sa);

if (!sa.getActivatingPlayer().getController().confirmAction(sa, null, message, null)) {
return;
}
}

for(Card c : defined) {
for(String attr : attributes) {
switch(attr.trim()) {
case "Solve":
case "Solved":
c.setSolved(activate);
break;
case "Suspect":
case "Suspected":
c.setSuspected(activate);
break;

// Other attributes: renown, monstrous, suspected, etc
// Other attributes: renown, monstrous, suspected, etc

default:
break;
Expand Down
43 changes: 36 additions & 7 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
protected KeywordsChange changedCardKeywordsByWord = new KeywordsChange(ImmutableList.<KeywordInterface>of(), ImmutableList.<KeywordInterface>of(), false); // Layer 3 by Word Change
private final Table<Long, Long, KeywordsChange> changedCardKeywords = TreeBasedTable.create(); // Layer 6

protected KeywordsChange suspectedKeywordChange = null;

// stores the keywords created by static abilities
private final Map<Triple<String, Long, Long>, KeywordInterface> storedKeywords = Maps.newHashMap();

Expand Down Expand Up @@ -216,6 +218,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {

private boolean renowned;
private boolean solved = false;
private boolean suspected = false;

private boolean manifested;

Expand Down Expand Up @@ -2599,6 +2602,9 @@ else if (o.grantsZonePermissions())
if (solved) {
sb.append("Solved\r\n");
}
if (suspected) {
sb.append("Suspected\r\n");
}
if (manifested) {
sb.append("Manifested\r\n");
}
Expand Down Expand Up @@ -3935,7 +3941,8 @@ public Iterable<KeywordsChange> getChangedCardKeywordsList() {
changedCardKeywordsByText.values(), // Layer 3
ImmutableList.of(changedCardKeywordsByWord), // Layer 3
ImmutableList.of(new KeywordsChange(ImmutableList.<KeywordInterface>of(), ImmutableList.<KeywordInterface>of(), this.hasRemoveIntrinsic())), // Layer 4
changedCardKeywords.values() // Layer 6
changedCardKeywords.values(), // Layer 6
getSuspectedKeywordChange() // Menace by Suspected
);
}

Expand Down Expand Up @@ -4414,21 +4421,21 @@ public final void addPerpetual(Map<String, Object> p) {
public final void executePerpetual(Map<String, Object> p) {
final String category = (String) p.get("Category");
if (category.equals("NewPT")) {
addNewPT((Integer) p.get("Power"), (Integer) p.get("Toughness"), (long)
addNewPT((Integer) p.get("Power"), (Integer) p.get("Toughness"), (long)
p.get("Timestamp"), (long) 0);
} else if (category.equals("PTBoost")) {
addPTBoost((Integer) p.get("Power"), (Integer) p.get("Toughness"), (long)
addPTBoost((Integer) p.get("Power"), (Integer) p.get("Toughness"), (long)
p.get("Timestamp"), (long) 0);
} else if (category.equals("Keywords")) {
boolean removeAll = p.containsKey("RemoveAll") && (boolean) p.get("RemoveAll") == true;
addChangedCardKeywords((List<String>) p.get("AddKeywords"), Lists.newArrayList(), removeAll,
addChangedCardKeywords((List<String>) p.get("AddKeywords"), Lists.newArrayList(), removeAll,
(long) p.get("Timestamp"), (long) 0);
} else if (category.equals("Types")) {
addChangedCardTypes((CardType) p.get("AddTypes"), (CardType) p.get("RemoveTypes"),
false, (Set<RemoveType>) p.get("RemoveXTypes"),
addChangedCardTypes((CardType) p.get("AddTypes"), (CardType) p.get("RemoveTypes"),
false, (Set<RemoveType>) p.get("RemoveXTypes"),
(long) p.get("Timestamp"), (long) 0, true, false);
} else if (category.equals("Colors")) {
addColor((ColorSet) p.get("Colors"), !(boolean) p.get("Overwrite"), (long) p.get("Timestamp"),
addColor((ColorSet) p.get("Colors"), !(boolean) p.get("Overwrite"), (long) p.get("Timestamp"),
(long) 0, false);
}
}
Expand Down Expand Up @@ -6226,6 +6233,28 @@ public final void setSolved(final boolean solved) {
this.solved = solved;
}

public final boolean isSuspected() {
return suspected;
}

public final void setSuspected(final boolean suspected) {
if (suspected && StaticAbilityCantBeSuspected.cantBeSuspected(this)) {
return;
}
this.suspected = suspected;
if (suspected) {
KeywordInterface kw = Keyword.getInstance("Menace");
kw.createTraits(this, false);
suspectedKeywordChange = new KeywordsChange(ImmutableList.of(kw), ImmutableList.<String>of(), false);
}
updateKeywords();
}

protected Iterable<KeywordsChange> getSuspectedKeywordChange()
{
return isSuspected() ? ImmutableList.of(this.suspectedKeywordChange) : ImmutableList.of();
}

public final boolean isManifested() {
return manifested;
}
Expand Down
8 changes: 8 additions & 0 deletions forge-game/src/main/java/forge/game/card/CardProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,14 @@ else if (property.equals("blocked")) {
if (card.isSolved()) {
return false;
}
} else if (property.equals("IsSuspected")) {
if (!card.isSuspected()) {
return false;
}
} else if (property.equals("IsUnsuspected")) {
if (card.isSuspected()) {
return false;
}
} else if (property.equals("IsRemembered")) {
if (!source.isRemembered(card)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions forge-game/src/main/java/forge/game/card/CardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public static Card getLKICopy(final Card in, Map<Integer, Card> cachedMap) {
newCopy.setMonstrous(in.isMonstrous());
newCopy.setRenowned(in.isRenowned());
newCopy.setSolved(in.isSolved());
newCopy.setSuspected(in.isSuspected());

newCopy.setColor(in.getColor().getColor());
newCopy.setPhasedOut(in.getPhasedOut());
Expand Down
4 changes: 4 additions & 0 deletions forge-game/src/main/java/forge/game/combat/CombatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ public static boolean canBlock(final Card blocker, final boolean nextTurn) {
return false;
}

if (blocker.isSuspected()) {
return false;
}

if (blocker.hasKeyword("CARDNAME can't block.") || blocker.hasKeyword("CARDNAME can't attack or block.")
|| blocker.isPhasedOut()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package forge.game.staticability;

import forge.game.Game;
import forge.game.card.Card;
import forge.game.zone.ZoneType;

public class StaticAbilityCantBeSuspected {

static String MODE = "CantBeSuspected";

public static boolean cantBeSuspected(final Card c) {
final Game game = c.getGame();
for (final Card ca : game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES)) {
for (final StaticAbility stAb : ca.getStaticAbilities()) {
if (!stAb.checkConditions(MODE)) {
continue;
}
if (cantBeSuspectedCheck(stAb, c)) {
return true;
}
}
}
return false;
}

private static boolean cantBeSuspectedCheck(final StaticAbility stAb, final Card card) {
if (stAb.matchesValidParam("ValidCard", card)) {
return true;
}
return false;
}
}

0 comments on commit 3dd7a6a

Please sign in to comment.