mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Added damage done watcher.
This commit is contained in:
parent
03dcc4a9f6
commit
1668783ba2
5 changed files with 112 additions and 2 deletions
|
@ -69,7 +69,11 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
if (mageObject != null) {
|
||||
this.zoneChangeCounter = mageObject.getZoneChangeCounter(game);
|
||||
} else {
|
||||
throw new IllegalArgumentException("The provided sourceId is not connected to an object in the game");
|
||||
if (game.getPlayerList().contains(sourceId)) {
|
||||
this.zoneChangeCounter = 0;
|
||||
} else {
|
||||
throw new IllegalArgumentException("The provided sourceId is not connected to an object in the game");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||
* @author Loki
|
||||
*/
|
||||
public class CardsInOpponentGraveCondition implements Condition {
|
||||
private int value;
|
||||
private final int value;
|
||||
|
||||
public CardsInOpponentGraveCondition(int value) {
|
||||
this.value = value;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.DamageDoneWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class SourceDealtDamageCondition implements Condition {
|
||||
private final int value;
|
||||
|
||||
public SourceDealtDamageCondition(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
DamageDoneWatcher watcher = (DamageDoneWatcher) game.getState().getWatchers().get("DamageDone");
|
||||
return watcher != null && watcher.damageDone(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game) >= value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{this} has dealt " + value + " or more damage this turn" ;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -122,6 +122,7 @@ import mage.watchers.Watchers;
|
|||
import mage.watchers.common.BlockedAttackerWatcher;
|
||||
import mage.watchers.common.BloodthirstWatcher;
|
||||
import mage.watchers.common.CastSpellLastTurnWatcher;
|
||||
import mage.watchers.common.DamageDoneWatcher;
|
||||
import mage.watchers.common.MorbidWatcher;
|
||||
import mage.watchers.common.PlayerDamagedBySourceWatcher;
|
||||
import mage.watchers.common.PlayerLostLifeWatcher;
|
||||
|
@ -912,6 +913,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
watchers.add(new SoulbondWatcher());
|
||||
watchers.add(new PlayerLostLifeWatcher());
|
||||
watchers.add(new BlockedAttackerWatcher());
|
||||
watchers.add(new DamageDoneWatcher());
|
||||
|
||||
//20100716 - 103.5
|
||||
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
|
||||
|
|
67
Mage/src/mage/watchers/common/DamageDoneWatcher.java
Normal file
67
Mage/src/mage/watchers/common/DamageDoneWatcher.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.watchers.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamageEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class DamageDoneWatcher extends Watcher {
|
||||
|
||||
// which object did how much damage during the turn
|
||||
public Map<MageObjectReference, Integer> damagingObjects = new HashMap<>();
|
||||
|
||||
public DamageDoneWatcher() {
|
||||
super("DamageDone", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public DamageDoneWatcher(final DamageDoneWatcher watcher) {
|
||||
super(watcher);
|
||||
this.damagingObjects.putAll(damagingObjects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageDoneWatcher copy() {
|
||||
return new DamageDoneWatcher(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
switch(event.getType()) {
|
||||
case DAMAGED_CREATURE:
|
||||
case DAMAGED_PLANESWALKER:
|
||||
case DAMAGED_PLAYER:
|
||||
{
|
||||
MageObjectReference mor = new MageObjectReference(event.getSourceId(), game);
|
||||
int count = damagingObjects.containsKey(mor) ? damagingObjects.get(mor) : 0;
|
||||
damagingObjects.put(mor, count + event.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
damagingObjects.clear();
|
||||
}
|
||||
|
||||
public int damageDone(UUID objectId, int zoneChangeCounter, Game game) {
|
||||
MageObjectReference mor = new MageObjectReference(objectId, zoneChangeCounter, game);
|
||||
return damagingObjects.containsKey(mor) ? damagingObjects.get(mor) : 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue