refactor: removed unused data from special action, improved code (related to #11137)

This commit is contained in:
Oleg Agafonov 2023-09-17 14:37:49 +04:00
parent a4daad1f92
commit 4e77ccb381
7 changed files with 31 additions and 38 deletions

View file

@ -1681,8 +1681,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
// pay special mana like convoke cost (tap for pay)
// GUI: user see "special" button while pay spell's cost
// TODO: AI can't prioritize special mana types to pay, e.g. it will use first available
SpecialAction specialAction = game.getState().getSpecialActions().getControlledBy(this.getId(), true)
.values().stream().findFirst().orElse(null);
SpecialAction specialAction = game.getState().getSpecialActions().getControlledBy(this.getId(), true).values()
.stream()
.findFirst()
.orElse(null);
ManaOptions specialMana = specialAction == null ? null : specialAction.getManaOptions(ability, game, unpaid);
if (specialMana != null) {
for (Mana netMana : specialMana) {
@ -1690,11 +1692,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (netMana instanceof ConditionalMana && !((ConditionalMana) netMana).apply(ability, game, getId(), cost)) {
continue;
}
specialAction.setUnpaidMana(unpaid);
if (activateAbility(specialAction, game)) {
return true;
}
// only one time try to pay
// only one time try to pay to skip infinite AI loop
break;
}
}

View file

@ -41,12 +41,7 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetAnyTarget;
import mage.target.common.TargetAttackingCreature;
import mage.target.common.TargetDefender;
import mage.util.CardUtil;
import mage.util.GameLog;
import mage.util.ManaUtil;
import mage.util.MessageToClient;
import mage.util.MultiAmountMessage;
import mage.util.*;
import org.apache.log4j.Logger;
import java.awt.*;
@ -2058,8 +2053,14 @@ public class HumanPlayer extends PlayerImpl {
}
@Override
public List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages,
int min, int max, MultiAmountType type, Game game) {
public List<Integer> getMultiAmountWithIndividualConstraints(
Outcome outcome,
List<MultiAmountMessage> messages,
int min,
int max,
MultiAmountType type,
Game game
) {
int needCount = messages.size();
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
if (needCount == 0 || (needCount == 1 && min == max)
@ -2146,14 +2147,9 @@ public class HumanPlayer extends PlayerImpl {
waitForResponse(game);
UUID responseId = getFixedResponseUUID(game);
if (responseId != null) {
if (specialActions.containsKey(responseId)) {
SpecialAction specialAction = specialActions.get(responseId);
if (unpaidForManaAction != null) {
specialAction.setUnpaidMana(unpaidForManaAction);
}
activateAbility(specialAction, game);
}
SpecialAction specialAction = specialActions.getOrDefault(responseId, null);
if (specialAction != null) {
activateAbility(specialAction, game);
}
}
}