checkstyle

This commit is contained in:
jendave
2012-01-03 17:42:47 +00:00
parent 30f1b373f3
commit 449ee4a476
10 changed files with 243 additions and 65 deletions

View File

@@ -455,6 +455,11 @@ public final class AllZone {
return Singletons.getModel().getGameState().getTriggerHandler();
}
/**
* Gets the replacement handler.
*
* @return the replacement handler
*/
public static ReplacementHandler getReplacementHandler() {
return Singletons.getModel().getGameState().getReplacementHandler();
}

View File

@@ -453,7 +453,7 @@ public class Card extends GameEntity implements Comparable<Card> {
// hacky code below, used to limit the number of times an ability
// can be used per turn like Vampire Bats
// should be put in SpellAbility, but it is put here for conveniance
// should be put in SpellAbility, but it is put here for convenience
// this is make public just to make things easy
// this code presumes that each card only has one ability that can be
// used a limited number of times per turn
@@ -2569,8 +2569,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
//Replacement effects
for (final ReplacementEffect RE : this.getCharacteristics().getReplacementEffects()) {
sb.append(RE.toString() + "\r\n");
for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) {
sb.append(replacementEffect.toString() + "\r\n");
}
// static abilities
@@ -2619,7 +2619,7 @@ public class Card extends GameEntity implements Comparable<Card> {
sb.insert(sb.indexOf(".) ") + 3, "\r\n");
}
// replace tripple line feeds with double line feeds
// replace triple line feeds with double line feeds
int start;
final String s = "\r\n\r\n\r\n";
while (sb.toString().contains(s)) {
@@ -2670,8 +2670,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
//Replacement effects
for (final ReplacementEffect RE : this.getCharacteristics().getReplacementEffects()) {
sb.append(RE.toString() + "\r\n");
for (final ReplacementEffect replacementEffect : this.getCharacteristics().getReplacementEffects()) {
sb.append(replacementEffect.toString() + "\r\n");
}
// static abilities
@@ -8673,21 +8673,36 @@ public class Card extends GameEntity implements Comparable<Card> {
return true;
}
/**
* Gets the replacement effects.
*
* @return the replacement effects
*/
public ArrayList<ReplacementEffect> getReplacementEffects() {
return this.getCharacteristics().getReplacementEffects();
}
/**
* Sets the replacement effects.
*
* @param res the new replacement effects
*/
public void setReplacementEffects(ArrayList<ReplacementEffect> res) {
this.getCharacteristics().getReplacementEffects().clear();
for (ReplacementEffect RE : res) {
addReplacementEffect(RE);
for (ReplacementEffect replacementEffect : res) {
addReplacementEffect(replacementEffect);
}
}
public void addReplacementEffect(ReplacementEffect RE) {
ReplacementEffect RECopy = RE.getCopy();
RECopy.setHostCard(this);
this.getCharacteristics().getReplacementEffects().add(RECopy);
/**
* Adds the replacement effect.
*
* @param replacementEffect the rE
*/
public void addReplacementEffect(ReplacementEffect replacementEffect) {
ReplacementEffect replacementEffectCopy = replacementEffect.getCopy();
replacementEffectCopy.setHostCard(this);
this.getCharacteristics().getReplacementEffects().add(replacementEffectCopy);
}
} // end Card class

View File

@@ -1,3 +1,20 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.replacement;
import java.util.HashMap;
@@ -15,8 +32,9 @@ public class ReplaceDamage extends ReplacementEffect {
/**
* TODO: Write javadoc for Constructor.
* @param map
* @param host
*
* @param map the map
* @param host the host
*/
public ReplaceDamage(HashMap<String, String> map, Card host) {
super(map, host);
@@ -30,33 +48,33 @@ public class ReplaceDamage extends ReplacementEffect {
if (!runParams.get("Event").equals("DamageDone")) {
return false;
}
if (mapParams.containsKey("ValidSource")) {
if (!AllZoneUtil.matchesValid(runParams.get("DamageSource"), mapParams.get("ValidSource").split(","), hostCard)) {
if (getMapParams().containsKey("ValidSource")) {
if (!AllZoneUtil.matchesValid(runParams.get("DamageSource"), getMapParams().get("ValidSource").split(","), getHostCard())) {
return false;
}
}
if (mapParams.containsKey("ValidTarget")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), mapParams.get("ValidTarget").split(","), hostCard)) {
if (getMapParams().containsKey("ValidTarget")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), getMapParams().get("ValidTarget").split(","), getHostCard())) {
return false;
}
}
if (mapParams.containsKey("DamageAmount")) {
String full = mapParams.get("DamageAmount");
if (getMapParams().containsKey("DamageAmount")) {
String full = getMapParams().get("DamageAmount");
String operator = full.substring(0, 2);
String operand = full.substring(2);
int intoperand = 0;
try {
intoperand = Integer.parseInt(operand);
} catch (NumberFormatException e) {
intoperand = CardFactoryUtil.xCount(hostCard, hostCard.getSVar(operand));
intoperand = CardFactoryUtil.xCount(getHostCard(), getHostCard().getSVar(operand));
}
if (!AllZoneUtil.compare((Integer) runParams.get("DamageAmount"), operator, intoperand)) {
return false;
}
}
if (mapParams.containsKey("IsCombat")) {
if (mapParams.get("IsCombat").equals("True")) {
if (getMapParams().containsKey("IsCombat")) {
if (getMapParams().get("IsCombat").equals("True")) {
if (!((Boolean) runParams.get("IsCombat"))) {
return false;
}
@@ -76,7 +94,7 @@ public class ReplaceDamage extends ReplacementEffect {
*/
@Override
public ReplacementEffect getCopy() {
return new ReplaceDamage(this.mapParams, this.hostCard);
return new ReplaceDamage(this.getMapParams(), this.getHostCard());
}
/* (non-Javadoc)

View File

@@ -1,3 +1,20 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.replacement;
import java.util.HashMap;
@@ -11,6 +28,12 @@ import forge.Card;
*/
public class ReplaceDraw extends ReplacementEffect {
/**
* Instantiates a new replace draw.
*
* @param params the params
* @param host the host
*/
public ReplaceDraw(final HashMap<String, String> params, final Card host) {
super(params, host);
}
@@ -32,9 +55,12 @@ public class ReplaceDraw extends ReplacementEffect {
return true;
}
/* (non-Javadoc)
* @see forge.card.replacement.ReplacementEffect#getCopy()
*/
@Override
public ReplacementEffect getCopy() {
return new ReplaceDraw(this.getMapParams(), hostCard);
return new ReplaceDraw(this.getMapParams(), getHostCard());
}
}

View File

@@ -1,3 +1,20 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.replacement;
import java.util.HashMap;
@@ -12,6 +29,12 @@ import forge.card.spellability.SpellAbility;
*/
public class ReplaceGainLife extends ReplacementEffect {
/**
* Instantiates a new replace gain life.
*
* @param map the map
* @param host the host
*/
public ReplaceGainLife(HashMap<String, String> map, Card host) {
super(map, host);
}
@@ -38,7 +61,7 @@ public class ReplaceGainLife extends ReplacementEffect {
*/
@Override
public ReplacementEffect getCopy() {
return new ReplaceGainLife(this.getMapParams(), hostCard);
return new ReplaceGainLife(this.getMapParams(), getHostCard());
}
/* (non-Javadoc)

View File

@@ -1,3 +1,20 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.replacement;
import java.util.HashMap;
@@ -6,7 +23,6 @@ import forge.AllZoneUtil;
import forge.Card;
import forge.CardList;
import forge.CardUtil;
import forge.Player;
import forge.Constant.Zone;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.cardfactory.CardFactoryUtil;
@@ -17,9 +33,13 @@ import forge.card.spellability.SpellAbility;
*
*/
public abstract class ReplacementEffect {
protected boolean hasRun = false;
/** The has run. */
private boolean hasRun = false;
/**
* Checks for run.
*
* @return the hasRun
*/
public final boolean hasRun() {
@@ -27,14 +47,16 @@ public abstract class ReplacementEffect {
}
/**
* @param hasRun0 the hasRun to set
* Sets the checks for run.
*
* @param hasRun the hasRun to set
*/
public final void setHasRun(boolean hasRun0) {
this.hasRun = hasRun0;
public final void setHasRun(boolean hasRun) {
this.hasRun = hasRun;
}
/** The map params, denoting what to replace. */
protected HashMap<String, String> mapParams = new HashMap<String, String>();
private HashMap<String, String> mapParams = new HashMap<String, String>();
/**
* <p>
@@ -50,15 +72,15 @@ public abstract class ReplacementEffect {
/**
* Sets the map params.
*
* @param mapParams0
* @param mapParams
* the mapParams to set
*/
public final void setMapParams(final HashMap<String, String> mapParams0) {
this.mapParams = mapParams0;
public final void setMapParams(final HashMap<String, String> mapParams) {
this.mapParams = mapParams;
}
/** The host card. */
protected Card hostCard;
private Card hostCard;
/**
* <p>
@@ -83,11 +105,20 @@ public abstract class ReplacementEffect {
this.hostCard = c;
}
/**
* Can replace.
*
* @param runParams the run params
* @return true, if successful
*/
public abstract boolean canReplace(final HashMap<String, Object> runParams);
/**
* @return a String
*/
public String toString() {
if (mapParams.containsKey("Description")) {
return mapParams.get("Description");
if (getMapParams().containsKey("Description")) {
return getMapParams().get("Description");
}
else {
return "";
@@ -289,14 +320,31 @@ public abstract class ReplacementEffect {
return true;
}
/**
* Gets the copy.
*
* @return the copy
*/
public abstract ReplacementEffect getCopy();
public void setReplacingObjects(HashMap<String, Object> runParams, SpellAbility sa) {
//Should be overriden by replacers that need it.
/**
* Sets the replacing objects.
*
* @param runParams the run params
* @param spellAbility the SpellAbility
*/
public void setReplacingObjects(HashMap<String, Object> runParams, SpellAbility spellAbility) {
//Should be overridden by replacers that need it.
}
/**
* Instantiates a new replacement effect.
*
* @param map the map
* @param host the host
*/
public ReplacementEffect(final HashMap<String, String> map, final Card host) {
this.mapParams = map;
this.hostCard = host;
this.setMapParams(map);
this.setHostCard(host);
}
}

View File

@@ -1,9 +1,25 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.replacement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import forge.AllZone;
import forge.Card;
@@ -35,7 +51,7 @@ public class ReplacementHandler {
Player decider = null;
//Figure out who decides which of multiple replacements to apply
//as well as wether or not to apply optional replacements.
//as well as whether or not to apply optional replacements.
if (affected instanceof Player) {
decider = (Player) affected;
} else {
@@ -43,19 +59,19 @@ public class ReplacementHandler {
}
//Round up Non-static replacement effects ("Until EOT," or "The next time you would..." etc)
for (ReplacementEffect RE : tmpEffects) {
if (!RE.hasRun() && RE.canReplace(runParams)) {
possibleReplacers.add(RE);
for (ReplacementEffect replacementEffect : tmpEffects) {
if (!replacementEffect.hasRun() && replacementEffect.canReplace(runParams)) {
possibleReplacers.add(replacementEffect);
}
}
//Round up Static replacement effects
for (Player p : AllZone.getPlayersInGame()) {
for (Card crd : p.getCardsIn(Zone.Battlefield)) {
for (ReplacementEffect RE : crd.getReplacementEffects()) {
if (RE.requirementsCheck()) {
if (!RE.hasRun() && RE.canReplace(runParams)) {
possibleReplacers.add(RE);
for (ReplacementEffect replacementEffect : crd.getReplacementEffects()) {
if (replacementEffect.requirementsCheck()) {
if (!replacementEffect.hasRun() && replacementEffect.canReplace(runParams)) {
possibleReplacers.add(replacementEffect);
}
}
}
@@ -94,7 +110,7 @@ public class ReplacementHandler {
return false;
}
} else {
//AI-logic for deciding wether or not to apply the optional replacement effect happens here.
//AI-logic for deciding whether or not to apply the optional replacement effect happens here.
}
}
executeReplacement(runParams, chosenRE);
@@ -108,37 +124,37 @@ public class ReplacementHandler {
/**
*
* Runs a single replacement effect.
* @param RE the replacment effect to run
* @param replacementEffect the replacement effect to run
*/
private void executeReplacement(HashMap<String, Object> runParams, ReplacementEffect RE) {
private void executeReplacement(HashMap<String, Object> runParams, ReplacementEffect replacementEffect) {
HashMap<String, String> mapParams = RE.getMapParams();
RE.setHasRun(true);
HashMap<String, String> mapParams = replacementEffect.getMapParams();
replacementEffect.setHasRun(true);
if (mapParams.containsKey("Prevent")) {
if (mapParams.get("Prevent").equals("True")) {
RE.setHasRun(false);
replacementEffect.setHasRun(false);
return; //Nothing should replace the event.
}
}
String effectSVar = mapParams.get("ReplaceWith");
String effectAbString = RE.getHostCard().getSVar(effectSVar);
String effectAbString = replacementEffect.getHostCard().getSVar(effectSVar);
AbilityFactory AF = new AbilityFactory();
AbilityFactory abilityFactory = new AbilityFactory();
SpellAbility effectSA = AF.getAbility(effectAbString, RE.getHostCard());
SpellAbility effectSA = abilityFactory.getAbility(effectAbString, replacementEffect.getHostCard());
RE.setReplacingObjects(runParams, effectSA);
replacementEffect.setReplacingObjects(runParams, effectSA);
if (RE.getHostCard().getController().isHuman()) {
if (replacementEffect.getHostCard().getController().isHuman()) {
AllZone.getGameAction().playSpellAbilityNoStack(effectSA, false);
}
else {
ComputerUtil.playNoStack(effectSA);
}
RE.setHasRun(false);
replacementEffect.setHasRun(false);
}
/**

View File

@@ -964,23 +964,51 @@ public abstract class SpellAbility {
this.triggeringObjects = new HashMap<String, Object>();
}
/**
* Gets the replacing objects.
*
* @return the replacing objects
*/
public HashMap<String, Object> getReplacingObjects() {
return this.replacingObjects;
}
/**
* Sets the all replacing objects.
*
* @param replacedObjects the replaced objects
*/
public void setAllReplacingObjects(final HashMap<String, Object> replacedObjects) {
this.replacingObjects = replacedObjects;
}
/**
* Sets the replacing object.
*
* @param type the type
* @param o the o
*/
public void setReplacingObject(final String type, final Object o) {
this.replacingObjects.put(type, o);
}
/**
* Gets the replacing object.
*
* @param type the type
* @return the replacing object
*/
public Object getReplacingObject(final String type) {
Object res = this.replacingObjects.get(type);
return res;
}
/**
* Checks for replacing object.
*
* @param type the type
* @return true, if successful
*/
public boolean hasReplacingObject(final String type) {
return this.replacingObjects.containsKey(type);
}

View File

@@ -28,7 +28,6 @@ import forge.Card;
import forge.CardList;
import forge.CardUtil;
import forge.Constant.Zone;
import forge.Player;
import forge.PlayerZone;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.cardfactory.CardFactoryUtil;