use of mage.game.combat.CombatGroup in project mage by magefree.
the class GoblinVandalTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent sourcePermanent = game.getPermanent(getSourceId());
if (sourcePermanent.isAttacking()) {
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
FilterPermanent filter = new FilterArtifactPermanent();
filter.add(new ControllerIdPredicate(defendingPlayerId));
Target target = new TargetPermanent(filter);
this.addTarget(target);
return true;
}
}
}
return false;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class VortexElementalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Combat combat = game.getState().getCombat();
Set<UUID> creaturesToReturn = new HashSet<>();
Set<UUID> playersToShuffle = new HashSet<>();
creaturesToReturn.add(source.getSourceId());
if (combat != null) {
for (CombatGroup combatGroup : combat.getGroups()) {
if (combatGroup.getAttackers().contains(source.getSourceId())) {
creaturesToReturn.addAll(combatGroup.getBlockers());
} else if (combatGroup.getBlockers().contains(source.getSourceId())) {
creaturesToReturn.addAll(combatGroup.getAttackers());
}
}
}
for (UUID creatureId : creaturesToReturn) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
playersToShuffle.add(creature.getControllerId());
}
}
Cards toLib = new CardsImpl(creaturesToReturn);
controller.putCardsOnTopOfLibrary(toLib, game, source, false);
for (UUID playerId : playersToShuffle) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class FeintEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && creature != null) {
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getAttackers().contains(creature.getId())) {
for (UUID blockerId : combatGroup.getBlockers()) {
Permanent blocker = game.getPermanent(blockerId);
if (blocker != null) {
blocker.tap(source, game);
PreventionEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, true);
effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
game.addEffect(effect, source);
}
}
}
}
return true;
}
return false;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class IbHalfheartGoblinTacticianEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent blockedCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (blockedCreature == null) {
// it can't be sacrificed, nothing happens
return true;
}
Set<UUID> blockingCreatures = new HashSet<>();
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getAttackers().contains(blockedCreature.getId())) {
blockingCreatures.addAll(combatGroup.getBlockers());
}
}
if (blockedCreature.sacrifice(source, game)) {
for (UUID blockerId : blockingCreatures) {
Permanent blockingCreature = game.getPermanent(blockerId);
if (blockingCreature != null) {
blockingCreature.damage(4, blockedCreature.getId(), source, game, false, true);
}
}
return true;
}
return false;
}
use of mage.game.combat.CombatGroup in project mage by magefree.
the class RandomPlayer method selectBlockers.
@Override
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
int numGroups = game.getCombat().getGroups().size();
if (numGroups == 0) {
return;
}
List<Permanent> blockers = getAvailableBlockers(game);
for (Permanent blocker : blockers) {
int check = RandomUtil.nextInt(numGroups + 1);
if (check < numGroups) {
CombatGroup group = game.getCombat().getGroups().get(check);
if (!group.getAttackers().isEmpty()) {
this.declareBlocker(this.getId(), blocker.getId(), group.getAttackers().get(0), game);
}
}
}
actionCount++;
}
Aggregations