Refactor: replaced sourceId by source and introduced source param in some methods;

This commit is contained in:
Oleg Agafonov 2020-12-12 20:23:19 +04:00
parent 2bb472607b
commit db239a1055
3205 changed files with 7080 additions and 6795 deletions

View file

@ -1,10 +1,14 @@
package mage.actions;
import mage.abilities.Ability;
import mage.actions.impl.MageAction;
import mage.actions.score.ArtificialScoringSystem;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.DrawCardEvent;
import mage.game.events.DrawCardsEvent;
import mage.game.events.DrewCardEvent;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.util.CardUtil;
@ -23,35 +27,34 @@ public class MageDrawAction extends MageAction {
private static final int NEGATIVE_VALUE = -1000000;
private final Player player;
private final List<UUID> appliedEffects;
private final List<Card> drawnCards;
private final GameEvent originalDrawEvent; // for replace effects
private int amount;
public MageDrawAction(Player player, int amount, List<UUID> appliedEffects) {
public MageDrawAction(Player player, int amount, GameEvent originalDrawEvent) {
this.player = player;
this.amount = amount;
this.appliedEffects = appliedEffects;
this.drawnCards = new ArrayList<>();
this.originalDrawEvent = originalDrawEvent;
}
/**
* Draw and set action score.
*
* @param sourceId
* @param source
* @param game Game context.
* @return
*/
@Override
public int doAction(UUID sourceId, Game game) {
public int doAction(Ability source, Game game) {
int numDrawn = 0;
int score = 0;
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARDS, player.getId(), null, player.getId(), null, amount);
event.addAppliedEffects(appliedEffects);
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(sourceId, game);
int value = drawCard(source, this.originalDrawEvent, game);
if (value == NEGATIVE_VALUE) {
continue;
}
@ -72,23 +75,23 @@ public class MageDrawAction extends MageAction {
* Draw a card if possible (there is no replacement effect that prevent us
* from drawing). Fire event about card drawn.
*
* @param sourceId
* @param source
* @param originalDrawEvent original draw event for replacement effects, can be null for normal calls
* @param game
* @return
*/
protected int drawCard(UUID sourceId, Game game) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), sourceId, player.getId());
event.addAppliedEffects(appliedEffects);
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);
card.moveToZone(Zone.HAND, null, game, false);
card.moveToZone(Zone.HAND, source, game, false); // if you want to use event.getSourceId() here then thinks x10 times
if (player.isTopCardRevealed()) {
game.fireInformEvent(player.getLogName() + " draws a revealed card (" + card.getLogName() + ')');
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DREW_CARD, card.getId(), player.getId()));
game.fireEvent(new DrewCardEvent(card.getId(), player.getId(), source, originalDrawEvent));
return ArtificialScoringSystem.inst.getCardScore(card);
}
}