/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package org.drools.games.adventures

import java.util.List

//import org.drools.games.adventures.Character
//import org.drools.games.adventures.Room
//import org.drools.games.adventures.Location
import org.drools.games.adventures.model.*;
import org.drools.games.adventures.UserSession;

query connect( Door d, Room x, Room y )
    d := Door(id, name, x, y;)
    or 
    d := Door(id, name, y, x;)
end

query isContainedIn( Thing $x, Thing $r, Thing $y )
    (Location($x, $y;) and
    $r := Thing() from $y)
    or 
    ( Location($z, $y;) and ?isContainedIn($x, $r, $z;) )
end

query things(Character character, List things)
    character := Character()
    Location( character, room; )
    things := List() from acc( Location(thing, room; thing != character),
                                collectList( thing ) )
end

query exits(Character character, List exits)
    character := Character()
    Location( character, room; )
    exits := List() from acc( connect(door, room, exit;),
                              collectList( exit ) )
end

query look(Character character, List things, List exits)
   character := Character()
   things( character, things; )
   exits( character, exits; )
end

query inventory(Character $char, List $inventory) 
    $char := Character()    
    $inventory := List() from acc( Holding( $char, $thing; ),
                                   collectList( $thing ) )
end