Fix bug in attached item position orienting

This commit is contained in:
2024-10-02 22:57:10 +01:00
parent 6bcd5bc591
commit 49ffbfafc2
8 changed files with 105 additions and 97 deletions
+26 -15
View File
@@ -3,6 +3,8 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.LightSource
import Dodge.WorldEvent.Flash
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
@@ -25,7 +27,7 @@ import Dodge.Item.Grammar
import Dodge.Item.HeldOffset
import Dodge.Prop.Gib
import Dodge.SoundLogic
import Dodge.WorldEvent.Flash
--import Dodge.WorldEvent.Flash
import Dodge.Zoning.Creature
import FoldableHelp
import Geometry
@@ -176,31 +178,40 @@ updateRootItem' itmtree cr =
chainLinkOrientation
chainLinkOrientation
(updateItemWithOrientation cr)
(Just (heldItemRelativeOrient (_ldtValue itmtree) cr (0, Q.qID)))
(heldItemRelativeOrient (_ldtValue itmtree) cr (0, Q.qID))
itmtree
-- need to check rotation
chainLinkOrientation ::
Maybe (Point3, Q.Quaternion Float) ->
(Point3, Q.Quaternion Float) ->
Item ->
ItemLink ->
Item ->
Maybe (Point3, Q.Quaternion Float)
chainLinkOrientation mo par (ILink lt f) child = do
(p, q) <- mo
(p1, q1) <- f par lt child
return (p + Q.rotate q1 p1, q * q1)
(Point3, Q.Quaternion Float)
chainLinkOrientation mo par (ILink lt f) child = (p + Q.rotate q p1, q * q1)
where
(p, q) = mo
(p1, q1) = f par lt child
updateItemWithOrientation :: Creature -> Maybe (Point3, Q.Quaternion Float) -> Item -> World -> World
updateItemWithOrientation :: Creature -> (Point3, Q.Quaternion Float) -> Item -> World -> World
updateItemWithOrientation cr m itm = case _itType itm of
HELD TORCH -> testtorch cr m
HELD TORCH -> testtorch cr itm m
_ -> id
testtorch :: Creature -> Maybe (Point3, Q.Quaternion Float) -> World -> World
testtorch cr m = fromMaybe id $ do
(pos, q) <- m
let d = _crDir cr + argV (Q.qToV2 q)
return $ muzFlareAt yellow (_crPos cr `v2z` 0 + rotate3z d pos) d
testtorch :: Creature -> Item -> (Point3, Q.Quaternion Float) -> World -> World
testtorch cr itm (p,q) = --createTorchLightOffset cr itm pos' .
muzFlareAt yellow pos'' d
.( cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 250 0.7 pos''
)
where
--pos = (_crPos cr `v2z` 0 + rotate3 cdir p)
pos = (_crPos cr `v2z` 0 + rotate3 cdir p)
--pos'' = pos
pos'' = pos + rotate3 d (V3 8 0 1.5)
cdir = _crDir cr
a = argV (Q.qToV2 q)
d = _crDir cr + a
itemInvSideEffect :: Creature -> Item -> World -> World
itemInvSideEffect cr itm = case _itType itm of