mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 20:11:59 -08:00
remove another game default watcher with one usage
This commit is contained in:
parent
f801c9851e
commit
cd439ab8c8
3 changed files with 53 additions and 77 deletions
|
|
@ -24,11 +24,15 @@ import mage.filter.StaticFilters;
|
|||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.ManaValuePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetadjustment.TargetAdjuster;
|
||||
import mage.watchers.common.PlayerLostLifeNonCombatWatcher;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -91,7 +95,8 @@ enum SupremeLeaderSnokeAdjuster implements TargetAdjuster {
|
|||
}
|
||||
}
|
||||
|
||||
class OpponentNoncombatLostLifeCount implements DynamicValue {
|
||||
enum OpponentNoncombatLostLifeCount implements DynamicValue {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
|
|
@ -104,7 +109,7 @@ class OpponentNoncombatLostLifeCount implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public OpponentNoncombatLostLifeCount copy() {
|
||||
return new OpponentNoncombatLostLifeCount();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -132,7 +137,7 @@ class SupremeLeaderSnokeCounterEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
int amount = new OpponentNoncombatLostLifeCount().calculate(game, source, this);
|
||||
int amount = OpponentNoncombatLostLifeCount.instance.calculate(game, source, this);
|
||||
if (amount > 0) {
|
||||
Counter counterToAdd = counter.copy();
|
||||
counterToAdd.add(amount - counter.getCount());
|
||||
|
|
@ -146,4 +151,47 @@ class SupremeLeaderSnokeCounterEffect extends OneShotEffect {
|
|||
public SupremeLeaderSnokeCounterEffect copy() {
|
||||
return new SupremeLeaderSnokeCounterEffect(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerLostLifeNonCombatWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> amountOfLifeLostThisTurn = new HashMap<>();
|
||||
|
||||
PlayerLostLifeNonCombatWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
// non combat lose life
|
||||
if (event.getType() == GameEvent.EventType.LOST_LIFE && !event.getFlag()) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
Integer amount = amountOfLifeLostThisTurn.get(playerId);
|
||||
if (amount == null) {
|
||||
amount = event.getAmount();
|
||||
} else {
|
||||
amount = amount + event.getAmount();
|
||||
}
|
||||
amountOfLifeLostThisTurn.put(playerId, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getAllOppLifeLost(UUID playerId, Game game) {
|
||||
int amount = 0;
|
||||
for (UUID opponentId : this.amountOfLifeLostThisTurn.keySet()) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent != null && opponent.hasOpponent(playerId, game)) {
|
||||
amount += this.amountOfLifeLostThisTurn.getOrDefault(opponentId, 0);
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
amountOfLifeLostThisTurn.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1339,7 +1339,6 @@ public abstract class GameImpl implements Game {
|
|||
newWatchers.add(new MorbidWatcher());
|
||||
newWatchers.add(new CastSpellLastTurnWatcher());
|
||||
newWatchers.add(new PlayerLostLifeWatcher());
|
||||
newWatchers.add(new PlayerLostLifeNonCombatWatcher());
|
||||
newWatchers.add(new BlockedAttackerWatcher());
|
||||
newWatchers.add(new DamageDoneWatcher());
|
||||
newWatchers.add(new PlanarRollWatcher());
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/*
|
||||
* Counts amount of life lost from noncombat sources current or last turn by players.
|
||||
* This watcher is automatically started in gameImpl.init for each game
|
||||
*
|
||||
* @author NinthWorld
|
||||
*/
|
||||
public class PlayerLostLifeNonCombatWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> amountOfLifeLostThisTurn = new HashMap<>();
|
||||
private final Map<UUID, Integer> amountOfLifeLostLastTurn = new HashMap<>();
|
||||
|
||||
public PlayerLostLifeNonCombatWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
// non combat lose life
|
||||
if (event.getType() == GameEvent.EventType.LOST_LIFE && !event.getFlag()) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
Integer amount = amountOfLifeLostThisTurn.get(playerId);
|
||||
if (amount == null) {
|
||||
amount = event.getAmount();
|
||||
} else {
|
||||
amount = amount + event.getAmount();
|
||||
}
|
||||
amountOfLifeLostThisTurn.put(playerId, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getLiveLost(UUID playerId) {
|
||||
return amountOfLifeLostThisTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
public int getAllOppLifeLost(UUID playerId, Game game) {
|
||||
int amount = 0;
|
||||
for (UUID opponentId : this.amountOfLifeLostThisTurn.keySet()) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent != null && opponent.hasOpponent(playerId, game)) {
|
||||
amount += this.amountOfLifeLostThisTurn.getOrDefault(opponentId, 0);
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
public int getLiveLostLastTurn(UUID playerId) {
|
||||
return amountOfLifeLostLastTurn.getOrDefault(playerId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
amountOfLifeLostLastTurn.clear();
|
||||
amountOfLifeLostLastTurn.putAll(amountOfLifeLostThisTurn);
|
||||
amountOfLifeLostThisTurn.clear();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue