mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Merge branch 'master' of https://github.com/magefree/mage
This commit is contained in:
commit
e57da7598e
162 changed files with 575 additions and 249 deletions
|
|
@ -30,7 +30,7 @@ package mage.abilities.condition.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.NonCombatDamageWatcher;
|
||||
import mage.watchers.common.LifeLossOtherFromCombatWatcher;
|
||||
|
||||
/**
|
||||
* Describes condition when an opponent has been dealt any amount of non-combat
|
||||
|
|
@ -54,8 +54,8 @@ public class HateCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
NonCombatDamageWatcher watcher = (NonCombatDamageWatcher) game.getState().getWatchers().get("NonCombatDamageWatcher");
|
||||
return watcher != null && watcher.opponentsBeenDealtNonCombatDamage(source.getControllerId());
|
||||
LifeLossOtherFromCombatWatcher watcher = (LifeLossOtherFromCombatWatcher) game.getState().getWatchers().get(LifeLossOtherFromCombatWatcher.class.getName());
|
||||
return watcher != null && watcher.opponentLostLifeOtherFromCombat(source.getControllerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class PayLifeCost extends CostImpl {
|
|||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
int lifeToPayAmount = amount.calculate(game, ability, null);
|
||||
this.paid = game.getPlayer(controllerId).loseLife(lifeToPayAmount, game) == lifeToPayAmount;
|
||||
this.paid = game.getPlayer(controllerId).loseLife(lifeToPayAmount, game, false) == lifeToPayAmount;
|
||||
return paid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class PhyrexianManaCost extends ColoredManaCost {
|
|||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
this.paid = game.getPlayer(controllerId).loseLife(2, game) == 2;
|
||||
this.paid = game.getPlayer(controllerId).loseLife(2, game, false) == 2;
|
||||
return paid;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class LoseHalfLifeEffect extends OneShotEffect {
|
|||
if (player != null) {
|
||||
int amount = (player.getLife() + 1) / 2;
|
||||
if (amount > 0) {
|
||||
player.loseLife(amount, game);
|
||||
player.loseLife(amount, game, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class LoseLifeAllPlayersEffect extends OneShotEffect {
|
|||
for (UUID playerId: game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source, this), game);
|
||||
player.loseLife(amount.calculate(game, source, this), game, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class LoseLifeControllerAttachedEffect extends OneShotEffect {
|
|||
if (creature != null) {
|
||||
Player player = game.getPlayer(creature.getControllerId());
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source, this), game);
|
||||
player.loseLife(amount.calculate(game, source, this), game, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class LoseLifeDefendingPlayerEffect extends OneShotEffect {
|
|||
defender = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
}
|
||||
if (defender != null) {
|
||||
defender.loseLife(amount.calculate(game, source, this), game);
|
||||
defender.loseLife(amount.calculate(game, source, this), game, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class LoseLifeOpponentsEffect extends OneShotEffect {
|
|||
for (UUID opponentId: game.getOpponents(source.getControllerId())) {
|
||||
Player player = game.getPlayer(opponentId);
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source, this), game);
|
||||
player.loseLife(amount.calculate(game, source, this), game, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class LoseLifeSourceControllerEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source, this), game);
|
||||
player.loseLife(amount.calculate(game, source, this), game, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class LoseLifeTargetControllerEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
if ( controller != null ) {
|
||||
controller.loseLife(amount, game);
|
||||
controller.loseLife(amount, game, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class LoseLifeTargetEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source, this), game);
|
||||
player.loseLife(amount.calculate(game, source, this), game, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class ExtortEffect extends OneShotEffect {
|
|||
if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) {
|
||||
int loseLife = 0;
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
loseLife += game.getPlayer(opponentId).loseLife(1, game);
|
||||
loseLife += game.getPlayer(opponentId).loseLife(1, game, false);
|
||||
}
|
||||
if (loseLife > 0) {
|
||||
game.getPlayer(source.getControllerId()).gainLife(loseLife, game);
|
||||
|
|
|
|||
|
|
@ -109,6 +109,13 @@ public class GameEvent implements Serializable {
|
|||
PLAYER_LIFE_CHANGE,
|
||||
GAIN_LIFE, GAINED_LIFE,
|
||||
LOSE_LIFE, LOST_LIFE,
|
||||
/* LOSE_LIFE + LOST_LIFE
|
||||
targetId the id of the player loosing life
|
||||
sourceId the id of the player loosing life
|
||||
playerId the id of the player loosing life
|
||||
amount amount of life loss
|
||||
flag true = from comabat damage - other from non combat damage
|
||||
*/
|
||||
PLAY_LAND, LAND_PLAYED,
|
||||
CREW_VEHICLE,
|
||||
/* CREW_VEHICLE
|
||||
|
|
|
|||
|
|
@ -111,7 +111,14 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
void setLife(int life, Game game);
|
||||
|
||||
int loseLife(int amount, Game game);
|
||||
/**
|
||||
*
|
||||
* @param amount amount of life loss
|
||||
* @param game
|
||||
* @param atCombat was the source combat damage
|
||||
* @return
|
||||
*/
|
||||
int loseLife(int amount, Game game, boolean atCombat);
|
||||
|
||||
int gainLife(int amount, Game game);
|
||||
|
||||
|
|
|
|||
|
|
@ -1699,7 +1699,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (life > this.life) {
|
||||
gainLife(life - this.life, game);
|
||||
} else if (life < this.life) {
|
||||
loseLife(this.life - life, game);
|
||||
loseLife(this.life - life, game, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1730,17 +1730,17 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int loseLife(int amount, Game game) {
|
||||
public int loseLife(int amount, Game game, boolean atCombat) {
|
||||
if (!canLoseLife) {
|
||||
return 0;
|
||||
}
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.LOSE_LIFE, playerId, playerId, playerId, amount, false);
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.LOSE_LIFE, playerId, playerId, playerId, amount, atCombat);
|
||||
if (!game.replaceEvent(event)) {
|
||||
this.life -= event.getAmount();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(this.getLogName() + " loses " + event.getAmount() + " life");
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST_LIFE, playerId, playerId, playerId, amount));
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.LOST_LIFE, playerId, playerId, playerId, amount, atCombat));
|
||||
return amount;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -1820,7 +1820,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
} else {
|
||||
GameEvent damageToLifeLossEvent = new GameEvent(EventType.DAMAGE_CAUSES_LIFE_LOSS, playerId, sourceId, playerId, actualDamage, combatDamage);
|
||||
if (!game.replaceEvent(damageToLifeLossEvent)) {
|
||||
this.loseLife(damageToLifeLossEvent.getAmount(), game);
|
||||
this.loseLife(damageToLifeLossEvent.getAmount(), game, combatDamage);
|
||||
}
|
||||
}
|
||||
if (sourceAbilities != null && sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
|
||||
|
|
|
|||
|
|
@ -32,58 +32,48 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamagedPlayerEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
/*
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class NonCombatDamageWatcher extends Watcher {
|
||||
public class LifeLossOtherFromCombatWatcher extends Watcher {
|
||||
|
||||
private final Set<UUID> playersBeenDealtNonCombatDamage = new HashSet<>();
|
||||
private final Set<UUID> players = new HashSet<>();
|
||||
|
||||
public NonCombatDamageWatcher() {
|
||||
super("NonCombatDamageWatcher", WatcherScope.GAME);
|
||||
public LifeLossOtherFromCombatWatcher() {
|
||||
super(LifeLossOtherFromCombatWatcher.class.getName(), WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public NonCombatDamageWatcher(final NonCombatDamageWatcher watcher) {
|
||||
public LifeLossOtherFromCombatWatcher(final LifeLossOtherFromCombatWatcher watcher) {
|
||||
super(watcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.LOST_LIFE) {
|
||||
if (event.getType() == GameEvent.EventType.LOST_LIFE && !event.getFlag()) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
playersBeenDealtNonCombatDamage.add(playerId);
|
||||
players.add(playerId);
|
||||
}
|
||||
} else if (event.getType() == EventType.DAMAGED_PLAYER) {
|
||||
DamagedPlayerEvent dEvent = (DamagedPlayerEvent) event;
|
||||
if (!dEvent.isCombatDamage()) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
playersBeenDealtNonCombatDamage.add(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean opponentsBeenDealtNonCombatDamage(UUID playerId) {
|
||||
return (!playersBeenDealtNonCombatDamage.contains(playerId) && playersBeenDealtNonCombatDamage.size() > 0)
|
||||
|| (playersBeenDealtNonCombatDamage.contains(playerId) && playersBeenDealtNonCombatDamage.size() > 1);
|
||||
public boolean opponentLostLifeOtherFromCombat(UUID playerId) {
|
||||
return (!players.contains(playerId) && players.size() > 0)
|
||||
|| (players.contains(playerId) && players.size() > 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
playersBeenDealtNonCombatDamage.clear();
|
||||
players.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonCombatDamageWatcher copy() {
|
||||
return new NonCombatDamageWatcher(this);
|
||||
public LifeLossOtherFromCombatWatcher copy() {
|
||||
return new LifeLossOtherFromCombatWatcher(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue