use of mage.MageObjectReference in project mage by magefree.
the class PetrifiedWoodKinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
DamageDoneWatcher watcher = game.getState().getWatcher(DamageDoneWatcher.class);
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (player == null || watcher == null || permanent == null) {
return false;
}
// the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
int amount = 0;
for (UUID opponentId : game.getOpponents(player.getId())) {
MageObjectReference mor = new MageObjectReference(opponentId, game);
amount += watcher.getDamagedObjects().getOrDefault(mor, 0);
}
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game, appliedEffects);
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class PsychicTheftWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
return;
}
map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
use of mage.MageObjectReference in project mage by magefree.
the class RepercussionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Integer playerDamage = (Integer) this.getValue(RepercussionTriggeredAbility.PLAYER_DAMAGE_AMOUNT_KEY);
MageObjectReference mor = (MageObjectReference) this.getValue(RepercussionTriggeredAbility.TRIGGERING_CREATURE_KEY);
if (playerDamage != null && mor != null) {
Permanent creature = mor.getPermanentOrLKIBattlefield(game);
if (creature != null) {
Player player = game.getPlayer(creature.getControllerId());
if (player != null) {
player.damage(playerDamage, source.getSourceId(), source, game);
}
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class RepercussionEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent == null || !permanent.isCreature(game)) {
return false;
}
getEffects().setValue(PLAYER_DAMAGE_AMOUNT_KEY, event.getAmount());
getEffects().setValue(TRIGGERING_CREATURE_KEY, new MageObjectReference(event.getTargetId(), game));
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class AttackIfAbleTargetRandoOpponentSourceEffect method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE) {
// Remove previous attacking creatures of the current combat's player if info exists
attackedLastCombatPlayers.remove(game.getCombat().getAttackingPlayerId());
}
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
// remember which attacker attacked which player
Map<MageObjectReference, UUID> attackedPlayers = new HashMap<>();
for (UUID attackerId : game.getCombat().getAttackers()) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null) {
attackedPlayers.put(new MageObjectReference(attacker, game), game.getCombat().getDefenderId(attackerId));
}
}
attackedLastCombatPlayers.put(game.getCombat().getAttackingPlayerId(), attackedPlayers);
}
}
Aggregations