* Crew ability - added selected and needed power info while choosing, colorozing;

This commit is contained in:
Oleg Agafonov 2019-03-10 15:33:04 +04:00
parent b45864070c
commit 83afca8bda
2 changed files with 27 additions and 3 deletions

View file

@ -29,7 +29,7 @@ public class HintUtils {
// text // text
if (text != null && color != null) { if (text != null && color != null) {
String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getGreen()); String hex = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
res = String.format("<font color=%s>%s</font>", hex, text); res = String.format("<font color=%s>%s</font>", hex, text);
} else { } else {
res = text; res = text;

View file

@ -1,12 +1,12 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl; import mage.abilities.costs.CostImpl;
import mage.abilities.effects.common.continuous.AddCardTypeSourceEffect; import mage.abilities.effects.common.continuous.AddCardTypeSourceEffect;
import mage.abilities.hint.HintUtils;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
@ -20,6 +20,10 @@ import mage.game.permanent.Permanent;
import mage.target.Target; import mage.target.Target;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
import java.awt.*;
import java.util.Objects;
import java.util.UUID;
/** /**
* @author emerald000 * @author emerald000
*/ */
@ -70,7 +74,24 @@ class CrewCost extends CostImpl {
@Override @Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true); Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filter, true) {
@Override
public String getMessage() {
// shows selected power
int selectedPower = this.targets.entrySet().stream()
.map(entry -> (game.getPermanent(entry.getKey())))
.filter(Objects::nonNull)
.mapToInt(p -> (p.getPower().getValue()))
.sum();
String extraInfo = "(selected power " + selectedPower + " of " + value + ")";
if (selectedPower >= value) {
extraInfo = HintUtils.prepareText(extraInfo, Color.GREEN);
}
return super.getMessage() + " " + extraInfo;
}
};
// can cancel
if (target.choose(Outcome.Tap, controllerId, sourceId, game)) { if (target.choose(Outcome.Tap, controllerId, sourceId, game)) {
int sumPower = 0; int sumPower = 0;
for (UUID targetId : target.getTargets()) { for (UUID targetId : target.getTargets()) {
@ -88,7 +109,10 @@ class CrewCost extends CostImpl {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREWED_VEHICLE, targetId, sourceId, controllerId)); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREWED_VEHICLE, targetId, sourceId, controllerId));
} }
} }
} else {
return false;
} }
return paid; return paid;
} }