{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, TupleSections #-}
module Game.LambdaHack.Common.Item
( Item(..), ItemIdentity(..)
, ItemKindIx, ItemDisco(..), ItemFull(..), ItemFullKit
, DiscoveryKind, DiscoveryAspect, ItemIxMap, Benefit(..), DiscoveryBenefit
, ItemTimer, ItemTimers, ItemQuant, ItemBag, ItemDict
, toItemKindIx, quantSingle, itemToFull6, aspectRecordFull, strongestSlot
, itemTimerZero, createItemTimer, shiftItemTimer
, deltaOfItemTimer, charging, ncharges, hasCharge
, strongestMelee, unknownMeleeBonus, unknownSpeedBonus
, conditionMeleeBonus, conditionSpeedBonus, armorHurtCalculation
, mergeItemQuant, listToolsToConsume, subtractIidfromGrps
#ifdef EXPOSE_INTERNAL
, valueAtEqpSlot, unknownAspect, countIidConsumed
#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 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 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, 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, 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)
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
newtype ItemTimer = ItemTimer {ItemTimer -> Time
itemTimer :: Time}
deriving (Int -> ItemTimer -> ShowS
[ItemTimer] -> ShowS
ItemTimer -> String
(Int -> ItemTimer -> ShowS)
-> (ItemTimer -> String)
-> ([ItemTimer] -> ShowS)
-> Show ItemTimer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ItemTimer] -> ShowS
$cshowList :: [ItemTimer] -> ShowS
show :: ItemTimer -> String
$cshow :: ItemTimer -> String
showsPrec :: Int -> ItemTimer -> ShowS
$cshowsPrec :: Int -> ItemTimer -> ShowS
Show, ItemTimer -> ItemTimer -> Bool
(ItemTimer -> ItemTimer -> Bool)
-> (ItemTimer -> ItemTimer -> Bool) -> Eq ItemTimer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ItemTimer -> ItemTimer -> Bool
$c/= :: ItemTimer -> ItemTimer -> Bool
== :: ItemTimer -> ItemTimer -> Bool
$c== :: ItemTimer -> ItemTimer -> Bool
Eq, Get ItemTimer
[ItemTimer] -> Put
ItemTimer -> Put
(ItemTimer -> Put)
-> Get ItemTimer -> ([ItemTimer] -> Put) -> Binary ItemTimer
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
putList :: [ItemTimer] -> Put
$cputList :: [ItemTimer] -> Put
get :: Get ItemTimer
$cget :: Get ItemTimer
put :: ItemTimer -> Put
$cput :: ItemTimer -> Put
Binary)
type ItemTimers = [ItemTimer]
type ItemQuant = (Int, ItemTimers)
type ItemBag = EM.EnumMap ItemId ItemQuant
type ItemDict = EM.EnumMap ItemId Item
toItemKindIx :: Word16 -> ItemKindIx
{-# INLINE toItemKindIx #-}
toItemKindIx :: Word16 -> ItemKindIx
toItemKindIx = Word16 -> ItemKindIx
ItemKindIx
quantSingle :: ItemQuant
quantSingle :: ItemQuant
quantSingle = (1, [])
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
idBonus :: Int
idBonus = if ItemFull -> Bool
itemSuspect ItemFull
itemFull then 1000 else 0
arItem :: AspectRecord
arItem = ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
uniqueBonus :: Int
uniqueBonus = if Flag -> AspectRecord -> Bool
IA.checkFlag Flag
Ability.Unique AspectRecord
arItem Bool -> Bool -> Bool
&& Int
ben Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 20
then 1000
else 0
in (Int
ben Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
idBonus Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
uniqueBonus, (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
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
itemTimerZero :: ItemTimer
itemTimerZero :: ItemTimer
itemTimerZero = Time -> ItemTimer
ItemTimer Time
timeZero
createItemTimer :: Time -> Delta Time -> ItemTimer
createItemTimer :: Time -> Delta Time -> ItemTimer
createItemTimer localTime :: Time
localTime delta :: Delta Time
delta = Time -> ItemTimer
ItemTimer (Time -> ItemTimer) -> Time -> ItemTimer
forall a b. (a -> b) -> a -> b
$ Time
localTime Time -> Delta Time -> Time
`timeShift` Delta Time
delta
shiftItemTimer :: Delta Time -> ItemTimer -> ItemTimer
shiftItemTimer :: Delta Time -> ItemTimer -> ItemTimer
shiftItemTimer delta :: Delta Time
delta t :: ItemTimer
t = Time -> ItemTimer
ItemTimer (Time -> ItemTimer) -> Time -> ItemTimer
forall a b. (a -> b) -> a -> b
$ ItemTimer -> Time
itemTimer ItemTimer
t Time -> Delta Time -> Time
`timeShift` Delta Time
delta
deltaOfItemTimer :: Time -> ItemTimer -> Delta Time
deltaOfItemTimer :: Time -> ItemTimer -> Delta Time
deltaOfItemTimer localTime :: Time
localTime t :: ItemTimer
t = Time -> Time -> Delta Time
timeDeltaToFrom (ItemTimer -> Time
itemTimer ItemTimer
t) Time
localTime
charging :: Time -> ItemTimer -> Bool
charging :: Time -> ItemTimer -> Bool
charging localTime :: Time
localTime = (Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
> Time
localTime) (Time -> Bool) -> (ItemTimer -> Time) -> ItemTimer -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ItemTimer -> Time
itemTimer
ncharges :: Time -> ItemQuant -> Int
ncharges :: Time -> ItemQuant -> Int
ncharges localTime :: Time
localTime (itemK :: Int
itemK, itemTimers :: [ItemTimer]
itemTimers) =
Int
itemK Int -> Int -> Int
forall a. Num a => a -> a -> a
- [ItemTimer] -> Int
forall a. [a] -> Int
length ((ItemTimer -> Bool) -> [ItemTimer] -> [ItemTimer]
forall a. (a -> Bool) -> [a] -> [a]
filter (Time -> ItemTimer -> Bool
charging Time
localTime) [ItemTimer]
itemTimers)
hasCharge :: Time -> ItemQuant -> Bool
hasCharge :: Time -> ItemQuant -> Bool
hasCharge localTime :: Time
localTime kit :: ItemQuant
kit = Time -> ItemQuant -> Int
ncharges Time
localTime ItemQuant
kit Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
strongestMelee :: Bool -> Maybe DiscoveryBenefit -> Time
-> [(ItemId, ItemFullKit)]
-> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
strongestMelee :: Bool
-> Maybe DiscoveryBenefit
-> Time
-> [(ItemId, ItemFullKit)]
-> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
strongestMelee _ _ _ [] = []
strongestMelee ignoreCharges :: Bool
ignoreCharges mdiscoBenefit :: Maybe DiscoveryBenefit
mdiscoBenefit localTime :: Time
localTime kitAss :: [(ItemId, ItemFullKit)]
kitAss =
let f :: (ItemId, ItemFullKit)
-> Maybe (Double, Bool, Int, Int, ItemId, ItemFullKit)
f (iid :: ItemId
iid, ifk :: ItemFullKit
ifk@(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
unIDedBonus :: Double
unIDedBonus = if ItemFull -> Bool
itemSuspect ItemFull
itemFull then 1000 else 0
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
arItem :: AspectRecord
arItem = ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
timeout :: Int
timeout = AspectRecord -> Int
IA.aTimeout AspectRecord
arItem
hasEffect :: Bool
hasEffect = (Effect -> Bool) -> [Effect] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (\eff :: Effect
eff -> Effect -> Bool
IK.forApplyEffect Effect
eff)
(ItemKind -> [Effect]
IK.ieffects (ItemKind -> [Effect]) -> ItemKind -> [Effect]
forall a b. (a -> b) -> a -> b
$ ItemFull -> ItemKind
itemKind ItemFull
itemFull)
ncha :: Int
ncha = Time -> ItemQuant -> Int
ncharges Time
localTime ItemQuant
kit
in if Bool
ignoreCharges Bool -> Bool -> Bool
|| Int
ncha Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
then (Double, Bool, Int, Int, ItemId, ItemFullKit)
-> Maybe (Double, Bool, Int, Int, ItemId, ItemFullKit)
forall a. a -> Maybe a
Just (Double
totalValue, Bool
hasEffect, Int
timeout, Int
ncha, ItemId
iid, ItemFullKit
ifk)
else Maybe (Double, Bool, Int, Int, ItemId, ItemFullKit)
forall a. Maybe a
Nothing
in ((Double, Bool, Int, Int, ItemId, ItemFullKit)
-> (Double, Bool, Int, ContentId ItemKind))
-> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
-> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (\(value :: Double
value, hasEffect :: Bool
hasEffect, timeout :: Int
timeout, _, _, (itemFull :: ItemFull
itemFull, _)) ->
let timN :: Int
timN = if Int
timeout Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0 then -99999 else - Int
timeout
in (Double
value, Bool -> Bool
not Bool
hasEffect, Int
timN, ItemFull -> ContentId ItemKind
itemKindId ItemFull
itemFull))
(((ItemId, ItemFullKit)
-> Maybe (Double, Bool, Int, Int, ItemId, ItemFullKit))
-> [(ItemId, ItemFullKit)]
-> [(Double, Bool, Int, Int, ItemId, ItemFullKit)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (ItemId, ItemFullKit)
-> Maybe (Double, Bool, Int, 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 :: ItemFull
itemFull@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 arItem :: AspectRecord
arItem = ItemFull -> AspectRecord
aspectRecordFull ItemFull
itemFull
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 (Flag -> AspectRecord -> Bool
IA.checkFlag Flag
Ability.MinorAspects AspectRecord
arItem)
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
max (-95) Int
itemBonus
mergeItemQuant :: ItemQuant -> ItemQuant -> ItemQuant
mergeItemQuant :: ItemQuant -> ItemQuant -> ItemQuant
mergeItemQuant (k2 :: Int
k2, it2 :: [ItemTimer]
it2) (k1 :: Int
k1, it1 :: [ItemTimer]
it1) = (Int
k1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k2, [ItemTimer]
it1 [ItemTimer] -> [ItemTimer] -> [ItemTimer]
forall a. [a] -> [a] -> [a]
++ [ItemTimer]
it2)
listToolsToConsume :: [(ItemId, ItemFullKit)] -> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
listToolsToConsume :: [(ItemId, ItemFullKit)]
-> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
listToolsToConsume kitAssG :: [(ItemId, ItemFullKit)]
kitAssG kitAssE :: [(ItemId, ItemFullKit)]
kitAssE =
let isDurable :: (a, (ItemFull, b)) -> Bool
isDurable = Flag -> AspectRecord -> Bool
IA.checkFlag Flag
Ability.Durable
(AspectRecord -> Bool)
-> ((a, (ItemFull, b)) -> AspectRecord)
-> (a, (ItemFull, b))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ItemFull -> AspectRecord
aspectRecordFull (ItemFull -> AspectRecord)
-> ((a, (ItemFull, b)) -> ItemFull)
-> (a, (ItemFull, b))
-> AspectRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ItemFull, b) -> ItemFull
forall a b. (a, b) -> a
fst ((ItemFull, b) -> ItemFull)
-> ((a, (ItemFull, b)) -> (ItemFull, b))
-> (a, (ItemFull, b))
-> ItemFull
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, (ItemFull, b)) -> (ItemFull, b)
forall a b. (a, b) -> b
snd
(kitAssGT :: [(ItemId, ItemFullKit)]
kitAssGT, kitAssGF :: [(ItemId, ItemFullKit)]
kitAssGF) = ((ItemId, ItemFullKit) -> Bool)
-> [(ItemId, ItemFullKit)]
-> ([(ItemId, ItemFullKit)], [(ItemId, ItemFullKit)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (ItemId, ItemFullKit) -> Bool
forall a b. (a, (ItemFull, b)) -> Bool
isDurable [(ItemId, ItemFullKit)]
kitAssG
(kitAssET :: [(ItemId, ItemFullKit)]
kitAssET, kitAssEF :: [(ItemId, ItemFullKit)]
kitAssEF) = ((ItemId, ItemFullKit) -> Bool)
-> [(ItemId, ItemFullKit)]
-> ([(ItemId, ItemFullKit)], [(ItemId, ItemFullKit)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (ItemId, ItemFullKit) -> Bool
forall a b. (a, (ItemFull, b)) -> Bool
isDurable [(ItemId, ItemFullKit)]
kitAssE
in [(CStore, Bool)]
-> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a b. [a] -> [b] -> [(a, b)]
zip ((CStore, Bool) -> [(CStore, Bool)]
forall a. a -> [a]
repeat (CStore
CGround, Bool
False)) [(ItemId, ItemFullKit)]
kitAssGF
[((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a. [a] -> [a] -> [a]
++ [(CStore, Bool)]
-> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a b. [a] -> [b] -> [(a, b)]
zip ((CStore, Bool) -> [(CStore, Bool)]
forall a. a -> [a]
repeat (CStore
CEqp, Bool
False)) [(ItemId, ItemFullKit)]
kitAssEF
[((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a. [a] -> [a] -> [a]
++ [(CStore, Bool)]
-> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a b. [a] -> [b] -> [(a, b)]
zip ((CStore, Bool) -> [(CStore, Bool)]
forall a. a -> [a]
repeat (CStore
CGround, Bool
True)) [(ItemId, ItemFullKit)]
kitAssGT
[((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a. [a] -> [a] -> [a]
++ [(CStore, Bool)]
-> [(ItemId, ItemFullKit)]
-> [((CStore, Bool), (ItemId, ItemFullKit))]
forall a b. [a] -> [b] -> [(a, b)]
zip ((CStore, Bool) -> [(CStore, Bool)]
forall a. a -> [a]
repeat (CStore
CEqp, Bool
True)) [(ItemId, ItemFullKit)]
kitAssET
countIidConsumed :: ItemFullKit
-> [(Bool, Int, GroupName IK.ItemKind)]
-> (Int, Int, [(Bool, Int, GroupName IK.ItemKind)])
countIidConsumed :: ItemFullKit
-> [(Bool, Int, GroupName ItemKind)]
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
countIidConsumed (ItemFull{ItemKind
itemKind :: ItemKind
itemKind :: ItemFull -> ItemKind
itemKind}, (k :: Int
k, _)) grps0 :: [(Bool, Int, GroupName ItemKind)]
grps0 =
let hasGroup :: GroupName ItemKind -> Bool
hasGroup grp :: GroupName ItemKind
grp =
Bool -> (Int -> Bool) -> Maybe Int -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0) (Maybe Int -> Bool) -> Maybe Int -> Bool
forall a b. (a -> b) -> a -> b
$ GroupName ItemKind -> [(GroupName ItemKind, Int)] -> Maybe Int
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup GroupName ItemKind
grp ([(GroupName ItemKind, Int)] -> Maybe Int)
-> [(GroupName ItemKind, Int)] -> Maybe Int
forall a b. (a -> b) -> a -> b
$ ItemKind -> [(GroupName ItemKind, Int)]
IK.ifreq ItemKind
itemKind
matchGroup :: (Int, Int, [(Bool, Int, GroupName ItemKind)])
-> (Bool, Int, GroupName ItemKind)
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
matchGroup (nToApplyIfDurable :: Int
nToApplyIfDurable, nToDestroyAlways :: Int
nToDestroyAlways, grps :: [(Bool, Int, GroupName ItemKind)]
grps)
(destroyAlways :: Bool
destroyAlways, n :: Int
n, grp :: GroupName ItemKind
grp) =
if GroupName ItemKind -> Bool
hasGroup GroupName ItemKind
grp
then let mkn :: Int
mkn = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
k Int
n
grps2 :: [(Bool, Int, GroupName ItemKind)]
grps2 = if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mkn Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
then (Bool
destroyAlways, Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mkn, GroupName ItemKind
grp) (Bool, Int, GroupName ItemKind)
-> [(Bool, Int, GroupName ItemKind)]
-> [(Bool, Int, GroupName ItemKind)]
forall a. a -> [a] -> [a]
: [(Bool, Int, GroupName ItemKind)]
grps
else [(Bool, Int, GroupName ItemKind)]
grps
in if Bool
destroyAlways
then ( Int
nToApplyIfDurable
, Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
nToDestroyAlways Int
mkn
, [(Bool, Int, GroupName ItemKind)]
grps2 )
else ( Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
nToApplyIfDurable Int
mkn
, Int
nToDestroyAlways
, [(Bool, Int, GroupName ItemKind)]
grps2 )
else ( Int
nToApplyIfDurable
, Int
nToDestroyAlways
, (Bool
destroyAlways, Int
n, GroupName ItemKind
grp) (Bool, Int, GroupName ItemKind)
-> [(Bool, Int, GroupName ItemKind)]
-> [(Bool, Int, GroupName ItemKind)]
forall a. a -> [a] -> [a]
: [(Bool, Int, GroupName ItemKind)]
grps )
in ((Int, Int, [(Bool, Int, GroupName ItemKind)])
-> (Bool, Int, GroupName ItemKind)
-> (Int, Int, [(Bool, Int, GroupName ItemKind)]))
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
-> [(Bool, Int, GroupName ItemKind)]
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (Int, Int, [(Bool, Int, GroupName ItemKind)])
-> (Bool, Int, GroupName ItemKind)
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
matchGroup (0, 0, []) [(Bool, Int, GroupName ItemKind)]
grps0
subtractIidfromGrps :: ( EM.EnumMap CStore ItemBag
, [(CStore, (ItemId, ItemFull))]
, [(Bool, Int, GroupName IK.ItemKind)] )
-> ((CStore, Bool), (ItemId, ItemFullKit))
-> ( EM.EnumMap CStore ItemBag
, [(CStore, (ItemId, ItemFull))]
, [(Bool, Int, GroupName IK.ItemKind)] )
subtractIidfromGrps :: (EnumMap CStore ItemBag, [(CStore, (ItemId, ItemFull))],
[(Bool, Int, GroupName ItemKind)])
-> ((CStore, Bool), (ItemId, ItemFullKit))
-> (EnumMap CStore ItemBag, [(CStore, (ItemId, ItemFull))],
[(Bool, Int, GroupName ItemKind)])
subtractIidfromGrps (bagsToLose1 :: EnumMap CStore ItemBag
bagsToLose1, iidsToApply1 :: [(CStore, (ItemId, ItemFull))]
iidsToApply1, grps1 :: [(Bool, Int, GroupName ItemKind)]
grps1)
((store :: CStore
store, durable :: Bool
durable), (iid :: ItemId
iid, itemFullKit :: ItemFullKit
itemFullKit@(itemFull :: ItemFull
itemFull, (_, it :: [ItemTimer]
it)))) =
let (nToApplyIfDurable :: Int
nToApplyIfDurable, nToDestroyAlways :: Int
nToDestroyAlways, grps2 :: [(Bool, Int, GroupName ItemKind)]
grps2) =
ItemFullKit
-> [(Bool, Int, GroupName ItemKind)]
-> (Int, Int, [(Bool, Int, GroupName ItemKind)])
countIidConsumed ItemFullKit
itemFullKit [(Bool, Int, GroupName ItemKind)]
grps1
(nToApply :: Int
nToApply, nToDestroy :: Int
nToDestroy) = if Bool
durable
then (Int
nToApplyIfDurable, Int
nToDestroyAlways)
else (0, Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
nToApplyIfDurable Int
nToDestroyAlways)
in ( if Int
nToDestroy Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0
then EnumMap CStore ItemBag
bagsToLose1
else let kit2 :: ItemQuant
kit2 = (Int
nToDestroy, Int -> [ItemTimer] -> [ItemTimer]
forall a. Int -> [a] -> [a]
take Int
nToDestroy [ItemTimer]
it)
removedBags :: EnumMap CStore ItemBag
removedBags = CStore -> ItemBag -> EnumMap CStore ItemBag
forall k a. Enum k => k -> a -> EnumMap k a
EM.singleton CStore
store (ItemBag -> EnumMap CStore ItemBag)
-> ItemBag -> EnumMap CStore ItemBag
forall a b. (a -> b) -> a -> b
$ ItemId -> ItemQuant -> ItemBag
forall k a. Enum k => k -> a -> EnumMap k a
EM.singleton ItemId
iid ItemQuant
kit2
in (ItemBag -> ItemBag -> ItemBag)
-> EnumMap CStore ItemBag
-> EnumMap CStore ItemBag
-> EnumMap CStore ItemBag
forall a k.
(a -> a -> a) -> EnumMap k a -> EnumMap k a -> EnumMap k a
EM.unionWith ((ItemQuant -> ItemQuant -> ItemQuant)
-> ItemBag -> ItemBag -> ItemBag
forall a k.
(a -> a -> a) -> EnumMap k a -> EnumMap k a -> EnumMap k a
EM.unionWith ItemQuant -> ItemQuant -> ItemQuant
mergeItemQuant)
EnumMap CStore ItemBag
removedBags EnumMap CStore ItemBag
bagsToLose1
, Int
-> (CStore, (ItemId, ItemFull)) -> [(CStore, (ItemId, ItemFull))]
forall a. Int -> a -> [a]
replicate Int
nToApply (CStore
store, (ItemId
iid, ItemFull
itemFull)) [(CStore, (ItemId, ItemFull))]
-> [(CStore, (ItemId, ItemFull))] -> [(CStore, (ItemId, ItemFull))]
forall a. [a] -> [a] -> [a]
++ [(CStore, (ItemId, ItemFull))]
iidsToApply1
, [(Bool, Int, GroupName ItemKind)]
grps2 )