{-# LANGUAGE DeriveGeneric #-}
-- | The type of kinds of weapons, treasure, organs, blasts, etc.
module Game.LambdaHack.Content.ItemKind
  ( ItemKind(..), makeData
  , Aspect(..), Effect(..), DetectKind(..), TimerDice, ThrowMod(..)
  , boostItemKindList, forApplyEffect
  , strengthOnSmash, getDropOrgans, getMandatoryHideAsFromKind, isEffEscape
  , isEffEscapeOrAscend, timeoutAspect, onSmashEffect, damageUsefulness
  , verbMsgNoLonger, verbMsgLess, toVelocity, toLinger
  , timerNone, isTimerNone, foldTimer, toOrganBad, toOrganGood, toOrganNoTimer
#ifdef EXPOSE_INTERNAL
    -- * Internal operations
  , boostItemKind, validateSingle, validateAll, validateDups, validateDamage
  , hardwiredItemGroups
#endif
  ) where

import Prelude ()

import Game.LambdaHack.Core.Prelude

import           Data.Binary
import           Data.Hashable (Hashable)
import qualified Data.Text as T
import           GHC.Generics (Generic)
import qualified System.Random as R

import qualified Game.LambdaHack.Core.Dice as Dice
import qualified Game.LambdaHack.Definition.Ability as Ability
import           Game.LambdaHack.Definition.ContentData
import           Game.LambdaHack.Definition.Defs
import           Game.LambdaHack.Definition.Flavour

-- | Item properties that are fixed for a given kind of items.
-- Of these, aspects and effects are jointly called item powers.
-- Note that this type is mutually recursive with 'Effect' and `Aspect`.
data ItemKind = ItemKind
  { ItemKind -> Char
isymbol  :: Char            -- ^ map symbol
  , ItemKind -> Text
iname    :: Text            -- ^ generic name; is pluralized if needed
  , ItemKind -> Freqs ItemKind
ifreq    :: Freqs ItemKind  -- ^ frequency within groups
  , ItemKind -> [Flavour]
iflavour :: [Flavour]       -- ^ possible flavours
  , ItemKind -> Dice
icount   :: Dice.Dice       -- ^ created in that quantity
  , ItemKind -> Rarity
irarity  :: Rarity          -- ^ rarity on given depths
  , ItemKind -> Text
iverbHit :: Text            -- ^ the verb for hitting
  , ItemKind -> Int
iweight  :: Int             -- ^ weight in grams
  , ItemKind -> Dice
idamage  :: Dice.Dice       -- ^ basic kinetic damage
  , ItemKind -> [Aspect]
iaspects :: [Aspect]        -- ^ affect the actor continuously
  , ItemKind -> [Effect]
ieffects :: [Effect]        -- ^ cause the effects when triggered
  , ItemKind -> [(GroupName ItemKind, CStore)]
ikit     :: [(GroupName ItemKind, CStore)]
                                -- ^ accompanying organs and equipment
  , ItemKind -> Text
idesc    :: Text            -- ^ description
  }
  deriving (Int -> ItemKind -> ShowS
[ItemKind] -> ShowS
ItemKind -> String
(Int -> ItemKind -> ShowS)
-> (ItemKind -> String) -> ([ItemKind] -> ShowS) -> Show ItemKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemKind] -> ShowS
$cshowList :: [ItemKind] -> ShowS
show :: ItemKind -> String
$cshow :: ItemKind -> String
showsPrec :: Int -> ItemKind -> ShowS
$cshowsPrec :: Int -> ItemKind -> ShowS
Show, (forall x. ItemKind -> Rep ItemKind x)
-> (forall x. Rep ItemKind x -> ItemKind) -> Generic ItemKind
forall x. Rep ItemKind x -> ItemKind
forall x. ItemKind -> Rep ItemKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ItemKind x -> ItemKind
$cfrom :: forall x. ItemKind -> Rep ItemKind x
Generic)  -- No Eq and Ord to make extending logically sound

-- | Aspects of items. Aspect @AddSkill@ is additive (starting at 0)
-- for all items wielded by an actor and it affects the actor.
-- The others affect only the item in question, not the actor carrying it,
-- and so are not additive in any sense.
data Aspect =
    Timeout Dice.Dice  -- ^ specifies the cooldown before an item may be
                       --   applied again; if a copy of an item is applied
                       --   manually (not via periodic activation),
                       --   all effects on a single copy of the item are
                       --   disabled until the copy recharges for the given
                       --   time expressed in game turns; all copies
                       --   recharge concurrently
  | AddSkill Ability.Skill Dice.Dice
                       -- ^ bonus to a skill; in content, avoid boosting
                       --   skills such as SkApply via permanent equipment,
                       --   to avoid micromanagement through swapping items
                       --   among party members before each skill use
  | SetFlag Ability.Flag
                       -- ^ item feature
  | ELabel Text        -- ^ extra label of the item; it's not pluralized
  | ToThrow ThrowMod   -- ^ parameters modifying a throw
  | HideAs (GroupName ItemKind)
                       -- ^ until identified, presents as this unique kind
  | EqpSlot Ability.EqpSlot
                       -- ^ AI and UI flag that leaks item intended use
  | Odds Dice.Dice [Aspect] [Aspect]
                       -- ^ if level-scaled dice roll > 50,
                       --   pick the former aspects, otherwise the latter
  deriving (Int -> Aspect -> ShowS
[Aspect] -> ShowS
Aspect -> String
(Int -> Aspect -> ShowS)
-> (Aspect -> String) -> ([Aspect] -> ShowS) -> Show Aspect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Aspect] -> ShowS
$cshowList :: [Aspect] -> ShowS
show :: Aspect -> String
$cshow :: Aspect -> String
showsPrec :: Int -> Aspect -> ShowS
$cshowsPrec :: Int -> Aspect -> ShowS
Show, Aspect -> Aspect -> Bool
(Aspect -> Aspect -> Bool)
-> (Aspect -> Aspect -> Bool) -> Eq Aspect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Aspect -> Aspect -> Bool
$c/= :: Aspect -> Aspect -> Bool
== :: Aspect -> Aspect -> Bool
$c== :: Aspect -> Aspect -> Bool
Eq, (forall x. Aspect -> Rep Aspect x)
-> (forall x. Rep Aspect x -> Aspect) -> Generic Aspect
forall x. Rep Aspect x -> Aspect
forall x. Aspect -> Rep Aspect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Aspect x -> Aspect
$cfrom :: forall x. Aspect -> Rep Aspect x
Generic)

