mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -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
|
|
@ -67,7 +67,7 @@ public class GainLifeOpponentCost extends CostImpl {
|
|||
if (controller.chooseTarget(Outcome.Detriment, target, ability, game)) {
|
||||
Player opponent = game.getPlayer(target.getFirstTarget());
|
||||
if (opponent != null) {
|
||||
opponent.gainLife(amount, game, source);
|
||||
opponent.gainLife(amount, game, sourceId);
|
||||
paid = true;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class GainLifePlayersCost extends CostImpl {
|
|||
if (!playerId.equals(controllerId)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.gainLife(amount, game, source);
|
||||
player.gainLife(amount, game, sourceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ public class ExchangeLifeTargetEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
|
||||
controller.setLife(lifePlayer, game);
|
||||
player.setLife(lifeController, game);
|
||||
controller.setLife(lifePlayer, game, source);
|
||||
player.setLife(lifeController, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class SetPlayerLifeAllEffect extends OneShotEffect {
|
|||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.setLife(amount.calculate(game, source, this), game);
|
||||
player.setLife(amount.calculate(game, source, this), game, source);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -70,7 +70,7 @@ public class SetPlayerLifeAllEffect extends OneShotEffect {
|
|||
for (UUID playerId : game.getOpponents(controller.getId())) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.setLife(amount.calculate(game, source, this), game);
|
||||
player.setLife(amount.calculate(game, source, this), game, source);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class SetPlayerLifeSourceEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.setLife(amount.calculate(game, source, this), game);
|
||||
player.setLife(amount.calculate(game, source, this), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class SetPlayerLifeTargetEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.setLife(amount.calculate(game, source, this), game);
|
||||
player.setLife(amount.calculate(game, source, this), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1565,14 +1565,14 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
state.addCommandObject(newPlane);
|
||||
informPlayers("You have planeswalked to " + newPlane.getLogName());
|
||||
|
||||
|
||||
// Fire off the planeswalked event
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.PLANESWALK, newPlane.getId(), null, newPlane.getId(), 0, true);
|
||||
if (!replaceEvent(event)) {
|
||||
GameEvent ge = new GameEvent(GameEvent.EventType.PLANESWALKED, newPlane.getId(), null, newPlane.getId(), 0, true);
|
||||
fireEvent(ge);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2821,7 +2821,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
if (s.length == 2) {
|
||||
try {
|
||||
Integer amount = Integer.parseInt(s[1]);
|
||||
player.setLife(amount, this);
|
||||
player.setLife(amount, this, ownerId);
|
||||
logger.info("Setting player's life: ");
|
||||
} catch (NumberFormatException e) {
|
||||
logger.fatal("error setting life", e);
|
||||
|
|
|
|||
|
|
@ -785,7 +785,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
if (source != null && sourceAbilities != null) {
|
||||
if (sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
player.gainLife(damageDone, game, source);
|
||||
player.gainLife(damageDone, game, sourceId);
|
||||
}
|
||||
if (sourceAbilities.containsKey(DeathtouchAbility.getInstance().getId())) {
|
||||
deathtouched = true;
|
||||
|
|
@ -946,8 +946,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (abilities.containsKey(HexproofFromBlackAbility.getInstance().getId()) ) {
|
||||
if (abilities.containsKey(HexproofFromBlackAbility.getInstance().getId())) {
|
||||
if (game.getPlayer(this.getControllerId()).hasOpponent(sourceControllerId, game)
|
||||
&& !game.getContinuousEffects().asThough(this.getId(), AsThoughEffectType.HEXPROOF, sourceControllerId, game)
|
||||
&& source.getColor(game).isBlack()) {
|
||||
|
|
@ -955,7 +954,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
}
|
||||
|
||||
if (abilities.containsKey(HexproofFromWhiteAbility.getInstance().getId()) ) {
|
||||
if (abilities.containsKey(HexproofFromWhiteAbility.getInstance().getId())) {
|
||||
if (game.getPlayer(this.getControllerId()).hasOpponent(sourceControllerId, game)
|
||||
&& !game.getContinuousEffects().asThough(this.getId(), AsThoughEffectType.HEXPROOF, sourceControllerId, game)
|
||||
&& source.getColor(game).isWhite()) {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,9 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
void initLife(int life);
|
||||
|
||||
void setLife(int life, Game game);
|
||||
void setLife(int life, Game game, Ability source);
|
||||
|
||||
void setLife(int life, Game game, UUID sourceId);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -125,6 +127,8 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
int gainLife(int amount, Game game, Ability source);
|
||||
|
||||
int gainLife(int amount, Game game, UUID sourceId);
|
||||
|
||||
int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable);
|
||||
|
||||
int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable, List<UUID> appliedEffects);
|
||||
|
|
@ -427,6 +431,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
PlanarDieRoll rollPlanarDie(Game game);
|
||||
|
||||
PlanarDieRoll rollPlanarDie(Game game, ArrayList<UUID> appliedEffects);
|
||||
|
||||
PlanarDieRoll rollPlanarDie(Game game, ArrayList<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides);
|
||||
|
||||
@Deprecated
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.io.Serializable;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import static jdk.nashorn.internal.objects.NativeRegExp.source;
|
||||
import mage.ConditionalMana;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
|
|
@ -439,7 +440,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
this.canLoseLife = true;
|
||||
this.topCardRevealed = false;
|
||||
this.payManaMode = false;
|
||||
this.setLife(game.getLife(), game);
|
||||
this.setLife(game.getLife(), game, UUID.randomUUID());
|
||||
this.setReachedNextTurnAfterLeaving(false);
|
||||
|
||||
this.castSourceIdWithAlternateMana = null;
|
||||
|
|
@ -1741,10 +1742,15 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setLife(int life, Game game) {
|
||||
public void setLife(int life, Game game, Ability source) {
|
||||
setLife(life, game, source.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLife(int life, Game game, UUID sourceId) {
|
||||
// rule 118.5
|
||||
if (life > this.life) {
|
||||
gainLife(life - this.life, game, source);
|
||||
gainLife(life - this.life, game, sourceId);
|
||||
} else if (life < this.life) {
|
||||
loseLife(this.life - life, game, false);
|
||||
}
|
||||
|
|
@ -1808,6 +1814,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public int gainLife(int amount, Game game, Ability source) {
|
||||
return gainLife(amount, game, source.getSourceId());
|
||||
}
|
||||
|
||||
public int gainLife(int amount, Game game, UUID sourceId) {
|
||||
if (!canGainLife || amount == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1820,7 +1830,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (!game.isSimulation()) {
|
||||
game.informPlayers(this.getLogName() + " gains " + event.getAmount() + " life");
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.GAINED_LIFE, playerId, source.getSourceId(), playerId, event.getAmount()));
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.GAINED_LIFE, playerId, sourceId, playerId, event.getAmount()));
|
||||
return event.getAmount();
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -1879,7 +1889,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
if (sourceAbilities != null && sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
player.gainLife(actualDamage, game, source);
|
||||
player.gainLife(actualDamage, game, sourceId);
|
||||
}
|
||||
// Unstable ability - Earl of Squirrel
|
||||
if (sourceAbilities != null && sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue