[C21] Implemented Combat Calligrapher

This commit is contained in:
Evan Kranzler 2021-04-27 09:29:27 -04:00
parent 1fad23b9fb
commit 0c3b294527
7 changed files with 193 additions and 41 deletions

View file

@ -10,6 +10,8 @@ import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author Loki
*/
@ -57,7 +59,7 @@ public class CreateTokenTargetEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int value = amount.calculate(game, source, this);
if (value > 0) {
return token.putOntoBattlefield(value, game, source, targetPointer.getFirst(game, source), tapped, attacking);
return token.putOntoBattlefield(value, game, source, targetPointer.getFirst(game, source), tapped, attacking, (UUID) getValue("playerToAttack"));
}
return true;
}

View file

@ -1,8 +1,7 @@
package mage.game.combat;
import java.io.Serializable;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.RestrictionEffect;
@ -23,11 +22,7 @@ import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.permanent.AttackingSameNotBandedPredicate;
import mage.filter.predicate.permanent.PermanentIdPredicate;
import mage.game.Game;
import mage.game.events.AttackerDeclaredEvent;
import mage.game.events.DeclareAttackerEvent;
import mage.game.events.DeclareBlockerEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.*;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.players.PlayerList;
@ -38,6 +33,9 @@ import mage.util.Copyable;
import mage.util.trace.TraceUtil;
import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -269,6 +267,7 @@ public class Combat implements Serializable, Copyable<Combat> {
@SuppressWarnings("deprecation")
public void resumeSelectAttackers(Game game) {
Map<UUID, Set<MageObjectReference>> morSetMap = new HashMap<>();
for (CombatGroup group : groups) {
for (UUID attacker : group.getAttackers()) {
if (attackersTappedByAttack.contains(attacker)) {
@ -282,10 +281,12 @@ public class Combat implements Serializable, Copyable<Combat> {
// This can only be used to modify the event, the attack can't be replaced here
game.replaceEvent(new AttackerDeclaredEvent(group.defenderId, attacker, attackingPlayerId));
game.addSimultaneousEvent(new AttackerDeclaredEvent(group.defenderId, attacker, attackingPlayerId));
morSetMap.computeIfAbsent(group.defenderId, x -> new HashSet<>()).add(new MageObjectReference(attacker, game));
}
}
attackersTappedByAttack.clear();
DefenderAttackedEvent.makeAddEvents(morSetMap, attackingPlayerId, game);
game.addSimultaneousEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackingPlayerId, attackingPlayerId));
if (!game.isSimulation()) {
Player player = game.getPlayer(attackingPlayerId);
@ -352,8 +353,8 @@ public class Combat implements Serializable, Copyable<Combat> {
if (game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, attackingPlayerId, attackingPlayerId))
|| (!canBand && !canBandWithOther)
|| !player.chooseUse(Outcome.Benefit,
(isBanded ? "Band " + attacker.getLogName()
+ " with another " : "Form a band with " + attacker.getLogName() + " and an ")
(isBanded ? "Band " + attacker.getLogName()
+ " with another " : "Form a band with " + attacker.getLogName() + " and an ")
+ "attacking creature?", null, game)) {
break;
}
@ -571,7 +572,7 @@ public class Combat implements Serializable, Copyable<Combat> {
* Handle the blocker selection process
*
* @param blockController player that controls how to block, if null the
* defender is the controller
* defender is the controller
* @param game
*/
public void selectBlockers(Player blockController, Ability source, Game game) {
@ -1388,7 +1389,7 @@ public class Combat implements Serializable, Copyable<Combat> {
* @param playerId
* @param game
* @param solveBanding check whether also add creatures banded with
* attackerId
* attackerId
*/
public void addBlockingGroup(UUID blockerId, UUID attackerId, UUID playerId, Game game, boolean solveBanding) {
Permanent blocker = game.getPermanent(blockerId);

View file

@ -0,0 +1,37 @@
package mage.game.events;
import mage.MageObjectReference;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author TheElk801
*/
public class DefenderAttackedEvent extends GameEvent {
private final Set<MageObjectReference> morSet = new HashSet<>();
public DefenderAttackedEvent(UUID targetId, UUID playerId) {
super(EventType.DEFENDER_ATTACKED, targetId, null, playerId);
}
public static void makeAddEvents(Map<UUID, Set<MageObjectReference>> morMapSet, UUID attackingPlayerId, Game game) {
for (Map.Entry<UUID, Set<MageObjectReference>> entry : morMapSet.entrySet()) {
DefenderAttackedEvent event = new DefenderAttackedEvent(entry.getKey(), attackingPlayerId);
event.morSet.addAll(entry.getValue());
game.addSimultaneousEvent(event);
}
}
public List<Permanent> getAttackers(Game game) {
return morSet
.stream()
.map(mor -> mor.getPermanent(game))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}

View file

@ -275,6 +275,7 @@ public class GameEvent implements Serializable {
amount not used for this event
flag not used for this event
*/
DEFENDER_ATTACKED,
DECLARING_BLOCKERS,
DECLARED_BLOCKERS,
DECLARE_BLOCKER,