-- | Effects of items. Can be invoked by the item wielder to affect
-- another actor or the wielder himself. Many occurences in the same item
-- are possible.
data Effect =
    Burn Dice.Dice     -- ^ burn with this damage
  | Explode (GroupName ItemKind)
                       -- ^ explode producing this group of blasts
  | RefillHP Int       -- ^ modify HP of the actor by this amount
  | RefillCalm Int     -- ^ modify Calm of the actor by this amount
  | Dominate           -- ^ change actor's allegiance
  | Impress            -- ^ make actor susceptible to domination
  | PutToSleep         -- ^ put actor to sleep, also calming him
  | Yell               -- ^ make the actor yell/yawn, waking him and others up
  | Summon (GroupName ItemKind) Dice.Dice
      -- ^ summon the given number of actors of this group
  | Ascend Bool           -- ^ ascend to another level of the dungeon
  | Escape                -- ^ escape from the dungeon
  | Paralyze Dice.Dice    -- ^ paralyze for this many game clips
  | ParalyzeInWater Dice.Dice
                          -- ^ paralyze for this many game clips due to water
  | InsertMove Dice.Dice  -- ^ give actor this many extra tenths of actor move
  | Teleport Dice.Dice    -- ^ teleport actor across rougly this distance
  | CreateItem CStore (GroupName ItemKind) TimerDice
      -- ^ create an item of the group and insert into the store with the given
      --   random timer
  | DropItem Int Int CStore (GroupName ItemKind)
      -- ^ make the actor drop items of the given group from the given store;
      --   the first integer says how many item kinds to drop, the second,
      --   how many copies of each kind to drop; for non-organs, beware of
      --   not dropping all, or cluttering store with rubbish becomes beneficial
  | PolyItem
      -- ^ get a suitable (i.e., numerous enough) non-unique common item stack
      --   on the floor and polymorph it to a stack of random common items,
      --   with current depth coefficient
  | RerollItem
      -- ^ get a suitable (i.e., with any random aspects) single item
      --   (even unique) on the floor and change the random bonuses
      --   of the items randomly, with maximal depth coefficient
  | DupItem
      -- ^ exactly duplicate a single non-unique, non-valuable item on the floor
  | Identify
      -- ^ find a suitable (i.e., not identified) item, starting from
      --   the floor, and identify it
  | Detect DetectKind Int -- ^ detect something on the map in the given radius
  | SendFlying ThrowMod   -- ^ send an actor flying (push or pull, depending)
  | PushActor ThrowMod    -- ^ push an actor
  | PullActor ThrowMod    -- ^ pull an actor
  | DropBestWeapon        -- ^ make the actor drop its best weapon
  | ActivateInv Char
      -- ^ activate all items with this symbol in inventory; space character
      --   means all symbols
  | ApplyPerfume          -- ^ remove all smell on the level
  | OneOf [Effect]        -- ^ trigger one of the effects with equal probability
  | OnSmash Effect
      -- ^ trigger the effect when item smashed (not when applied nor meleed);
  | Composite [Effect]    -- ^ only fire next effect if previous fully activated
  | VerbNoLonger Text
      -- ^ a sentence with the actor causing the effect as subject and the given
      --   text as verb is emitted when the activation causes item to expire;
      --   no spam is emitted if a projectile
  | VerbMsg Text
      -- ^ a sentence with the actor causing the effect as subject and the given
      --   text as verb is emitted whenever the item is activated;
      --   no spam is emitted if a projectile
  deriving (Int -> Effect -> ShowS
[Effect] -> ShowS
Effect -> String
(Int -> Effect -> ShowS)
-> (Effect -> String) -> ([Effect] -> ShowS) -> Show Effect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Effect] -> ShowS
$cshowList :: [Effect] -> ShowS
show :: Effect -> String
$cshow :: Effect -> String
showsPrec :: Int -> Effect -> ShowS
$cshowsPrec :: Int -> Effect -> ShowS
Show, Effect -> Effect -> Bool
(Effect -> Effect -> Bool)
-> (Effect -> Effect -> Bool) -> Eq Effect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Effect -> Effect -> Bool
$c/= :: Effect -> Effect -> Bool
== :: Effect -> Effect -> Bool
$c== :: Effect -> Effect -> Bool
Eq, (forall x. Effect -> Rep Effect x)
-> (forall x. Rep Effect x -> Effect) -> Generic Effect
forall x. Rep Effect x -> Effect
forall x. Effect -> Rep Effect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Effect x -> Effect
$cfrom :: forall x. Effect -> Rep Effect x
Generic)

