Skip to content

Commit

Permalink
improved stage condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf2323 committed Nov 5, 2023
1 parent ed87271 commit 4785b80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ protected BaseNumberCompareCondition(final Instruction instruction) {
* @param profile the profile to get the number from
* @return the number
* @throws QuestRuntimeException when the number cannot be parsed
* @throws IllegalStateException when getting the number fails caused by an invalid state
* that should cause the condition to be false
*/
protected abstract Double getFirst(Profile profile) throws QuestRuntimeException;
@SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures")
protected abstract Double getFirst(Profile profile) throws QuestRuntimeException, IllegalStateException;

/**
* Get the second number.
*
* @param profile the profile to get the number from
* @return the number
* @throws QuestRuntimeException when the number cannot be parsed
* @throws IllegalStateException when getting the number fails caused by an invalid state
* that should cause the condition to be false
*/
protected abstract Double getSecond(Profile profile) throws QuestRuntimeException;
@SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures")
protected abstract Double getSecond(Profile profile) throws QuestRuntimeException, IllegalStateException;

/**
* Get the operation.
Expand Down Expand Up @@ -67,7 +73,11 @@ protected Operation fromSymbol(final String symbol) throws InstructionParseExcep

@Override
protected Boolean execute(final Profile profile) throws QuestRuntimeException {
return getOperation().compare.check(getFirst(profile), getSecond(profile));
try {
return getOperation().compare.check(getFirst(profile), getSecond(profile));
} catch (final IllegalStateException e) {
return false;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ protected Double getFirst(final Profile profile) throws QuestRuntimeException {
if (stage.getData(profile) == null) {
return -1.0;
}
return (double) stage.getStageIndex(stage.getStage(profile)); // TODO return false for invalid stages
try {
return (double) stage.getStageIndex(stage.getStage(profile));
} catch (final QuestRuntimeException e) {
throw new IllegalStateException(profile + " has an invalid stage", e);
}
}

@Override
protected Double getSecond(final Profile profile) throws QuestRuntimeException {
final StageObjective stage = getStageObjective();
return (double) stage.getStageIndex(second.getString(profile)); // TODO return false for invalid stages
final String targetState = second.getString(profile);
try {
return (double) stage.getStageIndex(targetState);
} catch (final QuestRuntimeException e) {
throw new IllegalStateException("The stage " + targetState + "' does not exist", e);
}
}

@Override
Expand Down

0 comments on commit 4785b80

Please sign in to comment.