module Dodge.Item.Weapon.Drone where
import Dodge.Data
import Dodge.Default.Weapon
import Dodge.Default
import Dodge.SoundLogic.LoadSound
import Dodge.Item.Weapon.TriggerType
import Geometry
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

droneLauncher :: Item
droneLauncher = defaultWeapon 
    { _itUse = ruseRate 20 aDroneWithItemParams upHammer
        [ ammoCheckI
        , useTimeCheck
        , withSoundStart tap4S
        , useAmmoAmount 1
        ]
        & useAim . aimWeight .~ 8
        & useAim . aimRange .~ 0.5
        & useAim . aimStance .~ TwoHandTwist
    , _itEffect = NoItEffect
    }
    & itConsumption . laAmmoType .~ DroneAmmo { _amString = "LASDRONE" }
    & itConsumption . laMax .~ 2
    & itType . iyBase .~ DRONELAUNCHER

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 = _itConsumption 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
        { _prPos = pos
        , _pjStartPos = pos
        , _pjVel = rotateV dir (V2 1 0)
        , _prDraw = _amPjDraw $ _laAmmoType am
        , _pjID = i
        , _pjUpdate = const id
        }
