* Expropriate - Fixed a strange problem that the prompt text of the select permanent selection to get the control of the permanent was not shown. Still not clear what the exact reason was but using a player list to save the voters seemed to cause the problem.

This commit is contained in:
LevelX2 2019-12-27 23:22:32 +01:00
parent 06ed2f5927
commit 1dc8f37d20
5 changed files with 64 additions and 29 deletions

View file

@ -1,5 +1,12 @@
package mage.remote; package mage.remote;
import java.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
@ -28,14 +35,6 @@ import org.jboss.remoting.transport.bisocket.Bisocket;
import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transport.socket.SocketWrapper;
import org.jboss.remoting.transporter.TransporterClient; import org.jboss.remoting.transporter.TransporterClient;
import javax.swing.*;
import java.io.*;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.*;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
/** /**
* @author BetaSteward_at_googlemail.com, JayDi85 * @author BetaSteward_at_googlemail.com, JayDi85
*/ */
@ -557,8 +556,21 @@ public class SessionImpl implements Session {
@Override @Override
public void handleCallback(Callback callback) throws HandleCallbackException { public void handleCallback(Callback callback) throws HandleCallbackException {
//logger.info("callback handler"); try {
// Object object = callback.getCallbackObject();
// if (((ClientCallback) object).getMethod().equals(ClientCallbackMethod.GAME_TARGET)) {
// Object data = ((ClientCallback) object).getData();
// if (data instanceof GameClientMessage) {
// GameClientMessage message = (GameClientMessage) ((ClientCallback) object).getData();
// logger.info("Client Session Event->" + ((ClientCallback) object).getMethod() + " (id:" + ((ClientCallback) object).getMessageId() + ") " + message.getMessage()
// );
// }
// }
client.processCallback((ClientCallback) callback.getCallbackObject()); client.processCallback((ClientCallback) callback.getCallbackObject());
} catch (Exception ex) {
logger.error("handleCallback error", ex);
}
} }
} }

View file

