{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, TupleSections #-}
module Game.LambdaHack.Common.Item
( Item(..), ItemIdentity(..)
, ItemKindIx, ItemDisco(..), ItemFull(..), ItemFullKit
, DiscoveryKind, DiscoveryAspect, ItemIxMap, Benefit(..), DiscoveryBenefit
, ItemTimer, ItemQuant, ItemBag, ItemDict
, itemToFull6, aspectRecordFull, strongestSlot, ncharges, hasCharge
, strongestMelee, unknownMeleeBonus, unknownSpeedBonus
, conditionMeleeBonus, conditionSpeedBonus, armorHurtCalculation
#ifdef EXPOSE_INTERNAL
, valueAtEqpSlot, unknownAspect
#endif
) where
import Prelude ()
import Game.LambdaHack.Core.Prelude
import Data.Binary
import qualified Data.EnumMap.Strict as EM
import qualified Data.EnumSet as ES
import Data.Hashable (Hashable)
import qualified Data.Ix as Ix
import qualified Data.Ord as Ord
import GHC.Generics (Generic)
import qualified Game.LambdaHack.Common.ItemAspect as IA
import Game.LambdaHack.Common.Kind
import Game.LambdaHack.Common.Time
import Game.LambdaHack.Common.Types
import qualified Game.LambdaHack.Content.ItemKind as IK
import qualified Game.LambdaHack.Core.Dice as Dice
import Game.LambdaHack.Definition.Ability (EqpSlot (..))
import qualified Game.LambdaHack.Definition.Ability as Ability
import Game.LambdaHack.Definition.Defs
import Game.LambdaHack.Definition.Flavour
data Item = Item
{ Item -> ItemIdentity
jkind :: ItemIdentity
, Item -> Maybe FactionId
jfid :: Maybe FactionId
, Item -> Flavour
jflavour :: Flavour
}
deriving (Int -> Item -> ShowS
[Item] -> ShowS
Item -> String
(Int -> Item -> ShowS)
-> (Item -> String) -> ([Item] -> ShowS) -> Show Item
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Item] -> ShowS
$cshowList :: [Item] -> ShowS
show :: Item -> String
$cshow :: Item -> String
showsPrec :: Int -> Item -> ShowS
$cshowsPrec :: Int -> Item -> ShowS
Show, Item -> Item -> Bool
(Item -> Item -> Bool) -> (Item -> Item -> Bool) -> Eq Item
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Item -> Item -> Bool
$c/= :: Item -> Item -> Bool
== :: Item -> Item -> Bool
$c== :: Item -> Item -> Bool
Eq, (forall x. Item -> Rep Item x)
-> (forall x. Rep Item x -> Item) -> Generic Item
forall x. Rep Item x -> Item
forall x. Item -> Rep Item x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Item x -> Item
$cfrom :: forall x. Item -> Rep Item x
Generic)
instance Hashable Item
instance Binary Item
data ItemIdentity =
IdentityObvious (ContentId IK.ItemKind)
| IdentityCovered ItemKindIx (ContentId IK.ItemKind)
deriving (Int -> ItemIdentity -> ShowS
[ItemIdentity] -> ShowS
ItemIdentity -> String
(Int -> ItemIdentity -> ShowS)
-> (ItemIdentity -> String)
-> ([ItemIdentity] -> ShowS)
-> Show ItemIdentity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemIdentity] -> ShowS
$cshowList :: [ItemIdentity] -> ShowS
show :: ItemIdentity -> String
$cshow :: ItemIdentity -> String
showsPrec :: Int -> ItemIdentity -> ShowS
$cshowsPrec :: Int -> ItemIdentity -> ShowS
Show, ItemIdentity -> ItemIdentity -> Bool
(ItemIdentity -> ItemIdentity -> Bool)
-> (ItemIdentity -> ItemIdentity -> Bool) -> Eq ItemIdentity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ItemIdentity -> ItemIdentity -> Bool
$c/= :: ItemIdentity -> ItemIdentity -> Bool
== :: ItemIdentity -> ItemIdentity -> Bool
$c== :: ItemIdentity -> ItemIdentity -> Bool
Eq, (forall x. ItemIdentity -> Rep ItemIdentity x)
-> (forall x. Rep ItemIdentity x -> ItemIdentity)
-> Generic ItemIdentity
forall x. Rep ItemIdentity x -> ItemIdentity
forall x. ItemIdentity -> Rep ItemIdentity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ItemIdentity x -> ItemIdentity
$cfrom :: forall x. ItemIdentity -> Rep ItemIdentity x
Generic)
instance Hashable ItemIdentity
instance Binary ItemIdentity
type DiscoveryAspect = EM.EnumMap ItemId IA.AspectRecord
newtype ItemKindIx = ItemKindIx Word16
deriving (Int -> ItemKindIx -> ShowS
[ItemKindIx] -> ShowS
ItemKindIx -> String
(Int -> ItemKindIx -> ShowS)
-> (ItemKindIx -> String)
-> ([ItemKindIx] -> ShowS)
-> Show ItemKindIx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemKindIx] -> ShowS
$cshowList :: [ItemKindIx] -> ShowS
show :: ItemKindIx -> String
$cshow :: ItemKindIx -> String
showsPrec :: Int -> ItemKindIx -> ShowS
$cshowsPrec :: Int -> ItemKindIx -> ShowS
Show, ItemKindIx -> ItemKindIx -> Bool
(ItemKindIx -> ItemKindIx -> Bool)
-> (ItemKindIx -> ItemKindIx -> Bool) -> Eq ItemKindIx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ItemKindIx -> ItemKindIx -> Bool
$c/= :: ItemKindIx -> ItemKindIx -> Bool
== :: ItemKindIx -> ItemKindIx -> Bool
$c== :: ItemKindIx -> ItemKindIx -> Bool
Eq, Eq ItemKindIx
Eq ItemKindIx =>
(ItemKindIx -> ItemKindIx -> Ordering)
-> (ItemKindIx -> ItemKindIx -> Bool)
-> (ItemKindIx -> ItemKindIx -> Bool)
-> (ItemKindIx -> ItemKindIx -> Bool)
-> (ItemKindIx -> ItemKindIx -> Bool)
-> (ItemKindIx -> ItemKindIx -> ItemKindIx)
-> (ItemKindIx -> ItemKindIx -> ItemKindIx)
-> Ord ItemKindIx
ItemKindIx -> ItemKindIx -> Bool
ItemKindIx -> ItemKindIx -> Ordering
ItemKindIx -> ItemKindIx -> ItemKindIx
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 :: ItemKindIx -> ItemKindIx -> ItemKindIx
$cmin :: ItemKindIx -> ItemKindIx -> ItemKindIx
max :: ItemKindIx -> ItemKindIx -> ItemKindIx
$cmax :: ItemKindIx -> ItemKindIx -> ItemKindIx
>= :: ItemKindIx -> ItemKindIx -> Bool
$c>= :: ItemKindIx -> ItemKindIx -> Bool
> :: ItemKindIx -> ItemKindIx -> Bool
$c> :: ItemKindIx -> ItemKindIx -> Bool
<= :: ItemKindIx -> ItemKindIx -> Bool
$c<= :: ItemKindIx -> ItemKindIx -> Bool
< :: ItemKindIx -> ItemKindIx -> Bool
$c< :: ItemKindIx -> ItemKindIx -> Bool
compare :: ItemKindIx -> ItemKindIx -> Ordering
$ccompare :: ItemKindIx -> ItemKindIx -> Ordering
$cp1Ord :: Eq ItemKindIx
Ord, Int -> ItemKindIx
ItemKindIx -> Int
ItemKindIx -> [ItemKindIx]
ItemKindIx -> ItemKindIx
ItemKindIx -> ItemKindIx -> [ItemKindIx]
ItemKindIx -> ItemKindIx -> ItemKindIx -> [ItemKindIx]
(ItemKindIx -> ItemKindIx)
-> (ItemKindIx -> ItemKindIx)
-> (Int -> ItemKindIx)
-> (ItemKindIx -> Int)
-> (ItemKindIx -> [ItemKindIx])
-> (ItemKindIx -> ItemKindIx -> [ItemKindIx])
-> (ItemKindIx -> ItemKindIx -> [ItemKindIx])
-> (ItemKindIx -> ItemKindIx -> ItemKindIx -> [ItemKindIx])
-> Enum ItemKindIx
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: ItemKindIx -> ItemKindIx -> ItemKindIx -> [ItemKindIx]
$cenumFromThenTo :: ItemKindIx -> ItemKindIx -> ItemKindIx -> [ItemKindIx]
enumFromTo :: ItemKindIx -> ItemKindIx -> [ItemKindIx]
$cenumFromTo :: ItemKindIx -> ItemKindIx -> [ItemKindIx]
enumFromThen :: ItemKindIx -> ItemKindIx -> [ItemKindIx]
$cenumFromThen :: ItemKindIx -> ItemKindIx -> [ItemKindIx]
enumFrom :: ItemKindIx -> [ItemKindIx]
$cenumFrom :: ItemKindIx -> [ItemKindIx]
fromEnum :: ItemKindIx -> Int
$cfromEnum :: ItemKindIx -> Int
toEnum :: Int -> ItemKindIx
$ctoEnum :: Int -> ItemKindIx
pred :: ItemKindIx -> ItemKindIx
$cpred :: ItemKindIx -> ItemKindIx
succ :: ItemKindIx -> ItemKindIx
$csucc :: ItemKindIx -> ItemKindIx
Enum, Ord ItemKindIx
Ord ItemKindIx =>
((ItemKindIx, ItemKindIx) -> [ItemKindIx])
-> ((ItemKindIx, ItemKindIx) -> ItemKindIx -> Int)
-> ((ItemKindIx, ItemKindIx) -> ItemKindIx -> Int)
-> ((ItemKindIx, ItemKindIx) -> ItemKindIx -> Bool)
-> ((ItemKindIx, ItemKindIx) -> Int)
-> ((ItemKindIx, ItemKindIx) -> Int)
-> Ix ItemKindIx
(ItemKindIx, ItemKindIx) -> Int
(ItemKindIx, ItemKindIx) -> [ItemKindIx]
(ItemKindIx, ItemKindIx) -> ItemKindIx -> Bool
(ItemKindIx, ItemKindIx) -> ItemKindIx -> Int
forall a.
Ord a =>
((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (ItemKindIx, ItemKindIx) -> Int
$cunsafeRangeSize :: (ItemKindIx, ItemKindIx) -> Int
rangeSize :: (ItemKindIx, ItemKindIx) -> Int
$crangeSize :: (ItemKindIx, ItemKindIx) -> Int
inRange :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Bool
$cinRange :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Bool
unsafeIndex :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Int
$cunsafeIndex :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Int
index :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Int
$cindex :: (ItemKindIx, ItemKindIx) -> ItemKindIx -> Int
range :: (ItemKindIx, ItemKindIx) -> [ItemKindIx]
$crange :: (ItemKindIx, ItemKindIx) -> [ItemKindIx]
$cp1Ix :: Ord ItemKindIx
Ix.Ix, Int -> ItemKindIx -> Int
ItemKindIx -> Int
(Int -> ItemKindIx -> Int)
-> (ItemKindIx -> Int) -> Hashable ItemKindIx
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: ItemKindIx -> Int
$chash :: ItemKindIx -> Int
hashWithSalt :: Int -> ItemKindIx -> Int
$chashWithSalt :: Int -> ItemKindIx -> Int
Hashable, Get ItemKindIx
[ItemKindIx] -> Put
ItemKindIx -> Put
(ItemKindIx -> Put)
-> Get ItemKindIx -> ([ItemKindIx] -> Put) -> Binary ItemKindIx
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
putList :: [ItemKindIx] -> Put
$cputList :: [ItemKindIx] -> Put
get :: Get ItemKindIx
$cget :: Get ItemKindIx
put :: ItemKindIx -> Put
$cput :: ItemKindIx -> Put
Binary)
data ItemDisco =
ItemDiscoFull IA.AspectRecord
| ItemDiscoMean IA.KindMean
deriving (Int -> ItemDisco -> ShowS
[ItemDisco] -> ShowS
ItemDisco -> String
(Int -> ItemDisco -> ShowS)
-> (ItemDisco -> String)
-> ([ItemDisco] -> ShowS)
-> Show ItemDisco
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemDisco] -> ShowS
$cshowList :: [ItemDisco] -> ShowS
show :: ItemDisco -> String
$cshow :: ItemDisco -> String
showsPrec :: Int -> ItemDisco -> ShowS
$cshowsPrec :: Int -> ItemDisco -> ShowS
Show, ItemDisco -> ItemDisco -> Bool
(ItemDisco -> ItemDisco -> Bool)
-> (ItemDisco -> ItemDisco -> Bool) -> Eq ItemDisco
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ItemDisco -> ItemDisco -> Bool
$c/= :: ItemDisco -> ItemDisco -> Bool
== :: ItemDisco -> ItemDisco -> Bool
$c== :: ItemDisco -> ItemDisco -> Bool
Eq, Eq ItemDisco
Eq ItemDisco =>
(ItemDisco -> ItemDisco -> Ordering)
-> (ItemDisco -> ItemDisco -> Bool)
-> (ItemDisco -> ItemDisco -> Bool)
-> (ItemDisco -> ItemDisco -> Bool)
-> (ItemDisco -> ItemDisco -> Bool)
-> (ItemDisco -> ItemDisco -> ItemDisco)
-> (ItemDisco -> ItemDisco -> ItemDisco)
-> Ord ItemDisco
ItemDisco -> ItemDisco -> Bool
ItemDisco -> ItemDisco -> Ordering
ItemDisco -> ItemDisco -> ItemDisco
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 :: ItemDisco -> ItemDisco -> ItemDisco
$cmin :: ItemDisco -> ItemDisco -> ItemDisco
max :: ItemDisco -> ItemDisco -> ItemDisco
$cmax :: ItemDisco -> ItemDisco -> ItemDisco
>= :: ItemDisco -> ItemDisco -> Bool
$c>= :: ItemDisco -> ItemDisco -> Bool
> :: ItemDisco -> ItemDisco -> Bool
$c> :: ItemDisco -> ItemDisco -> Bool
<= :: ItemDisco -> ItemDisco -> Bool
$c<= :: ItemDisco -> ItemDisco -> Bool
< :: ItemDisco -> ItemDisco -> Bool
$c< :: ItemDisco -> ItemDisco -> Bool
compare :: ItemDisco -> ItemDisco -> Ordering
$ccompare :: ItemDisco -> ItemDisco -> Ordering
$cp1Ord :: Eq ItemDisco
Ord)
data ItemFull = ItemFull
{ ItemFull -> Item
itemBase :: Item
, ItemFull -> ContentId ItemKind
itemKindId :: ContentId IK.ItemKind
, ItemFull -> ItemKind
itemKind :: IK.ItemKind
, ItemFull -> ItemDisco
itemDisco :: ItemDisco
, ItemFull -> Bool
itemSuspect :: Bool
}
deriving Int -> ItemFull -> ShowS
[ItemFull] -> ShowS
ItemFull -> String
(Int -> ItemFull -> ShowS)
-> (ItemFull -> String) -> ([ItemFull] -> ShowS) -> Show ItemFull
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemFull] -> ShowS
$cshowList :: [ItemFull] -> ShowS
show :: ItemFull -> String
$cshow :: ItemFull -> String
showsPrec :: Int -> ItemFull -> ShowS
$cshowsPrec :: Int -> ItemFull -> ShowS
Show
type ItemFullKit = (ItemFull, ItemQuant)
type DiscoveryKind = EM.EnumMap ItemKindIx (ContentId IK.ItemKind)
type ItemIxMap = EM.EnumMap ItemKindIx (ES.EnumSet ItemId)
data Benefit = Benefit
{ Benefit -> Bool
benInEqp :: Bool
, Benefit -> Double
benPickup :: Double
, Benefit -> Double
benApply :: Double
, Benefit -> Double
benMelee :: Double
, Benefit -> Double
benFling :: Double
}
deriving (Int -> Benefit -> ShowS
[Benefit] -> ShowS
Benefit -> String
(Int -> Benefit -> ShowS)
-> (Benefit -> String) -> ([Benefit] -> ShowS) -> Show Benefit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Benefit] -> ShowS
$cshowList :: [Benefit] -> ShowS
show :: Benefit -> String
$cshow :: Benefit -> String
showsPrec :: Int -> Benefit -> ShowS
$cshowsPrec :: Int -> Benefit -> ShowS
Show, (forall x. Benefit -> Rep Benefit x)
-> (forall x. Rep Benefit x -> Benefit) -> Generic Benefit
forall x. Rep Benefit x -> Benefit
forall x. Benefit -> Rep Benefit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Benefit x -> Benefit
$cfrom :: forall x. Benefit -> Rep Benefit x
Generic)
instance Binary Benefit
type DiscoveryBenefit = EM.EnumMap ItemId Benefit
type ItemTimer = [Time]
type ItemQuant = (Int, ItemTimer)
type ItemBag = EM.EnumMap ItemId ItemQuant
type ItemDict = EM.EnumMap ItemId Item
itemToFull6 :: COps -> DiscoveryKind -> DiscoveryAspect -> ItemId -> Item
-> ItemFull
itemToFull6 :: COps
-> DiscoveryKind -> DiscoveryAspect -> ItemId -> Item -> ItemFull
itemToFull6 COps{ContentData ItemKind
coitem :: COps -> ContentData ItemKind
coitem :: ContentData ItemKind
coitem, ItemSpeedup
coItemSpeedup :: COps -> ItemSpeedup
coItemSpeedup :: ItemSpeedup
coItemSpeedup} discoKind :: DiscoveryKind
discoKind discoAspect :: DiscoveryAspect
discoAspect iid :: ItemId
iid itemBase :: Item
itemBase =
let (itemKindId :: ContentId ItemKind
itemKindId, itemSuspect :: Bool
itemSuspect) = case Item -> ItemIdentity
jkind Item
itemBase of
IdentityObvious ik :: ContentId ItemKind
ik -> (ContentId ItemKind
ik, Bool
False)
IdentityCovered ix :: ItemKindIx
ix ik :: ContentId ItemKind
ik ->
(ContentId ItemKind, Bool)
-> (ContentId ItemKind -> (ContentId ItemKind, Bool))
-> Maybe (ContentId ItemKind)
-> (ContentId ItemKind, Bool)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (ContentId ItemKind
ik, Bool
True) (, Bool
False) (Maybe (ContentId ItemKind) -> (ContentId ItemKind, Bool))
-> Maybe (ContentId ItemKind) -> (ContentId ItemKind, Bool)
forall a b. (a -> b) -> a -> b
$ ItemKindIx
ix ItemKindIx -> DiscoveryKind -> Maybe (ContentId ItemKind)
forall k a. Enum k => k -> EnumMap k a -> Maybe a
`EM.lookup` DiscoveryKind
discoKind
itemKind :: ItemKind
itemKind = ContentData ItemKind -> ContentId ItemKind -> ItemKind
forall a. ContentData a -> ContentId a -> a
okind ContentData ItemKind
coitem ContentId ItemKind
itemKindId
km :: KindMean
km = ContentId ItemKind -> ItemSpeedup -> KindMean
getKindMean ContentId ItemKind
itemKindId ItemSpeedup
coItemSpeedup
itemAspectMean :: KindMean
itemAspectMean | Bool
itemSuspect = KindMean
km {kmConst :: Bool
IA.kmConst = Bool
False}
| Bool
otherwise = KindMean
km
itemDisco :: ItemDisco
itemDisco = case ItemId -> DiscoveryAspect -> Maybe AspectRecord
forall k a. Enum k => k -> EnumMap k a -> Maybe a
EM.lookup ItemId
iid DiscoveryAspect
discoAspect of
Just itemAspect :: AspectRecord
itemAspect -> AspectRecord -> ItemDisco
ItemDiscoFull AspectRecord
itemAspect
Nothing -> KindMean -> ItemDisco
ItemDiscoMean KindMean
itemAspectMean
in $WItemFull :: Item
-> ContentId ItemKind -> ItemKind -> ItemDisco -> Bool -> ItemFull
ItemFull {..}
aspectRecordFull :: ItemFull -> IA.AspectRecord
aspectRecordFull :: ItemFull -> AspectRecord
aspectRecordFull itemFull :: ItemFull
itemFull =
case ItemFull -> ItemDisco
itemDisco ItemFull
itemFull of
ItemDiscoFull itemAspect :: AspectRecord
itemAspect -> AspectRecord
itemAspect
ItemDiscoMean itemAspectMean :: KindMean
itemAspectMean -> KindMean -> AspectRecord
IA.kmMean KindMean
itemAspectMean
strongestSlot :: DiscoveryBenefit -> Ability.EqpSlot -> [(ItemId, ItemFullKit)]
-> [(Int, (ItemId, ItemFullKit))]
strongestSlot :: DiscoveryBenefit
-> EqpSlot
-> [(ItemId, ItemFullKit)]
-> [(Int, (ItemId, ItemFullKit))]
strongestSlot discoBenefit :: DiscoveryBenefit
discoBenefit eqpSlot :: EqpSlot
eqpSlot is :: [(ItemId, ItemFullKit)]
is =
let f :: (ItemId, ItemFullKit) -> Maybe (Int, (ItemId, ItemFullKit))
f (iid :: ItemId
iid, (itemFull :: ItemFull
itemFull, kit :: ItemQuant
kit)) =
let Benefit{Bool
benInEqp :: Bool
benInEqp :: Benefit -> Bool
benInEqp, Double
benPickup :: Double
benPickup :: Benefit -> Double
benPickup, Double
benMelee :: Double
benMelee :: Benefit -> Double
benMelee} = DiscoveryBenefit
discoBenefit DiscoveryBenefit -> ItemId -> Benefit
forall k a. Enum k => EnumMap k a -> k -> a
EM.! ItemId
iid
in if Bool -> Bool
not Bool
benInEqp
then Maybe (Int, (ItemId, ItemFullKit))
forall a. Maybe a
Nothing
else (Int, (ItemId, ItemFullKit)) -> Maybe (Int, (ItemId, ItemFullKit))
forall a. a -> Maybe a
Just ((Int, (ItemId, ItemFullKit))
-> Maybe (Int, (ItemId, ItemFullKit)))
-> (Int, (ItemId, ItemFullKit))
-> Maybe (Int, (ItemId, ItemFullKit))
forall a b. (a -> b) -> a -> b
$
let ben :: Int
ben = case EqpSlot
eqpSlot of
EqpSlotWeaponFast ->
Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
ceiling Double
benPickup
EqpSlotWeaponBig ->
Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (- Double
benMelee)
_ -> EqpSlot -> AspectRecord -> Int
valueAtEqpSlot EqpSlot
eqpSlot (AspectRecord -> Int) -> AspectRecord -> Int
forall a b. (a -> b) -> a -> b
$ ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
in (Int
ben, (ItemId
iid, (ItemFull
itemFull, ItemQuant
kit)))
in ((Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit)) -> Ordering)
-> [(Int, (ItemId, ItemFullKit))] -> [(Int, (ItemId, ItemFullKit))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit)) -> Ordering)
-> (Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit))
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit)) -> Ordering)
-> (Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit))
-> Ordering)
-> ((Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit)) -> Ordering)
-> (Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit))
-> Ordering
forall a b. (a -> b) -> a -> b
$ ((Int, (ItemId, ItemFullKit)) -> Int)
-> (Int, (ItemId, ItemFullKit))
-> (Int, (ItemId, ItemFullKit))
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
Ord.comparing (Int, (ItemId, ItemFullKit)) -> Int
forall a b. (a, b) -> a
fst) ([(Int, (ItemId, ItemFullKit))] -> [(Int, (ItemId, ItemFullKit))])
-> [(Int, (ItemId, ItemFullKit))] -> [(Int, (ItemId, ItemFullKit))]
forall a b. (a -> b) -> a -> b
$ ((ItemId, ItemFullKit) -> Maybe (Int, (ItemId, ItemFullKit)))
-> [(ItemId, ItemFullKit)] -> [(Int, (ItemId, ItemFullKit))]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (ItemId, ItemFullKit) -> Maybe (Int, (ItemId, ItemFullKit))
f [(ItemId, ItemFullKit)]
is
valueAtEqpSlot :: EqpSlot -> IA.AspectRecord -> Int
valueAtEqpSlot :: EqpSlot -> AspectRecord -> Int
valueAtEqpSlot eqpSlot :: EqpSlot
eqpSlot arItem :: AspectRecord
arItem@IA.AspectRecord{..} =
case EqpSlot
eqpSlot of
EqpSlotMove -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMove Skills
aSkills
EqpSlotMelee -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMelee Skills
aSkills
EqpSlotDisplace -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkDisplace Skills
aSkills
EqpSlotAlter -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkAlter Skills
aSkills
EqpSlotWait -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkWait Skills
aSkills
EqpSlotMoveItem -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMoveItem Skills
aSkills
EqpSlotProject -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkProject Skills
aSkills
EqpSlotApply -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkApply Skills
aSkills
EqpSlotSwimming -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSwimming Skills
aSkills
EqpSlotFlying -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkFlying Skills
aSkills
EqpSlotHurtMelee -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkHurtMelee Skills
aSkills
EqpSlotArmorMelee -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkArmorMelee Skills
aSkills
EqpSlotArmorRanged -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkArmorRanged Skills
aSkills
EqpSlotMaxHP -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxHP Skills
aSkills
EqpSlotSpeed -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSpeed Skills
aSkills
EqpSlotSight -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSight Skills
aSkills
EqpSlotShine -> Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkShine Skills
aSkills
EqpSlotMiscBonus ->
Int
aTimeout
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkMaxCalm Skills
aSkills
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkSmell Skills
aSkills
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkNocto Skills
aSkills
EqpSlotWeaponFast -> String -> Int
forall a. HasCallStack => String -> a
error (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ "" String -> AspectRecord -> String
forall v. Show v => String -> v -> String
`showFailure` AspectRecord
arItem
EqpSlotWeaponBig -> String -> Int
forall a. HasCallStack => String -> a
error (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ "" String -> AspectRecord -> String
forall v. Show v => String -> v -> String
`showFailure` AspectRecord
arItem
ncharges :: Time -> ItemFull -> ItemQuant -> Int
ncharges :: Time -> ItemFull -> ItemQuant -> Int
ncharges localTime :: Time
localTime itemFull :: ItemFull
itemFull (itemK :: Int
itemK, itemTimer :: ItemTimer
itemTimer) =
let timeout :: Int
timeout = AspectRecord -> Int
IA.aTimeout (AspectRecord -> Int) -> AspectRecord -> Int
forall a b. (a -> b) -> a -> b
$ ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
timeoutTurns :: Delta Time
timeoutTurns = Delta Time -> Int -> Delta Time
timeDeltaScale (Time -> Delta Time
forall a. a -> Delta a
Delta Time
timeTurn) Int
timeout
charging :: Time -> Bool
charging startT :: Time
startT = Time -> Delta Time -> Time
timeShift Time
startT Delta Time
timeoutTurns Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
> Time
localTime
it1 :: ItemTimer
it1 = (Time -> Bool) -> ItemTimer -> ItemTimer
forall a. (a -> Bool) -> [a] -> [a]
filter Time -> Bool
charging ItemTimer
itemTimer
in Int
itemK Int -> Int -> Int
forall a. Num a => a -> a -> a
- ItemTimer -> Int
forall a. [a] -> Int
length ItemTimer
it1
hasCharge :: Time -> ItemFull -> ItemQuant -> Bool
hasCharge :: Time -> ItemFull -> ItemQuant -> Bool
hasCharge localTime :: Time
localTime itemFull :: ItemFull
itemFull (itemK :: Int
itemK, itemTimer :: ItemTimer
itemTimer) =
Time -> ItemFull -> ItemQuant -> Int
ncharges Time
localTime ItemFull
itemFull (Int
itemK, ItemTimer
itemTimer) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
strongestMelee :: Bool -> Maybe DiscoveryBenefit -> Time
-> [(ItemId, ItemFullKit)]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
strongestMelee :: Bool
-> Maybe DiscoveryBenefit
-> Time
-> [(ItemId, ItemFullKit)]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
strongestMelee _ _ _ [] = []
strongestMelee ignoreCharges :: Bool
ignoreCharges mdiscoBenefit :: Maybe DiscoveryBenefit
mdiscoBenefit localTime :: Time
localTime kitAss :: [(ItemId, ItemFullKit)]
kitAss =
let f :: (ItemId, ItemFullKit) -> (Double, (Int, (ItemId, ItemFullKit)))
f (iid :: ItemId
iid, (itemFull :: ItemFull
itemFull, kit :: ItemQuant
kit)) =
let rawDmg :: Double
rawDmg = ItemKind -> Double
IK.damageUsefulness (ItemKind -> Double) -> ItemKind -> Double
forall a b. (a -> b) -> a -> b
$ ItemFull -> ItemKind
itemKind ItemFull
itemFull
knownOrConstantAspects :: Bool
knownOrConstantAspects = case ItemFull -> ItemDisco
itemDisco ItemFull
itemFull of
ItemDiscoMean IA.KindMean{Bool
kmConst :: Bool
kmConst :: KindMean -> Bool
kmConst} -> Bool
kmConst
ItemDiscoFull{} -> Bool
True
unIDedBonus :: Double
unIDedBonus | Bool
knownOrConstantAspects
Bool -> Bool -> Bool
|| Maybe DiscoveryBenefit -> Bool
forall a. Maybe a -> Bool
isNothing Maybe DiscoveryBenefit
mdiscoBenefit = 0
| Bool
otherwise = 1000
totalValue :: Double
totalValue = case Maybe DiscoveryBenefit
mdiscoBenefit of
Just discoBenefit :: DiscoveryBenefit
discoBenefit ->
let Benefit{Double
benMelee :: Double
benMelee :: Benefit -> Double
benMelee} = DiscoveryBenefit
discoBenefit DiscoveryBenefit -> ItemId -> Benefit
forall k a. Enum k => EnumMap k a -> k -> a
EM.! ItemId
iid
in - Double
benMelee Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
unIDedBonus
Nothing -> Double
rawDmg
ncha :: Int
ncha = Time -> ItemFull -> ItemQuant -> Int
ncharges Time
localTime ItemFull
itemFull ItemQuant
kit
in ( if Bool
ignoreCharges Bool -> Bool -> Bool
|| Int
ncha Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
then Double
totalValue
else -100000
, (Int
ncha, (ItemId
iid, (ItemFull
itemFull, ItemQuant
kit))) )
in ((Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit))) -> Ordering)
-> [(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit))) -> Ordering)
-> (Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit)))
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit))) -> Ordering)
-> (Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit)))
-> Ordering)
-> ((Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit))) -> Ordering)
-> (Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit)))
-> Ordering
forall a b. (a -> b) -> a -> b
$ ((Double, (Int, (ItemId, ItemFullKit))) -> Double)
-> (Double, (Int, (ItemId, ItemFullKit)))
-> (Double, (Int, (ItemId, ItemFullKit)))
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
Ord.comparing (Double, (Int, (ItemId, ItemFullKit))) -> Double
forall a b. (a, b) -> a
fst)
([(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))])
-> [(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
forall a b. (a -> b) -> a -> b
$ ((Double, (Int, (ItemId, ItemFullKit))) -> Bool)
-> [(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> -100000) (Double -> Bool)
-> ((Double, (Int, (ItemId, ItemFullKit))) -> Double)
-> (Double, (Int, (ItemId, ItemFullKit)))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double, (Int, (ItemId, ItemFullKit))) -> Double
forall a b. (a, b) -> a
fst) ([(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))])
-> [(Double, (Int, (ItemId, ItemFullKit)))]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
forall a b. (a -> b) -> a -> b
$ ((ItemId, ItemFullKit) -> (Double, (Int, (ItemId, ItemFullKit))))
-> [(ItemId, ItemFullKit)]
-> [(Double, (Int, (ItemId, ItemFullKit)))]
forall a b. (a -> b) -> [a] -> [b]
map (ItemId, ItemFullKit) -> (Double, (Int, (ItemId, ItemFullKit)))
f [(ItemId, ItemFullKit)]
kitAss
unknownAspect :: (IK.Aspect -> [Dice.Dice]) -> ItemFull -> Bool
unknownAspect :: (Aspect -> [Dice]) -> ItemFull -> Bool
unknownAspect f :: Aspect -> [Dice]
f ItemFull{itemKind :: ItemFull -> ItemKind
itemKind=IK.ItemKind{[Aspect]
iaspects :: ItemKind -> [Aspect]
iaspects :: [Aspect]
iaspects}, ..} =
case ItemDisco
itemDisco of
ItemDiscoMean IA.KindMean{Bool
kmConst :: Bool
kmConst :: KindMean -> Bool
kmConst} ->
let unknown :: Dice -> Bool
unknown x :: Dice
x = let (minD :: Int
minD, maxD :: Int
maxD) = Dice -> (Int, Int)
Dice.infsupDice Dice
x
in Int
minD Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
maxD
in Bool
itemSuspect Bool -> Bool -> Bool
|| Bool -> Bool
not Bool
kmConst Bool -> Bool -> Bool
&& [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ((Aspect -> [Bool]) -> [Aspect] -> [Bool]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((Dice -> Bool) -> [Dice] -> [Bool]
forall a b. (a -> b) -> [a] -> [b]
map Dice -> Bool
unknown ([Dice] -> [Bool]) -> (Aspect -> [Dice]) -> Aspect -> [Bool]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Aspect -> [Dice]
f) [Aspect]
iaspects)
ItemDiscoFull{} -> Bool
False
unknownMeleeBonus :: [ItemFull] -> Bool
unknownMeleeBonus :: [ItemFull] -> Bool
unknownMeleeBonus =
let p :: Aspect -> [Dice]
p (IK.AddSkill Ability.SkHurtMelee k :: Dice
k) = [Dice
k]
p _ = []
f :: ItemFull -> Bool -> Bool
f itemFull :: ItemFull
itemFull b :: Bool
b = Bool
b Bool -> Bool -> Bool
|| (Aspect -> [Dice]) -> ItemFull -> Bool
unknownAspect Aspect -> [Dice]
p ItemFull
itemFull
in (ItemFull -> Bool -> Bool) -> Bool -> [ItemFull] -> Bool
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ItemFull -> Bool -> Bool
f Bool
False
unknownSpeedBonus :: [ItemFull] -> Bool
unknownSpeedBonus :: [ItemFull] -> Bool
unknownSpeedBonus =
let p :: Aspect -> [Dice]
p (IK.AddSkill Ability.SkSpeed k :: Dice
k) = [Dice
k]
p _ = []
f :: ItemFull -> Bool -> Bool
f itemFull :: ItemFull
itemFull b :: Bool
b = Bool
b Bool -> Bool -> Bool
|| (Aspect -> [Dice]) -> ItemFull -> Bool
unknownAspect Aspect -> [Dice]
p ItemFull
itemFull
in (ItemFull -> Bool -> Bool) -> Bool -> [ItemFull] -> Bool
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ItemFull -> Bool -> Bool
f Bool
False
conditionMeleeBonus :: [ItemFullKit] -> Int
conditionMeleeBonus :: [ItemFullKit] -> Int
conditionMeleeBonus kitAss :: [ItemFullKit]
kitAss =
let f :: (ItemFull, (Int, b)) -> Int -> Int
f (itemFull :: ItemFull
itemFull, (itemK :: Int
itemK, _)) k :: Int
k =
let arItem :: AspectRecord
arItem = ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
in if Flag -> AspectRecord -> Bool
IA.checkFlag Flag
Ability.Condition AspectRecord
arItem
then Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
itemK Int -> Int -> Int
forall a. Num a => a -> a -> a
* Skill -> AspectRecord -> Int
IA.getSkill Skill
Ability.SkHurtMelee AspectRecord
arItem
else Int
k
in (ItemFullKit -> Int -> Int) -> Int -> [ItemFullKit] -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ItemFullKit -> Int -> Int
forall b. (ItemFull, (Int, b)) -> Int -> Int
f 0 [ItemFullKit]
kitAss
conditionSpeedBonus :: [ItemFullKit] -> Int
conditionSpeedBonus :: [ItemFullKit] -> Int
conditionSpeedBonus kitAss :: [ItemFullKit]
kitAss =
let f :: (ItemFull, (Int, b)) -> Int -> Int
f (itemFull :: ItemFull
itemFull, (itemK :: Int
itemK, _)) k :: Int
k =
let arItem :: AspectRecord
arItem = ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
in if Flag -> AspectRecord -> Bool
IA.checkFlag Flag
Ability.Condition AspectRecord
arItem
then Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
itemK Int -> Int -> Int
forall a. Num a => a -> a -> a
* Skill -> AspectRecord -> Int
IA.getSkill Skill
Ability.SkSpeed AspectRecord
arItem
else Int
k
in (ItemFullKit -> Int -> Int) -> Int -> [ItemFullKit] -> Int
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ItemFullKit -> Int -> Int
forall b. (ItemFull, (Int, b)) -> Int -> Int
f 0 [ItemFullKit]
kitAss
armorHurtCalculation :: Bool -> Ability.Skills -> Ability.Skills -> Int
armorHurtCalculation :: Bool -> Skills -> Skills -> Int
armorHurtCalculation proj :: Bool
proj sMaxSk :: Skills
sMaxSk tMaxSk :: Skills
tMaxSk =
let trim200 :: a -> a
trim200 n :: a
n = a -> a -> a
forall a. Ord a => a -> a -> a
min 200 (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
forall a. Ord a => a -> a -> a
max (-200) a
n
itemBonus :: Int
itemBonus =
Int -> Int
forall a. (Ord a, Num a) => a -> a
trim200 (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkHurtMelee Skills
sMaxSk)
Int -> Int -> Int
forall a. Num a => a -> a -> a
- if Bool
proj
then Int -> Int
forall a. (Ord a, Num a) => a -> a
trim200 (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkArmorRanged Skills
tMaxSk)
else Int -> Int
forall a. (Ord a, Num a) => a -> a
trim200 (Skill -> Skills -> Int
Ability.getSk Skill
Ability.SkArmorMelee Skills
tMaxSk)
in 100 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
forall a. Ord a => a -> a -> a
min 99 (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max (-99) Int
itemBonus)