85 lines
2.2 KiB
Haskell
85 lines
2.2 KiB
Haskell
module Dodge.Item.Equipment.Booster
|
|
( boosterGun
|
|
, boostSelfL
|
|
) where
|
|
import Dodge.Data
|
|
import Dodge.Base
|
|
import Dodge.Default.Weapon
|
|
import Geometry
|
|
import qualified IntMapHelp as IM
|
|
import Picture
|
|
|
|
import Data.Maybe
|
|
import Control.Lens
|
|
{- | Move a creature towards the mouse position, with shockwave -}
|
|
boostPoint
|
|
:: Float -- ^ boost amount
|
|
-> Creature
|
|
-> World
|
|
-> Either Point2 Point2
|
|
boostPoint x cr w = case mayp2 of
|
|
Nothing -> Right p1
|
|
Just p2 -> Left $ mvPointTowardAtSpeed r cpos $ fst p2
|
|
where
|
|
cpos = _crPos cr
|
|
r = 1.5 * _crRad cr
|
|
p1 = cpos +.+ x *.* squashNormalizeV (mouseWorldPos w -.- cpos)
|
|
mayp2 = bouncePoint (const True) 1 cpos p1 w
|
|
|
|
boostSelfL
|
|
:: Float -- ^ boost amount
|
|
-> Item
|
|
-> Creature
|
|
-> World
|
|
-> World
|
|
boostSelfL x itm cr w = case boostPoint x cr w of
|
|
Left p -> crEff p (itConsumption . laLoaded .~ 0)
|
|
Right p -> crEff p (itConsumption . laLoaded -~ 1)
|
|
where
|
|
invid = _ipInvID $ _itPos itm
|
|
cid = _crID cr
|
|
cpos = _crPos cr
|
|
r = _crRad cr
|
|
pid = fromMaybe (IM.newKey $ _props w)
|
|
(cr ^? crInv . ix invid . itAttachment . atInt)
|
|
crEff p ammoEff = addBoostShockwave pid p (r *.* normalizeV (p -.- cpos)) w
|
|
& creatures . ix cid %~
|
|
(crPos .~ p)
|
|
. (crInv . ix invid %~
|
|
ammoEff
|
|
. (itEffect . ieCounter .~ 1)
|
|
. (itAttachment .~ AttachInt pid)
|
|
)
|
|
|
|
addBoostShockwave
|
|
:: Int
|
|
-> Point2
|
|
-> Point2
|
|
-> World
|
|
-> World
|
|
addBoostShockwave pjid p v w = w & linearShockwaves %~
|
|
IM.insertWith f pjid thePJ
|
|
where
|
|
thePJ = LinearShockwave
|
|
{ _lwPos = p
|
|
, _lwID = pjid
|
|
, _lwPoints = [(p,v)]
|
|
, _lwTimer = maxT
|
|
}
|
|
f newVal oldVal = newVal & lwPoints %~ (++ _lwPoints oldVal)
|
|
|
|
maxT :: Int
|
|
maxT = 20
|
|
|
|
boosterGun :: Item
|
|
boosterGun = defaultLeftItem
|
|
{ _itInvColor = cyan
|
|
, _itConsumption = defaultChargeable
|
|
, _itUse = luseInstantNoH LBoost
|
|
, _itEffect = resetAttachmentID
|
|
}
|
|
& itType . iyBase .~ LEFT BOOSTER
|
|
resetAttachmentID :: ItEffect
|
|
resetAttachmentID = ItInvEffect ResetAttachmentEffect 0
|
|
|