data DetectKind =
    DetectAll
  | DetectActor
  | DetectLoot
  | DetectExit
  | DetectHidden
  | DetectEmbed
  deriving (Int -> DetectKind -> ShowS
[DetectKind] -> ShowS
DetectKind -> String
(Int -> DetectKind -> ShowS)
-> (DetectKind -> String)
-> ([DetectKind] -> ShowS)
-> Show DetectKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectKind] -> ShowS
$cshowList :: [DetectKind] -> ShowS
show :: DetectKind -> String
$cshow :: DetectKind -> String
showsPrec :: Int -> DetectKind -> ShowS
$cshowsPrec :: Int -> DetectKind -> ShowS
Show, DetectKind -> DetectKind -> Bool
(DetectKind -> DetectKind -> Bool)
-> (DetectKind -> DetectKind -> Bool) -> Eq DetectKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectKind -> DetectKind -> Bool
$c/= :: DetectKind -> DetectKind -> Bool
== :: DetectKind -> DetectKind -> Bool
$c== :: DetectKind -> DetectKind -> Bool
Eq, (forall x. DetectKind -> Rep DetectKind x)
-> (forall x. Rep DetectKind x -> DetectKind) -> Generic DetectKind
forall x. Rep DetectKind x -> DetectKind
forall x. DetectKind -> Rep DetectKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectKind x -> DetectKind
$cfrom :: forall x. DetectKind -> Rep DetectKind x
Generic)

-- | Specification of how to randomly roll a timer at item creation
-- to obtain a fixed timer for the item's lifetime.
data TimerDice =
    TimerNone
  | TimerGameTurn Dice.Dice
  | TimerActorTurn Dice.Dice
  deriving (TimerDice -> TimerDice -> Bool
(TimerDice -> TimerDice -> Bool)
-> (TimerDice -> TimerDice -> Bool) -> Eq TimerDice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimerDice -> TimerDice -> Bool
$c/= :: TimerDice -> TimerDice -> Bool
== :: TimerDice -> TimerDice -> Bool
$c== :: TimerDice -> TimerDice -> Bool
Eq, (forall x. TimerDice -> Rep TimerDice x)
-> (forall x. Rep TimerDice x -> TimerDice) -> Generic TimerDice
forall x. Rep TimerDice x -> TimerDice
forall x. TimerDice -> Rep TimerDice x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimerDice x -> TimerDice
$cfrom :: forall x. TimerDice -> Rep TimerDice x
Generic)

instance Show TimerDice where
  show :: TimerDice -> String
show TimerNone = "0"
  show (TimerGameTurn nDm :: Dice
nDm) =
    Dice -> String
forall a. Show a => a -> String
show Dice
nDm String -> ShowS
forall a. [a] -> [a] -> [a]
++ " " String -> ShowS
forall a. [a] -> [a] -> [a]
++ if Dice
nDm Dice -> Dice -> Bool
forall a. Eq a => a -> a -> Bool
== 1 then "turn" else "turns"
  show (TimerActorTurn nDm :: Dice
nDm) =
    Dice -> String
forall a. Show a => a -> String
show Dice
nDm String -> ShowS
forall a. [a] -> [a] -> [a]
++ " " String -> ShowS
forall a. [a] -> [a] -> [a]
++ if Dice
nDm Dice -> Dice -> Bool
forall a. Eq a => a -> a -> Bool
== 1 then "move" else "moves"

-- | Parameters modifying a throw of a projectile or flight of pushed actor.
-- Not additive and don't start at 0.
data ThrowMod = ThrowMod
  { ThrowMod -> Int
throwVelocity :: Int  -- ^ fly with this percentage of base throw speed
  , ThrowMod -> Int
throwLinger   :: Int  -- ^ fly for this percentage of 2 turns
  , ThrowMod -> Int
throwHP       :: Int  -- ^ start flight with this many HP
  }
  deriving (Int -> ThrowMod -> ShowS
[ThrowMod] -> ShowS
ThrowMod -> String
(Int -> ThrowMod -> ShowS)
-> (ThrowMod -> String) -> ([ThrowMod] -> ShowS) -> Show ThrowMod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ThrowMod] -> ShowS
$cshowList :: [ThrowMod] -> ShowS
show :: ThrowMod -> String
$cshow :: ThrowMod -> String
showsPrec :: Int -> ThrowMod -> ShowS
$cshowsPrec :: Int -> ThrowMod -> ShowS
Show, ThrowMod -> ThrowMod -> Bool
(ThrowMod -> ThrowMod -> Bool)
-> (ThrowMod -> ThrowMod -> Bool) -> Eq ThrowMod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ThrowMod -> ThrowMod -> Bool
$c/= :: ThrowMod -> ThrowMod -> Bool
== :: ThrowMod -> ThrowMod -> Bool
$c== :: ThrowMod -> ThrowMod -> Bool
Eq, Eq ThrowMod
Eq ThrowMod =>
(ThrowMod -> ThrowMod -> Ordering)
-> (ThrowMod -> ThrowMod -> Bool)
-> (ThrowMod -> ThrowMod -> Bool)
-> (ThrowMod -> ThrowMod -> Bool)
-> (ThrowMod -> ThrowMod -> Bool)
-> (ThrowMod -> ThrowMod -> ThrowMod)
-> (ThrowMod -> ThrowMod -> ThrowMod)
-> Ord ThrowMod
ThrowMod -> ThrowMod -> Bool
ThrowMod -> ThrowMod -> Ordering
ThrowMod -> ThrowMod -> ThrowMod
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ThrowMod -> ThrowMod -> ThrowMod
$cmin :: ThrowMod -> ThrowMod -> ThrowMod
max :: ThrowMod -> ThrowMod -> ThrowMod
$cmax :: ThrowMod -> ThrowMod -> ThrowMod
>= :: ThrowMod -> ThrowMod -> Bool
$c>= :: ThrowMod -> ThrowMod -> Bool
> :: ThrowMod -> ThrowMod -> Bool
$c> :: ThrowMod -> ThrowMod -> Bool
<= :: ThrowMod -> ThrowMod -> Bool
$c<= :: ThrowMod -> ThrowMod -> Bool
< :: ThrowMod -> ThrowMod -> Bool
$c< :: ThrowMod -> ThrowMod -> Bool
compare :: ThrowMod -> ThrowMod -> Ordering
$ccompare :: ThrowMod -> ThrowMod -> Ordering
$cp1Ord :: Eq ThrowMod
Ord, (forall x. ThrowMod -> Rep ThrowMod x)
-> (forall x. Rep ThrowMod x -> ThrowMod) -> Generic ThrowMod
forall x. Rep ThrowMod x -> ThrowMod
forall x. ThrowMod -> Rep ThrowMod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ThrowMod x -> ThrowMod
$cfrom :: forall x. ThrowMod -> Rep ThrowMod x
Generic)

