Ability picker shows now the name of the object instead of {this] in ability text..

This commit is contained in:
LevelX2 2013-11-06 14:32:50 +01:00
parent e8a7a66b52
commit 33c6bf1385
9 changed files with 37 additions and 20 deletions

View file

@ -44,9 +44,13 @@ public class AbilityPickerView implements Serializable {
private Map<UUID, String> choices = new LinkedHashMap<UUID, String>();
public AbilityPickerView(List<? extends Ability> abilities) {
public AbilityPickerView(String objectName, List<? extends Ability> abilities) {
for (Ability ability: abilities) {
if (objectName == null) {
choices.put(ability.getId(), ability.getRule(true));
} else {
choices.put(ability.getId(), ability.getRule(objectName));
}
}
}

View file

@ -1243,7 +1243,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
if (object != null) {
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(object, game.getState().getZone(object.getId()), game);
if (useableAbilities != null && useableAbilities.size() > 0) {
game.fireGetChoiceEvent(playerId, name, new ArrayList<ActivatedAbility>(useableAbilities.values()));
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<ActivatedAbility>(useableAbilities.values()));
// TODO: Improve this
return (SpellAbility) useableAbilities.values().iterator().next();
}

View file

@ -452,7 +452,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
}
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getUseableActivatedAbilities(object, zone, game);
if (useableAbilities != null && useableAbilities.size() > 0) {
activateAbility(useableAbilities, game);
activateAbility(useableAbilities, object, game);
}
}
}
@ -539,7 +539,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
LinkedHashMap<UUID, ManaAbility> useableAbilities = getUseableManaAbilities(object, zone, game);
if (useableAbilities != null && useableAbilities.size() > 0) {
useableAbilities = ManaUtil.tryToAutoPay(unpaid, useableAbilities);
activateAbility(useableAbilities, game);
activateAbility(useableAbilities, object, game);
}
}
}
@ -741,7 +741,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
protected void specialAction(Game game) {
updateGameStatePriority("specialAction", game);
LinkedHashMap<UUID, SpecialAction> specialActions = game.getState().getSpecialActions().getControlledBy(playerId);
game.fireGetChoiceEvent(playerId, name, new ArrayList<SpecialAction>(specialActions.values()));
game.fireGetChoiceEvent(playerId, name, null, new ArrayList<SpecialAction>(specialActions.values()));
waitForResponse(game);
if (response.getUUID() != null) {
if (specialActions.containsKey(response.getUUID())) {
@ -750,7 +750,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
}
}
protected void activateAbility(LinkedHashMap<UUID, ? extends ActivatedAbility> abilities, Game game) {
protected void activateAbility(LinkedHashMap<UUID, ? extends ActivatedAbility> abilities, MageObject object, Game game) {
updateGameStatePriority("activateAbility", game);
if (abilities.size() == 1) {
ActivatedAbility ability = abilities.values().iterator().next();
@ -759,7 +759,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
return;
}
}
game.fireGetChoiceEvent(playerId, name, new ArrayList<ActivatedAbility>(abilities.values()));
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<ActivatedAbility>(abilities.values()));
waitForResponse(game);
if (response.getUUID() != null) {
if (abilities.containsKey(response.getUUID())) {
@ -779,7 +779,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
if (useableAbilities != null && useableAbilities.size() == 1) {
return (SpellAbility) useableAbilities.values().iterator().next();
} else if (useableAbilities != null && useableAbilities.size() > 0) {
game.fireGetChoiceEvent(playerId, name, new ArrayList<ActivatedAbility>(useableAbilities.values()));
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<ActivatedAbility>(useableAbilities.values()));
waitForResponse(game);
if (response.getUUID() != null) {
if (useableAbilities.containsKey(response.getUUID())) {

View file

@ -213,7 +213,11 @@ public class GameController implements GameCallback {
playXMana(event.getPlayerId(), event.getMessage());
break;
case CHOOSE_ABILITY:
chooseAbility(event.getPlayerId(), event.getAbilities());
String objectName = null;
if(event.getChoices() != null && event.getChoices().size() > 0) {
objectName = event.getChoices().iterator().next();
}
chooseAbility(event.getPlayerId(), objectName, event.getAbilities());
break;
case CHOOSE_PILE:
choosePile(event.getPlayerId(), event.getMessage(), event.getPile1(), event.getPile2());
@ -510,11 +514,11 @@ public class GameController implements GameCallback {
}
private synchronized void chooseAbility(UUID playerId, final List<? extends Ability> choices) throws MageException {
private synchronized void chooseAbility(UUID playerId, final String objectName, final List<? extends Ability> choices) throws MageException {
perform(playerId, new Command() {
@Override
public void execute(UUID playerId) {
getGameSession(playerId).chooseAbility(new AbilityPickerView(choices));
getGameSession(playerId).chooseAbility(new AbilityPickerView(objectName, choices));
}
});
}

View file

@ -140,7 +140,7 @@ public interface Game extends MageItem, Serializable {
void firePriorityEvent(UUID playerId);
void firePlayManaEvent(UUID playerId, String message);
void firePlayXManaEvent(UUID playerId, String message);
void fireGetChoiceEvent(UUID playerId, String message, List<? extends ActivatedAbility> choices);
void fireGetChoiceEvent(UUID playerId, String message, MageObject object, List<? extends ActivatedAbility> choices);
void fireGetModeEvent(UUID playerId, String message, Map<UUID, String> modes);
void fireGetAmountEvent(UUID playerId, String message, int min, int max);
void fireChoosePileEvent(UUID playerId, String message, List<? extends Card> pile1, List<? extends Card> pile2);

View file

@ -1506,11 +1506,15 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
}
@Override
public void fireGetChoiceEvent(UUID playerId, String message, List<? extends ActivatedAbility> choices) {
public void fireGetChoiceEvent(UUID playerId, String message, MageObject object, List<? extends ActivatedAbility> choices) {
if (simulation) {
return;
}
playerQueryEventSource.chooseAbility(playerId, message, choices);
String objectName = null;
if (object != null) {
objectName = object.getName();
}
playerQueryEventSource.chooseAbility(playerId, message, objectName, choices);
}
@Override

View file

@ -30,6 +30,7 @@ package mage.game.events;
import java.io.Serializable;
import java.util.EventObject;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -142,8 +143,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false);
}
public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, List<? extends ActivatedAbility> choices) {
return new PlayerQueryEvent(playerId, message, choices, null, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false);
public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, String objectName, List<? extends ActivatedAbility> choices) {
Set<String> nameAsSet = null;
if (objectName != null) {
nameAsSet = new HashSet<String>();
nameAsSet.add(objectName);
}
return new PlayerQueryEvent(playerId, message, choices, nameAsSet, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false);
}
public static PlayerQueryEvent choosePileEvent(UUID playerId, String message, List<? extends Card> pile1, List<? extends Card> pile2) {

View file

@ -58,8 +58,8 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
dispatcher.fireEvent(PlayerQueryEvent.selectEvent(playerId, message));
}
public void chooseAbility(UUID playerId, String message, List<? extends ActivatedAbility> choices) {
dispatcher.fireEvent(PlayerQueryEvent.chooseAbilityEvent(playerId, message, choices));
public void chooseAbility(UUID playerId, String message, String objectName, List<? extends ActivatedAbility> choices) {
dispatcher.fireEvent(PlayerQueryEvent.chooseAbilityEvent(playerId, message, objectName, choices));
}
public void choosePile(UUID playerId, String message, List<? extends Card> pile1, List<? extends Card> pile2) {

View file

@ -914,7 +914,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<UUID, ActivatedAbility>();
if (!(object instanceof Permanent) || ((Permanent)object).canUseActivatedAbilities(game)) {
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(zone)) {
if (ability.canActivate(playerId, game)) {
useable.put(ability.getId(), ability);
}