@ -1,4 +1,3 @@
package mage.server; package mage.server;
import java.util.*; import java.util.*;
@ -352,7 +351,16 @@ public class Session {
if (valid && callBackLock.tryLock(50, TimeUnit.MILLISECONDS)) { if (valid && callBackLock.tryLock(50, TimeUnit.MILLISECONDS)) {
call.setMessageId(messageId++); call.setMessageId(messageId++);
lockSet = true; lockSet = true;
callbackHandler.handleCallbackOneway(new Callback(call)); Callback callback = new Callback(call);
// if (call.getMethod().equals(ClientCallbackMethod.GAME_TARGET)) {
// Object object = call.getData();
// if (object instanceof GameClientMessage) {
// String message = ((GameClientMessage) object).getMessage();
// logger.info("Server Session Event->" + call.getMethod() + " (id:" + call.getMessageId() + ") " + message);
// logger.info(callback.toString());
// }
// }
callbackHandler.handleCallbackOneway(callback);
} }
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
logger.warn("SESSION LOCK - fireCallback - userId: " + userId + " messageId: " + call.getMessageId(), ex); logger.warn("SESSION LOCK - fireCallback - userId: " + userId + " messageId: " + call.getMessageId(), ex);
@ -364,6 +372,8 @@ public class Session {
logger.trace("Stack trace:", ex); logger.trace("Stack trace:", ex);
SessionManager.instance.disconnect(sessionId, LostConnection); SessionManager.instance.disconnect(sessionId, LostConnection);
}); });
} catch (Exception ex) {
logger.warn("Unspecific exception:", ex);
} finally { } finally {
if (lockSet) { if (lockSet) {
callBackLock.unlock(); callBackLock.unlock();

View file

@ -47,6 +47,8 @@ public final class Expropriate extends CardImpl {
class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect { class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
private ArrayList<UUID> choiceTwoVoters = new ArrayList<>();
public ExpropriateDilemmaEffect() { public ExpropriateDilemmaEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
this.staticText = "<i>Council's dilemma</i> — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it"; this.staticText = "<i>Council's dilemma</i> — Starting with you, each player votes for time or money. For each time vote, take an extra turn after this one. For each money vote, choose a permanent owned by the voter and gain control of it";
@ -56,10 +58,6 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
super(effect); super(effect);
} }
public ExpropriateDilemmaEffect(Outcome outcome) {
super(outcome);
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
@ -99,7 +97,7 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
private void controlForMoneyVote(Player controller, Game game, Ability source) { private void controlForMoneyVote(Player controller, Game game, Ability source) {
List<Permanent> chosenCards = new ArrayList<>(); List<Permanent> chosenCards = new ArrayList<>();
for (UUID playerId : choiceTwoVoters.keySet()) { for (UUID playerId : choiceTwoVoters) {
FilterPermanent filter = new FilterPermanent("permanent owned by " + game.getPlayer(playerId).getName()); FilterPermanent filter = new FilterPermanent("permanent owned by " + game.getPlayer(playerId).getName());
filter.add(new OwnerIdPredicate(playerId)); filter.add(new OwnerIdPredicate(playerId));
@ -125,6 +123,25 @@ class ExpropriateDilemmaEffect extends CouncilsDilemmaVoteEffect {
} }
} }
@Override
protected void vote(String choiceOne, String choiceTwo, Player controller, Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.chooseUse(Outcome.Vote,
"Choose " + choiceOne + " or " + choiceTwo + "?",
source.getRule(), choiceOne, choiceTwo, source, game)) {
voteOneCount++;
game.informPlayers(player.getName() + " has voted for " + choiceOne);
} else {
voteTwoCount++;
game.informPlayers(player.getName() + " has voted for " + choiceTwo);
choiceTwoVoters.add(player.getId());
}
}
}
}
@Override @Override
public ExpropriateDilemmaEffect copy() { public ExpropriateDilemmaEffect copy() {
return new ExpropriateDilemmaEffect(this); return new ExpropriateDilemmaEffect(this);
@ -154,8 +171,11 @@ class ExpropriateControlEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
return permanent != null if (permanent == null || controllerId == null) {
&& controllerId != null this.discard();
&& permanent.changeControllerId(controllerId, game); } else {
permanent.changeControllerId(controllerId, game);
}
return true;
} }
} }

View file

@ -6,7 +6,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.players.Players;
/** /**
* @author JRHerlehy * @author JRHerlehy
@ -14,8 +13,6 @@ import mage.players.Players;
public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect { public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect {
protected int voteOneCount = 0, voteTwoCount = 0; protected int voteOneCount = 0, voteTwoCount = 0;
protected final Players choiceOneVoters = new Players();
protected final Players choiceTwoVoters = new Players();
public CouncilsDilemmaVoteEffect(Outcome outcome) { public CouncilsDilemmaVoteEffect(Outcome outcome) {
super(outcome); super(outcome);
@ -33,11 +30,9 @@ public abstract class CouncilsDilemmaVoteEffect extends OneShotEffect {
"Choose " + choiceOne + " or " + choiceTwo + "?", "Choose " + choiceOne + " or " + choiceTwo + "?",
source.getRule(), choiceOne, choiceTwo, source, game)) { source.getRule(), choiceOne, choiceTwo, source, game)) {
voteOneCount++; voteOneCount++;
choiceOneVoters.addPlayer(player);
game.informPlayers(player.getName() + " has voted for " + choiceOne); game.informPlayers(player.getName() + " has voted for " + choiceOne);
} else { } else {
voteTwoCount++; voteTwoCount++;
choiceTwoVoters.addPlayer(player);
game.informPlayers(player.getName() + " has voted for " + choiceTwo); game.informPlayers(player.getName() + " has voted for " + choiceTwo);
} }
} }

View file

@ -1,5 +1,3 @@
package mage.game.events; package mage.game.events;
import java.io.Serializable; import java.io.Serializable;