refactored Player.gainLife() to include source

This commit is contained in:
Evan Kranzler 2018-04-18 20:27:49 -04:00
parent 254935da39
commit 3798f34c38
209 changed files with 221 additions and 218 deletions

View file

@ -103,7 +103,7 @@ class GainThatMuchLifeEffect extends OneShotEffect {
if (controller != null) {
int amount = (Integer) getValue("damage");
if (amount > 0) {
controller.gainLife(amount, game);
controller.gainLife(amount, game, source);
}
return true;

View file

@ -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);
opponent.gainLife(amount, game, source);
paid = true;
}

View file

@ -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);
player.gainLife(amount, game, source);
}
}
}

View file

@ -62,7 +62,7 @@ public class ExileAndGainLifeEqualPowerTargetEffect extends OneShotEffect {
int creaturePower = permanent.getPower().getValue();
permanent.moveToExile(null, null, source.getSourceId(), game);
game.applyEffects();
player.gainLife(creaturePower, game);
player.gainLife(creaturePower, game, source);
}
return true;
}

View file

@ -74,7 +74,7 @@ public class GainLifeEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.gainLife(life.calculate(game, source, this), game);
player.gainLife(life.calculate(game, source, this), game, source);
}
return true;
}

View file

@ -71,7 +71,7 @@ public class GainLifeTargetEffect extends OneShotEffect {
for (UUID playerId: targetPointer.getTargets(game, source)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.gainLife(life.calculate(game, source, this), game);
player.gainLife(life.calculate(game, source, this), game, source);
}
}
return true;

View file

@ -109,7 +109,7 @@ class ExtortEffect extends OneShotEffect {
loseLife += game.getPlayer(opponentId).loseLife(1, game, false);
}
if (loseLife > 0) {
game.getPlayer(source.getControllerId()).gainLife(loseLife, game);
game.getPlayer(source.getControllerId()).gainLife(loseLife, game, source);
}
if (!game.isSimulation())
game.informPlayers(new StringBuilder(permanent.getName()).append(" extorted opponents ").append(loseLife).append(" life").toString());

View file

@ -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);
player.gainLife(damageDone, game, source);
}
if (sourceAbilities.containsKey(DeathtouchAbility.getInstance().getId())) {
deathtouched = true;

View file

@ -123,7 +123,7 @@ public interface Player extends MageItem, Copyable<Player> {
*/
int loseLife(int amount, Game game, boolean atCombat);
int gainLife(int amount, Game game);
int gainLife(int amount, Game game, Ability source);
int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable);

View file

@ -1744,7 +1744,7 @@ public abstract class PlayerImpl implements Player, Serializable {
public void setLife(int life, Game game) {
// rule 118.5
if (life > this.life) {
gainLife(life - this.life, game);
gainLife(life - this.life, game, source);
} else if (life < this.life) {
loseLife(this.life - life, game, false);
}
@ -1807,7 +1807,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public int gainLife(int amount, Game game) {
public int gainLife(int amount, Game game, Ability source) {
if (!canGainLife || amount == 0) {
return 0;
}
@ -1820,7 +1820,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, playerId, playerId, event.getAmount()));
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.GAINED_LIFE, playerId, source.getSourceId(), playerId, event.getAmount()));
return event.getAmount();
}
return 0;
@ -1879,7 +1879,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);
player.gainLife(actualDamage, game, source);
}
// Unstable ability - Earl of Squirrel
if (sourceAbilities != null && sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
@ -2491,12 +2491,16 @@ public abstract class PlayerImpl implements Player, Serializable {
public PlanarDieRoll rollPlanarDie(Game game, ArrayList<UUID> appliedEffects) {
return rollPlanarDie(game, appliedEffects, 1, 1);
}
/**
* @param game
* @param appliedEffects
* @param numberChaosSides The number of chaos sides the planar die currently has (normally 1 but can be 5)
* @param numberPlanarSides The number of chaos sides the planar die currently has (normally 1)
* @return the outcome that the player rolled. Either ChaosRoll, PlanarRoll or NilRoll
* @param numberChaosSides The number of chaos sides the planar die
* currently has (normally 1 but can be 5)
* @param numberPlanarSides The number of chaos sides the planar die
* currently has (normally 1)
* @return the outcome that the player rolled. Either ChaosRoll, PlanarRoll
* or NilRoll
*/
@Override
public PlanarDieRoll rollPlanarDie(Game game, ArrayList<UUID> appliedEffects, int numberChaosSides, int numberPlanarSides) {
@ -2508,8 +2512,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
if (result <= numberChaosSides) {
roll = PlanarDieRoll.CHAOS_ROLL;
}
else if (result > 6 - numberPlanarSides) {
} else if (result > 6 - numberPlanarSides) {
roll = PlanarDieRoll.PLANAR_ROLL;
}
if (!game.isSimulation()) {