<?xml version="1.0" encoding="utf-8"?>
<Patch>

	<!-- ========== patch HP so ammo damage matches vanilla ========== -->

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VQED_Gun_MachinePistol_Ancient"]/statBases</xpath>
		<value>
			<MaxHitPoints>350</MaxHitPoints>
		</value>
	</Operation>

	<!-- ========== Tools ========== -->

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VQED_Gun_Autopistol_Ancient" or defName="VQED_Gun_MachinePistol_Ancient"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>grip</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>2</power>
					<cooldownTime>1.54</cooldownTime>
					<chanceFactor>1.5</chanceFactor>
					<armorPenetrationBlunt>0.555</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Grip</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>muzzle</label>
					<capacities>
						<li>Poke</li>
					</capacities>
					<power>2</power>
					<cooldownTime>1.54</cooldownTime>
					<armorPenetrationBlunt>0.555</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Muzzle</linkedBodyPartsGroup>
				</li>
			</tools>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VQED_Gun_PumpShotgun_Ancient" or defName="VQED_Gun_LMG_Ancient"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>stock</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>8</power>
					<cooldownTime>1.55</cooldownTime>
					<chanceFactor>1.5</chanceFactor>
					<armorPenetrationBlunt>2.755</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Stock</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>barrel</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>5</power>
					<cooldownTime>2.02</cooldownTime>
					<armorPenetrationBlunt>1.630</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Barrel</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>muzzle</label>
					<capacities>
						<li>Poke</li>
					</capacities>
					<power>8</power>
					<cooldownTime>1.55</cooldownTime>
					<armorPenetrationBlunt>2.755</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Muzzle</linkedBodyPartsGroup>
				</li>
			</tools>
		</value>
	</Operation>

	<!-- ========== Autopistol ========== -->

	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VQED_Gun_Autopistol_Ancient</defName>
		<statBases>
			<Mass>0.87</Mass>
			<RangedWeapon_Cooldown>0.38</RangedWeapon_Cooldown>
			<SightsEfficiency>0.7</SightsEfficiency>
			<ShotSpread>0.17</ShotSpread>
			<SwayFactor>1.03</SwayFactor>
			<Bulk>2.22</Bulk>
		</statBases>
		<Properties>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>true</hasStandardCommand>
			<defaultProjectile>Bullet_9x19mmPara_FMJ_VQEDL</defaultProjectile>
			<warmupTime>0.6</warmupTime>
			<range>12</range>
			<soundCast>Shot_Autopistol</soundCast>
			<soundCastTail>GunTail_Light</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
			<recoilAmount>2.72</recoilAmount>
		</Properties>
		<AmmoUser>
			<magazineSize>8</magazineSize>
			<reloadTime>4.5</reloadTime>
			<ammoSet>AmmoSet_9x19mmPara_VQEDL</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiUseBurstMode>FALSE</aiUseBurstMode>
			<aiAimMode>Snapshot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>CE_Sidearm</li>
			<li>CE_AI_BROOM</li>
			<li>CE_OneHandedWeapon</li>
		</weaponTags>
	</Operation>

	<!-- ========== Pump Shotgun ========== -->

	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VQED_Gun_PumpShotgun_Ancient</defName>
		<statBases>
			<Mass>4.5</Mass>
			<RangedWeapon_Cooldown>0.99</RangedWeapon_Cooldown>
			<ShotSpread>0.14</ShotSpread>
			<SwayFactor>1.31</SwayFactor>
			<Bulk>12.0</Bulk>
			<SightsEfficiency>1</SightsEfficiency>
		</statBases>
		<Properties>
			<recoilAmount>2.72</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>true</hasStandardCommand>
			<defaultProjectile>Bullet_12Gauge_Buck_VQEDL</defaultProjectile>
			<warmupTime>0.6</warmupTime>
			<range>16</range>
			<soundCast>Shot_Shotgun</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
		</Properties>
		<AmmoUser>
			<magazineSize>5</magazineSize>
			<reloadTime>0.85</reloadTime>
			<ammoSet>AmmoSet_12Gauge_VQEDL</ammoSet>
			<reloadOneAtATime>true</reloadOneAtATime>
		</AmmoUser>
		<FireModes>
			<aiAimMode>Snapshot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>SimpleGun</li>
			<li>CE_AI_BROOM</li>
		</weaponTags>
	</Operation>

	<!-- ========== Machine pistol ========== -->

	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VQED_Gun_MachinePistol_Ancient</defName>
		<statBases>
			<Mass>3.97</Mass>
			<RangedWeapon_Cooldown>0.36</RangedWeapon_Cooldown>
			<SightsEfficiency>1.00</SightsEfficiency>
			<ShotSpread>0.13</ShotSpread>
			<SwayFactor>1.23</SwayFactor>
			<Bulk>6.30</Bulk>
		</statBases>
		<Properties>
			<recoilAmount>1.16</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>true</hasStandardCommand>
			<defaultProjectile>Bullet_9x19mmPara_FMJ_VQEDL</defaultProjectile>
			<warmupTime>0.6</warmupTime>
			<range>20</range>
			<burstShotCount>6</burstShotCount>
			<ticksBetweenBurstShots>7</ticksBetweenBurstShots>
			<soundCast>Shot_MachinePistol</soundCast>
			<soundCastTail>GunTail_Medium</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
		</Properties>
		<AmmoUser>
			<magazineSize>30</magazineSize>
			<reloadTime>4</reloadTime>
			<ammoSet>AmmoSet_9x19mmPara_VQEDL</ammoSet>
		</AmmoUser>
		<FireModes>
			<aimedBurstShotCount>3</aimedBurstShotCount>
			<aiUseBurstMode>FALSE</aiUseBurstMode>
			<aiAimMode>Snapshot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>CE_SMG</li>
			<li>CE_AI_BROOM</li>
			<li>CE_OneHandedWeapon</li>
		</weaponTags>
	</Operation>

	<!-- ========== LMG ========== -->

	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VQED_Gun_LMG_Ancient</defName>
		<statBases>
			<Mass>15.20</Mass>
			<RangedWeapon_Cooldown>0.56</RangedWeapon_Cooldown>
			<SightsEfficiency>1</SightsEfficiency>
			<ShotSpread>0.06</ShotSpread>
			<SwayFactor>1.67</SwayFactor>
			<Bulk>11.60</Bulk>
		</statBases>
		<Properties>
			<recoilAmount>1.25</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>true</hasStandardCommand>
			<defaultProjectile>Bullet_792x57mmMauser_FMJ_VQEDL</defaultProjectile>
			<warmupTime>1.3</warmupTime>
			<range>62</range>
			<ticksBetweenBurstShots>3</ticksBetweenBurstShots>
			<burstShotCount>10</burstShotCount>
			<soundCast>Shot_Minigun</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
			<targetParams>
				<canTargetLocations>true</canTargetLocations>
			</targetParams>
			<recoilPattern>Mounted</recoilPattern>
		</Properties>
		<AmmoUser>
			<magazineSize>50</magazineSize>
			<reloadTime>7.8</reloadTime>
			<ammoSet>AmmoSet_792x57mmMauser_VQEDL</ammoSet>
		</AmmoUser>
		<FireModes>
			<aimedBurstShotCount>5</aimedBurstShotCount>
			<aiUseBurstMode>FALSE</aiUseBurstMode>
			<aiAimMode>SuppressFire</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>CE_MachineGun</li>
			<li>CE_AI_LMG</li>
			<li>Bipod_LMG</li>
		</weaponTags>
		<AllowWithRunAndGun>false</AllowWithRunAndGun>
	</Operation>

	<!-- ========== Remove vanilla comp if present ========== -->

	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VQED_Gun_Autopistol_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		<match Class="PatchOperationRemove">
			<xpath>Defs/ThingDef[defName="VQED_Gun_Autopistol_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		</match>
	</Operation>

	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VQED_Gun_MachinePistol_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		<match Class="PatchOperationRemove">
			<xpath>Defs/ThingDef[defName="VQED_Gun_MachinePistol_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		</match>
	</Operation>

	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VQED_Gun_PumpShotgun_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		<match Class="PatchOperationRemove">
			<xpath>Defs/ThingDef[defName="VQED_Gun_PumpShotgun_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		</match>
	</Operation>

	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VQED_Gun_LMG_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		<match Class="PatchOperationRemove">
			<xpath>Defs/ThingDef[defName="VQED_Gun_LMG_Ancient"]/comps/li[@Class="VanillaQuestsExpandedDeadlife.CompProperties_WeaponDeteriorable"]</xpath>
		</match>
	</Operation>

	<!-- ========== Loot table ========== -->

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VQED_MysteriousAncientWeaponBox"]/modExtensions/li[@Class="VEF.Buildings.LootableBuildingDetails"]/contents</xpath>
		<value>
			<li>
				<thing>Ammo_9x19mmPara_HP</thing>
				<count>210</count>
			</li>
			<li>
				<thing>Ammo_12Gauge_Buck</thing>
				<count>50</count>
			</li>
			<li>
				<thing>Ammo_792x57mmMauser_HP</thing>
				<count>200</count>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VQED_MysteriousAncientWeaponBox"]/modExtensions/li[@Class="VEF.Buildings.LootableBuildingDetails"]/totalRandomLoops</xpath>
		<value>
			<totalRandomLoops>2~2</totalRandomLoops>
		</value>
	</Operation>
</Patch>