More refactoring
This commit is contained in:
@@ -414,9 +414,11 @@ public class BuiltLotroCardBlueprint implements LotroCardBlueprint {
|
||||
if (twilightCostModifiers == null)
|
||||
return 0;
|
||||
|
||||
DefaultActionContext actionContext = new DefaultActionContext(self.getOwner(), game, self, null, null);
|
||||
|
||||
int result = 0;
|
||||
for (TwilightCostModifierSource twilightCostModifier : twilightCostModifiers)
|
||||
result += twilightCostModifier.getTwilightCostModifier(game, self);
|
||||
result += twilightCostModifier.getTwilightCostModifier(actionContext);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -546,9 +548,11 @@ public class BuiltLotroCardBlueprint implements LotroCardBlueprint {
|
||||
if (extraPlayCosts == null)
|
||||
return null;
|
||||
|
||||
DefaultActionContext actionContext = new DefaultActionContext(self.getOwner(), game, self, null, null);
|
||||
|
||||
List<ExtraPlayCost> result = new LinkedList<>();
|
||||
for (ExtraPlayCostSource extraPlayCost : extraPlayCosts) {
|
||||
result.add(extraPlayCost.getExtraPlayCost(game, self));
|
||||
result.add(extraPlayCost.getExtraPlayCost(actionContext));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.gempukku.lotro.cards.build;
|
||||
|
||||
import com.gempukku.lotro.game.ExtraPlayCost;
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
|
||||
public interface ExtraPlayCostSource {
|
||||
ExtraPlayCost getExtraPlayCost(LotroGame game, PhysicalCard card);
|
||||
ExtraPlayCost getExtraPlayCost(ActionContext actionContext);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.gempukku.lotro.cards.build;
|
||||
|
||||
import com.gempukku.lotro.game.PhysicalCard;
|
||||
import com.gempukku.lotro.game.state.LotroGame;
|
||||
|
||||
public interface TwilightCostModifierSource {
|
||||
int getTwilightCostModifier(LotroGame game, PhysicalCard card);
|
||||
int getTwilightCostModifier(ActionContext actionContext);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.gempukku.lotro.cards.build.field.effect;
|
||||
|
||||
import com.gempukku.lotro.cards.build.BuiltLotroCardBlueprint;
|
||||
import com.gempukku.lotro.cards.build.CardGenerationEnvironment;
|
||||
import com.gempukku.lotro.cards.build.DefaultActionContext;
|
||||
import com.gempukku.lotro.cards.build.InvalidCardDefinitionException;
|
||||
import com.gempukku.lotro.cards.build.field.EffectProcessor;
|
||||
import com.gempukku.lotro.cards.build.field.FieldUtils;
|
||||
@@ -21,16 +20,14 @@ public class ExtraCost implements EffectProcessor {
|
||||
final EffectAppender costAppender = environment.getEffectAppenderFactory().getEffectAppender((JSONObject) value.get("cost"), environment);
|
||||
|
||||
blueprint.appendExtraPlayCost(
|
||||
(game, card) -> new ExtraPlayCost() {
|
||||
(actionContext) -> new ExtraPlayCost() {
|
||||
@Override
|
||||
public void appendExtraCosts(LotroGame game, CostToEffectAction action, PhysicalCard card) {
|
||||
DefaultActionContext actionContext = new DefaultActionContext(card.getOwner(), game, card, null, null);
|
||||
costAppender.appendEffect(true, action, actionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPayExtraCostsToPlay(LotroGame game, PhysicalCard card) {
|
||||
DefaultActionContext actionContext = new DefaultActionContext(card.getOwner(), game, card, null, null);
|
||||
return costAppender.isPlayableInFull(actionContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,10 @@ import com.gempukku.lotro.logic.timing.Effect;
|
||||
public abstract class AbstractEffectAppender implements EffectAppender {
|
||||
@Override
|
||||
public final void appendEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
action.appendEffect(createEffect(cost, action, actionContext));
|
||||
if (cost)
|
||||
action.appendCost(createEffect(cost, action, actionContext));
|
||||
else
|
||||
action.appendEffect(createEffect(cost, action, actionContext));
|
||||
}
|
||||
|
||||
protected abstract Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.gempukku.lotro.cards.build.field.effect.EffectAppenderProducer;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.decisions.YesNoDecision;
|
||||
import com.gempukku.lotro.logic.effects.PlayoutDecisionEffect;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class Optional implements EffectAppenderProducer {
|
||||
@@ -21,17 +22,16 @@ public class Optional implements EffectAppenderProducer {
|
||||
|
||||
final EffectAppender effectAppender = environment.getEffectAppenderFactory().getEffectAppender(effect, environment);
|
||||
|
||||
return new EffectAppender() {
|
||||
return new AbstractEffectAppender() {
|
||||
@Override
|
||||
public void appendEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
action.appendCost(
|
||||
new PlayoutDecisionEffect(actionContext.getPerformingPlayer(),
|
||||
new YesNoDecision(text) {
|
||||
@Override
|
||||
protected void yes() {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
}));
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
return new PlayoutDecisionEffect(actionContext.getPerformingPlayer(),
|
||||
new YesNoDecision(text) {
|
||||
@Override
|
||||
protected void yes() {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.gempukku.lotro.game.state.LotroGame;
|
||||
import com.gempukku.lotro.logic.actions.CostToEffectAction;
|
||||
import com.gempukku.lotro.logic.decisions.YesNoDecision;
|
||||
import com.gempukku.lotro.logic.effects.PlayoutDecisionEffect;
|
||||
import com.gempukku.lotro.logic.timing.Effect;
|
||||
import com.gempukku.lotro.logic.timing.UnrespondableEffect;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -29,33 +30,32 @@ public class PreventableAppenderProducer implements EffectAppenderProducer {
|
||||
final EffectAppender effectAppender = environment.getEffectAppenderFactory().getEffectAppender(effect, environment);
|
||||
final EffectAppender costAppender = environment.getEffectAppenderFactory().getEffectAppender(cost, environment);
|
||||
|
||||
return new EffectAppender() {
|
||||
return new AbstractEffectAppender() {
|
||||
@Override
|
||||
public void appendEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
action.appendEffect(
|
||||
new UnrespondableEffect() {
|
||||
@Override
|
||||
protected void doPlayEffect(LotroGame game) {
|
||||
if (costAppender.isPlayableInFull(actionContext)) {
|
||||
final String preventingPlayer = preventingPlayerSource.getPlayer(actionContext);
|
||||
action.insertEffect(
|
||||
new PlayoutDecisionEffect(preventingPlayer,
|
||||
new YesNoDecision(text) {
|
||||
@Override
|
||||
protected void yes() {
|
||||
costAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
protected Effect createEffect(boolean cost, CostToEffectAction action, ActionContext actionContext) {
|
||||
return new UnrespondableEffect() {
|
||||
@Override
|
||||
protected void doPlayEffect(LotroGame game) {
|
||||
if (costAppender.isPlayableInFull(actionContext)) {
|
||||
final String preventingPlayer = preventingPlayerSource.getPlayer(actionContext);
|
||||
action.insertEffect(
|
||||
new PlayoutDecisionEffect(preventingPlayer,
|
||||
new YesNoDecision(text) {
|
||||
@Override
|
||||
protected void yes() {
|
||||
costAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void no() {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected void no() {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
effectAppender.appendEffect(cost, action, actionContext);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,15 +18,14 @@ public class ModifyOwnCost implements EffectProcessor {
|
||||
final Requirement[] requirements = environment.getRequirementFactory().getRequirements(conditionArray, environment);
|
||||
|
||||
blueprint.appendTwilightCostModifier(
|
||||
(game, card) -> {
|
||||
DefaultActionContext dummy = new DefaultActionContext(card.getOwner(), game, card, null, null);
|
||||
(actionContext) -> {
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.accepts(dummy))
|
||||
if (!requirement.accepts(actionContext))
|
||||
return 0;
|
||||
}
|
||||
|
||||
final Evaluator evaluator = amountSource.getEvaluator(null);
|
||||
return evaluator.evaluateExpression(game, card);
|
||||
final Evaluator evaluator = amountSource.getEvaluator(actionContext);
|
||||
return evaluator.evaluateExpression(actionContext.getGame(), actionContext.getSource());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public abstract class AbstractCostToEffectAction implements CostToEffectAction {
|
||||
private LinkedList<Effect> _costs = new LinkedList<Effect>();
|
||||
private LinkedList<Effect> _processedCosts = new LinkedList<Effect>();
|
||||
private LinkedList<Effect> _effects = new LinkedList<Effect>();
|
||||
private LinkedList<Effect> _processedEffects = new LinkedList<Effect>();
|
||||
|
||||
private Phase _actionTimeword;
|
||||
private String _performingPlayer;
|
||||
@@ -117,7 +118,10 @@ public abstract class AbstractCostToEffectAction implements CostToEffectAction {
|
||||
}
|
||||
|
||||
protected final Effect getNextEffect() {
|
||||
return _effects.poll();
|
||||
final Effect effect = _effects.poll();
|
||||
if (effect != null)
|
||||
_processedEffects.add(effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
protected final DiscountEffect getNextPotentialDiscount() {
|
||||
@@ -126,4 +130,16 @@ public abstract class AbstractCostToEffectAction implements CostToEffectAction {
|
||||
_processedDiscounts.add(discount);
|
||||
return discount;
|
||||
}
|
||||
|
||||
public boolean wasCarriedOut() {
|
||||
if (isCostFailed())
|
||||
return false;
|
||||
|
||||
for (Effect processedEffect : _processedEffects) {
|
||||
if (!processedEffect.wasCarriedOut())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user