(int n, final ZoneType destination, SpellAbility sa, Map<AbilityKey, Object> params)
| 1551 | } |
| 1552 | |
| 1553 | public final CardCollectionView mill(int n, final ZoneType destination, SpellAbility sa, Map<AbilityKey, Object> params) { |
| 1554 | // Replacement effects |
| 1555 | final Map<AbilityKey, Object> repRunParams = AbilityKey.mapFromAffected(this); |
| 1556 | repRunParams.put(AbilityKey.Number, n); |
| 1557 | if (params != null) { |
| 1558 | repRunParams.putAll(params); |
| 1559 | } |
| 1560 | |
| 1561 | if (destination == ZoneType.Graveyard) { |
| 1562 | switch (getGame().getReplacementHandler().run(ReplacementType.Mill, repRunParams)) { |
| 1563 | case NotReplaced: |
| 1564 | break; |
| 1565 | case Updated: |
| 1566 | // check if this is still the affected player |
| 1567 | if (this.equals(repRunParams.get(AbilityKey.Affected))) { |
| 1568 | n = (int) repRunParams.get(AbilityKey.Number); |
| 1569 | } else { |
| 1570 | return CardCollection.EMPTY; |
| 1571 | } |
| 1572 | break; |
| 1573 | default: |
| 1574 | return CardCollection.EMPTY; |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | Iterable<Card> milledView = getCardsIn(ZoneType.Library); |
| 1579 | // CR 614.13c |
| 1580 | if (sa.getRootAbility().getReplacingObject(AbilityKey.SimultaneousETB) != null) { |
| 1581 | milledView = IterableUtil.filter(milledView, c -> !((CardCollection) sa.getRootAbility().getReplacingObject(AbilityKey.SimultaneousETB)).contains(c)); |
| 1582 | } |
| 1583 | CardCollectionView milled = new CardCollection(Iterables.limit(milledView, n)); |
| 1584 | |
| 1585 | if (destination == ZoneType.Graveyard) { |
| 1586 | milled = GameActionUtil.orderCardsByTheirOwners(game, milled, ZoneType.Graveyard, sa); |
| 1587 | } |
| 1588 | |
| 1589 | for (Card m : milled) { |
| 1590 | Card moved = game.getAction().moveTo(destination, m, sa, params); |
| 1591 | moved.setMilled(true); |
| 1592 | |
| 1593 | final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(this); |
| 1594 | runParams.put(AbilityKey.Card, m); |
| 1595 | game.getTriggerHandler().runTrigger(TriggerType.Milled, runParams, false); |
| 1596 | } |
| 1597 | |
| 1598 | if (!milled.isEmpty()) { |
| 1599 | final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(this); |
| 1600 | runParams.put(AbilityKey.Cards, milled); |
| 1601 | game.getTriggerHandler().runTrigger(TriggerType.MilledOnce, runParams, false); |
| 1602 | } |
| 1603 | |
| 1604 | return milled; |
| 1605 | } |
| 1606 | |
| 1607 | public final CardCollection getTopXCardsFromLibrary(int amount) { |
| 1608 | final CardCollection topCards = new CardCollection(); |
no test coverage detected