mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
refactor: removed unused data from special action, improved code (related to #11137)
This commit is contained in:
parent
a4daad1f92
commit
4e77ccb381
7 changed files with 31 additions and 38 deletions
|
|
@ -1681,8 +1681,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
// pay special mana like convoke cost (tap for pay)
|
// pay special mana like convoke cost (tap for pay)
|
||||||
// GUI: user see "special" button while pay spell's cost
|
// 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
|
// 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)
|
SpecialAction specialAction = game.getState().getSpecialActions().getControlledBy(this.getId(), true).values()
|
||||||
.values().stream().findFirst().orElse(null);
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
ManaOptions specialMana = specialAction == null ? null : specialAction.getManaOptions(ability, game, unpaid);
|
ManaOptions specialMana = specialAction == null ? null : specialAction.getManaOptions(ability, game, unpaid);
|
||||||
if (specialMana != null) {
|
if (specialMana != null) {
|
||||||
for (Mana netMana : specialMana) {
|
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)) {
|
if (netMana instanceof ConditionalMana && !((ConditionalMana) netMana).apply(ability, game, getId(), cost)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
specialAction.setUnpaidMana(unpaid);
|
|
||||||
if (activateAbility(specialAction, game)) {
|
if (activateAbility(specialAction, game)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// only one time try to pay
|
// only one time try to pay to skip infinite AI loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,7 @@ import mage.target.TargetPermanent;
|
||||||
import mage.target.common.TargetAnyTarget;
|
import mage.target.common.TargetAnyTarget;
|
||||||
import mage.target.common.TargetAttackingCreature;
|
import mage.target.common.TargetAttackingCreature;
|
||||||
import mage.target.common.TargetDefender;
|
import mage.target.common.TargetDefender;
|
||||||
import mage.util.CardUtil;
|
import mage.util.*;
|
||||||
import mage.util.GameLog;
|
|
||||||
import mage.util.ManaUtil;
|
|
||||||
import mage.util.MessageToClient;
|
|
||||||
import mage.util.MultiAmountMessage;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
@ -2058,8 +2053,14 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages,
|
public List<Integer> getMultiAmountWithIndividualConstraints(
|
||||||
int min, int max, MultiAmountType type, Game game) {
|
Outcome outcome,
|
||||||
|
List<MultiAmountMessage> messages,
|
||||||
|
int min,
|
||||||
|
int max,
|
||||||
|
MultiAmountType type,
|
||||||
|
Game game
|
||||||
|
) {
|
||||||
int needCount = messages.size();
|
int needCount = messages.size();
|
||||||
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
|
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
|
||||||
if (needCount == 0 || (needCount == 1 && min == max)
|
if (needCount == 0 || (needCount == 1 && min == max)
|
||||||
|
|
@ -2146,14 +2147,9 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
|
|
||||||
UUID responseId = getFixedResponseUUID(game);
|
UUID responseId = getFixedResponseUUID(game);
|
||||||
if (responseId != null) {
|
SpecialAction specialAction = specialActions.getOrDefault(responseId, null);
|
||||||
if (specialActions.containsKey(responseId)) {
|
if (specialAction != null) {
|
||||||
SpecialAction specialAction = specialActions.get(responseId);
|
activateAbility(specialAction, game);
|
||||||
if (unpaidForManaAction != null) {
|
|
||||||
specialAction.setUnpaidMana(unpaidForManaAction);
|
|
||||||
}
|
|
||||||
activateAbility(specialAction, game);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4294,10 +4294,11 @@ public class TestPlayer implements Player {
|
||||||
if (specialAction.canActivate(this.getId(), game).canActivate()) {
|
if (specialAction.canActivate(this.getId(), game).canActivate()) {
|
||||||
choices.remove(0);
|
choices.remove(0);
|
||||||
choiceRemoved = true;
|
choiceRemoved = true;
|
||||||
specialAction.setUnpaidMana(unpaid);
|
|
||||||
if (activateAbility(specialAction, game)) {
|
if (activateAbility(specialAction, game)) {
|
||||||
choiceUsed = true;
|
choiceUsed = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Assert.fail("Found non active special mana action, but must generates only active: " + specialAction.getRule(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import java.util.UUID;
|
||||||
public abstract class SpecialAction extends ActivatedAbilityImpl {
|
public abstract class SpecialAction extends ActivatedAbilityImpl {
|
||||||
|
|
||||||
private final AlternateManaPaymentAbility manaAbility; // mana actions generates on every pay cycle, no need to copy it
|
private final AlternateManaPaymentAbility manaAbility; // mana actions generates on every pay cycle, no need to copy it
|
||||||
protected ManaCost unpaidMana;
|
|
||||||
|
|
||||||
public SpecialAction() {
|
public SpecialAction() {
|
||||||
this(Zone.ALL);
|
this(Zone.ALL);
|
||||||
|
|
@ -35,7 +34,6 @@ public abstract class SpecialAction extends ActivatedAbilityImpl {
|
||||||
|
|
||||||
protected SpecialAction(final SpecialAction action) {
|
protected SpecialAction(final SpecialAction action) {
|
||||||
super(action);
|
super(action);
|
||||||
this.unpaidMana = action.unpaidMana;
|
|
||||||
this.manaAbility = action.manaAbility;
|
this.manaAbility = action.manaAbility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,14 +41,6 @@ public abstract class SpecialAction extends ActivatedAbilityImpl {
|
||||||
return manaAbility != null;
|
return manaAbility != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnpaidMana(ManaCost manaCost) {
|
|
||||||
this.unpaidMana = manaCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ManaCost getUnpaidMana() {
|
|
||||||
return unpaidMana;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
|
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
|
||||||
if (manaAbility != null) {
|
if (manaAbility != null) {
|
||||||
return manaAbility.getManaOptions(source, game, unpaid);
|
return manaAbility.getManaOptions(source, game, unpaid);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
package mage.abilities;
|
package mage.abilities;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
@ -7,6 +5,12 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Special actions to activate at any priority time (GUI has special button to show a special commands list)
|
||||||
|
* <p>
|
||||||
|
* Two types of action:
|
||||||
|
* - mana actions (auto-generated on each mana pay cycle, auto-clean)
|
||||||
|
* - another actions (manual added, manual removed - like one short effects)
|
||||||
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class SpecialActions extends AbilitiesImpl<SpecialAction> {
|
public class SpecialActions extends AbilitiesImpl<SpecialAction> {
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,22 @@ import java.util.UUID;
|
||||||
public class CreateSpecialActionEffect extends OneShotEffect {
|
public class CreateSpecialActionEffect extends OneShotEffect {
|
||||||
|
|
||||||
private final SpecialAction action;
|
private final SpecialAction action;
|
||||||
private final UUID playerId; // If set, that player can activate the special action. If null, use the source controller instead.
|
private final UUID newActionControllerId; // another player can activate the special action
|
||||||
|
|
||||||
public CreateSpecialActionEffect(SpecialAction action) {
|
public CreateSpecialActionEffect(SpecialAction action) {
|
||||||
this(action, null);
|
this(action, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateSpecialActionEffect(SpecialAction action, UUID playerId) {
|
public CreateSpecialActionEffect(SpecialAction action, UUID newActionControllerId) {
|
||||||
super(action.getEffects().getOutcome(action));
|
super(action.getEffects().getOutcome(action));
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.playerId = playerId;
|
this.newActionControllerId = newActionControllerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CreateSpecialActionEffect(final CreateSpecialActionEffect effect) {
|
protected CreateSpecialActionEffect(final CreateSpecialActionEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.action = (SpecialAction) effect.action.copy();
|
this.action = (SpecialAction) effect.action.copy();
|
||||||
this.playerId = effect.playerId;
|
this.newActionControllerId = effect.newActionControllerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -41,7 +41,7 @@ public class CreateSpecialActionEffect extends OneShotEffect {
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
SpecialAction newAction = (SpecialAction) action.copy();
|
SpecialAction newAction = (SpecialAction) action.copy();
|
||||||
newAction.setSourceId(source.getSourceId());
|
newAction.setSourceId(source.getSourceId());
|
||||||
newAction.setControllerId(playerId == null ? source.getControllerId() : playerId);
|
newAction.setControllerId(newActionControllerId != null ? newActionControllerId : source.getControllerId());
|
||||||
newAction.getTargets().addAll(source.getTargets());
|
newAction.getTargets().addAll(source.getTargets());
|
||||||
game.getState().getSpecialActions().add(newAction);
|
game.getState().getSpecialActions().add(newAction);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ class ConvokeEffect extends OneShotEffect {
|
||||||
if (chooseManaType.getChoices().size() > 1) {
|
if (chooseManaType.getChoices().size() > 1) {
|
||||||
chooseManaType.getChoices().add("Colorless");
|
chooseManaType.getChoices().add("Colorless");
|
||||||
chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName());
|
chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName());
|
||||||
|
// TODO: must be AI optimization to pay most rare mana color first
|
||||||
if (!controller.choose(Outcome.Benefit, chooseManaType, game)) {
|
if (!controller.choose(Outcome.Benefit, chooseManaType, game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue