use of mage.game.events.GameEvent in project mage by magefree.
the class Mulligan method executeMulliganPhase.
public void executeMulliganPhase(Game game, int startingHandSize) {
/*
* 103.4. Each player draws a number of cards equal to their starting hand size,
* which is normally seven. (Some effects can modify a player’s starting hand size.)
* A player who is dissatisfied with their initial hand may take a mulligan. First
* the starting player declares whether they will take a mulligan. Then each other
* player in turn order does the same. Once each player has made a declaration, all
* players who decided to take mulligans do so at the same time. To take a mulligan,
* a player shuffles their hand back into their library, then draws a new hand of one
* fewer cards than they had before. If a player kept their hand of cards, those cards
* become the player’s opening hand, and that player may not take any further mulligans.
* This process is then repeated until no player takes a mulligan. (Note that if a
* player’s hand size reaches zero cards, that player must keep that hand.)
*/
List<UUID> keepPlayers = new ArrayList<>();
List<UUID> mulliganPlayers = new ArrayList<>();
do {
mulliganPlayers.clear();
for (UUID playerId : game.getState().getPlayerList(game.getStartingPlayerId())) {
if (!keepPlayers.contains(playerId)) {
Player player = game.getPlayer(playerId);
boolean keep = true;
while (true) {
if (!canTakeMulligan(game, player)) {
break;
}
GameEvent event = new GameEvent(GameEvent.EventType.CAN_TAKE_MULLIGAN, null, null, playerId);
if (!game.replaceEvent(event)) {
game.fireEvent(event);
game.getState().setChoosingPlayerId(playerId);
if (player.chooseMulligan(game)) {
keep = false;
}
break;
}
}
if (keep) {
game.endMulligan(player.getId());
keepPlayers.add(playerId);
game.fireInformEvent(player.getLogName() + " keeps hand");
} else {
mulliganPlayers.add(playerId);
game.fireInformEvent(player.getLogName() + " decides to take mulligan");
}
}
}
for (UUID mulliganPlayerId : mulliganPlayers) {
mulligan(game, mulliganPlayerId);
}
game.saveState(false);
} while (!mulliganPlayers.isEmpty());
}
use of mage.game.events.GameEvent in project mage by magefree.
the class TestOfFaithPreventDamageTargetEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
if (!game.replaceEvent(preventEvent)) {
int prevented = 0;
if (event.getAmount() >= this.amount) {
int damage = amount;
event.setAmount(event.getAmount() - amount);
this.used = true;
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
prevented = damage;
} else {
int damage = event.getAmount();
event.setAmount(0);
amount -= damage;
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
prevented = damage;
}
// add counters now
if (prevented > 0) {
Permanent targetPermanent = game.getPermanent(source.getTargets().getFirstTarget());
if (targetPermanent != null) {
targetPermanent.addCounters(CounterType.P1P1.createInstance(prevented), source.getControllerId(), source, game);
game.informPlayers("Test of Faith: Prevented " + prevented + " damage ");
game.informPlayers("Test of Faith: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
}
}
}
return false;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class WoodlandChampionTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
if (zEvent != null && Zone.BATTLEFIELD == zEvent.getToZone() && zEvent.getTokens() != null) {
int tokenCount = zEvent.getTokens().stream().mapToInt(card -> card.isControlledBy(this.getControllerId()) ? 1 : 0).sum();
if (tokenCount > 0) {
this.getEffects().clear();
this.addEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(tokenCount)));
return true;
}
}
return false;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class AbilityImpl method resolve.
@Override
public boolean resolve(Game game) {
boolean result = true;
// 20100716 - 117.12
if (checkIfClause(game)) {
// Ability has started resolving. Fire event.
// Used for abilities counting the number of resolutions like Ashling the Pilgrim.
game.fireEvent(new GameEvent(GameEvent.EventType.RESOLVING_ABILITY, this.getOriginalId(), this, this.getControllerId()));
if (this instanceof TriggeredAbility) {
for (UUID modeId : this.getModes().getSelectedModes()) {
this.getModes().setActiveMode(modeId);
result = resolveMode(game);
}
} else {
result = resolveMode(game);
}
}
return result;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class AdaptEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// Verify source object did not change zone and is on the battlefield
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (sourceObject == null) {
if (game.getState().getZone(source.getSourceId()).equals(Zone.BATTLEFIELD) && source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId())) {
sourceObject = game.getPermanent(source.getSourceId());
}
}
Permanent permanent = ((Permanent) sourceObject);
if (permanent == null) {
return false;
}
GameEvent event = new GameEvent(GameEvent.EventType.ADAPT, source.getSourceId(), source, source.getControllerId(), adaptNumber, false);
if (game.replaceEvent(event)) {
return false;
}
if (permanent.getCounters(game).getCount(CounterType.P1P1) == 0 || event.getFlag()) {
permanent.addCounters(CounterType.P1P1.createInstance(event.getAmount()), source.getControllerId(), source, game);
}
return true;
}
Aggregations