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

	<!-- Larvae -->
	<Operation Class="PatchOperationAddModExtension">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetleLarvae"]</xpath>
		<value>
			<li Class="CombatExtended.RacePropertiesExtensionCE">
				<bodyShape>Quadruped</bodyShape>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetleLarvae"]/statBases</xpath>
		<value>
			<MeleeDodgeChance>0</MeleeDodgeChance>
			<MeleeCritChance>0.01</MeleeCritChance>
			<MeleeParryChance>0.01</MeleeParryChance>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetleLarvae"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>head</label>
					<capacities>
						<li>Bite</li>
					</capacities>
					<power>3</power>
					<cooldownTime>2</cooldownTime>
					<linkedBodyPartsGroup>HeadAttackTool</linkedBodyPartsGroup>
					<ensureLinkedBodyPartsGroupAlwaysUsable>true</ensureLinkedBodyPartsGroupAlwaysUsable>
					<armorPenetrationSharp>0.1</armorPenetrationSharp>
					<armorPenetrationBlunt>0.25</armorPenetrationBlunt>
				</li>
			</tools>
		</value>
	</Operation>

	<!-- Pupae -->
	<Operation Class="PatchOperationAddModExtension">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]</xpath>
		<value>
			<li Class="CombatExtended.RacePropertiesExtensionCE">
				<bodyShape>Quadruped</bodyShape>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]/statBases</xpath>
		<value>
			<MeleeDodgeChance>0</MeleeDodgeChance>
			<MeleeCritChance>0</MeleeCritChance>
			<MeleeParryChance>0</MeleeParryChance>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]/statBases/ArmorRating_Sharp</xpath>
		<value>
			<ArmorRating_Sharp>4.5</ArmorRating_Sharp>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>Twitching</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>1</power>
					<cooldownTime>1000</cooldownTime>
					<linkedBodyPartsGroup>HeadAttackTool</linkedBodyPartsGroup>
					<armorPenetrationSharp>0.12</armorPenetrationSharp>
					<armorPenetrationBlunt>0.25</armorPenetrationBlunt>
				</li>

			</tools>
		</value>
	</Operation>
	
	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]/comps</xpath>
		<nomatch Class="PatchOperationAdd">
			<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]</xpath>
			<value>
				<comps />
			</value>
		</nomatch>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetlePupa"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_ArmorDurability">
				<Durability>450</Durability>
				<Regenerates>true</Regenerates>
				<RegenInterval>600</RegenInterval>
				<RegenValue>5</RegenValue>
				<MinArmorPct>0.25</MinArmorPct>
			</li>
		</value>
	</Operation>

	<!-- Fully Grown -->
	<Operation Class="PatchOperationAddModExtension">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]</xpath>
		<value>
			<li Class="CombatExtended.RacePropertiesExtensionCE">
				<bodyShape>Quadruped</bodyShape>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]/statBases</xpath>
		<value>
			<MeleeDodgeChance>0.03</MeleeDodgeChance>
			<MeleeCritChance>0.24</MeleeCritChance>
			<MeleeParryChance>0.13</MeleeParryChance>
			<ArmorRating_Sharp>3.5</ArmorRating_Sharp>
			<ArmorRating_Blunt>1</ArmorRating_Blunt>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>Head Claw</label>
					<capacities>
						<li>Cut</li>
					</capacities>
					<power>20</power>
					<cooldownTime>2</cooldownTime>
					<linkedBodyPartsGroup>HeadClaw</linkedBodyPartsGroup>
					<armorPenetrationBlunt>2</armorPenetrationBlunt>
					<armorPenetrationSharp>9</armorPenetrationSharp>
					<chanceFactor>0.7</chanceFactor>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>head</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>14</power>
					<cooldownTime>2.9</cooldownTime>
					<linkedBodyPartsGroup>HeadAttackTool</linkedBodyPartsGroup>
					<armorPenetrationBlunt>6</armorPenetrationBlunt>
					<ensureLinkedBodyPartsGroupAlwaysUsable>true</ensureLinkedBodyPartsGroupAlwaysUsable>
				</li>
			</tools>
		</value>
	</Operation>
	
	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]/comps</xpath>
		<nomatch Class="PatchOperationAdd">
			<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]</xpath>
			<value>
				<comps />
			</value>
		</nomatch>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="BMT_FoundryBeetle"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_ArmorDurability">
				<Durability>1037</Durability>
				<Regenerates>true</Regenerates>
				<RegenInterval>600</RegenInterval>
				<RegenValue>5</RegenValue>
				<MinArmorPct>0.25</MinArmorPct>
			</li>
		</value>
	</Operation>

</Patch>