{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Item
( Category (..)
, Condition (..)
, DamageType (..)
, EffectType (..)
, Element (..)
, HasItemDetails (..)
, HasTarget (..)
, Item (Item)
, ItemDetails (..)
, ItemName (..)
, Target (..)
, items
, mkItemName
) where
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import qualified Data.Text as T
import Control.Lens
import Control.Lens.TH
newtype ItemName = ItemName { unItemName :: T.Text }
deriving (Eq, Ord, Show)
data Category
= Use
| Potion
| Weapon
| Armor
| Grid
| Other deriving (Show, Eq, Ord)
data Target = Single | Multi deriving (Show, Eq, Ord)
makeClassy ''Target
data Rarity = Common | Uncommon | Rare | VeryRare deriving (Show, Eq)
data EffectType = Healing
| Damage DamageType
| Condition Condition
| Buff Buff
| Restore Condition
deriving (Show, Eq, Ord)
data Condition = Blindness | Silence | Sleep deriving (Show, Eq, Ord)
data Buff = Regen deriving (Show, Eq, Ord)
data DamageType = Normal
| Elemental Element
| Force
deriving (Show, Eq, Ord)
data Element = Fire | Water | Ice | Lightning deriving (Show, Eq, Ord)
data ItemDetails = ItemDetails
{ _name :: ItemName
, _description :: T.Text
}
deriving (Show, Eq, Ord)
makeClassy ''ItemDetails
data Item = Item
{ details :: ItemDetails
, itemTarget :: Target
, _effects :: [EffectType]
, _category :: Category
, _rarity :: Rarity
}
deriving (Show, Eq)
makeLenses ''Item
instance HasItemDetails Item where
itemDetails :: Lens' Item ItemDetails
itemDetails = lens details (\x y -> x { details = y })
instance HasTarget Item where
target = lens itemTarget (\x y -> x { itemTarget = y })
mkItemName :: T.Text -> Maybe ItemName
mkItemName name
| T.all isSpace name = Nothing
| otherwise = Just $ ItemName name
items :: [Item]
items =
[ Item (ItemDetails (mkName "Bomb Core") "A bomb core") Single [Damage Normal] Use Rare
, Item (ItemDetails (mkName "Potion") "Heals 200 HP") Single [Healing] Potion Common
, Item (ItemDetails (mkName "Hi-Potion") "Heals 1,000 HP") Single [Healing] Potion Common
, Item (ItemDetails (mkName "X-Potion") "Fully heals") Single [Healing] Potion Uncommon
, Item (ItemDetails (mkName "Ether") "Restores 100 MP") Single [] Potion Common
, Item (ItemDetails (mkName "Eye Drops") "Removes Blindness") Single [] Potion Common
, Item (ItemDetails (mkName "Grenade") "Damages all enemies") Multi [Damage Normal] Use Uncommon
, Item (ItemDetails (mkName "Power Sphere") "Unlocks a Power node") Single [] Grid Common
, Item (ItemDetails (mkName "Speed Sphere") "Unlocks a Speed node") Single [] Grid Common
]
where
mkName = fromJust . mkItemName