41 lines
1.3 KiB
Haskell
41 lines
1.3 KiB
Haskell
module Dodge.Creature.Property
|
|
( crIsArmouredFrom
|
|
, crNearSeg
|
|
, crNearPoint
|
|
) where
|
|
import Dodge.Data
|
|
import Dodge.Creature.HandPos
|
|
import Geometry
|
|
|
|
import Data.Maybe
|
|
import Control.Lens
|
|
|
|
-- the use of crOldPos is because the damage position is calculated on the
|
|
-- previous frame
|
|
-- Not sure if it is a good idea
|
|
crIsArmouredFrom :: Point2 -> Creature -> Bool
|
|
crIsArmouredFrom p cr = hasFrontArmour p cr
|
|
|
|
hasFrontArmour :: Point2 -> Creature -> Bool
|
|
hasFrontArmour p cr = fromMaybe False $ do
|
|
invid <- cr ^? crEquipment . ix OnChest
|
|
ittype <- cr ^? crInv . ix invid . itType
|
|
return $ FRONTARMOUR == ittype
|
|
&& p /= _crOldPos cr
|
|
&& angleVV (unitVectorAtAngle (_crDir cr + frontarmdirection)) (p -.- _crOldPos cr) < pi/2
|
|
-- even though angleVV can generate NaN, the comparison seems to deal with it
|
|
where
|
|
frontarmdirection
|
|
| crInStance OneHand cr = 0.5
|
|
| crInStance TwoHandTwist cr = negate 1
|
|
| otherwise = 0
|
|
|
|
--crOnSeg :: Point2 -> Point2 -> Creature -> Bool
|
|
--crOnSeg p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr)
|
|
|
|
crNearSeg :: Float -> Point2 -> Point2 -> Creature -> Bool
|
|
crNearSeg d p1 p2 cr = circOnSeg p1 p2 (_crPos cr) (_crRad cr + d)
|
|
|
|
crNearPoint :: Float -> Point2 -> Creature -> Bool
|
|
crNearPoint d p cr = dist (_crPos cr) p < d + _crRad cr
|