|  |  | @ -5,8 +5,8 @@ where | 
			
		
	
		
		
			
				
					
					|  |  |  | import GHC.IO (unsafePerformIO) |  |  |  | import GHC.IO (unsafePerformIO) | 
			
		
	
		
		
			
				
					
					|  |  |  | import System.Directory (getDirectoryContents) |  |  |  | import System.Directory (getDirectoryContents) | 
			
		
	
		
		
			
				
					
					|  |  |  | import RPGEngine.Input.Core (ListSelector(..)) |  |  |  | import RPGEngine.Input.Core (ListSelector(..)) | 
			
		
	
		
		
			
				
					
					|  |  |  | import RPGEngine.Data (Action(..), Level (..), Physical (..), Direction (..), Entity (..), Game (..), Item (..), Player (..), State (..), X, Y, Layout, Condition (InventoryFull, InventoryContains, Not, AlwaysFalse)) |  |  |  | import RPGEngine.Data (Action(..), Level (..), Physical (..), Direction (..), Entity (..), Game (..), Item (..), Player (..), State (..), X, Y, Layout, Condition (InventoryFull, InventoryContains, Not, AlwaysFalse), ItemId) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import RPGEngine.Config (levelFolder) |  |  |  | import RPGEngine.Config (levelFolder, inventorySize) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | import Data.Foldable (find) |  |  |  | import Data.Foldable (find) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | ------------------------------ Exported ------------------------------ |  |  |  | ------------------------------ Exported ------------------------------ | 
			
		
	
	
		
		
			
				
					|  |  | @ -53,21 +53,33 @@ getActions (Left item)    = itemActions item | 
			
		
	
		
		
			
				
					
					|  |  |  | getActions (Right entity) = entityActions entity |  |  |  | getActions (Right entity) = entityActions entity | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | getActionText :: Action -> String |  |  |  | getActionText :: Action -> String | 
			
		
	
		
		
			
				
					
					|  |  |  | getActionText Leave            = "Leave" |  |  |  | getActionText Leave                = "Leave" | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | getActionText (RetrieveItem _) = "Pick up" |  |  |  | getActionText (RetrieveItem _)     = "Pick up" | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | getActionText (UseItem _)      = "Use item" |  |  |  | getActionText (UseItem _)          = "Use item" | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | getActionText (IncreasePlayerHp _) = "Take a healing potion" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | getActionText (DecreaseHp _ used)  = "Attack using " ++ used | 
			
		
	
		
		
			
				
					
					|  |  |  | getActionText _ = "ERROR" |  |  |  | getActionText _ = "ERROR" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | -- TODO Check conditions |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | -- Filter based on the conditions, keep only the actions of which the |  |  |  | -- Filter based on the conditions, keep only the actions of which the | 
			
		
	
		
		
			
				
					
					|  |  |  | -- conditions are met. |  |  |  | -- conditions are met. | 
			
		
	
		
		
			
				
					
					|  |  |  | filterActions :: [([Condition], Action)] -> [Action] |  |  |  | -- Should receive a Playing state | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | filterActions [] = [] |  |  |  | filterActions :: State -> [([Condition], Action)] -> [Action] | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | filterActions ((conditions, action):others) = action:filterActions others |  |  |  | filterActions _ [] = [] | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | filterActions s (entry:others) = met entry $ filterActions  s others | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     where met (conditions, action) l | all (meetsCondition s) conditions = action:l | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                      | otherwise = l | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | -- Check if a condition is met or not. |  |  |  | -- Check if a condition is met or not. | 
			
		
	
		
		
			
				
					
					|  |  |  | meetsCondition :: Condition -> Bool |  |  |  | meetsCondition :: State -> Condition -> Bool | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | meetsCondition InventoryFull          = False -- TODO |  |  |  | meetsCondition s InventoryFull          = isInventoryFull $ player s | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | meetsCondition (InventoryContains id) = True -- TODO |  |  |  | meetsCondition s (InventoryContains id) = inventoryContains id $ player s | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | meetsCondition (Not condition)        = not $ meetsCondition condition |  |  |  | meetsCondition s (Not condition)        = not $ meetsCondition s condition | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | meetsCondition AlwaysFalse            = False |  |  |  | meetsCondition _ AlwaysFalse            = False | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | -- Check if the inventory of the player is full. | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | isInventoryFull :: Player -> Bool | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | isInventoryFull p = inventorySize <= length (inventory p) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | -- Check if the inventory of the player contains an item. | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | inventoryContains :: ItemId -> Player -> Bool | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | inventoryContains id p = any ((== id) . itemId) $ inventory p |