Permalink
Browse files

ElementalMutipleEffectCharms don't reference the character.

Fixes part of #236.
  • Loading branch information...
UrsKR committed Jun 17, 2012
1 parent 1e4a183 commit 6811d7efdb6fc53112a8b6d30f359b26784e8aa6
@@ -5,7 +5,6 @@
import net.sf.anathema.character.generic.magic.charms.special.ISubeffect;
import net.sf.anathema.character.generic.magic.charms.special.SubEffects;
-import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -3,18 +3,21 @@
import net.sf.anathema.character.generic.IBasicCharacterData;
import net.sf.anathema.character.generic.magic.ICharm;
import net.sf.anathema.character.generic.magic.charms.ICharmLearnableArbitrator;
+import net.sf.anathema.character.generic.magic.charms.special.ISubeffect;
+import net.sf.anathema.character.generic.magic.charms.special.SubEffects;
import net.sf.anathema.character.generic.type.CharacterType;
import net.sf.anathema.lib.gui.wizard.workflow.ICondition;
public class ElementalCharmLearnCondition implements ICondition {
+ private final SubEffects allEffects;
private final ICharmLearnableArbitrator arbitrator;
private final ICharm charm;
private final IBasicCharacterData data;
- private final ElementalMultipleEffectCharm multiEffectCharm;
private final Element element;
- public ElementalCharmLearnCondition(ElementalMultipleEffectCharm multiEffectCharm, ICharmLearnableArbitrator arbitrator, ICharm charm, IBasicCharacterData data, Element element) {
- this.multiEffectCharm = multiEffectCharm;
+ public ElementalCharmLearnCondition(SubEffects allEffects, ICharmLearnableArbitrator arbitrator,
+ ICharm charm, IBasicCharacterData data, Element element) {
+ this.allEffects = allEffects;
this.arbitrator = arbitrator;
this.charm = charm;
this.data = data;
@@ -28,17 +31,16 @@ public boolean isFulfilled() {
return learnable;
}
if (data.getCasteType().getId() == null) {
- return false;
+ return false;
}
if (element.matches(data.getCasteType())) {
return learnable;
}
- if (multiEffectCharm != null) {
- for (ElementalSubeffect effect : multiEffectCharm.getSessionSubeffects(data)) {
- if (effect.isLearned() && effect.matches(data.getCasteType())) {
- return learnable;
- }
- }
+ for (ISubeffect effect : allEffects) {
+ ElementalSubeffect elemental = (ElementalSubeffect) effect;
+ if (effect.isLearned() && elemental.matches(data.getCasteType())) {
+ return learnable;
+ }
}
return false;
}
@@ -1,10 +1,5 @@
package net.sf.anathema.character.generic.impl.magic.charm.special;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import net.sf.anathema.character.generic.IBasicCharacterData;
import net.sf.anathema.character.generic.character.IGenericTraitCollection;
import net.sf.anathema.character.generic.magic.ICharm;
@@ -16,8 +11,6 @@
public class ElementalMultipleEffectCharm implements IMultipleEffectCharm {
- private final Map<IBasicCharacterData, ElementalSubeffect[]> sessionSubeffects =
- new HashMap<IBasicCharacterData, ElementalSubeffect[]>();
private final String charmId;
public ElementalMultipleEffectCharm(String charmId) {
@@ -37,20 +30,17 @@ public String getCharmId() {
@Override
public SubEffects buildSubeffects(IBasicCharacterData data, IGenericTraitCollection traitCollection,
ICharmLearnableArbitrator arbitrator, ICharm charm) {
- List<ElementalSubeffect> effectList = new ArrayList<ElementalSubeffect>();
+ CollectionSubEffects subEffects = new CollectionSubEffects();
for (Element element : Element.values()) {
- effectList.add(new ElementalSubeffect(element, data, buildLearnCondition(element, data, arbitrator, charm)));
+ ICondition condition = buildLearnCondition(element, data, arbitrator, charm, subEffects);
+ subEffects.add(new ElementalSubeffect(element, data, condition));
}
- ElementalSubeffect[] list = effectList.toArray(new ElementalSubeffect[effectList.size()]);
- sessionSubeffects.put(data, list);
- return new ArraySubEffects(list);
- }
-
- public ElementalSubeffect[] getSessionSubeffects(IBasicCharacterData data) {
- return sessionSubeffects.get(data);
+ return subEffects;
}
- private ICondition buildLearnCondition(Element element, IBasicCharacterData data, ICharmLearnableArbitrator arbitrator, ICharm charm) {
- return new ElementalCharmLearnCondition(this, arbitrator, charm, data, element);
+ private ICondition buildLearnCondition(Element element, IBasicCharacterData data,
+ ICharmLearnableArbitrator arbitrator, ICharm charm,
+ CollectionSubEffects subEffects) {
+ return new ElementalCharmLearnCondition(subEffects, arbitrator, charm, data, element);
}
}
@@ -28,7 +28,7 @@ public boolean isFulfilled() {
if (prereqEffect == null) {
return true;
}
- for (ISubeffect effect : allEffects.getEffects()) {
+ for (ISubeffect effect : allEffects) {
if (effect.getId().equals(prereqEffect) && effect.isLearned()) {
return true;
}
@@ -5,7 +5,7 @@
public class UpgradableSubEffects extends CollectionSubEffects {
public int getUpgradeBPCost() {
int total = 0;
- for (ISubeffect subeffect : getEffects()) {
+ for (ISubeffect subeffect : this) {
Upgrade upgrade = (Upgrade) subeffect;
total += subeffect.isCreationLearned() ? upgrade.getBPCost() : 0;
}
@@ -14,7 +14,7 @@ public int getUpgradeBPCost() {
public int getUpgradeXPCost() {
int total = 0;
- for (ISubeffect subeffect : getEffects()) {
+ for (ISubeffect subeffect : this) {
Upgrade upgrade = (Upgrade) subeffect;
total += subeffect.isLearned() && !subeffect.isCreationLearned() ? upgrade.getXPCost() : 0;
}
@@ -24,7 +24,7 @@
private Element element = Air;
private List<ElementalSubeffect> effects = new ArrayList<ElementalSubeffect>();
private DummyBasicCharacterData character = new DummyBasicCharacterData();
- private ElementalCharmLearnCondition condition = new ElementalCharmLearnCondition(null, arbitrator, charm, character, element);
+ private ElementalCharmLearnCondition condition = new ElementalCharmLearnCondition(new CollectionSubEffects(), arbitrator, charm, character, element);
@Before
public void markCharmLearnable() throws Exception {

0 comments on commit 6811d7e

Please sign in to comment.