Start allowing for more granular control of remote projectiles, cleanup

This commit is contained in:
2024-12-26 10:16:18 +00:00
parent ae557f3fd4
commit 53c981718c
14 changed files with 273 additions and 218 deletions
+15 -3
View File
@@ -2,6 +2,9 @@ module Dodge.Projectile.Create (
createShell,
) where
import NewInt
--import Dodge.Data.ComposedItem
--import Dodge.Data.DoubleTree
import Dodge.Item.Location
import Data.Maybe
import Dodge.Data.World
@@ -16,9 +19,13 @@ homingDrawType ht = case ht of
HomeUsingTargeting {} -> DrawRemoteShell
-- assumes the mscreen is in your inventory
createShell :: ProjectileHoming -> Payload -> Muzzle -> Creature -> World -> World
createShell homing payload muz cr w = w
createShell :: ProjectileHoming
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Payload -> Muzzle -> Creature -> World -> World
createShell homing mdetonator mscreen payload muz cr w = w
& updatescreen
& updatedetonator
& cWorld . lWorld . projectiles . at i
?~ Shell
{ _prjPos = pos
@@ -33,7 +40,7 @@ createShell homing payload muz cr w = w
, _prjPayload = payload
, _prjTimer = 350
, _prjUpdates =
[ CollisionEffectPU (homing ^? phRemoteID) --Just screenid)
[ CollisionEffectPU (homing ^? phRemoteID) mdetonator mscreen
, TimePU
, StartSpinPU 335 (_crID cr) spinamount
, RemoteDirectionPU (350 - thrustdelay) 0 homing
@@ -45,6 +52,11 @@ createShell homing payload muz cr w = w
spindrag = 1
spinamount = 2
thrustdelay = 20
updatedetonator = fromMaybe id $ do
screenid <- mdetonator
return $ pointerToItemID screenid . itUse . uaParams
. apLinkedProjectile
?~ i
updatescreen = fromMaybe id $ do
screenid <- homing ^? phRemoteID
return $ pointerToItemID screenid . itUse . uaParams
+24 -8
View File
@@ -25,8 +25,8 @@ updateProjectile pj w = foldl' (\w' pu -> upProjectile pu pj w') w (_prjUpdates
upProjectile :: ProjectileUpdate -> Projectile -> World -> World
upProjectile pu pj = case pu of
CollisionEffectPU mscreenid -> shellCollisionCheck
mscreenid pj
CollisionEffectPU mcontrolid mdetonatorid mscreenid -> shellCollisionCheck
mcontrolid mdetonatorid mscreenid pj
TimePU -> decTimMvVel pj
ThrustPU st et
| act st et -> doThrust pj
@@ -47,14 +47,17 @@ upProjectile pu pj = case pu of
act st et = time <= st && time >= et
--shellCollisionCheck :: (Projectile -> World -> World) -> Projectile -> World -> World
shellCollisionCheck :: Maybe (NewInt ItmInt) -> Projectile -> World -> World
shellCollisionCheck f pj w
shellCollisionCheck :: Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Maybe (NewInt ItmInt)
-> Projectile -> World -> World
shellCollisionCheck controlid detid screenid pj w
| time > 330 && circOnSomeWall oldPos 4 w = g
| time <= 330 && anythingHitCirc 2 oldPos newPos w = g
| time <= 0 = g
| otherwise = w
where
g = explodeShell f pj w
g = explodeShell controlid detid screenid pj w
time = _prjTimer pj
oldPos = _prjPos pj
newPos = oldPos +.+ _prjVel pj
@@ -154,12 +157,25 @@ decTimMvVel pj =
vel = _prjVel pj
pjid = _prjID pj
explodeShell :: Maybe (NewInt ItmInt) -> Projectile -> World -> World
explodeShell mitid pj w =
explodeShell :: Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Maybe (NewInt ItmInt) ->
Projectile -> World -> World
explodeShell controlid mdetid screenid pj w =
w
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU mitid 30]
& cWorld . lWorld . projectiles . ix pjid . prjUpdates .~ [DestroyPU screenid 30]
& cWorld . lWorld . projectiles . ix pjid . prjDraw .~ DrawBlankProjectile
& usePayload (_prjPayload pj) (_prjPos pj) (_prjVel pj)
& stopSoundFrom (ShellSound pjid)
& updatedetonator
& updatecontroller
where
updatedetonator = fromMaybe id $ do
detid <- mdetid
return $ pointerToItemID detid . itUse . uaParams . apLinkedProjectile %~ deleteif
deleteif (Just x) | x == pjid = Nothing
deleteif x = x
updatecontroller = fromMaybe id $ do
cid <- controlid
return $ pointerToItemID cid . itUse . uaParams . apLinkedProjectile %~ deleteif
pjid = pj ^. prjID