mirror of
https://github.com/magefree/mage.git
synced 2026-01-24 12:19:59 -08:00
refactored Player.setLife() to include source, some more changes
This commit is contained in:
parent
2205db105f
commit
3c2a8ee17d
41 changed files with 120 additions and 133 deletions
|
|
@ -113,7 +113,7 @@ class AliFromCairoReplacementEffect extends ReplacementEffectImpl {
|
|||
game.fireEvent(event);
|
||||
|
||||
if (controller != null) {
|
||||
controller.setLife(1, game);
|
||||
controller.setLife(1, game, source);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class ArbiterOfKnollridgeEffect extends OneShotEffect {
|
|||
for (UUID pid : playerList) {
|
||||
Player p = game.getPlayer(pid);
|
||||
if (p != null) {
|
||||
p.setLife(maxLife, game);
|
||||
p.setLife(maxLife, game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ class AxisOfMortalityEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
|
||||
player1.setLife(lifePlayer2, game);
|
||||
player2.setLife(lifePlayer1, game);
|
||||
player1.setLife(lifePlayer2, game, source);
|
||||
player2.setLife(lifePlayer1, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ class DarthTyranusEffect extends OneShotEffect {
|
|||
Player player1 = game.getPlayer(targetPointer.getTargets(game, source).get(0));
|
||||
Player player2 = game.getPlayer(targetPointer.getTargets(game, source).get(1));
|
||||
if (player1 != null && player2 != null) {
|
||||
player1.setLife(5, game);
|
||||
player1.setLife(30, game);
|
||||
player1.setLife(5, game, source);
|
||||
player1.setLife(30, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class ElderscaleWurmSetLifeEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
|
||||
if (player != null && player.getLife() < 7) {
|
||||
player.setLife(7, game);
|
||||
player.setLife(7, game, source);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ class EternityVesselEffect2 extends OneShotEffect {
|
|||
Permanent vessel = game.getPermanent(source.getSourceId());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (vessel != null && controller != null) {
|
||||
controller.setLife(vessel.getCounters(game).getCount(CounterType.CHARGE), game);
|
||||
controller.setLife(vessel.getCounters(game).getCount(CounterType.CHARGE), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class EvraHalcyonWitnessEffect extends OneShotEffect {
|
|||
if (life > amount && !player.isCanLoseLife()) {
|
||||
return false;
|
||||
}
|
||||
player.setLife(amount, game);
|
||||
player.setLife(amount, game, source);
|
||||
game.addEffect(new SetPowerToughnessSourceEffect(life, Integer.MIN_VALUE, Duration.Custom, SubLayer.SetPT_7b), source);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class ExquisiteArchangelEffect extends ReplacementEffectImpl {
|
|||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||
if (player != null && sourcePermanent != null) {
|
||||
new ExileSourceEffect().apply(game, source);
|
||||
player.setLife(game.getLife(), game);
|
||||
player.setLife(game.getLife(), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -34,25 +34,16 @@ import mage.MageObject;
|
|||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.GainLifeControllerTriggeredAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.common.SimpleTriggeredAbility;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.DamageTargetEffect;
|
||||
import mage.abilities.effects.common.DoIfCostPaid;
|
||||
import mage.abilities.effects.common.GainLifeEffect;
|
||||
import mage.abilities.keyword.LifelinkAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.GainAbilitySpellsEffect;
|
||||
import mage.cards.a.AgelessEntityEffect;
|
||||
import mage.cards.s.SpiritualFocusDrawCardEffect;
|
||||
import mage.constants.*;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.filter.FilterObject;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
|
|
@ -107,6 +98,7 @@ class FiresongAndSunspeakerTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
public FiresongAndSunspeakerTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new DamageTargetEffect(3), false);
|
||||
this.addTarget(new TargetCreatureOrPlayer());
|
||||
}
|
||||
|
||||
public FiresongAndSunspeakerTriggeredAbility(final FiresongAndSunspeakerTriggeredAbility ability) {
|
||||
|
|
@ -124,7 +116,7 @@ class FiresongAndSunspeakerTriggeredAbility extends TriggeredAbilityImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Game game) {
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
MageObject object = game.getObject(event.getSourceId());
|
||||
if (object != null && object instanceof Spell) {
|
||||
if (object.getColor(game).equals(ObjectColor.WHITE)
|
||||
|
|
@ -170,26 +162,6 @@ class GainAbilitySpellsEffect extends ContinuousEffectImpl {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (player != null && permanent != null) {
|
||||
for (Card card : game.getExile().getAllCards(game)) {
|
||||
if (card.getOwnerId().equals(source.getControllerId()) && filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getLibrary().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getHand().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (StackObject stackObject : game.getStack()) {
|
||||
if (stackObject.getControllerId().equals(source.getControllerId())) {
|
||||
Card card = game.getCard(stackObject.getSourceId());
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import mage.target.common.TargetOpponent;
|
|||
public class GameOfChaos extends CardImpl {
|
||||
|
||||
public GameOfChaos(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{R}{R}{R}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{R}{R}{R}");
|
||||
|
||||
// Flip a coin.
|
||||
// If you win the flip, you gain 1 life and target opponent loses 1 life, and you decide whether to flip again.
|
||||
|
|
@ -66,51 +66,52 @@ public class GameOfChaos extends CardImpl {
|
|||
}
|
||||
|
||||
class GameOfChaosEffect extends OneShotEffect {
|
||||
|
||||
|
||||
public GameOfChaosEffect() {
|
||||
super(Outcome.Detriment);
|
||||
this.staticText = "Flip a coin. If you win the flip, you gain 1 life and target opponent loses 1 life, and you decide whether to flip again. If you lose the flip, you lose 1 life and that opponent gains 1 life, and that player decides whether to flip again. Double the life stakes with each flip.";
|
||||
}
|
||||
|
||||
|
||||
public GameOfChaosEffect(final GameOfChaosEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameOfChaosEffect copy() {
|
||||
return new GameOfChaosEffect(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player you = game.getPlayer(source.getControllerId());
|
||||
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
|
||||
|
||||
if (you != null && targetOpponent != null) {
|
||||
|
||||
|
||||
boolean continueFlipping = true;
|
||||
boolean youWonFlip = you.flipCoin(game); // controller flips first
|
||||
boolean youWonLastFlip = false; // tracks if you won the flip last, negation of it means opponent won last
|
||||
int lifeAmount = 1; // starts stakes with 1 life
|
||||
|
||||
while (continueFlipping) {
|
||||
|
||||
while (continueFlipping) {
|
||||
if (youWonFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1
|
||||
handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount);
|
||||
handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount, source);
|
||||
if (!cannotContinueFlipping(you, targetOpponent)) {
|
||||
continueFlipping = you.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game);
|
||||
youWonLastFlip = true;
|
||||
}
|
||||
} else { // non-flipper wins, flipper lose 1 and non-flipper gains 1
|
||||
handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount);
|
||||
handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount, source);
|
||||
if (!cannotContinueFlipping(you, targetOpponent)) {
|
||||
continueFlipping = targetOpponent.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game);
|
||||
youWonLastFlip = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (cannotContinueFlipping(you, targetOpponent))
|
||||
|
||||
if (cannotContinueFlipping(you, targetOpponent)) {
|
||||
continueFlipping = false;
|
||||
|
||||
}
|
||||
|
||||
if (continueFlipping) {
|
||||
lifeAmount *= 2; // double the life each time
|
||||
youWonFlip = youWonLastFlip ? you.flipCoin(game) : !targetOpponent.flipCoin(game); // negate the opponent's results for proper evaluation of if you won in next iteration
|
||||
|
|
@ -121,13 +122,13 @@ class GameOfChaosEffect extends OneShotEffect {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleLifeChangesFromFlip(Game game, Player playerGainingLife, Player playerLosingLife, int lifeAmount) {
|
||||
|
||||
private void handleLifeChangesFromFlip(Game game, Player playerGainingLife, Player playerLosingLife, int lifeAmount, Ability source) {
|
||||
playerGainingLife.gainLife(lifeAmount, game, source);
|
||||
playerLosingLife.loseLife(lifeAmount, game, false);
|
||||
}
|
||||
|
||||
|
||||
private boolean cannotContinueFlipping(Player you, Player opponent) {
|
||||
return (!you.canRespond() || !opponent.canRespond() || (you.canLoseByZeroOrLessLife() && you.getLife() <= 0) || (opponent.canLoseByZeroOrLessLife() && opponent.getLife() <= 0));
|
||||
return (!you.canRespond() || !opponent.canRespond() || (you.canLoseByZeroOrLessLife() && you.getLife() <= 0) || (opponent.canLoseByZeroOrLessLife() && opponent.getLife() <= 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class LichsMirrorEffect extends ReplacementEffectImpl {
|
|||
|
||||
player.drawCards(7, game);
|
||||
|
||||
player.setLife(20, game);
|
||||
player.setLife(20, game, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class MagisterSphinxEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player targetPlayer = game.getPlayer(source.getFirstTarget());
|
||||
if (targetPlayer != null) {
|
||||
targetPlayer.setLife(10, game);
|
||||
targetPlayer.setLife(10, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class MasterOfCrueltiesEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player defendingPlayer = game.getPlayer(game.getCombat().getDefenderId(source.getSourceId()));
|
||||
if (defendingPlayer != null) {
|
||||
defendingPlayer.setLife(1, game);
|
||||
defendingPlayer.setLife(1, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class OketrasLastMercyEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
controller.setLife(game.getLife(), game);
|
||||
controller.setLife(game.getLife(), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ class PsychicTransferEffect extends OneShotEffect
|
|||
return false;
|
||||
}
|
||||
|
||||
sourcePlayer.setLife(lifePlayer2, game);
|
||||
targetPlayer.setLife(lifePlayer1, game);
|
||||
sourcePlayer.setLife(lifePlayer2, game, source);
|
||||
targetPlayer.setLife(lifePlayer1, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class RepayInKindEffect extends OneShotEffect {
|
|||
}
|
||||
for (Player playerId : game.getPlayers().values()) {
|
||||
if (playerId != null) {
|
||||
playerId.setLife(lowestLife, game);
|
||||
playerId.setLife(lowestLife, game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class ResoluteArchangelEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
controller.setLife(game.getLife(), game);
|
||||
controller.setLife(game.getLife(), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class ReverseTheSandsEffect extends OneShotEffect {
|
|||
if (index > 0) {
|
||||
String lifeString = selectedChoice.substring(0, index);
|
||||
int life = Integer.parseInt(lifeString);
|
||||
player.setLife(life, game);
|
||||
player.setLife(life, game, source);
|
||||
choices.remove(selectedChoice);
|
||||
game.informPlayers(new StringBuilder("Player ").append(player.getLogName()).append(" life set to ").append(life).toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ class ShamanOfForgottenWaysEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(playerId);
|
||||
if (player != null){
|
||||
int numberCreatures = game.getBattlefield().getAllActivePermanents(filter, playerId, game).size();
|
||||
player.setLife(numberCreatures, game);
|
||||
player.setLife(numberCreatures, game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class SorinMarkovEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.setLife(10, game);
|
||||
player.setLife(10, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -109,8 +109,8 @@ class SoulConduitEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
|
||||
player1.setLife(lifePlayer2, game);
|
||||
player2.setLife(lifePlayer1, game);
|
||||
player1.setLife(lifePlayer2, game, source);
|
||||
player2.setLife(lifePlayer1, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class SoulfireGrandMaster extends CardImpl {
|
|||
}
|
||||
|
||||
public SoulfireGrandMaster(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{W}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}");
|
||||
this.subtype.add(SubType.HUMAN);
|
||||
this.subtype.add(SubType.MONK);
|
||||
this.power = new MageInt(2);
|
||||
|
|
@ -130,26 +130,6 @@ class GainAbilitySpellsEffect extends ContinuousEffectImpl {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (player != null && permanent != null) {
|
||||
for (Card card : game.getExile().getAllCards(game)) {
|
||||
if (card.getOwnerId().equals(source.getControllerId()) && filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getLibrary().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getHand().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (StackObject stackObject : game.getStack()) {
|
||||
if (stackObject.getControllerId().equals(source.getControllerId())) {
|
||||
Card card = game.getCard(stackObject.getSourceId());
|
||||
|
|
@ -225,7 +205,8 @@ class SoulfireGrandMasterCastFromHandReplacementEffect extends ReplacementEffect
|
|||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
//Something hit the stack from the hand, see if its a spell with this ability.
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
if (spellId == null && // because this effect works only once, spellId has to be null here
|
||||
if (spellId == null
|
||||
&& // because this effect works only once, spellId has to be null here
|
||||
zEvent.getFromZone() == Zone.HAND
|
||||
&& zEvent.getToZone() == Zone.STACK
|
||||
&& event.getPlayerId().equals(source.getControllerId())) {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class TorgaarFamineIncarnateEffect extends OneShotEffect {
|
|||
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (targetPlayer != null) {
|
||||
int startingLifeTotal = game.getLife();
|
||||
targetPlayer.setLife(startingLifeTotal / 2, game);
|
||||
targetPlayer.setLife(startingLifeTotal / 2, game, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class TouchOfTheEternalEffect extends OneShotEffect {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
int permanentsInPlay = game.getBattlefield().countAll(filter, source.getControllerId(), game);
|
||||
if (player != null) {
|
||||
player.setLife(permanentsInPlay, game);
|
||||
player.setLife(permanentsInPlay, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class TreeOfPerditionEffect extends OneShotEffect {
|
|||
if (life > amount && !opponent.isCanLoseLife()) {
|
||||
return false;
|
||||
}
|
||||
opponent.setLife(amount, game);
|
||||
opponent.setLife(amount, game, source);
|
||||
perm.getToughness().modifyBaseValue(life);
|
||||
// game.addEffect(new SetPowerToughnessSourceEffect(Integer.MIN_VALUE, life, Duration.Custom, SubLayer.SetPT_7b), source);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class TreeOfRedemptionEffect extends OneShotEffect {
|
|||
if (life > amount && !player.isCanLoseLife()) {
|
||||
return false;
|
||||
}
|
||||
player.setLife(amount, game);
|
||||
player.setLife(amount, game, source);
|
||||
game.addEffect(new SetPowerToughnessSourceEffect(Integer.MIN_VALUE, life, Duration.Custom, SubLayer.SetPT_7b), source);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ class VraskaRelicSeekerLifeTotalEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.setLife(1, game);
|
||||
player.setLife(1, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class WorldfireEffect extends OneShotEffect {
|
|||
c.moveToExile(null, null, source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
player.setLife(1, game);
|
||||
player.setLife(1, game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue