-
Notifications
You must be signed in to change notification settings - Fork 748
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
Add life lost event and batch event to implement Ob Nixilis, Captive Kingpin #11974
Changes from 6 commits
cdcb797
cea3eb7
196d232
dd1c90d
6777640
5e29221
a31468f
90bc630
c2cfbc0
c7a11d0
778eca8
0faa61d
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package mage.cards.o; | ||
|
||
import java.util.UUID; | ||
import mage.MageInt; | ||
import mage.abilities.Ability; | ||
import mage.abilities.TriggeredAbilityImpl; | ||
import mage.abilities.effects.Effect; | ||
import mage.abilities.effects.common.ExileTopXMayPlayUntilEffect; | ||
import mage.abilities.effects.common.counter.AddCountersSourceEffect; | ||
import mage.constants.*; | ||
import mage.abilities.keyword.FlyingAbility; | ||
import mage.abilities.keyword.TrampleAbility; | ||
import mage.cards.CardImpl; | ||
import mage.cards.CardSetInfo; | ||
import mage.counters.CounterType; | ||
import mage.game.Game; | ||
import mage.game.events.*; | ||
import mage.util.CardUtil; | ||
|
||
/** | ||
* | ||
* @author jimga150 | ||
*/ | ||
public final class ObNixilisCaptiveKingpin extends CardImpl { | ||
|
||
public ObNixilisCaptiveKingpin(UUID ownerId, CardSetInfo setInfo) { | ||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}{R}"); | ||
|
||
this.supertype.add(SuperType.LEGENDARY); | ||
this.subtype.add(SubType.DEMON); | ||
this.power = new MageInt(4); | ||
this.toughness = new MageInt(3); | ||
|
||
// Flying | ||
this.addAbility(FlyingAbility.getInstance()); | ||
|
||
// Trample | ||
this.addAbility(TrampleAbility.getInstance()); | ||
|
||
// Whenever one or more opponents each lose exactly 1 life, put a +1/+1 counter on Ob Nixilis, Captive Kingpin. Exile the top card of your library. Until your next end step, you may play that card. | ||
Ability ability = new ObNixilisCaptiveKingpinAbility( | ||
new AddCountersSourceEffect(CounterType.P1P1.createInstance()) | ||
); | ||
ability.addEffect(new ExileTopXMayPlayUntilEffect(1, Duration.UntilYourNextEndStep) | ||
.withTextOptions("that card", false)); | ||
|
||
this.addAbility(ability); | ||
|
||
} | ||
|
||
private ObNixilisCaptiveKingpin(final ObNixilisCaptiveKingpin card) { | ||
super(card); | ||
} | ||
|
||
@Override | ||
public ObNixilisCaptiveKingpin copy() { | ||
return new ObNixilisCaptiveKingpin(this); | ||
} | ||
} | ||
|
||
class ObNixilisCaptiveKingpinAbility extends TriggeredAbilityImpl { | ||
|
||
ObNixilisCaptiveKingpinAbility(Effect effect) { | ||
super(Zone.BATTLEFIELD, effect); | ||
setTriggerPhrase("Whenever one or more opponents each lose exactly 1 life, "); | ||
} | ||
|
||
private ObNixilisCaptiveKingpinAbility(final ObNixilisCaptiveKingpinAbility ability) { | ||
super(ability); | ||
} | ||
|
||
@Override | ||
public boolean checkEventType(GameEvent event, Game game) { | ||
return event.getType() == GameEvent.EventType.LOST_LIFE_BATCH; | ||
} | ||
|
||
@Override | ||
public boolean checkTrigger(GameEvent event, Game game) { | ||
|
||
LifeLostBatchEvent lifeLostBatchEvent = (LifeLostBatchEvent) event; | ||
|
||
boolean opponentLostLife = false; | ||
boolean allis1 = true; | ||
|
||
for (UUID targetPlayer : CardUtil.getEventTargets(lifeLostBatchEvent)){ | ||
// skip controller | ||
if (targetPlayer.equals(getControllerId())){ | ||
continue; | ||
} | ||
opponentLostLife = true; | ||
|
||
int lifelost = lifeLostBatchEvent.getAmount(targetPlayer); | ||
if (lifelost != 1){ | ||
allis1 = false; | ||
break; | ||
} | ||
} | ||
return opponentLostLife && allis1; | ||
} | ||
|
||
@Override | ||
public ObNixilisCaptiveKingpinAbility copy() { | ||
return new ObNixilisCaptiveKingpinAbility(this); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package mage.game.events; | ||
|
||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author jimga150 | ||
*/ | ||
public class LifeLostBatchEvent extends GameEvent implements BatchGameEvent<LifeLostEvent> { | ||
|
||
private final Set<LifeLostEvent> events = new HashSet<>(); | ||
|
||
public LifeLostBatchEvent(LifeLostEvent event) { | ||
super(EventType.LOST_LIFE_BATCH, null, null, null); | ||
addEvent(event); | ||
} | ||
|
||
@Override | ||
public Set<LifeLostEvent> getEvents() { | ||
return events; | ||
} | ||
|
||
@Override | ||
public Set<UUID> getTargets() { | ||
return events.stream() | ||
.map(GameEvent::getTargetId) | ||
.filter(Objects::nonNull) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
@Override | ||
public int getAmount() { | ||
return events | ||
.stream() | ||
.mapToInt(GameEvent::getAmount) | ||
.sum(); | ||
} | ||
|
||
public int getAmount(UUID targetID) { | ||
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. Raname to getLifeLoseByPlayer |
||
return events | ||
.stream() | ||
.filter(ev -> ev.getTargetId().equals(targetID)) | ||
.mapToInt(GameEvent::getAmount) | ||
.sum(); | ||
} | ||
|
||
public boolean isCombatDamage() { | ||
return events.stream().anyMatch(LifeLostEvent::isCombatDamage); | ||
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. Can be wrong usage. Related card must use events list or use method like getLifeLoseByCombatDamage(isCombatDamage::Boolaean) > 0, not isCombatDamage. |
||
} | ||
|
||
@Override | ||
@Deprecated // events can store a diff value, so search it from events list instead | ||
public UUID getTargetId() { | ||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list or use CardUtil.getEventTargets(event)"); | ||
} | ||
|
||
@Override | ||
@Deprecated // events can store a diff value, so search it from events list instead | ||
public UUID getSourceId() { | ||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list."); | ||
} | ||
|
||
public void addEvent(LifeLostEvent event) { | ||
this.events.add(event); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mage.game.events; | ||
|
||
import mage.abilities.Ability; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* @author jimga150 | ||
*/ | ||
public class LifeLostEvent extends GameEvent{ | ||
public LifeLostEvent(UUID playerId, Ability source, int amount, boolean atCombat){ | ||
super(GameEvent.EventType.LOST_LIFE, | ||
playerId, source, playerId, amount, atCombat); | ||
} | ||
|
||
public boolean isCombatDamage() { | ||
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. this should be renamed same as the batch event for clarity (also... is there existing card that cares about it? if not, maybe better to just remove entirely.) 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. No, currently no card uses this, but its a short road to walk. |
||
return flag; | ||
} | ||
} |
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.
Current naming logic of all batch methods is wrong - it does not add real events to sim queue, only batches. So it must be renamed to addSimultaneousXxxEventToBatches - damaged, loseLife, tapped, etc.
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.
Going to rename just this function in this PR for now, unless youre good with renaming the rest in here.