Skip to content

Commit

Permalink
refact: take advantage of method overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Jun 4, 2022
1 parent 86a95f7 commit dde3b6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/main/java/io/rpg/model/actions/condition/ConditionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import java.lang.ref.WeakReference;

public class ConditionEngine {
public final class ConditionEngine {
private final WeakReference<Controller> weakRefController;

public ConditionEngine(final Controller controller) {
this.weakRefController = new WeakReference<>(controller);
}

public boolean evaluateItemRequiredCondition(ItemRequiredCondition condition) {
public boolean evaluate(ItemRequiredCondition condition) {
// TODO: Implement this when the inventory gets implemented.
// Scheme:
// return weakRefControler
Expand All @@ -24,12 +24,23 @@ public boolean evaluateItemRequiredCondition(ItemRequiredCondition condition) {
return true;
}

public boolean evaluateDefeatOpponentCondition(DefeatOpponentCondition condition) {
public boolean evaluate(DefeatOpponentCondition condition) {
return weakRefController
.get()
.getPlayerController()
.getPlayer()
.getDefeatedOpponents()
.contains(condition.getOpponentTag());
}

public boolean evaluate(LevelRequiredCondition condition) {
// TODO: Implement this when the level system is implemented.
// For now I just return true.
// return weakRefController
// .get()
// .getPlayerController()
// .getPlayer()
// .getLevel() >= condition.getLevel();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.rpg.config.model.ConditionConfigBundle;
import org.jetbrains.annotations.Nullable;

public class ConditionFactory {
public final class ConditionFactory {
@Nullable
public static Condition fromConfig(ConditionConfigBundle config) {
if (config == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DefeatOpponentCondition(@NotNull final String tag) {

@Override
public boolean acceptEngine(ConditionEngine engine) {
return engine.evaluateDefeatOpponentCondition(this);
return engine.evaluate(this);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ItemRequiredCondition(@NotNull final String tag) {

@Override
public boolean acceptEngine(ConditionEngine engine) {
return engine.evaluateItemRequiredCondition(this);
return engine.evaluate(this);
}

@NotNull
Expand Down

0 comments on commit dde3b6c

Please sign in to comment.