Move item effect functions

This commit is contained in:
2022-07-20 22:43:30 +01:00
parent b36e7f8b78
commit 866196ab3e
16 changed files with 257 additions and 229 deletions
-86
View File
@@ -2,98 +2,12 @@
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Item.Data where
import Control.Lens
data HammerType
= NoHammer
| HasHammer {_hammerPosition :: HammerPosition}
deriving
(Eq, Ord, Show)
data HammerPosition
= HammerDown
| HammerReleased
| HammerUp
deriving
(Eq, Ord, Show)
--data ItemIdentity
-- = Pistol
-- | SpreadGun
-- | MultGun
-- | HvAutoGun
-- | AutoGun
-- | LtAutoGun
-- | MiniGun
-- | Medkit25
-- | MagShield
-- | FrontArmour
-- | JetPack
-- | FlameShield
-- | Generic
-- | SparkGun
-- | ShatterGun
-- | LongGun
-- | Flamethrower
-- | Blinker
-- | Rewinder
-- | Grenade
-- | RemoteBomb
-- | TeslaGun
-- | LasGun
-- | ForceFieldGun
-- | GrapGun
-- | TractorGun
-- | Launcher
-- | RemoteLauncher
-- | LightningGun
-- | PoisonSprayer
-- | FlatShield
-- deriving
-- (Eq,Show,Ord,Enum)
data AimStance
= TwoHandTwist
| TwoHandFlat
| OneHand
| LeaveHolstered
deriving
(Eq,Show,Ord,Enum)
-- TODO check how much of this is necessary
data ItZoom = ItZoom
{ _itZoomMax :: Float
, _itZoomMin :: Float
, _itZoomFac :: Float
}
data CurseStatus
= Uncursed
| UndroppableIdentified
| UndroppableUnidentified
data AimParams = AimParams
{ _aimWeight :: Int
, _aimRange :: Float
, _aimZoom :: ItZoom
, _aimStance :: AimStance
, _aimHandlePos :: Float
, _aimMuzPos :: Float
}
data UseDelay -- should just be Delay
= NoDelay
| FixedRate
{_rateMax :: Int
,_rateTime :: Int
}
| VariableRate
{_rateMax :: Int
,_rateTime :: Int
,_rateMaxMax :: Int
,_rateMinMax :: Int
}
| WarmUpNoDelay
{_warmTime :: Int
,_warmMax :: Int
}
data BarrelSpread
= AlignedBarrels
| SpreadBarrels {_spreadAngle :: Float}
| RotatingBarrels {_rotatingBarrelInaccuracy :: Float}
makeLenses ''BarrelSpread
makeLenses ''HammerType
makeLenses ''ItZoom
makeLenses ''AimParams
makeLenses ''UseDelay
+16 -27
View File
@@ -22,9 +22,11 @@ module Dodge.Item.Equipment
, overCID
, onEquipWristShield
, onRemoveWristShield
, createShieldWall
, removeShieldWall
) where
import Dodge.Data
import Dodge.LightSource.Torch
import Dodge.Item.Draw
import Dodge.Item.Equipment.Booster
import Dodge.LightSource
@@ -38,7 +40,8 @@ import Picture
import Geometry
import qualified IntMapHelp as IM
import LensHelp
--import ShortShow
import Data.Maybe
magShield :: Item
magShield = defaultEquipment
@@ -116,22 +119,14 @@ setWristShieldPos itm cr w = w
torch :: Item
torch = defaultWeapon
& itEffect .~ effectOnOffHeld createHeldLight (const $ const id)
& itEffect .~ effectOnOffHeld CreateHeldLight NoInvEffect-- createHeldLight (const $ const id)
& itType . iyBase .~ HELD TORCH
& itUse . useAim . aimHandlePos .~ 5
& itUse . useAim . aimMuzPos .~ 10
createHeldLight :: Creature -> Int -> World -> World
createHeldLight cr i = createTorchLightOffset cr itm 0
-- tempLightSources .:~ tlsTimeRadColPos 1 250 0.7
-- (p +.+.+ rotate3 (_crDir cr) (heldItemOffset itm cr (V3 8 0 1.5)))
where
-- p = addZ 0 $ _crPos cr
itm = cr ^?! crInv . ix i
flatShield :: Item
flatShield = defaultWeapon
& itEffect .~ effectOnOffHeld createShieldWall removeShieldWall
& itEffect .~ effectOnOffHeld CreateShieldWall RemoveShieldWall --createShieldWall removeShieldWall
-- the above seems to work, but I am not sure why: it may break on edge
-- cases
& itUse .~ defaultrUse
@@ -171,14 +166,14 @@ shieldWall crid = defaultWall
-- _ | isMovementDam dm -> w & creatures . ix crid . crState . crDamage .:~ dm
-- _ -> w
createShieldWall :: Creature -> Int -> World -> World
createShieldWall cr invid w = case _ieMID $ _itEffect it of
createShieldWall :: Item -> Creature -> World -> World
createShieldWall it cr w = case _ieMID $ _itEffect it of
Nothing -> let (wlid,w') = createWall ((shieldWall crid) {_wlLine = wlline,_wlID = wlid}) w
in w' & creatures . ix crid . crInv . ix invid . itEffect . ieMID ?~ wlid
Just wid -> moveWallID wid wlline w
where
invid = fromJust $ _itID it
crid = _crID cr
it = _crInv (_creatures w IM.! crid) IM.! invid
wlline = (a,b)
crdirv = unitVectorAtAngle $ _crDir cr
crpos = _crPos cr
@@ -187,29 +182,23 @@ createShieldWall cr invid w = case _ieMID $ _itEffect it of
b = crpos +.+ rad *.* crdirv +.+ 10 *.* therot crdirv
therot | crIsAiming cr = vNormal
| otherwise = rotateV (twoFlatHRot cr) . vNormal
removeShieldWall :: Creature -> Int -> World -> World
removeShieldWall cr invid w = case _ieMID $ _itEffect it of
removeShieldWall :: Item -> Creature -> World -> World
removeShieldWall it cr w = case _ieMID $ _itEffect it of
Nothing -> w
Just wid -> w & deleteWallID wid
& creatures . ix crid . crInv . ix invid . itEffect . ieMID .~ Nothing
where
crid = _crID cr
it = _crInv (_creatures w IM.! crid) IM.! invid
invid = fromJust (_itID it)
effectOnOffHeld
:: (Creature -> Int -> World -> World) -- ^ effect when held
-> (Creature -> Int -> World -> World) -- ^ effect when not held
:: ItInvEffect -- ^ effect when held
-> ItInvEffect -- ^ effect when not held
-> ItEffect
effectOnOffHeld f f' = ItInvEffectID
{ _ieInv = g
{ _ieInv = OnOffHeldEffect f f'
, _ieMID = Nothing
}
where
g itm cr w
| crSel cr == invid = f cr invid w
| otherwise = f' cr invid w
where
invid = _ipInvID $ _itPos itm
{- | Increases speed, reduces friction, cannot only move forwards. -}
jetPack :: Item
+2 -9
View File
@@ -118,12 +118,5 @@ boosterGun = defaultLeftItem
}
& itType . iyBase .~ LEFT BOOSTER
resetAttachmentID :: ItEffect
resetAttachmentID = ItInvEffect f 0
where
f itm cr w
| _ieCounter iteff < 0 = w & pointToIt . itAttachment .~ NoItAttachment
| otherwise = w & pointToIt . itEffect . ieCounter -~ 1
where
iteff = _itEffect itm
invid = _ipInvID $ _itPos itm
pointToIt = creatures . ix (_crID cr) . crInv . ix invid
resetAttachmentID = ItInvEffect ResetAttachmentEffect 0
+43 -43
View File
@@ -76,50 +76,50 @@ grenadeDraw :: Float -> Prop -> SPic
grenadeDraw dir prop = translateSPz (_pjZ prop) $ uncurryV translateSPf (_prPos prop)
$ rotateSP dir $ grenadePic $ _pjTimer prop
throwGrenade
:: (Point2 -> World -> World) -- ^ Payload
-> Creature
-> World
-> World
throwGrenade thePayload cr w = setWp $ removePict $ over props addG w
where
n = _crID cr
addG = IM.insert i $ Bomb
{ _prPos = p
, _pjZ = 10
, _pjVelZ = 2
, _pjVel = v
, _prDraw = grenadeDraw dir
, _pjID = i
, _pjUpdate = moveGrenade
, _pjPayload = thePayload
, _pjTimer = fuseTime
}
j = crSel cr
removePict = id -- set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank
i = IM.newKey $ _props w
v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w)
v | magV v' > 6 = 6 *.* normalizeV v'
| otherwise = v'
p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
| otherwise = p'
dir = argV v
setWp :: World -> World
setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
fuseTime = _atFuseTime $ _itAttachment $ _crInv cr IM.! j
--throwGrenade
-- :: (Point2 -> World -> World) -- ^ Payload
-- -> Creature
-- -> World
-- -> World
--throwGrenade thePayload cr w = setWp $ removePict $ over props addG w
-- where
-- n = _crID cr
-- addG = IM.insert i $ Bomb
-- { _prPos = p
-- , _pjZ = 10
-- , _pjVelZ = 2
-- , _pjVel = v
-- , _prDraw = grenadeDraw dir
-- , _pjID = i
-- , _pjUpdate = moveGrenade
-- , _pjPayload = thePayload
-- , _pjTimer = fuseTime
-- }
-- j = crSel cr
-- removePict = id -- set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank
-- i = IM.newKey $ _props w
-- v' = 1 / (fromIntegral fuseTime * _cameraZoom w) *.* rotateV (_cameraRot w) ( _mousePos w)
-- v | magV v' > 6 = 6 *.* normalizeV v'
-- | otherwise = v'
-- p' = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr) 0)
-- p | circOnSomeWall p' 4 w = _crPos cr +.+ rotateV (_crDir cr) (V2 (_crRad cr-4) 0)
-- | otherwise = p'
-- dir = argV v
-- setWp :: World -> World
-- setWp w' = w' & creatures . ix n . crInv . ix j . itEffect .~ throwArmReset 20
-- fuseTime = _atFuseTime $ _itAttachment $ _crInv cr IM.! j
throwArmReset :: Int -> ItEffect
throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x }
where
f itm cr = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
where
i = _ipInvID $ _itPos itm
counterDown it
| _ieCounter (_itEffect it) == 0 = it
& itUse . useHammer .~ HammerUp
-- & itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50)
| otherwise = it & itEffect . ieCounter -~ 1
--throwArmReset :: Int -> ItEffect
--throwArmReset x = ItInvEffect {_ieInv = f ,_ieCounter = x }
-- where
-- f itm cr = creatures . ix (_crID cr) . crInv %~ IM.adjust counterDown i
-- where
-- i = _ipInvID $ _itPos itm
-- counterDown it
-- | _ieCounter (_itEffect it) == 0 = it
-- & itUse . useHammer .~ HammerUp
---- & itEquipPict .~ pictureWeaponAim (\_ -> grenadePic 50)
-- | otherwise = it & itEffect . ieCounter -~ 1
--flameGrenade :: Item
--flameGrenade = grenade {
+1 -13
View File
@@ -20,24 +20,12 @@ rewindGun = defaultLeftItem
{ _wpMaxCharge = 250
, _wpCharge = 0
}
, _itEffect = ItRewindEffect rewindEffect []
, _itEffect = ItRewindEffect RewindEffect []
, _itUse = defaultlUse
& lUse .~ LRewind --useRewindGun
& eqEq . eqSite .~ GoesOnChest
}
& itType . iyBase .~ LEFT REWINDER
rewindEffect :: Item -> Creature -> World -> World
rewindEffect itm cr w
| Just invid == _crLeftInvSel cr = w & rewindWorlds %~ (take maxcharge . (w' : ))
& ptrWpCharge .~ length (_rewindWorlds w)
| otherwise = w & rewindWorlds .~ []
& ptrWpCharge .~ 0
where
invid = _ipInvID $ _itPos itm
ptrWpCharge = creatures . ix (_crID cr) . crInv . ix invid . itConsumption . wpCharge
maxcharge = _wpMaxCharge . _itConsumption $ itm
w' = w & rewindWorlds .~ []
& timeFlow .~ NormalTimeFlow
-- needs to shift this item to the current inventory slot
shrinkGun :: Item