Improve possible manipulation of equipment

This commit is contained in:
2022-05-23 10:18:36 +01:00
parent 295c50f0d9
commit 46123de69c
9 changed files with 88 additions and 40 deletions
+12 -8
View File
@@ -4,6 +4,7 @@ module Dodge.Creature.Property
, crNearPoint
) where
import Dodge.Data
import Dodge.Creature.HandPos
import Geometry
import Data.Maybe
@@ -13,18 +14,21 @@ import Control.Lens
-- previous frame
-- Not sure if it is a good idea
crIsArmouredFrom :: Point2 -> Creature -> Bool
crIsArmouredFrom p cr
= p /= _crOldPos cr
-- && any (\it -> it ^? itType == Just FRONTARMOUR) (_crInv cr)
&& hasFrontArmour cr
&& angleVV (unitVectorAtAngle $ _crDir cr) (p -.- _crOldPos cr) < pi/2
-- even though angleVV can generate NaN, the comparison seems to deal with it
crIsArmouredFrom p cr = hasFrontArmour p cr
hasFrontArmour :: Creature -> Bool
hasFrontArmour cr = fromMaybe False $ do
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)