Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/AI_ATTACK_TIMEOUT' into AI_ATTAC…
Browse files Browse the repository at this point in the history
…K_TIMEOUT
  • Loading branch information
kevlahnota committed Nov 25, 2024
2 parents e1d7c4a + 8fa1ce1 commit c317d1f
Show file tree
Hide file tree
Showing 235 changed files with 3,465 additions and 3,418 deletions.
1 change: 1 addition & 0 deletions .github/workflows/remove-stale-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
remove-stale-branches:
if: github.repository_owner == 'Card-Forge'
name: Remove Stale Branches
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/snapshots-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,10 @@ jobs:
local-dir: upload/
server-dir: downloads/dailysnapshots/
state-name: .ftp-deploy-android-sync-state.json

- name: Send failure notification to Discord
if: failure() # This step runs only if the job fails
run: |
curl -X POST -H "Content-Type: application/json" \
-d "{\"content\": \"🔴 Android Snapshot Build Failed in branch: \`${{ github.ref_name }}\` by \`${{ github.actor }}\`.\nCheck logs: ${{ github.run_url }}\"}" \
${{ secrets.DISCORD_AUTOMATION_WEBHOOK }}
7 changes: 7 additions & 0 deletions .github/workflows/snapshots-pc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ jobs:
*.pom
*.repositories
*.xml
- name: Send failure notification to Discord
if: failure() # This step runs only if the job fails
run: |
curl -X POST -H "Content-Type: application/json" \
-d "{\"content\": \"🔴 Desktop Snapshot Build Failed in branch: \`${{ github.ref_name }}\` by \`${{ github.actor }}\`.\nCheck logs: ${{ github.run_url }}\"}" \
${{ secrets.DISCORD_AUTOMATION_WEBHOOK }}
8 changes: 1 addition & 7 deletions forge-ai/src/main/java/forge/ai/simulation/GameCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,7 @@ private void addCard(Game newGame, ZoneType zone, Card c, Player aiPlayer) {
newCard.setDamage(c.getDamage());
newCard.setDamageReceivedThisTurn(c.getDamageReceivedThisTurn());

newCard.setChangedCardColors(c.getChangedCardColorsTable());
newCard.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningTable());

newCard.setChangedCardTypes(c.getChangedCardTypesTable());
newCard.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningTable());
newCard.setChangedCardKeywords(c.getChangedCardKeywords());
newCard.setChangedCardNames(c.getChangedCardNames());
newCard.copyFrom(c);

for (Table.Cell<Long, Long, List<String>> kw : c.getHiddenExtrinsicKeywordsTable().cellSet()) {
newCard.addHiddenExtrinsicKeywords(kw.getRowKey(), kw.getColumnKey(), kw.getValue());
Expand Down
10 changes: 9 additions & 1 deletion forge-game/src/main/java/forge/game/GameActionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,15 @@ public static SpellAbility addExtraKeywordCost(final SpellAbility sa) {
host.getGame().getTriggerHandler().resetActiveTriggers(false);
}

return result != null ? result : sa;
if (result != null) {
// sanity check if need to update castSA
if (sa.getHostCard().getCastSA() == sa) {
sa.getHostCard().setCastSA(result);
}
return result;
}

return sa;
}

