module Dodge.Particle.Damage where
import Dodge.Data
import Geometry
import LensHelp

import System.Random
import Control.Monad.State

-- TODO unify particle position in a sensible manner
spawnAtBulDams :: (Point2 -> State StdGen Particle)
    -> Particle -> Point2 -> [Damage]
spawnAtBulDams thespawn bt p =
    [ Damage PIERCING 50 sp p ep (DamageSpawn $ \_ dm -> thespawn (_dmAt dm))
    , Damage PUSHDAM   1 sp p ep . PushBackDamage $ 2 *.* bulVel
    ]
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

simpleDam :: DamageType -> Int -> Particle -> Point2 -> [Damage]
simpleDam dt amount bt p = [ Damage dt amount sp p ep NoDamageEffect ]
  where
    sp = case bt ^? ptTrail of
        Nothing -> _ptPos bt
        Just xs -> head xs
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

heavyBulDams :: Particle -> Point2 -> [Damage]
heavyBulDams bt p =
    [ Damage PIERCING 300 sp p ep NoDamageEffect
    , Damage PUSHDAM    1 sp p ep . PushBackDamage $ 2 *.* bulVel
    ]
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

basicBulDams :: Particle -> Point2 -> [Damage]
basicBulDams bt p =
    [ Damage PIERCING 100 sp p ep NoDamageEffect
    , Damage PUSHDAM    1 sp p ep . PushBackDamage $ 2 *.* bulVel
    ]
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

basicSparkDams :: Particle -> Point2 -> [Damage]
basicSparkDams bt p = [ Damage SPARKING 1 sp p ep NoDamageEffect ]
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

hvBulDams :: Particle -> Point2 -> [Damage]
hvBulDams bt p =
    [ Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage PIERCING  25 sp p ep NoDamageEffect
    , Damage TORQUEDAM  1 sp p ep $ TorqueDamage 0.7
    , Damage PUSHDAM    1 sp p ep . PushBackDamage $ 3 *.* (ep -.- sp)
    ] 
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel

bounceBulDams :: Particle -> Point2 -> [Damage]
bounceBulDams bt p =
    [ Damage PIERCING 80 sp p ep (BounceBullet bt)
    , Damage PUSHDAM   1 sp p ep . PushBackDamage $ 2 *.* bulVel
    ]
  where
    sp = head $ _ptTrail bt
    bulVel = _ptVel bt
    ep = sp +.+ bulVel
