|
|
|
@ -5,8 +5,8 @@ where
|
|
|
|
|
import GHC.IO (unsafePerformIO)
|
|
|
|
|
import System.Directory (getDirectoryContents)
|
|
|
|
|
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.Config (levelFolder)
|
|
|
|
|
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, inventorySize)
|
|
|
|
|
import Data.Foldable (find)
|
|
|
|
|
|
|
|
|
|
------------------------------ Exported ------------------------------
|
|
|
|
@ -56,18 +56,30 @@ getActionText :: Action -> String
|
|
|
|
|
getActionText Leave = "Leave"
|
|
|
|
|
getActionText (RetrieveItem _) = "Pick up"
|
|
|
|
|
getActionText (UseItem _) = "Use item"
|
|
|
|
|
getActionText (IncreasePlayerHp _) = "Take a healing potion"
|
|
|
|
|
getActionText (DecreaseHp _ used) = "Attack using " ++ used
|
|
|
|
|
getActionText _ = "ERROR"
|
|
|
|
|
|
|
|
|
|
-- TODO Check conditions
|
|
|
|
|
-- Filter based on the conditions, keep only the actions of which the
|
|
|
|
|
-- conditions are met.
|
|
|
|
|
filterActions :: [([Condition], Action)] -> [Action]
|
|
|
|
|
filterActions [] = []
|
|
|
|
|
filterActions ((conditions, action):others) = action:filterActions others
|
|
|
|
|
-- Should receive a Playing state
|
|
|
|
|
filterActions :: State -> [([Condition], Action)] -> [Action]
|
|
|
|
|
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.
|
|
|
|
|
meetsCondition :: Condition -> Bool
|
|
|
|
|
meetsCondition InventoryFull = False -- TODO
|
|
|
|
|
meetsCondition (InventoryContains id) = True -- TODO
|
|
|
|
|
meetsCondition (Not condition) = not $ meetsCondition condition
|
|
|
|
|
meetsCondition AlwaysFalse = False
|
|
|
|
|
meetsCondition :: State -> Condition -> Bool
|
|
|
|
|
meetsCondition s InventoryFull = isInventoryFull $ player s
|
|
|
|
|
meetsCondition s (InventoryContains id) = inventoryContains id $ player s
|
|
|
|
|
meetsCondition s (Not condition) = not $ meetsCondition s condition
|
|
|
|
|
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
|