public static Card createETBCountersEffect(Card sourceCard, Card c, Player controller, String counter, String amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ public class ChooseCardNameEffect extends SpellAbilityEffect {

@Override
protected String getStackDescription(SpellAbility sa) {
final StringBuilder sb = new StringBuilder();

sb.append(Lang.joinHomogenous(getTargetPlayers(sa)));
sb.append("names a card.");

return sb.toString();
return Lang.joinHomogenous(getTargetPlayers(sa)) + " names a card.";
}

@Override
Expand Down Expand Up @@ -66,7 +62,7 @@ public void resolve(SpellAbility sa) {
if (!p.isInGame()) {
continue;
}
String chosen = "";
String chosen;
//This section was used for Momir Avatar, which no longer uses it - commented out 7/28/2021
//if (randomChoice) {
//String numericAmount = "X";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void resolve(final SpellAbility sa) {
final boolean forget = sa.hasParam("ForgetPlayed");
final boolean hasTotalCMCLimit = sa.hasParam("WithTotalCMC");
final boolean altCost = sa.hasParam("WithoutManaCost") || sa.hasParam("PlayCost");
final boolean altCostManaCost = "ManaCost".equals(sa.getParam("PlayCost"));
int totalCMCLimit = Integer.MAX_VALUE;
final Player controller;
if (sa.hasParam("Controller")) {
Expand Down Expand Up @@ -308,6 +309,10 @@ public void resolve(final SpellAbility sa) {
sas.removeIf(sp -> !sp.isValid(valid, controller , source, sa));
}

if (altCostManaCost) {
sas.removeIf(sp -> sp.getPayCosts().getCostMana().getMana().isNoCost());
}

if (hasTotalCMCLimit) {
Iterator<SpellAbility> it = sas.iterator();
while (it.hasNext()) {
Expand Down Expand Up @@ -380,11 +385,8 @@ public void resolve(final SpellAbility sa) {
} else if (sa.hasParam("PlayCost")) {
Cost abCost;
String cost = sa.getParam("PlayCost");
if (cost.equals("ManaCost")) {
if (unpayableCost) {
continue;
}
abCost = new Cost(source.getManaCost(), false);
if (altCostManaCost) {
abCost = new Cost(tgtSA.getCardState().getManaCost(), false);
} else if (cost.equals("SuspendCost")) {
abCost = Iterables.find(tgtCard.getNonManaAbilities(), s -> s.isKeyword(Keyword.SUSPEND)).getPayCosts();
} else {
Expand Down Expand Up @@ -428,7 +430,7 @@ public void resolve(final SpellAbility sa) {
tgtSA.putParam("RaiseCost", raise);
}

if (sa.hasParam("Madness")) {
if (sa.isKeyword(Keyword.MADNESS)) {
tgtSA.setAlternativeCost(AlternativeCost.Madness);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void resolve(SpellAbility sa) {
pool = CardLists.getValidCards(pool, seekType, source.getController(), source, sa);
}
if (pool.isEmpty()) {
if (notify.length() != 0) notify.append("\r\n");
if (!notify.isEmpty()) notify.append("\r\n");
notify.append(Localizer.getInstance().getMessage("lblSeekFailed", seekType));
continue; // can't find if nothing to seek
}
Expand All @@ -88,7 +88,7 @@ public void resolve(SpellAbility sa) {

}
}
if (notify.length() != 0) {
if (!notify.isEmpty()) {
game.getAction().notifyOfValue(sa, source, notify.toString(), null);
}
if (!soughtCards.isEmpty()) {
Expand All @@ -98,7 +98,9 @@ public void resolve(SpellAbility sa) {
if (sa.hasParam("ImprintFound")) {
source.addImprintedCards(soughtCards);
}
game.getTriggerHandler().runTrigger(TriggerType.SeekAll, AbilityKey.mapFromPlayer(seeker), false);
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(seeker);
runParams.put(AbilityKey.Cards, soughtCards);
game.getTriggerHandler().runTrigger(TriggerType.SeekAll, runParams, false);
}
}
triggerList.triggerChangesZoneAll(game, sa);
Expand Down
102 changes: 43 additions & 59 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import forge.game.event.*;
import forge.game.event.GameEventCardDamaged.DamageType;
import forge.game.keyword.*;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.Player;
import forge.game.player.PlayerCollection;
import forge.game.replacement.*;
Expand Down Expand Up @@ -988,15 +989,6 @@ public void updateNameforView() {
currentState.getView().updateName(currentState);
}

public Table<Long, Long, CardChangedName> getChangedCardNames() {
return changedCardNames;
}

public void setChangedCardNames(Table<Long, Long, CardChangedName> changedCardNames) {
this.changedCardNames.clear();
this.changedCardNames.putAll(changedCardNames);
}

public void setGamePieceType(GamePieceType gamePieceType) {
this.gamePieceType = gamePieceType;
this.view.updateGamePieceType(this);
Expand Down Expand Up @@ -2349,7 +2341,21 @@ public final String keywordsToText(final Collection<KeywordInterface> keywords)
String[] k = keyword.split(":");
sbLong.append(k[0]);
if (k.length > 1) {
final Cost mCost = new Cost(k[1], true);
final Cost mCost;
if ("ManaCost".equals(k[1])) {
ManaCost cost;
if (keyword.startsWith("Miracle") && k.length > 2) {
// TODO better handle 2 hybrid, these should not be reduced?
ManaCostBeingPaid mcbp = new ManaCostBeingPaid(getManaCost());
mcbp.decreaseGenericMana(Integer.valueOf(k[2]));
cost = mcbp.toManaCost();
} else {
cost = getManaCost();
}
mCost = new Cost(cost, true);
} else {
mCost = new Cost(k[1], true);
}
if (mCost.isOnlyManaCost()) {
sbLong.append(" ");
} else {
Expand All @@ -2363,17 +2369,13 @@ public final String keywordsToText(final Collection<KeywordInterface> keywords)
if (!mCost.isOnlyManaCost()) {
sbLong.append(".");
}
if (k.length > 2) {
if (k.length > 3) {
sbLong.append(". " + k[3]);
}
}
sbLong.append(" (").append(inst.getReminderText()).append(")");
sbLong.append("\r\n");
}
} else if (keyword.startsWith("Madness")) {
// If no colon exists in Madness keyword, it must have been granted and assumed the cost from host
sbLong.append("Madness ").append(this.getManaCost()).append(" (").append(inst.getReminderText());
sbLong.append(")").append("\r\n");
} else if (keyword.startsWith("Reflect")) {
final String[] k = keyword.split(":");
sbLong.append(k[0]).append(" ").append(ManaCostParser.parse(k[1]));
Expand Down Expand Up @@ -3181,15 +3183,20 @@ private StringBuilder abilityTextInstantSorcery(CardState state) {
|| keyword.startsWith("Disturb") || keyword.startsWith("Overload")
|| keyword.startsWith("Plot")) {
final String[] k = keyword.split(":");
final Cost cost = new Cost(k[1], false);
final Cost mCost;
if ("ManaCost".equals(k[1])) {
mCost = new Cost(getManaCost(), false);
} else {
mCost = new Cost(k[1], false);
}

StringBuilder sbCost = new StringBuilder(k[0]);
if (!cost.isOnlyManaCost()) {
if (!mCost.isOnlyManaCost()) {
sbCost.append("—");
} else {
sbCost.append(" ");
}
sbCost.append(cost.toSimpleString());
sbCost.append(mCost.toSimpleString());
sbAfter.append(sbCost).append(" (").append(inst.getReminderText()).append(")");
sbAfter.append("\r\n");
} else if (keyword.equals("Gift")) {
Expand Down Expand Up @@ -4137,14 +4144,7 @@ public final void setCreatureTypes(Collection<String> ctypes) {
}

public final CardTypeView getType() {
return getType(currentState);
}
public final CardTypeView getType(CardState state) {
final Iterable<CardChangedType> changedCardTypes = getChangedCardTypes();
if (Iterables.isEmpty(changedCardTypes)) {
return state.getType();
}
return state.getType().getTypeWithChanges(changedCardTypes);
return currentState.getTypeWithChanges();
}

public final CardTypeView getOriginalType() {
Expand All @@ -4162,19 +4162,12 @@ public Iterable<CardChangedType> getChangedCardTypes() {
return ImmutableList.of();
}
Iterable<CardChangedType> byText = changedTypeByText == null ? ImmutableList.of() : ImmutableList.of(this.changedTypeByText);
return Iterables.unmodifiableIterable(Iterables.concat(
return ImmutableList.copyOf(Iterables.concat(
changedCardTypesByText.values(), // Layer 3
byText, // Layer 3 by Word Changes,
changedCardTypesCharacterDefining.values(), // Layer 4
changedCardTypes.values() // Layer 6
));
}

public Table<Long, Long, CardChangedType> getChangedCardTypesTable() {
return Tables.unmodifiableTable(changedCardTypes);
}
public Table<Long, Long, CardChangedType> getChangedCardTypesCharacterDefiningTable() {
return Tables.unmodifiableTable(changedCardTypesCharacterDefining);
));
}

public boolean clearChangedCardTypes() {
Expand Down Expand Up @@ -4234,12 +4227,6 @@ public Table<Long, Long, KeywordsChange> getChangedCardKeywords() {
return changedCardKeywords;
}

public Table<Long, Long, CardColor> getChangedCardColorsTable() {
return changedCardColors;
}
public Table<Long, Long, CardColor> getChangedCardColorsCharacterDefiningTable() {
return changedCardColorsCharacterDefining;
}
public Iterable<CardColor> getChangedCardColors() {
return Iterables.concat(changedCardColorsByText.values(), changedCardColorsCharacterDefining.values(), changedCardColors.values());
}
Expand Down Expand Up @@ -7761,31 +7748,13 @@ public List<KeywordInterface> getKeywords() {
}
}

public void setChangedCardTypes(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypes.clear();
this.changedCardTypes.putAll(changedCardTypes);
}
public void setChangedCardTypesCharacterDefining(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypesCharacterDefining.clear();
this.changedCardTypesCharacterDefining.putAll(changedCardTypes);
}

public void setChangedCardKeywords(Table<Long, Long, KeywordsChange> changedCardKeywords) {
this.changedCardKeywords.clear();
for (Table.Cell<Long, Long, KeywordsChange> entry : changedCardKeywords.cellSet()) {
this.changedCardKeywords.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue().copy(this, true));
}
}

public void setChangedCardColors(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColors.clear();
this.changedCardColors.putAll(changedCardColors);
}
public void setChangedCardColorsCharacterDefining(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColorsCharacterDefining.clear();
this.changedCardColorsCharacterDefining.putAll(changedCardColors);
}

public void cleanupCopiedChangesFrom(Card c) {
for (StaticAbility stAb : c.getStaticAbilities()) {
this.removeChangedCardTypes(c.getLayerTimestamp(), stAb.getId(), false);
Expand Down Expand Up @@ -8260,4 +8229,19 @@ public SpellAbility getUnlockAbility(CardStateName state) {
}
return unlockAbilities.get(state);
}

public void copyFrom(Card in) {
// clean is not needed?
this.changedCardColors.putAll(in.changedCardColors);
this.changedCardColorsCharacterDefining.putAll(in.changedCardColorsCharacterDefining);

setChangedCardKeywords(in.getChangedCardKeywords());

this.changedCardTypes.putAll(in.changedCardTypes);
this.changedCardTypesCharacterDefining.putAll(in.changedCardTypesCharacterDefining);

this.changedCardNames.putAll(in.changedCardNames);
setChangedCardTraits(in.getChangedCardTraits());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,7 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {

newCopy.setUnearthed(copyFrom.isUnearthed());

newCopy.setChangedCardColors(copyFrom.getChangedCardColorsTable());
newCopy.setChangedCardColorsCharacterDefining(copyFrom.getChangedCardColorsCharacterDefiningTable());
newCopy.setChangedCardKeywords(copyFrom.getChangedCardKeywords());
newCopy.setChangedCardTypes(copyFrom.getChangedCardTypesTable());
newCopy.setChangedCardTypesCharacterDefining(copyFrom.getChangedCardTypesCharacterDefiningTable());
newCopy.setChangedCardNames(copyFrom.getChangedCardNames());
newCopy.setChangedCardTraits(copyFrom.getChangedCardTraits());
newCopy.copyFrom(copyFrom);

// for getReplacementList (run after setChangedCardKeywords for caching)
newCopy.setStoredKeywords(copyFrom.getStoredKeywords(), true);
Expand Down
Loading

0 comments on commit c317d1f

Please sign in to comment.