Search in sources :

Example 6 with Player

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;
}
Also used : Player(mage.players.Player) Game(mage.game.Game)

Example 7 with Player

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;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 8 with Player

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);
}
Also used : Player(mage.players.Player)

Example 9 with Player

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;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 10 with Player

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;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Spell(mage.game.stack.Spell)

Aggregations

Player (mage.players.Player)3909 Permanent (mage.game.permanent.Permanent)1705 Card (mage.cards.Card)1099 UUID (java.util.UUID)962 MageObject (mage.MageObject)556 FilterCard (mage.filter.FilterCard)515 CardsImpl (mage.cards.CardsImpl)498 FixedTarget (mage.target.targetpointer.FixedTarget)387 TargetPermanent (mage.target.TargetPermanent)353 Cards (mage.cards.Cards)345 TargetCard (mage.target.TargetCard)328 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)317 TargetPlayer (mage.target.TargetPlayer)312 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)301 FilterPermanent (mage.filter.FilterPermanent)292 Target (mage.target.Target)289 OneShotEffect (mage.abilities.effects.OneShotEffect)230 ContinuousEffect (mage.abilities.effects.ContinuousEffect)227 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)207 Effect (mage.abilities.effects.Effect)170