package org.drools.games.wumpus.server.view

import org.drools.games.wumpus.Reset
import org.drools.games.wumpus.Play
import org.drools.games.wumpus.Init
import org.drools.games.wumpus.Wumpus
import org.drools.games.wumpus.Gold
import org.drools.games.wumpus.Hero
import org.drools.games.wumpus.Score
import org.drools.games.wumpus.WumpusDeath
import org.drools.games.wumpus.PitDeath
import org.drools.games.wumpus.GoldWin
import org.drools.games.wumpus.view.GameView
import org.drools.games.wumpus.view.GameUI

import javax.swing.JOptionPane

import java.util.ArrayList
import org.kie.internal.logger.KnowledgeRuntimeLogger
import org.kie.internal.logger.KnowledgeRuntimeLoggerFactory
import org.kie.internal.runtime.StatefulKnowledgeSession

global org.drools.games.wumpus.WumpusWorldConfiguration wumpusWorldConfiguration;

dialect "mvel"

rule "Score Updated" agenda-group "UpdateScore" when
    $gv : GameView()
    $s : Score() @watch(*)
then
    channels["score"].send( $s );
end

rule "Wumpus Death View" agenda-group "EndGame" when
    $g  : GameView()
    $ui : GameUI()    
    $wd : WumpusDeath()       
then
	JOptionPane.showMessageDialog( $ui.getParentJFrame(),
                                   "Oh No! You where killed by the Wumpus" );
    retract( $wd );                                   
    insert( new Reset() );
    setFocus( "Reset" );
end

rule "Pit Game View" agenda-group "EndGame" when
    $g : GameView()
    $ui : GameUI()    
    $pd : PitDeath()
then    
	JOptionPane.showMessageDialog( $ui.getParentJFrame(),
                                   "Oh No! You where killed by a Pit" );
    retract( $pd );                                   
    insert( new Reset() );
    setFocus( "Reset" );
end

rule "Gold Win View" agenda-group "EndGame" when
    $g : GameView()
    $ui : GameUI()    
    $gw : GoldWin()    
then
	JOptionPane.showMessageDialog( $ui.getParentJFrame(),
                                   "Congratulations! You retreived the gold from the cave" );
    retract( $gw );                                       
    insert( new Reset() );
    setFocus( "Reset" );
end
