I am new to Drools and I've been trying to figure this out through the
user guide and examples I've been finding, but I'm not sure what the
best way is to write this rule (or set of rules).
What I'm trying to write is a set of rules for determining when
someone has earned (or is starting to earn) a badge. I want to be able
to show their progress on badge completion as well as when they
finally complete said badge.
I'm passing in the following to the rule:
- Player
- Earned Badges (list)
- All possible badges
The first rule only deals with one specific badge. So I have something
like this in my when:
$badge : Badge(name == "Something") //my assumption is that Badge
comes from the list of all possible badges I've just passed in
Then, I decided to split the rule into two. One rule for when they had
not earned it yet:
and I call a function
function earnedBadge(List<EarnedBadge> badges, String name) {
boolean found = false;
for(EarnedBadge badge : badges) {
if(badge.getBadge().getName().equals(name)) {
found = true;
}
}
return found;
}
when:
earnedBadge(badges, $badge (name))
Then I got stuck. If they have completed one or more tasks I would
like to create (or use the badge they've started to earn) to track
their progress. So, If I have 5 possible things they need to do and
they've done three of those I'd like to create a new EarnedBadge for
the one they are earning and give it a percentage of 60%. What would
be the best way to do something like this?
Thanks for helping out the newbie, it's greatly appreciated :).
-warner