module Dodge.Item.Weapon.Drone where
import Dodge.Data
import Dodge.Default.Weapon
import Dodge.SoundLogic.LoadSound
import Dodge.Item.Weapon.TriggerType
import Geometry
import Geometry.Vector3D
import Picture
import qualified IntMapHelp as IM
import ShapePicture
import Shape

--import qualified Data.Set as S
--import qualified SDL
--import Data.Maybe
import Control.Lens
--import Control.Applicative
--import Control.Monad.State
--import System.Random

lasDrones :: Item
lasDrones = defaultGun 
    { _itName = "DRONES"
    , _itIdentity = Generic
    , _wpMaxAmmo = 2
    , _wpLoadedAmmo = 2
    , _wpReloadTime = 80
    , _wpReloadState = 0
    , _itUseRate = 20
    , _itUseTime = 0
    , _itUse = aDroneWithItemParams
    , _itUseModifiers =
        [ ammoCheckI
        , useTimeCheckI
        , withSoundStart tap4S
        , useAmmo 1
        ]
    , _wpSpread = 0.02
    , _wpRange = 20
    , _itFloorPict = lasDronesPic
    , _itAimingSpeed = 0.2
    , _itAimingRange = 0.5
    , _itHammer = NoHammer
    , _itEffect = NoItEffect
    , _wpAmmo = DroneAmmo
        { _amString = "LASDRONE" }
    , _itAimStance = TwoHandTwist
    }

lasDronesPic :: Item -> SPic
lasDronesPic _ = 
    ( colorSH chartreuse $ prismPoly
        (map (+.+.+ V3 10 0 4.5) $ polyCircx 4 5)
        (map (+.+.+ V3 (-10) 0 4.5) $ polyCircx 4 5)
    , mempty
    )

aDroneWithItemParams
    :: Item   -- ^ Firing item
    -> Creature
    -> World
    -> World
aDroneWithItemParams it cr w = over props (IM.insert i theShell) w
  where 
    am = _wpAmmo it
    i = IM.newKey $ _props w
    pos = _crPos cr +.+ ((_crRad cr +1) *.* unitVectorAtAngle dir)
    dir = _crDir cr
    --ammoMvs pj w' = foldr (\pjP -> _pjMoveParam pjP (_pjIntParam pjP) it cr pj) w' (_amPjParams am)
    theShell = Drone
        { _pjPos = pos
        , _pjStartPos = pos
        , _pjVel = rotateV dir (V2 1 0)
        , _prDraw = _amPjDraw am
        , _pjID = i
        , _pjUpdate = const id
        }
