use of mage.game.events.GameEvent in project mage by magefree.
the class MageDrawAction method doAction.
/**
* Draw and set action score.
*
* @param source
* @param game Game context.
* @return
*/
@Override
public int doAction(Ability source, Game game) {
int numDrawn = 0;
int score = 0;
GameEvent event = new DrawCardsEvent(this.player.getId(), source, this.originalDrawEvent, this.amount);
if (amount < 2 || !game.replaceEvent(event)) {
amount = event.getAmount();
for (int i = 0; i < amount; i++) {
int value = drawCard(source, this.originalDrawEvent, game);
if (value == NEGATIVE_VALUE) {
continue;
}
numDrawn++;
score += value;
}
if (!player.isTopCardRevealed() && numDrawn > 0) {
game.fireInformEvent(player.getLogName() + " draws " + CardUtil.numberToText(numDrawn, "a") + " card" + (numDrawn > 1 ? "s" : ""));
}
setScore(player, score);
}
return numDrawn;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class MageDrawAction method drawCard.
/**
* Draw a card if possible (there is no replacement effect that prevent us
* from drawing). Fire event about card drawn.
*
* @param source
* @param originalDrawEvent original draw event for replacement effects, can be null for normal calls
* @param game
* @return
*/
protected int drawCard(Ability source, GameEvent originalDrawEvent, Game game) {
GameEvent event = new DrawCardEvent(this.player.getId(), source, originalDrawEvent);
if (!game.replaceEvent(event)) {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
drawnCards.add(card);
// if you want to use event.getSourceId() here then thinks x10 times
card.moveToZone(Zone.HAND, source, game, false);
if (player.isTopCardRevealed()) {
game.fireInformEvent(player.getLogName() + " draws a revealed card (" + card.getLogName() + ')');
}
game.fireEvent(new DrewCardEvent(card.getId(), player.getId(), source, originalDrawEvent));
return ArtificialScoringSystem.inst.getCardScore(card);
}
}
return NEGATIVE_VALUE;
}
use of mage.game.events.GameEvent in project mage by magefree.
the class CombatDamageStep method priority.
@Override
public void priority(Game game, UUID activePlayerId, boolean resuming) {
game.fireEvent(new GameEvent(GameEvent.EventType.COMBAT_DAMAGE_STEP_PRIORITY, null, null, activePlayerId));
super.priority(game, activePlayerId, resuming);
}
use of mage.game.events.GameEvent in project mage by magefree.
the class ManaPaidSourceWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
switch(event.getType()) {
case ZONE_CHANGE:
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
manaMap.remove(event.getTargetId());
}
return;
case MANA_PAID:
ManaPaidEvent manaEvent = (ManaPaidEvent) event;
manaMap.computeIfAbsent(manaEvent.getTargetId(), x -> new ManaPaidTracker()).increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
manaMap.computeIfAbsent(manaEvent.getSourcePaidId(), x -> new ManaPaidTracker()).increment(manaEvent.getSourceObject(), manaEvent.getManaType(), game);
}
}
use of mage.game.events.GameEvent in project mage by magefree.
the class ProwlWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != EventType.DAMAGED_PLAYER) {
return;
}
DamagedPlayerEvent dEvent = (DamagedPlayerEvent) event;
if (!dEvent.isCombatDamage()) {
return;
}
Permanent creature = game.getPermanent(dEvent.getSourceId());
if (creature == null || allSubtypes.contains(creature.getControllerId())) {
return;
}
if (creature.isAllCreatureTypes(game)) {
allSubtypes.add(creature.getControllerId());
return;
}
damagingSubtypes.computeIfAbsent(creature.getControllerId(), m -> new LinkedHashSet<>()).addAll(creature.getSubtype(game));
}
Aggregations