instance Binary Effect

instance Binary DetectKind

instance Binary TimerDice

instance Binary ThrowMod

instance Hashable ThrowMod

boostItemKindList :: R.StdGen -> [ItemKind] -> [ItemKind]
boostItemKindList :: StdGen -> [ItemKind] -> [ItemKind]
boostItemKindList _ [] = []
boostItemKindList initialGen :: StdGen
initialGen l :: [ItemKind]
l =
  let (r :: Int
r, _) = (Int, Int) -> StdGen -> (Int, StdGen)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
R.randomR (0, [ItemKind] -> Int
forall a. [a] -> Int
length [ItemKind]
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1) StdGen
initialGen
  in case Int -> [ItemKind] -> ([ItemKind], [ItemKind])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
r [ItemKind]
l of
    (pre :: [ItemKind]
pre, i :: ItemKind
i : post :: [ItemKind]
post) -> [ItemKind]
pre [ItemKind] -> [ItemKind] -> [ItemKind]
forall a. [a] -> [a] -> [a]
++ ItemKind -> ItemKind
boostItemKind ItemKind
i ItemKind -> [ItemKind] -> [ItemKind]
forall a. a -> [a] -> [a]
: [ItemKind]
post
    _               -> String -> [ItemKind]
forall a. HasCallStack => String -> a
error (String -> [ItemKind]) -> String -> [ItemKind]
forall a b. (a -> b) -> a -> b
$  "" String -> [ItemKind] -> String
forall v. Show v => String -> v -> String
`showFailure` [ItemKind]
l

boostItemKind :: ItemKind -> ItemKind
boostItemKind :: ItemKind -> ItemKind
boostItemKind i :: ItemKind
i =
  let mainlineLabel :: (a, b) -> Bool
mainlineLabel (label :: a
label, _) =
        a
label a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["common item", "curious item", "treasure"]
  in if ((GroupName ItemKind, Int) -> Bool) -> Freqs ItemKind -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (GroupName ItemKind, Int) -> Bool
forall a b. (Eq a, IsString a) => (a, b) -> Bool
mainlineLabel (ItemKind -> Freqs ItemKind
ifreq ItemKind
i)
     then ItemKind
i { ifreq :: Freqs ItemKind
ifreq = ("common item", 10000) (GroupName ItemKind, Int) -> Freqs ItemKind -> Freqs ItemKind
forall a. a -> [a] -> [a]
: ((GroupName ItemKind, Int) -> Bool)
-> Freqs ItemKind -> Freqs ItemKind
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((GroupName ItemKind, Int) -> Bool)
-> (GroupName ItemKind, Int)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GroupName ItemKind, Int) -> Bool
forall a b. (Eq a, IsString a) => (a, b) -> Bool
mainlineLabel) (ItemKind -> Freqs ItemKind
ifreq ItemKind
i)
            , iaspects :: [Aspect]
iaspects = Aspect -> [Aspect] -> [Aspect]
forall a. Eq a => a -> [a] -> [a]
delete (Flag -> Aspect
SetFlag Flag
Ability.Unique) ([Aspect] -> [Aspect]) -> [Aspect] -> [Aspect]
forall a b. (a -> b) -> a -> b
$ ItemKind -> [Aspect]
iaspects ItemKind
i
            }
     else ItemKind
i

-- | Whether the effect has a chance of exhibiting any potentially
-- noticeable behaviour, except when the item is destroyed.
-- We assume at least one of @OneOf@ effects must be noticeable.
forApplyEffect :: Effect -> Bool
forApplyEffect :: Effect -> Bool
forApplyEffect eff :: Effect
eff = case Effect
eff of
  OnSmash{} -> Bool
False
  Composite effs :: [Effect]
