module Dodge.Item.Weapon.BulletGun.Rod 
    ( bangRod
    , elephantGun
    , amr
    , autoAmr
    , sniperRifle
    , machineGun
    ) where
import Dodge.Data
import Dodge.Reloading.Action
import Dodge.Item.Weapon.BulletGun.Clip
import Dodge.Particle.HitEffect
import Dodge.Particle.Damage
--import Dodge.ChainEffect
--import Dodge.TweakBullet
import Dodge.Default.Weapon
--import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Default
import Dodge.Item.Weapon.ZoomScope
--import Dodge.Particle.HitEffect.ExpireAndDamage
--import Dodge.Particle.Damage
import Dodge.Item.Weapon.ExtraEffect
--import Dodge.Item.Weapon.InventoryDisplay
import Dodge.Item.Weapon.AmmoParams
--import Dodge.Item.Draw
import Dodge.Item.Weapon.TriggerType
import Dodge.SoundLogic.LoadSound
import Picture
import Geometry
import ShapePicture
import Shape
--import Sound.Data
import LensHelp

--import qualified Data.Sequence as Seq
--import Control.Lens
--import Control.Monad.State
--import System.Random

bangRod :: Item
bangRod = defaultBulletWeapon
    { _itParams = BulletShooter
        { _muzVel = 0.8
        , _rifling = 1
        , _bore = 2
        , _gunBarrels = SingleBarrel 0.1
        , _recoil = 50
        , _torqueAfter = 0.3
        , _randomOffset = 0
        }
    , _itUse = ruseAmmoParamsRate 12 upHammer
        [ ammoHammerCheck
        , useTimeCheck
        , withSoundStart bangEchoS
        , useAmmoAmount 1
        , withTorqueAfter
        , applyInaccuracy
        , withThickSmokeI
        , withMuzFlareI
        , withRecoil
        ]
    , _itDimension = ItemDimension
        { _dimRad = 12
        , _dimCenter = V3 5 0 0
        , _dimPortage = HeldItem
            {_handlePos =  5
            ,_muzPos    = 30
            }
        , _dimSPic = \it -> noPic $ baseRodShape
            <> makeSingleClipAt (V3 5 0 3) it
        }
    } 
    & itConsumption . laMax .~ 1
    & itConsumption . laCycle .~ [loadEject 5, loadInsert 10 , loadPrime 5]
    & itType . iyBase .~ BANGROD
    & itUse . useAim . aimWeight .~ 8
    & itUse . useAim . aimRange .~ 1
    & itUse . useAim . aimStance .~ OneHand
    & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
    & itConsumption . laAmmoType . amBulEff .~ expireAndDamage heavyBulDams
baseRodShape :: Shape
baseRodShape = colorSH orange $ upperPrismPoly 3 $ rectXH 20 2
baseAMRShape :: Shape
baseAMRShape = colorSH orange $ upperPrismPoly 3 $ rectXH 30 2
elephantGun :: Item
elephantGun = bangRod
    & itType . iyBase .~ ELEPHANTGUN
    & itUse . useAim . aimStance .~ TwoHandTwist
    & itParams . gunBarrels .~ SingleBarrel 0.05
    & itDimension . dimSPic .~ (\it -> noPic $ baseAMRShape
            <> makeSingleClipAt (V3 5 0 3) it
            )
    & itUse . useMods .~
        [ ammoHammerCheck
        , useTimeCheck
        , withSoundStart bangEchoS
        , useAmmoAmount 1
        , withTorqueAfter
        , applyInaccuracy
        , withThickSmokeI
        , withMuzFlareI
        , withRecoil
        ]
    & itParams . recoil .~ 50
    & itParams . torqueAfter .~ 0.1
amr :: Item
amr = elephantGun
    & itType . iyBase .~ AMR
    & itConsumption . laMax .~ 15
    & itDimension . dimSPic .~ (\it -> noPic $ baseAMRShape
            <> makeTinClipAt 0 (V3 10 (-2) 0) it
            )

autoAmr :: Item
autoAmr = amr
    & itType . iyBase .~ AUTOAMR
    & itUse . useMods %~ ((ammoCheckI :) . tail)

sniperRifle :: Item
sniperRifle = elephantGun
    & itType . iyBase .~ SNIPERRIFLE
    & itParams . gunBarrels .~ SingleBarrel 0
    & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}
    & itUse . heldScroll  .~ zoomLongGun
    & itScope   .~ ZoomScope (V2 0 0) 0 1 0.5 False
    & itTargeting .~ targetLaser
    & itUse . useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1}
machineGun :: Item
machineGun = bangRod
    & itType . iyBase .~ MACHINEGUN
    & itUse .~ (ruseAmmoParamsRate 25 NoHammer
        [ ammoCheckI
        , rateIncAB (torqueBeforeAtLeast 0.1 0.1) withTorqueAfter
        , withSoundStart bangEchoS
        , withThinSmokeI
        , withMuzFlareI
        ]
        & useAim . aimWeight .~ 8
        & useAim . aimRange .~ 1
        & useAim . aimStance .~ TwoHandTwist
        & useAim . aimZoom .~ defaultItZoom {_itZoomFac = 1.5}
        & useDelay .~ VariableRate {_rateMax = 25, _rateMaxMax = 24, _rateMinMax = 7, _rateTime = 0}
        )
    & itConsumption . laMax .~ 100
    & itConsumption . laCycle .~ [loadEject 10, loadInsert 40 , loadPrime 10]
    & itInvSize .~ 3
    & itParams. torqueAfter .~ 0.2 -- not sure if this is necessary?
