performance: improved CPU/memory usage with copy of cost's targets (related to #11285), added runtime check for wrong targets usage

This commit is contained in:
Oleg Agafonov 2023-11-07 02:47:48 +04:00
parent d6c858ecaf
commit ddc1ec8ef8
32 changed files with 173 additions and 107 deletions

View file

@ -42,7 +42,7 @@ public class DiscardTargetCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
this.cards.clear();
this.targets.clearChosen();
this.getTargets().clearChosen();
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
@ -50,9 +50,9 @@ public class DiscardTargetCost extends CostImpl {
int amount = this.getTargets().get(0).getNumberOfTargets();
if (randomDiscard) {
this.cards.addAll(player.discard(amount, true, true, source, game).getCards(game));
} else if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), source, game)) {
} else if (this.getTargets().choose(Outcome.Discard, controllerId, source.getSourceId(), source, game)) {
Cards toDiscard = new CardsImpl();
toDiscard.addAll(targets.get(0).getTargets());
toDiscard.addAll(this.getTargets().get(0).getTargets());
Cards discarded = player.discard(toDiscard, true, source, game);
if (!discarded.isEmpty()) {
cards.addAll(discarded.getCards(game));
@ -70,7 +70,7 @@ public class DiscardTargetCost extends CostImpl {
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return targets.canChoose(controllerId, source, game);
return this.getTargets().canChoose(controllerId, source, game);
}
@Override