refactored targets

This commit is contained in:
BetaSteward 2011-09-14 12:46:47 -04:00
parent 37cec55493
commit 5c01b832b9
16 changed files with 46 additions and 48 deletions

View file

@ -86,12 +86,12 @@ class FireballEffect extends OneShotEffect<FireballEffect> {
@Override
public boolean apply(Game game, Ability source) {
int numTargets = source.getTargets().get(0).getTargets().size();
int numTargets = targetPointer.getTargets(source).size();
int damage = source.getManaCostsToPay().getX();
if (numTargets > 0) {
int damagePer = damage/numTargets;
if (damagePer > 0) {
for (UUID targetId: source.getTargets().get(0).getTargets()) {
for (UUID targetId: targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.damage(damagePer, source.getSourceId(), game, true, false);

View file

@ -88,13 +88,10 @@ class MorbidPlunderEffect extends OneShotEffect<MorbidPlunderEffect> {
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
List<UUID> targets = source.getTargets().get(0).getTargets();
if (targets.size() > 0) {
for (UUID target : targets) {
Card card = game.getCard(target);
if (card != null) {
result |= card.moveToZone(Zone.HAND, source.getId(), game, true);
}
for (UUID target : targetPointer.getTargets(source)) {
Card card = game.getCard(target);
if (card != null) {
result |= card.moveToZone(Zone.HAND, source.getId(), game, true);
}
}
return result;

View file

@ -95,7 +95,7 @@ class ArcTrailEffect extends OneShotEffect {
boolean twoDamageDone = false;
int damage = 2;
for ( UUID target : source.getTargets().get(0).getTargets() ) {
for ( UUID target : targetPointer.getTargets(source) ) {
Permanent permanent = game.getPermanent(target);
if ( twoDamageDone ) {

View file

@ -83,7 +83,7 @@ class FulgentDistractionEffect extends OneShotEffect<FulgentDistractionEffect> {
@Override
public boolean apply(Game game, Ability source) {
for ( UUID target : source.getTargets().get(0).getTargets() ) {
for ( UUID target : targetPointer.getTargets(source) ) {
Permanent creature = game.getPermanent(target);
List<UUID> copiedAttachments = new ArrayList<UUID>(creature.getAttachments());

View file

@ -174,7 +174,7 @@ class LiegeOfTheTangleEffect extends ContinuousEffectImpl<LiegeOfTheTangleEffect
public void init(Ability source, Game game) {
super.init(source, game);
if (this.affectedObjectsSet) {
for (UUID permId: source.getTargets().get(0).getTargets()) {
for (UUID permId: targetPointer.getTargets(source)) {
objects.add(permId);
}
}

View file

@ -97,7 +97,7 @@ class RustTickTapTargetEffect extends TapTargetEffect {
public boolean apply(Game game, Ability source) {
Permanent rustTick = game.getPermanent(source.getSourceId());
if (rustTick != null) rustTick.clearConnectedCards();
for (UUID target : source.getTargets().get(0).getTargets()) {
for (UUID target : targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
rustTick.addConnectedCard(permanent.getId());

View file

@ -101,7 +101,7 @@ class KhalniGemReturnToHandTargetEffect extends OneShotEffect<KhalniGemReturnToH
@Override
public boolean apply(Game game, Ability source) {
for ( UUID target : source.getTargets().get(0).getTargets() ) {
for ( UUID target : targetPointer.getTargets(source) ) {
Permanent permanent = game.getPermanent(target);
if ( permanent != null ) {
permanent.moveToZone(Zone.HAND, source.getId(), game, true);

View file

@ -67,19 +67,21 @@ public class DamageMultiEffect extends OneShotEffect<DamageMultiEffect> {
@Override
public boolean apply(Game game, Ability source) {
Target multiTarget = source.getTargets().get(0);
for (UUID target: multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.damage(multiTarget.getTargetAmount(target), source.getId(), game, true, false);
}
else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getId(), game, false, true);
}
}
}
if (source.getTargets().size() > 0) {
Target multiTarget = source.getTargets().get(0);
for (UUID target: multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.damage(multiTarget.getTargetAmount(target), source.getId(), game, true, false);
}
else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(multiTarget.getTargetAmount(target), source.getId(), game, false, true);
}
}
}
}
return true;
}

View file

@ -61,7 +61,7 @@ public class GainLifeTargetEffect extends OneShotEffect<GainLifeTargetEffect> {
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId: source.getTargets().get(0).getTargets()) {
for (UUID playerId: targetPointer.getTargets(source)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.gainLife(life, game);

View file

@ -59,7 +59,7 @@ public class SacrificeTargetEffect extends OneShotEffect<SacrificeTargetEffect>
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
for (UUID permanentId : targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.sacrifice(source.getSourceId(), game);

View file

@ -74,7 +74,7 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (source.getTargets().get(0).getTargets().size() < 2) {
if (targetPointer.getTargets(source).size() < 2) {
used = true;
} else {
count++;
@ -82,7 +82,7 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
// not clear how to turn off the effect for more than one target
// especially as some targets may leave the battlefield since the effect creation
// so handling this in applies method is the only option for now for such cases
if (count == source.getTargets().get(0).getTargets().size()) {
if (count == targetPointer.getTargets(source).size()) {
// this won't work for targets disappeared before applies() return true
used = true;
}
@ -91,18 +91,16 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP &&
event.getType() == EventType.UNTAP) {
for (UUID target : source.getTargets().get(0).getTargets()) {
if (event.getTargetId().equals(target)) {
if (!usedFor.contains(target)) {
usedFor.add(target);
return true;
}
break;
}
}
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == EventType.UNTAP) {
for (UUID target : targetPointer.getTargets(source)) {
if (event.getTargetId().equals(target)) {
if (!usedFor.contains(target)) {
usedFor.add(target);
return true;
}
break;
}
}
return false;
}

View file

@ -58,7 +58,7 @@ public class TapTargetEffect extends OneShotEffect<TapTargetEffect> {
@Override
public boolean apply(Game game, Ability source) {
for (UUID target: source.getTargets().get(0).getTargets()) {
for (UUID target: targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.tap(game);

View file

@ -74,7 +74,7 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
for (UUID permanentId : targetPointer.getTargets(source)) {
Permanent target = (Permanent) game.getPermanent(permanentId);
if (target != null) {
target.addPower(power.calculate(game, source));

View file

@ -67,7 +67,7 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
for (UUID permanentId : targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.addAbility(ability);

View file

@ -62,7 +62,7 @@ public class LoseAllAbilitiesTargetEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
for (UUID permanentId : source.getTargets().get(0).getTargets()) {
for (UUID permanentId : targetPointer.getTargets(source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
permanent.getAbilities().clear();

View file

@ -16,7 +16,8 @@ public class FirstTargetPointer implements TargetPointer {
@Override
public List<UUID> getTargets(Ability source) {
ArrayList<UUID> target = new ArrayList<UUID>();
target.addAll(source.getTargets().get(0).getTargets());
if (source.getTargets().size() > 0)
target.addAll(source.getTargets().get(0).getTargets());
return target;
}