* Some rework for TargetPointer handling.

This commit is contained in:
LevelX2 2017-07-26 17:21:03 +02:00
parent 0d24b8df14
commit 847c6981ca
9 changed files with 58 additions and 82 deletions

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards.d;
import java.util.UUID;
@ -47,7 +46,6 @@ import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author L_J
@ -55,7 +53,7 @@ import mage.target.targetpointer.FixedTarget;
public class DaruSpiritualist extends CardImpl {
public DaruSpiritualist(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}");
this.subtype.add("Human");
this.subtype.add("Cleric");
@ -104,12 +102,9 @@ class DaruSpiritualistTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
UUID targetId = event.getTargetId();
Permanent creature = game.getPermanent(event.getTargetId());
if (creature != null && filter.match(creature, getSourceId(), getControllerId(), game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
this.getEffects().setTargetPointer(new FixedTarget(creature, game));
return true;
}
return false;

View file

@ -74,21 +74,16 @@ public class AttackedByCreatureTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
UUID playerId = game.getCombat().getDefendingPlayerId(event.getSourceId(), game);
UUID defendingPlayer = game.getCombat().getDefendingPlayerId(event.getSourceId(), game);
Permanent attackingCreature = game.getPermanent(event.getSourceId());
if (getControllerId().equals(playerId) && attackingCreature != null) {
if (setTargetPointer != SetTargetPointer.NONE) {
for (Effect effect : this.getEffects()) {
switch (setTargetPointer) {
case PERMANENT:
effect.setTargetPointer(new FixedTarget(attackingCreature.getId()));
break;
case PLAYER:
effect.setTargetPointer(new FixedTarget(attackingCreature.getControllerId()));
break;
}
}
if (getControllerId().equals(defendingPlayer) && attackingCreature != null) {
switch (setTargetPointer) {
case PERMANENT:
this.getEffects().setTargetPointer(new FixedTarget(attackingCreature, game));
break;
case PLAYER:
this.getEffects().setTargetPointer(new FixedTarget(attackingCreature.getControllerId()));
break;
}
return true;
}

View file

@ -24,8 +24,7 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
@ -84,9 +83,7 @@ public class AttacksCreatureYouControlTriggeredAbility extends TriggeredAbilityI
Permanent sourcePermanent = game.getPermanent(event.getSourceId());
if (sourcePermanent != null && filter.match(sourcePermanent, sourceId, controllerId, game)) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}

View file

@ -71,9 +71,7 @@ public class BecomesBlockedAllTriggeredAbility extends TriggeredAbilityImpl {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}

View file

@ -68,9 +68,7 @@ public class BecomesBlockedByCreatureTriggeredAbility extends TriggeredAbilityIm
if (event.getTargetId().equals(this.getSourceId())) {
Permanent blocker = game.getPermanent(event.getSourceId());
if (filter.match(blocker, game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
this.getEffects().setTargetPointer(new FixedTarget(blocker, game));
return true;
}
}

View file

@ -8,7 +8,6 @@ package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -20,8 +19,6 @@ import mage.target.targetpointer.FixedTarget;
*/
public class BecomesMonstrousTriggeredAbility extends TriggeredAbilityImpl {
protected FilterCreaturePermanent filter = new FilterCreaturePermanent();
public BecomesMonstrousTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
@ -43,11 +40,9 @@ public class BecomesMonstrousTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (filter.match(permanent, sourceId, controllerId, game)
&& (permanent.getControllerId().equals(this.controllerId))) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
if (permanent != null && permanent.isCreature()
&& (permanent.getControllerId().equals(getControllerId()))) {
this.getEffects().setTargetPointer(new FixedTarget(permanent, game));
return true;
}
return false;
@ -55,6 +50,6 @@ public class BecomesMonstrousTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " becomes monstrous, " + super.getRule();
return "Whenever a creature you control becomes monstrous, " + super.getRule();
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
@ -38,14 +37,16 @@ import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl {
private TargetController targetController;
/**
* The Ability sets if no target is defined the target pointer to the active player of the current draw phase
*
* The Ability sets if no target is defined the target pointer to the active
* player of the current draw phase
*
* @param effect
* @param targetController
* @param isOptional
* @param isOptional
*/
public BeginningOfDrawTriggeredAbility(Effect effect, TargetController targetController, boolean isOptional) {
this(Zone.BATTLEFIELD, effect, targetController, isOptional);
@ -78,18 +79,14 @@ public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl {
boolean yours = event.getPlayerId().equals(this.controllerId);
if (yours) {
if (getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}
}
return yours;
case OPPONENT:
if (game.getPlayer(this.controllerId).hasOpponent(event.getPlayerId(), game)) {
if (getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}
@ -97,9 +94,7 @@ public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl {
case NOT_YOU:
if (!this.controllerId.equals(event.getPlayerId())) {
if (getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}
@ -110,9 +105,7 @@ public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl {
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
if (attachedTo != null && attachedTo.getControllerId().equals(event.getPlayerId())) {
if (getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}
@ -120,9 +113,7 @@ public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl {
break;
case ANY:
if (getTargets().isEmpty()) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
this.getEffects().setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}

View file

@ -24,8 +24,7 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.abilities.effects;
import java.util.ArrayList;
@ -34,6 +33,7 @@ import java.util.List;
import java.util.Set;
import mage.abilities.Mode;
import mage.constants.Outcome;
import mage.target.targetpointer.TargetPointer;
/**
*
@ -41,10 +41,11 @@ import mage.constants.Outcome;
*/
public class Effects extends ArrayList<Effect> {
public Effects() {}
public Effects() {
}
public Effects(final Effects effects) {
for (Effect effect: effects) {
for (Effect effect : effects) {
this.add(effect.copy());
}
}
@ -64,7 +65,7 @@ public class Effects extends ArrayList<Effect> {
public String getText(Mode mode) {
StringBuilder sbText = new StringBuilder();
String lastRule = null;
for (Effect effect: this) {
for (Effect effect : this) {
String endString = "";
String nextRule = effect.getText(mode);
if (nextRule != null) {
@ -72,7 +73,7 @@ public class Effects extends ArrayList<Effect> {
endString = " ";
} else if (nextRule.startsWith(",") || nextRule.startsWith(" ")) {
endString = "";
} else if (lastRule != null && lastRule.length()> 3) {
} else if (lastRule != null && lastRule.length() > 3) {
if (!lastRule.endsWith(".") && !lastRule.endsWith("<br>")) {
endString = ". ";
}
@ -84,19 +85,19 @@ public class Effects extends ArrayList<Effect> {
}
lastRule = nextRule;
}
if (lastRule != null && lastRule.length()> 3 &&
!lastRule.endsWith(".") &&
!lastRule.endsWith("\"") &&
!lastRule.startsWith("<b>Level ") &&
!lastRule.endsWith(".)") &&
!lastRule.endsWith("</i>") ) {
if (lastRule != null && lastRule.length() > 3
&& !lastRule.endsWith(".")
&& !lastRule.endsWith("\"")
&& !lastRule.startsWith("<b>Level ")
&& !lastRule.endsWith(".)")
&& !lastRule.endsWith("</i>")) {
sbText.append('.');
}
return sbText.toString();
}
public boolean hasOutcome(Outcome outcome) {
for (Effect effect: this) {
for (Effect effect : this) {
if (effect.getOutcome() == outcome) {
return true;
}
@ -106,7 +107,7 @@ public class Effects extends ArrayList<Effect> {
public List<Outcome> getOutcomes() {
Set<Outcome> outcomes = new HashSet<>();
for (Effect effect: this) {
for (Effect effect : this) {
outcomes.add(effect.getOutcome());
}
return new ArrayList<>(outcomes);
@ -114,11 +115,10 @@ public class Effects extends ArrayList<Effect> {
public int getOutcomeTotal() {
int total = 0;
for (Effect effect: this) {
for (Effect effect : this) {
if (effect.getOutcome().isGood()) {
total++;
}
else {
} else {
total--;
}
}
@ -126,8 +126,18 @@ public class Effects extends ArrayList<Effect> {
}
public void newId() {
for (Effect effect: this) {
for (Effect effect : this) {
effect.newId();
}
}
public void setTargetPointer(TargetPointer targetPointer) {
if (targetPointer == null) {
return;
}
for (Effect effect : this) {
effect.setTargetPointer(targetPointer.copy());
}
}
}

View file

@ -55,7 +55,6 @@ public class DarettiScrapSavantEmblem extends Emblem {
setName("Emblem Daretti");
this.setExpansionSetCodeForImage("C14");
this.getAbilities().add(new DarettiScrapSavantTriggeredAbility());
}
}
@ -87,9 +86,7 @@ class DarettiScrapSavantTriggeredAbility extends TriggeredAbilityImpl {
&& zEvent.getFromZone() == Zone.BATTLEFIELD
&& zEvent.getTarget().isArtifact()
&& zEvent.getTarget().getOwnerId().equals(this.controllerId)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(zEvent.getTargetId()));
}
this.getEffects().setTargetPointer(new FixedTarget(zEvent.getTargetId()));
return true;
}
return false;