effs -> (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
forApplyEffect [Effect]
effs
  VerbNoLonger{} -> Bool
False
  VerbMsg{} -> Bool
False
  ParalyzeInWater{} -> Bool
False  -- barely noticeable, spams when resisted
  _ -> Bool
True

isEffEscape :: Effect -> Bool
isEffEscape :: Effect -> Bool
isEffEscape Escape{} = Bool
True
isEffEscape (OneOf l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
isEffEscape [Effect]
l
isEffEscape (Composite l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
isEffEscape [Effect]
l
isEffEscape _ = Bool
False

isEffEscapeOrAscend :: Effect -> Bool
isEffEscapeOrAscend :: Effect -> Bool
isEffEscapeOrAscend Ascend{} = Bool
True
isEffEscapeOrAscend Escape{} = Bool
True
isEffEscapeOrAscend (OneOf l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
isEffEscapeOrAscend [Effect]
l
isEffEscapeOrAscend (Composite l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
isEffEscapeOrAscend [Effect]
l
isEffEscapeOrAscend _ = Bool
False

timeoutAspect :: Aspect -> Bool
timeoutAspect :: Aspect -> Bool
timeoutAspect Timeout{} = Bool
True
timeoutAspect _ = Bool
False

onSmashEffect :: Effect -> Bool
onSmashEffect :: Effect -> Bool
onSmashEffect OnSmash{} = Bool
True
onSmashEffect _ = Bool
False

strengthOnSmash :: ItemKind -> [Effect]
strengthOnSmash :: ItemKind -> [Effect]
strengthOnSmash =
  let f :: Effect -> [Effect]
f (OnSmash eff :: Effect
eff) = [Effect
eff]
      f _ = []
  in (Effect -> [Effect]) -> [Effect] -> [Effect]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Effect -> [Effect]
f ([Effect] -> [Effect])
-> (ItemKind -> [Effect]) -> ItemKind -> [Effect]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ItemKind -> [Effect]
ieffects

getDropOrgans :: ItemKind -> [GroupName ItemKind]
getDropOrgans :: ItemKind -> [GroupName ItemKind]
getDropOrgans =
  let f :: Effect -> [GroupName ItemKind]
f (DropItem _ _ COrgan grp :: GroupName ItemKind
grp) = [GroupName ItemKind
grp]
      f Impress = ["impressed"]
      f (OneOf l :: [Effect]
l) = (Effect -> [GroupName ItemKind])
-> [Effect] -> [GroupName ItemKind]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Effect -> [GroupName ItemKind]
f [Effect]
l  -- even remote possibility accepted
      f (Composite l :: [Effect]
l) = (Effect -> [GroupName ItemKind])
-> [Effect] -> [GroupName ItemKind]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Effect -> [GroupName ItemKind]
f [Effect]
l  -- not certain, but accepted
      f _ = []
  in (Effect -> [GroupName ItemKind])
-> [Effect] -> [GroupName ItemKind]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Effect -> [GroupName ItemKind]
f ([Effect] -> [GroupName ItemKind])
-> (ItemKind -> [Effect]) -> ItemKind -> [GroupName ItemKind]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ItemKind -> [Effect]
ieffects

-- Anything under @Odds@ is ignored, because it's not mandatory.
getMandatoryHideAsFromKind :: ItemKind -> Maybe (GroupName ItemKind)
getMandatoryHideAsFromKind :: ItemKind -> Maybe (GroupName ItemKind)
getMandatoryHideAsFromKind itemKind :: ItemKind
itemKind =
  let f :: Aspect -> [GroupName ItemKind]
f (HideAs grp :: GroupName ItemKind
grp) = [GroupName ItemKind
grp]
      f _ = []
  in [GroupName ItemKind] -> Maybe (GroupName ItemKind)
forall a. [a] -> Maybe a
listToMaybe ([GroupName ItemKind] -> Maybe (GroupName ItemKind))
-> [GroupName ItemKind] -> Maybe (GroupName ItemKind)
forall a b. (a -> b) -> a -> b
$ (Aspect -> [GroupName ItemKind])
-> [Aspect] -> [GroupName ItemKind]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Aspect -> [GroupName ItemKind]
f (ItemKind -> [Aspect]
iaspects ItemKind
itemKind)

damageUsefulness :: ItemKind -> Double
damageUsefulness :: ItemKind -> Double
damageUsefulness itemKind :: ItemKind
itemKind =
  let v :: Double
v = Double -> Double -> Double
forall a. Ord a => a -> a -> a
min 1000 (10 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Dice -> Double
Dice.meanDice (ItemKind -> Dice
idamage ItemKind
itemKind))
  in Bool -> Double -> Double
forall a. HasCallStack => Bool -> a -> a
assert (Double
v Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= 0) Double
v

verbMsgNoLonger :: Text -> Effect
verbMsgNoLonger :: Text -> Effect
verbMsgNoLonger name :: Text
name = Text -> Effect
VerbNoLonger (Text -> Effect) -> Text -> Effect
forall a b. (a -> b) -> a -> b
$ "be no longer" Text -> Text -> Text
<+> Text
name

verbMsgLess :: Text -> Effect
verbMsgLess :: Text -> Effect
verbMsgLess name :: Text
name = Text -> Effect
VerbMsg (Text -> Effect) -> Text -> Effect
forall a b. (a -> b) -> a -> b
$ "look less" Text -> Text -> Text
<+> Text
name

toVelocity :: Int -> Aspect
toVelocity :: Int -> Aspect
toVelocity n :: Int
n = ThrowMod -> Aspect
ToThrow (ThrowMod -> Aspect) -> ThrowMod -> Aspect
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> ThrowMod
ThrowMod Int
n 100 1

toLinger :: Int -> Aspect
toLinger :: Int -> Aspect
toLinger n :: Int
n = ThrowMod -> Aspect
ToThrow (ThrowMod -> Aspect) -> ThrowMod -> Aspect
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> ThrowMod
ThrowMod 100 Int
n 1

timerNone :: TimerDice
timerNone :: TimerDice
timerNone = TimerDice
TimerNone

isTimerNone :: TimerDice -> Bool
isTimerNone :: TimerDice -> Bool
isTimerNone tim :: TimerDice
tim = TimerDice
tim TimerDice -> TimerDice -> Bool
forall a. Eq a => a -> a -> Bool
== TimerDice
TimerNone

foldTimer :: a -> (Dice.Dice -> a) -> (Dice.Dice -> a) -> TimerDice -> a
foldTimer :: a -> (Dice -> a) -> (Dice -> a) -> TimerDice -> a
foldTimer a :: a
a fgame :: Dice -> a
fgame factor :: Dice -> a
factor tim :: TimerDice
tim = case TimerDice
tim of
  TimerNone -> a
a
  TimerGameTurn nDm :: Dice
nDm -> Dice -> a
fgame Dice
nDm
  TimerActorTurn nDm :: Dice
nDm -> Dice -> a
factor Dice
nDm

toOrganBad :: GroupName ItemKind -> Dice.Dice -> Effect
toOrganBad :: GroupName ItemKind -> Dice -> Effect
toOrganBad grp :: GroupName ItemKind
grp nDm :: Dice
nDm =
  Bool -> Effect -> Effect
forall a. HasCallStack => Bool -> a -> a
assert (Dice -> Int
Dice.infDice Dice
nDm Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
          Bool -> (String, (GroupName ItemKind, Dice)) -> Bool
forall a. Show a => Bool -> a -> Bool
`blame` "dice at organ creation should always roll above zero"
          String
-> (GroupName ItemKind, Dice)
-> (String, (GroupName ItemKind, Dice))
forall v. String -> v -> (String, v)
`swith` (GroupName ItemKind
grp, Dice
nDm))
  (Effect -> Effect) -> Effect -> Effect
forall a b. (a -> b) -> a -> b
$ CStore -> GroupName ItemKind -> TimerDice -> Effect
CreateItem CStore
COrgan GroupName ItemKind
grp (Dice -> TimerDice
TimerGameTurn Dice
nDm)

toOrganGood :: GroupName ItemKind -> Dice.Dice -> Effect
toOrganGood :: GroupName ItemKind -> Dice -> Effect
toOrganGood grp :: GroupName ItemKind
grp nDm :: Dice
nDm =
  Bool -> Effect -> Effect
forall a. HasCallStack => Bool -> a -> a
assert (Dice -> Int
Dice.infDice Dice
nDm Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
          Bool -> (String, (GroupName ItemKind, Dice)) -> Bool
forall a. Show a => Bool -> a -> Bool
`blame` "dice at organ creation should always roll above zero"
          String
-> (GroupName ItemKind, Dice)
-> (String, (GroupName ItemKind, Dice))
forall v. String -> v -> (String, v)
`swith` (GroupName ItemKind
grp, Dice
nDm))
  (Effect -> Effect) -> Effect -> Effect
forall a b. (a -> b) -> a -> b
$ CStore -> GroupName ItemKind -> TimerDice -> Effect
CreateItem CStore
COrgan GroupName ItemKind
grp (Dice -> TimerDice
TimerActorTurn Dice
nDm)

toOrganNoTimer :: GroupName ItemKind -> Effect
toOrganNoTimer :: GroupName ItemKind -> Effect
toOrganNoTimer grp :: GroupName ItemKind
grp = CStore -> GroupName ItemKind -> TimerDice -> Effect
CreateItem CStore
COrgan GroupName ItemKind
grp TimerDice
TimerNone

-- | Catch invalid item kind definitions.
validateSingle :: ItemKind -> [Text]
validateSingle :: ItemKind -> [Text]
validateSingle ik :: ItemKind
ik@ItemKind{..} =
  ["iname longer than 23" | Text -> Int
T.length Text
iname Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 23]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ ["icount < 0" | Dice -> Int
Dice.infDice Dice
icount Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ Rarity -> [Text]
validateRarity Rarity
irarity
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ Dice -> [Text]
validateDamage Dice
idamage
  -- Reject duplicate Timeout, because it's not additive.
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter Aspect -> Bool
timeoutAspect [Aspect]
iaspects
      in ["more than one Timeout specification" | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "Conflicting Fragile and Durable"
     | Flag -> Aspect
SetFlag Flag
Ability.Fragile Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects
       Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Durable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects ]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Aspect -> Bool
          f :: Aspect -> Bool
f EqpSlot{} = Bool
True
          f _ = Bool
False
          ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter Aspect -> Bool
f [Aspect]
iaspects
      in [ "EqpSlot specified but not Equipable nor Meleeable"
         | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Equipable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Aspect]
iaspects
                         Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Meleeable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Aspect]
iaspects ])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "Redundant Equipable or Meleeable"
     | Flag -> Aspect
SetFlag Flag
Ability.Equipable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects
       Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Meleeable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects ]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "Conflicting Durable and Blast"
     | Flag -> Aspect
SetFlag Flag
Ability.Durable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects
       Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Blast Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects ]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "Conflicting Durable and Condition"
     | Flag -> Aspect
SetFlag Flag
Ability.Durable Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects
       Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Condition Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects ]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "Conflicting Blast and Condition"
     | Flag -> Aspect
