module Dodge.Item.Weapon.Spawn where
import Dodge.Data
import Dodge.Item.Weapon.TriggerType
--import Dodge.Item.Weapon.Remote
import Dodge.Default.Weapon
import Dodge.Default
--import Dodge.Item.Weapon.Grenade
import Geometry
import qualified IntMapHelp as IM

import Data.Function
import Control.Lens


{- |
Creates a creature next to the creature using the item.  -}
spawnGun :: Creature -> Item
spawnGun cr = defaultWeapon
    { _itConsumption = defaultLoadable
    , _itUse       = ruseRate 100 
        (\_ -> spawnCrNextTo cr)
        upHammer
        [ ammoCheckI
        , hammerCheckI
        ]
    }
    & itType . iyBase .~ SPAWNER
spawnCrNextTo 
    :: Creature -- ^ Creature to spawn
    -> Creature -- ^ existing creature that will be spawned next to
    -> World 
    -> World
spawnCrNextTo cr sCr w = w & creatures %~ IM.insert k newCr
  where
    k = IM.newKey $ _creatures w
    newCr = cr
        & crID  .~ k
        & crPos .~ _crPos sCr +.+ unitVectorAtAngle (_crDir sCr)
        & crOldPos .~ _crPos sCr +.+ unitVectorAtAngle (_crDir sCr)
