use of mage.players.Player in project mage by magefree.
the class ComputerPlayer2 method createSimulation.
/**
* Copies game and replaces all players in copy with simulated players
*
* @param game
* @return a new game object with simulated players
*/
protected Game createSimulation(Game game) {
Game sim = game.copy();
for (Player oldPlayer : sim.getState().getPlayers().values()) {
Player origPlayer = game.getState().getPlayers().get(oldPlayer.getId()).copy();
SimulatedPlayer newPlayer = new SimulatedPlayer(oldPlayer, oldPlayer.getId().equals(playerId), maxDepth);
newPlayer.restore(origPlayer);
sim.getState().getPlayers().put(oldPlayer.getId(), newPlayer);
}
sim.setSimulation(true);
return sim;
}
use of mage.players.Player in project mage by magefree.
the class AuraFinesseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent aura = game.getPermanent(source.getFirstTarget());
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (aura != null && creature != null) {
Permanent oldCreature = game.getPermanent(aura.getAttachedTo());
if (oldCreature != null && !oldCreature.equals(creature)) {
Target auraTarget = aura.getSpellAbility().getTargets().get(0);
if (!auraTarget.canTarget(creature.getId(), game)) {
game.informPlayers(aura.getLogName() + " was not attched to " + creature.getLogName() + " because it's no legal target for the aura");
} else if (oldCreature.removeAttachment(aura.getId(), source, game)) {
game.informPlayers(aura.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + creature.getLogName());
creature.addAttachment(aura.getId(), source, game);
}
}
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class AuspiciousStarrixEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = SourceMutatedCount.instance.calculate(game, source, this);
int count = 0;
Cards toExile = new CardsImpl();
Cards toBattlefield = new CardsImpl();
for (Card card : player.getLibrary().getCards(game)) {
if (card != null && card.isPermanent(game)) {
toBattlefield.add(card);
count++;
}
toExile.add(card);
if (count >= xValue) {
break;
}
}
player.moveCards(toExile, Zone.EXILED, source, game);
return player.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game);
}
use of mage.players.Player in project mage by magefree.
the class BarrinsSpiteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
if (permanents.isEmpty()) {
return false;
}
if (permanents.size() == 1) {
permanents.get(0).sacrifice(source, game);
return true;
}
if (permanents.size() > 2) {
throw new IllegalStateException("Too many permanents in list, shouldn't be possible");
}
Player player = game.getPlayer(permanents.get(0).getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player == null || controller == null) {
return false;
}
Permanent perm1 = permanents.get(0);
Permanent perm2 = permanents.get(1);
if (player.chooseUse(outcome, "Choose which permanent to sacrifice", "The other will be returned to your hand", perm1.getIdName(), perm2.getIdName(), source, game)) {
perm1.sacrifice(source, game);
controller.moveCards(perm2, Zone.HAND, source, game);
return true;
}
perm2.sacrifice(source, game);
controller.moveCards(perm1, Zone.HAND, source, game);
return true;
}
use of mage.players.Player in project mage by magefree.
the class BeamsplitterMageApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) getValue("spellCast");
if (player == null || spell == null) {
return false;
}
FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
filter.add(AnotherPredicate.instance);
filter.add(new BeamsplitterMagePredicate(spell));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
return true;
}
Aggregations