Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (64 sloc) 3.54 KB
package org.drools.game.horserace;
import org.drools.game.core.api.*;
import org.drools.game.model.api.*;
import org.drools.game.horserace.model.*;
import org.drools.game.horserace.cmds.*;
import java.util.*;
global GameMessageService messageService;
global GameCallbackService callback;
rule "Player Setup"
when
$player : Player()
not ( PlayerScore(player == $player) )
then
insert( messageService.newGameMessage( "Welcome, " + $player.getName() + ". Venture forth to the stables and mount a mighty steed!" ) );
insert( new PlayerScore($player, 0, 0) );
callback.addCallback(GameCallbackService.newCallback(CommandRegistry.get("NOTIFY_ALL_VIA_CHAT_CALLBACK"), $player,
"Welcome, " + $player.getName() + ". Venture forth to the stables and mount a mighty steed!" ));
end
rule "general checkpoint"
lock-on-active true
when
$player : Player()
$playerscore : PlayerScore(player == $player)
$checkpoint : Checkpoint(players contains $player.getName())
then
insert(new CheckpointHit($player, $checkpoint.getOrder()));
insert( messageService.newGameMessage( "Contestant " + $player.getName() + " has crossed a checkpoint!" ) );
end
rule "passess general checkpoint hit"
lock-on-active true
when
$playerscore : PlayerScore($player: player)
$checkpoints : List( ) from collect( Checkpoint() )
$checkpointhit : CheckpointHit(checkpointNumber == (($playerscore.currentCheckpoint + 1) % $checkpoints.size()))
$checkpoint : Checkpoint(order == $checkpointhit.checkpointNumber && !isStartFinish)
then
int modTo = $checkpointhit.getCheckpointNumber();
modify($playerscore){setCurrentCheckpoint(modTo)};
insert( messageService.newGameMessage( "Contestant " + $playerscore.getPlayer().getName() + " has crossed checkpoint " + modTo ) );
callback.addCallback(GameCallbackService.newCallback(CommandRegistry.get("NOTIFY_ALL_VIA_CHAT_CALLBACK"), $player,
"Contestant " + $playerscore.getPlayer().getName() + " has crossed checkpoint " + modTo ));
end
rule "passess victory checkpoint hit"
lock-on-active true
when
$playerscore : PlayerScore( $player: player )
$checkpoints : List( ) from collect( Checkpoint() )
$checkpointhit : CheckpointHit(checkpointNumber == (($playerscore.currentCheckpoint + 1) % $checkpoints.size()))
$checkpoint : Checkpoint(order == $checkpointhit.checkpointNumber && isStartFinish)
$checkpointHitsToRetract : List( ) from collect( CheckpointHit() )
then
int modTo = $checkpointhit.getCheckpointNumber();
modify($playerscore){setCurrentCheckpoint(modTo)};
insert( messageService.newGameMessage( "Contestant " + $playerscore.getPlayer().getName() + " has crossed a the finish line!" ) );
callback.addCallback(GameCallbackService.newCallback(CommandRegistry.get("NOTIFY_ALL_VIA_CHAT_CALLBACK"), $player,
"Contestant " + $playerscore.getPlayer().getName() + " has crossed a the finish line!" ));
//reset the race
for(Object hit : $checkpointHitsToRetract)
{
retract(hit);
}
modify($playerscore){setLaps($playerscore.getLaps() + 1)};
callback.addCallback(GameCallbackService.newCallback(CommandRegistry.get("CHANGE_SCORE_CALLBACK"), $player, $playerscore.getLaps()));
end