Major item refactor, still broken
This commit is contained in:
+19
-21
@@ -4,6 +4,7 @@ module Dodge.Creature.State (
|
||||
invItemEffs,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Control.Applicative
|
||||
import Control.Monad
|
||||
import qualified Data.Map.Strict as M
|
||||
@@ -53,7 +54,7 @@ applyPastDamages cr w
|
||||
where
|
||||
dojitter x y =
|
||||
let (p, g) = runState (randInCirc x) (_randGen w)
|
||||
in w & cWorld . lWorld . creatures . ix (_crID cr) %~ crMvBy p
|
||||
in w & cWorld . lWorld . creatures . ix (_crID cr) %~ crMvBy p (w ^. cWorld . lWorld)
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crPain -~ y
|
||||
& randGen .~ g
|
||||
|
||||
@@ -64,7 +65,7 @@ invItemEffs cid w = fromMaybe w $ do
|
||||
return . appEndo (
|
||||
foldMap
|
||||
(reduceLocDT (Endo . invItemLocUpdate cr) . LocDT TopDT)
|
||||
(invDT' (_crInv cr))) $ w
|
||||
(invDT' $ fmap (\k -> w ^?! cWorld . lWorld . items . ix k) (_crInv cr))) $ w
|
||||
|
||||
invItemLocUpdate :: Creature -> LocationDT OItem -> World -> World
|
||||
invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of
|
||||
@@ -132,7 +133,7 @@ copierItemUpdate itm cr w = fromMaybe w $ do
|
||||
invid <- itm ^? itLocation . ilInvID
|
||||
ip <- itm ^? itType . ibtPathing
|
||||
i <- getInventoryPath x ip invid cr
|
||||
itm' <- cr ^? crInv . ix i
|
||||
itm' <- cr ^? crInv . ix i >>= \k -> w ^? cWorld . lWorld . items . ix k
|
||||
v <- getItemValue itm' w cr
|
||||
return $ w & pointerToItem itm . itUse . uValue .~ v
|
||||
|
||||
@@ -149,22 +150,22 @@ tryUseParent loc w = fromMaybe w $ do
|
||||
tryDrawToCapacitor :: LocationDT OItem -> World -> World
|
||||
tryDrawToCapacitor loc w = fromMaybe w $ do
|
||||
itm <- loc ^? locDT . dtValue . _1
|
||||
i <- itm ^? itLocation . ilInvID
|
||||
i <- itm ^? itID . unNInt
|
||||
x <- loc ^? locDT . dtValue . _1 . itConsumables . _Just
|
||||
guard $ x < 200
|
||||
bat <- loc ^? locDT . dtLeft . ix 0 . dtValue . _1
|
||||
j <- bat ^? itLocation . ilInvID
|
||||
j <- bat ^? itID . unNInt
|
||||
y <- bat ^? itConsumables . _Just
|
||||
let z = min y 10
|
||||
return $ w
|
||||
& invpoint . ix i . itConsumables . _Just +~ z
|
||||
& invpoint . ix j . itConsumables . _Just -~ z
|
||||
where
|
||||
invpoint = cWorld . lWorld . creatures . ix 0 . crInv
|
||||
invpoint = cWorld . lWorld . items
|
||||
|
||||
trySynthBullet :: LocationDT OItem -> World -> World
|
||||
trySynthBullet loc w = fromMaybe w $ do
|
||||
i <- itm ^? itLocation . ilInvID
|
||||
i <- itm ^? itID . unNInt
|
||||
x <- itm ^? itUse . uaParams . apInt
|
||||
if x < 100
|
||||
then do
|
||||
@@ -177,7 +178,7 @@ trySynthBullet loc w = fromMaybe w $ do
|
||||
& invpoint . ix j . itConsumables . _Just -~ 1
|
||||
else do
|
||||
mag <- loc ^? locDtContext . cdtParent . _1
|
||||
j <- mag ^? itLocation . ilInvID
|
||||
j <- mag ^? itID . unNInt
|
||||
y <- mag ^. itConsumables
|
||||
ymax <- maxAmmo mag
|
||||
guard $ y < ymax
|
||||
@@ -186,7 +187,7 @@ trySynthBullet loc w = fromMaybe w $ do
|
||||
& invpoint . ix j . itConsumables . _Just +~ 1
|
||||
where
|
||||
itm = loc ^. locDT . dtValue . _1
|
||||
invpoint = cWorld . lWorld . creatures . ix 0 . crInv
|
||||
invpoint = cWorld . lWorld . items
|
||||
|
||||
drawARHUD :: LocationDT OItem -> World -> World
|
||||
drawARHUD (LocDT con _) w = fromMaybe w $ do
|
||||
@@ -202,13 +203,12 @@ shineTargetLaser cr loc w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ d
|
||||
mag <- find (isammolink . (^. dtValue . _2)) (itmtree ^. dtLeft)
|
||||
i <- mag ^. dtValue . _1 . itConsumables
|
||||
guard $ i >= x
|
||||
maginvid <- mag ^? dtValue . _1 . itLocation . ilInvID
|
||||
magitid <- mag ^? dtValue . _1 . itID . unNInt
|
||||
return $
|
||||
w
|
||||
& worldEventFlags . at InventoryChange ?~ ()
|
||||
& cWorld . lWorld . creatures . ix (_crID cr)
|
||||
. crInv
|
||||
. ix maginvid
|
||||
& cWorld . lWorld . items
|
||||
. ix magitid
|
||||
. itConsumables
|
||||
. _Just
|
||||
-~ x
|
||||
@@ -230,9 +230,8 @@ shineTargetLaser cr loc w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ d
|
||||
pos = _crPos cr + xyV3 (rotate3 cdir p)
|
||||
cdir = _crDir cr
|
||||
itm = itmtree ^. dtValue . _1
|
||||
pointittarg = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itTargeting
|
||||
cid = _crID cr
|
||||
invid = _ilInvID $ _itLocation itm
|
||||
pointittarg = cWorld . lWorld . items . ix itid . itTargeting
|
||||
itid = itm ^. itID . unNInt
|
||||
col = blue -- mixColors reloadFrac (1-reloadFrac) blue red
|
||||
|
||||
shineTorch :: Creature -> LocationDT OItem -> World -> World
|
||||
@@ -241,10 +240,10 @@ shineTorch cr loc = fromMaybe id $ do
|
||||
i <- mag ^. dtValue . _1 . itConsumables
|
||||
guard $ crIsAiming cr
|
||||
guard $ i >= x
|
||||
invid <- mag ^? dtValue . _1 . itLocation . ilInvID
|
||||
itid <- mag ^? dtValue . _1 . itID . unNInt
|
||||
return $
|
||||
(cWorld . lWorld . lights .:~ LSParam pos 250 0.7)
|
||||
. (cWorld . lWorld . creatures . ix (_crID cr) . crInv . ix invid . itConsumables . _Just -~ x)
|
||||
. (cWorld . lWorld . items . ix itid . itConsumables . _Just -~ x)
|
||||
where
|
||||
itmtree = loc ^. locDT
|
||||
(p, q) = locOrient loc cr
|
||||
@@ -281,9 +280,8 @@ updateItemTargeting tt cr itm w = case tt of
|
||||
Nothing
|
||||
True
|
||||
where
|
||||
pointittarg = cWorld . lWorld . creatures . ix cid . crInv . ix invid . itTargeting
|
||||
cid = _crID cr
|
||||
invid = _ilInvID $ _itLocation itm
|
||||
pointittarg = cWorld . lWorld . items . ix itid . itTargeting
|
||||
itid = itm ^. itID . unNInt
|
||||
isattached = itm ^?! itLocation . ilIsAttached
|
||||
rbpressed = SDL.ButtonRight `M.member` _mouseButtons (_input w)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user