Fix angled recoil

This commit is contained in:
2025-07-05 23:18:37 +01:00
parent 7b9c1678f1
commit d6bdd0098b
2 changed files with 104 additions and 100 deletions
+11 -7
View File
@@ -127,7 +127,7 @@ getVolleyBurst i g =
heldEffectMuzzles :: LocationLDT ItemLink OItem -> Creature -> World -> World
heldEffectMuzzles loc cr w =
setusetime . doHeldUseEffect t cr
. uncurry (applyCME (_ldtValue t ^. _1) cr)
. uncurry (applyCME loc cr)
. foldl' (useLoadedAmmo loc cr) (False, w)
$ loadedmuzzles
where
@@ -393,14 +393,14 @@ doHeldUseEffect t cr w = case t ^. ldtValue . _1 . itType of
-- & ldtValue . itUse . heldFrame .~ x
-- should probably unify failure with time use check in some way...
applyCME :: Item -> Creature -> Bool -> World -> World
applyCME itm cr cme
applyCME :: LocationLDT ItemLink OItem -> Creature -> Bool -> World -> World
applyCME loc cr cme
| cme =
applyInvLock itm cr
. applySoundCME itm cr
. applySidePush spush cr
. applyTorqueCME itm cr
. applyRecoil itm cr
. applyRecoil loc cr
| otherwise = case itm ^. itType of
HELD MACHINEPISTOL ->
cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix itid . itParams
@@ -408,6 +408,7 @@ applyCME itm cr cme
-- the above is quite hacky for now
_ -> failsound
where
itm = loc ^. locLDT . ldtValue . _1
coolstart = fromMaybe 0 $ baseItemTriggerType itm ^? coolStart
itid = itm ^?! itLocation . ilInvID -- unsafe
spush = maybe 0 itemSidePush $ itm ^? itType . ibtHeld
@@ -491,10 +492,13 @@ applySoundCME itm cr = fromMaybe id $ do
where
cid = _crID cr
applyRecoil :: Item -> Creature -> World -> World
applyRecoil itm cr =
applyRecoil :: LocationLDT ItemLink OItem -> Creature -> World -> World
applyRecoil loc cr =
cWorld . lWorld . creatures . ix (_crID cr) . crPos
+~ rotateV (_crDir cr) (V2 ((- recoilAmount itm) / crMass (_crType cr)) 0)
+~ rotateV (_crDir cr + Q.qToAng q) (V2 ((- recoilAmount itm) / crMass (_crType cr)) 0)
where
itm = loc ^. locLDT . ldtValue . _1
(_,q) = locOrient loc cr
recoilAmount :: Item -> Float
recoilAmount itm