-
Notifications
You must be signed in to change notification settings - Fork 845
Perpetual: use StaticAbilities #9680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4630,15 +4630,21 @@ public final boolean hasIntensity() { | |
| } | ||
|
|
||
| private List<PerpetualInterface> perpetual = new ArrayList<>(); | ||
| private Multimap<PerpetualInterface, StaticAbility> perpetualEffects = MultimapBuilder.hashKeys().arrayListValues().build(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove List above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not all are transformed yet, the list will be removed later (i don't know yet if the new one needs to be a Multimap or if a List is enough) |
||
| public final boolean hasPerpetual() { | ||
| return !perpetual.isEmpty(); | ||
| } | ||
| public final List<PerpetualInterface> getPerpetual() { | ||
| return perpetual; | ||
| } | ||
|
|
||
| public final void addPerpetual(PerpetualInterface p) { | ||
| public final void addPerpetual(PerpetualInterface p, long timestamp) { | ||
| perpetual.add(p); | ||
| StaticAbility st = p.createEffect(this); | ||
| if (st != null) { | ||
| st.putParam("Timestamp", String.valueOf(timestamp)); | ||
| this.perpetualEffects.put(p, st); | ||
| } | ||
| } | ||
|
|
||
| public final void removePerpetual(final long timestamp) { | ||
|
|
@@ -4653,16 +4659,28 @@ public final void removePerpetual(final long timestamp) { | |
| } | ||
|
|
||
| public final void setPerpetual(final Card oldCard) { | ||
| setPerpetual(oldCard, true); | ||
| setPerpetual(oldCard, false); | ||
| } | ||
|
|
||
| public final void setPerpetual(final Card oldCard, boolean applyEffects) { | ||
| public final void setPerpetual(final Card oldCard, boolean lki) { | ||
| perpetual = oldCard.getPerpetual(); | ||
| if (applyEffects) { | ||
| if (!lki) { | ||
| for (PerpetualInterface p : perpetual) { | ||
| p.applyEffect(this); | ||
| } | ||
| } | ||
|
|
||
| long currentGameTimestamp = this.getGame().getTimestamp(); | ||
| for (Map.Entry<PerpetualInterface, StaticAbility> e : oldCard.perpetualEffects.entries()) { | ||
| StaticAbility st = e.getValue().copy(this, lki); | ||
| long oldTimestamp = Long.valueOf(st.getParam("Timestamp")); | ||
| if (!lki && oldTimestamp > 0) { | ||
| // change zone sets the timestamp of negative infinite, but still relative | ||
| // use current game timestamp to shift these timestamps back | ||
| st.putParam("Timestamp", String.valueOf(Long.MIN_VALUE + oldTimestamp)); | ||
| } | ||
| this.perpetualEffects.put(e.getKey(), st); | ||
| } | ||
| } | ||
|
|
||
| public final boolean isUntapped() { | ||
|
|
@@ -7106,6 +7124,7 @@ public final FCollectionView<StaticAbility> getHiddenStaticAbilities() { | |
| result.add(e.getValue()); | ||
| } | ||
| } | ||
| result.addAll(this.perpetualEffects.values()); | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| package forge.game.card.perpetual; | ||
|
|
||
| import java.util.stream.Collectors; | ||
|
|
||
| import forge.card.ColorSet; | ||
| import forge.card.MagicColor; | ||
| import forge.game.card.Card; | ||
| import forge.game.staticability.StaticAbility; | ||
|
|
||
| public record PerpetualColors(long timestamp, ColorSet colors, boolean overwrite) implements PerpetualInterface { | ||
|
|
||
| public record PerpetualColors(ColorSet colors, boolean overwrite) implements PerpetualInterface { | ||
| @Override | ||
| public long getTimestamp() { | ||
| return timestamp; | ||
| } | ||
| public StaticAbility createEffect(Card c) { | ||
| StringBuilder sb = new StringBuilder("Mode$ Continuous | AffectedDefined$ Self | EffectZone$ All | "); | ||
| sb.append( overwrite ? "SetColor" : "AddColor").append("$ "); | ||
| sb.append(colors.stream().map(MagicColor.Color::getName).collect(Collectors.joining(","))); | ||
|
|
||
| @Override | ||
| public void applyEffect(Card c) { | ||
| c.addColor(colors, !overwrite, timestamp, null); | ||
| return StaticAbility.create(sb.toString(), c, c.getCurrentState(), true); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,13 @@ | ||
| package forge.game.card.perpetual; | ||
|
|
||
| import forge.card.ColorSet; | ||
| import forge.card.mana.ManaCost; | ||
| import forge.game.card.Card; | ||
| import forge.game.staticability.StaticAbility; | ||
|
|
||
| public record PerpetualIncorporate(long timestamp, ManaCost incorporate) implements PerpetualInterface { | ||
| public record PerpetualIncorporate(ManaCost incorporate) implements PerpetualInterface { | ||
| @Override | ||
| public long getTimestamp() { | ||
| return timestamp; | ||
| } | ||
|
|
||
| @Override | ||
| public void applyEffect(Card c) { | ||
| ColorSet colors = ColorSet.fromMask(incorporate.getColorProfile()); | ||
| c.addChangedManaCost(incorporate, true, timestamp, (long) 0); | ||
| c.addColorByText(colors, true, timestamp, null); | ||
| public StaticAbility createEffect(Card c) { | ||
| String s = "Mode$ Continuous | AffectedDefined$ Self | EffectZone$ All | Incorporate$ " + incorporate.getShortString(); | ||
| return StaticAbility.create(s, c, c.getCurrentState(), true); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package forge.game.card.perpetual; | ||
|
|
||
| import forge.game.card.Card; | ||
| import forge.game.staticability.StaticAbility; | ||
|
|
||
| public interface PerpetualInterface { | ||
| long getTimestamp(); | ||
| void applyEffect(Card c); | ||
| default long getTimestamp() { return -1; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reminder to remove this later |
||
| default void applyEffect(Card c) {} | ||
|
|
||
| default StaticAbility createEffect(Card c) {return null;} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| package forge.game.card.perpetual; | ||
|
|
||
| import forge.game.card.Card; | ||
| import forge.game.staticability.StaticAbility; | ||
|
|
||
| public record PerpetualNewPT(long timestamp, Integer power, Integer toughness) implements PerpetualInterface { | ||
|
|
||
| @Override | ||
| public long getTimestamp() { | ||
| return timestamp; | ||
| } | ||
|
|
||
| public record PerpetualNewPT(Integer power, Integer toughness) implements PerpetualInterface { | ||
| @Override | ||
| public void applyEffect(Card c) { | ||
| c.addNewPT(power, toughness, timestamp, (long) 0); | ||
| public StaticAbility createEffect(Card c) { | ||
| StringBuilder sb = new StringBuilder("Mode$ Continuous | AffectedDefined$ Self | EffectZone$ All "); | ||
| if (power != null) { | ||
| sb.append("| SetPower$ ").append(power); | ||
| } | ||
| if (toughness != null) { | ||
| sb.append("| SetToughness$ ").append(toughness); | ||
| } | ||
| return StaticAbility.create(sb.toString(), c, c.getCurrentState(), true); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| package forge.game.card.perpetual; | ||
|
|
||
| import forge.game.card.Card; | ||
| import forge.game.staticability.StaticAbility; | ||
|
|
||
| public record PerpetualPTBoost(long timestamp, Integer power, Integer toughness) implements PerpetualInterface { | ||
|
|
||
| @Override | ||
| public long getTimestamp() { | ||
| return timestamp; | ||
| } | ||
|
|
||
| public record PerpetualPTBoost(Integer power, Integer toughness) implements PerpetualInterface { | ||
| @Override | ||
| public void applyEffect(Card c) { | ||
| c.addPTBoost(power, toughness, timestamp, (long) 0); | ||
| public StaticAbility createEffect(Card c) { | ||
| StringBuilder sb = new StringBuilder("Mode$ Continuous | AffectedDefined$ Self | EffectZone$ All "); | ||
| if (power != null) { | ||
| sb.append("| AddPower$ ").append(power); | ||
| } | ||
| if (toughness != null) { | ||
| sb.append("| AddToughness$ ").append(toughness); | ||
| } | ||
| return StaticAbility.create(sb.toString(), c, c.getCurrentState(), true); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't all be
elsenow?