SetFlag Flag
Ability.Blast Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects
       Bool -> Bool -> Bool
&& Flag -> Aspect
SetFlag Flag
Ability.Condition Aspect -> [Aspect] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Aspect]
iaspects ]
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Aspect -> Bool
          f :: Aspect -> Bool
f ELabel{} = Bool
True
          f _ = Bool
False
          ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter Aspect -> Bool
f [Aspect]
iaspects
      in ["more than one ELabel specification" | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Aspect -> Bool
          f :: Aspect -> Bool
f ToThrow{} = Bool
True
          f _ = Bool
False
          ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter Aspect -> Bool
f [Aspect]
iaspects
      in ["more than one ToThrow specification" | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Aspect -> Bool
          f :: Aspect -> Bool
f HideAs{} = Bool
True
          f _ = Bool
False
          ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter Aspect -> Bool
f [Aspect]
iaspects
      in ["more than one HideAs specification" | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (Aspect -> [Text]) -> [Aspect] -> [Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (ItemKind -> Aspect -> [Text]
validateDups ItemKind
ik) ((Flag -> Aspect) -> [Flag] -> [Aspect]
forall a b. (a -> b) -> [a] -> [b]
map Flag -> Aspect
SetFlag [Flag
forall a. Bounded a => a
minBound .. Flag
forall a. Bounded a => a
maxBound])
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Effect -> Bool
          f :: Effect -> Bool
f VerbMsg{} = Bool
True
          f _ = Bool
False
      in [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateOnlyOne [Effect]
ieffects "VerbMsg" Effect -> Bool
f)  -- may be duplicated if nested
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let f :: Effect -> Bool
          f :: Effect -> Bool
f VerbNoLonger{} = Bool
True
          f _ = Bool
False
      in [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateOnlyOne [Effect]
ieffects "VerbNoLonger" Effect -> Bool
f)  -- may be duped if nested
  [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ ([Effect] -> Text -> (Effect -> Bool) -> [Text]
validateNotNested [Effect]
ieffects "OnSmash" Effect -> Bool
onSmashEffect)
       -- duplicates permitted

-- We only check there are no duplicates at top level. If it may be nested,
-- it may presumably be duplicated inside the nesting as well.
validateOnlyOne :: [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateOnlyOne :: [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateOnlyOne effs :: [Effect]
effs t :: Text
t f :: Effect -> Bool
f =
  let ts :: [Effect]
ts = (Effect -> Bool) -> [Effect] -> [Effect]
forall a. (a -> Bool) -> [a] -> [a]
filter Effect -> Bool
f [Effect]
effs
  in ["more than one" Text -> Text -> Text
<+> Text
t Text -> Text -> Text
<+> "specification" | [Effect] -> Int
forall a. [a] -> Int
length [Effect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1]

-- We check it's not nested one nor more levels.
validateNotNested :: [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateNotNested :: [Effect] -> Text -> (Effect -> Bool) -> [Text]
validateNotNested effs :: [Effect]
effs t :: Text
t f :: Effect -> Bool
f =
  let g :: Effect -> Bool
g (OneOf l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
f [Effect]
l Bool -> Bool -> Bool
|| (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
g [Effect]
l
      g (OnSmash effect :: Effect
effect) = Effect -> Bool
f Effect
effect Bool -> Bool -> Bool
|| Effect -> Bool
g Effect
effect
      g (Composite l :: [Effect]
l) = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
f [Effect]
l Bool -> Bool -> Bool
|| (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Effect -> Bool
g [Effect]
l
      g _ = Bool
False
      ts :: [Effect]
ts = (Effect -> Bool) -> [Effect] -> [Effect]
forall a. (a -> Bool) -> [a] -> [a]
filter Effect -> Bool
g [Effect]
effs
  in [ "effect" Text -> Text -> Text
<+> Text
t Text -> Text -> Text
<+> "should be specified at top level, not nested"
     | [Effect] -> Int
forall a. [a] -> Int
length [Effect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 ]

validateDups :: ItemKind -> Aspect -> [Text]
validateDups :: ItemKind -> Aspect -> [Text]
validateDups ItemKind{..} feat :: Aspect
feat =
  let ts :: [Aspect]
ts = (Aspect -> Bool) -> [Aspect] -> [Aspect]
forall a. (a -> Bool) -> [a] -> [a]
filter (Aspect -> Aspect -> Bool
forall a. Eq a => a -> a -> Bool
== Aspect
feat) [Aspect]
iaspects
  in ["more than one" Text -> Text -> Text
<+> Aspect -> Text
forall a. Show a => a -> Text
tshow Aspect
feat Text -> Text -> Text
<+> "specification" | [Aspect] -> Int
forall a. [a] -> Int
length [Aspect]
ts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1]

validateDamage :: Dice.Dice -> [Text]
validateDamage :: Dice -> [Text]
validateDamage dice :: Dice
dice = [ "potentially negative dice:" Text -> Text -> Text
<+> Dice -> Text
forall a. Show a => a -> Text
tshow Dice
dice
                      | Dice -> Int
Dice.infDice Dice
dice Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0]

-- | Validate all item kinds.
validateAll :: [ItemKind] -> ContentData ItemKind -> [Text]
validateAll :: [ItemKind] -> ContentData ItemKind -> [Text]
validateAll content :: [ItemKind]
content coitem :: ContentData ItemKind
coitem =
  let missingKitGroups :: [GroupName ItemKind]
missingKitGroups = [ GroupName ItemKind
cgroup
                      | ItemKind
k <- [ItemKind]
content
                      , (cgroup :: GroupName ItemKind
cgroup, _) <- ItemKind -> [(GroupName ItemKind, CStore)]
ikit ItemKind
k
                      , Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ContentData ItemKind -> GroupName ItemKind -> Bool
forall a. ContentData a -> GroupName a -> Bool
omemberGroup ContentData ItemKind
coitem GroupName ItemKind
cgroup ]
      f :: Aspect -> Bool
      f :: Aspect -> Bool
f HideAs{} = Bool
True
      f _ = Bool
False
      wrongHideAsGroups :: [GroupName ItemKind]
wrongHideAsGroups =
        [ GroupName ItemKind
cgroup
        | ItemKind
k <- [ItemKind]
content
        , let (cgroup :: GroupName ItemKind
cgroup, notSingleton :: Bool
notSingleton) = case (Aspect -> Bool) -> [Aspect] -> Maybe Aspect
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find Aspect -> Bool
f (ItemKind -> [Aspect]
iaspects ItemKind
k) of
                Just (HideAs grp :: GroupName ItemKind
grp) | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ContentData ItemKind -> GroupName ItemKind -> Bool
forall a. ContentData a -> GroupName a -> Bool
oisSingletonGroup ContentData ItemKind
coitem GroupName ItemKind
grp ->
                  (GroupName ItemKind
grp, Bool
True)
                _ -> (GroupName ItemKind
forall a. HasCallStack => a
undefined, Bool
False)
        , Bool
notSingleton
        ]
      g :: Effect -> Maybe (GroupName ItemKind)
      g :: Effect -> Maybe (GroupName ItemKind)
g (Explode grp :: GroupName ItemKind
grp) = GroupName ItemKind -> Maybe (GroupName ItemKind)
forall a. a -> Maybe a
Just GroupName ItemKind
grp
      g (Summon grp :: GroupName ItemKind
grp _) = GroupName ItemKind -> Maybe (GroupName ItemKind)
forall a. a -> Maybe a
Just GroupName ItemKind
grp
      g (CreateItem _ grp :: GroupName ItemKind
grp _) = GroupName ItemKind -> Maybe (GroupName ItemKind)
forall a. a -> Maybe a
Just GroupName ItemKind
grp
      g (DropItem _ _ _ grp :: GroupName ItemKind
grp) = GroupName ItemKind -> Maybe (GroupName ItemKind)
forall a. a -> Maybe a
Just GroupName ItemKind
grp
      g _ = Maybe (GroupName ItemKind)
forall a. Maybe a
Nothing
      missingEffectGroups :: [(Text, [GroupName ItemKind])]
missingEffectGroups =
        [ (ItemKind -> Text
iname ItemKind
k, [GroupName ItemKind]
absGroups)
        | ItemKind
k <- [ItemKind]
content
        , let grps :: [GroupName ItemKind]
grps = (Effect -> Maybe (GroupName ItemKind))
-> [Effect] -> [GroupName ItemKind]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Effect -> Maybe (GroupName ItemKind)
g ([Effect] -> [GroupName ItemKind])
-> [Effect] -> [GroupName ItemKind]
forall a b. (a -> b) -> a -> b
$ ItemKind -> [Effect]
ieffects ItemKind
k
              absGroups :: [GroupName ItemKind]
absGroups = (GroupName ItemKind -> Bool)
-> [GroupName ItemKind] -> [GroupName ItemKind]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> (GroupName ItemKind -> Bool) -> GroupName ItemKind -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContentData ItemKind -> GroupName ItemKind -> Bool
forall a. ContentData a -> GroupName a -> Bool
omemberGroup ContentData ItemKind
coitem) [GroupName ItemKind]
grps
        , Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GroupName ItemKind] -> Bool
forall a. [a] -> Bool
null [GroupName ItemKind]
absGroups
        ]
      missingHardwiredGroups :: [GroupName ItemKind]
missingHardwiredGroups =
        (GroupName ItemKind -> Bool)
-> [GroupName ItemKind] -> [GroupName ItemKind]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> (GroupName ItemKind -> Bool) -> GroupName ItemKind -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContentData ItemKind -> GroupName ItemKind -> Bool
forall a. ContentData a -> GroupName a -> Bool
omemberGroup ContentData ItemKind
coitem) [GroupName ItemKind]
hardwiredItemGroups
  in [ "no ikit groups in content:" Text -> Text -> Text
<+> [GroupName ItemKind] -> Text
forall a. Show a => a -> Text
tshow [GroupName ItemKind]
missingKitGroups
     | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GroupName ItemKind] -> Bool
forall a. [a] -> Bool
null [GroupName ItemKind]
missingKitGroups ]
     [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "HideAs groups not singletons:" Text -> Text -> Text
<+> [GroupName ItemKind] -> Text
forall a. Show a => a -> Text
tshow [GroupName ItemKind]
wrongHideAsGroups
        | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GroupName ItemKind] -> Bool
forall a. [a] -> Bool
null [GroupName ItemKind]
wrongHideAsGroups ]
     [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "mentioned groups not in content:" Text -> Text -> Text
<+> [(Text, [GroupName ItemKind])] -> Text
forall a. Show a => a -> Text
tshow [(Text, [GroupName ItemKind])]
missingEffectGroups
        | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [(Text, [GroupName ItemKind])] -> Bool
forall a. [a] -> Bool
null [(Text, [GroupName ItemKind])]
missingEffectGroups ]
     [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ "hardwired groups not in content:" Text -> Text -> Text
<+> [GroupName ItemKind] -> Text
forall a. Show a => a -> Text
tshow [GroupName ItemKind]
missingHardwiredGroups
        | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [GroupName ItemKind] -> Bool
forall a. [a] -> Bool
null [GroupName ItemKind]
missingHardwiredGroups ]

hardwiredItemGroups :: [GroupName ItemKind]
hardwiredItemGroups :: [GroupName ItemKind]
hardwiredItemGroups =
  -- From Preferences.hs:
  ["condition", "common item"]
    -- the others are optional:
    -- "curious item", "treasure", "any scroll", "any vial",
    -- "potion", "explosive", "any jewelry"
  -- Assorted:
  [GroupName ItemKind]
-> [GroupName ItemKind] -> [GroupName ItemKind]
forall a. [a] -> [a] -> [a]
++ ["bonus HP", "braced", "asleep", "impressed", "currency", "mobile"]

makeData :: [ItemKind] -> ContentData ItemKind
makeData :: [ItemKind] -> ContentData ItemKind
makeData = String
-> (ItemKind -> Text)
-> (ItemKind -> Freqs ItemKind)
-> (ItemKind -> [Text])
-> ([ItemKind] -> ContentData ItemKind -> [Text])
-> [ItemKind]
-> ContentData ItemKind
forall c.
Show c =>
String
-> (c -> Text)
-> (c -> Freqs c)
-> (c -> [Text])
-> ([c] -> ContentData c -> [Text])
-> [c]
-> ContentData c
makeContentData "ItemKind" ItemKind -> Text
iname ItemKind -> Freqs ItemKind
ifreq ItemKind -> [Text]
validateSingle [ItemKind] -> ContentData ItemKind -> [Text]
validateAll