#POD diablerie effects

POD_diablerie_effect = {
	save_temporary_scope_as = diablerist
	$VICTIM$ = { save_temporary_scope_as = victim }
	
	POD_give_diablerist_secret_or_trait_effect = yes
	POD_diablerie_piety_loss_effect = yes

	stress_impact = {
		ambitious = major_stress_impact_loss
		compassionate = major_stress_impact_gain
	}

	POD_diablerie_V5_effect = yes	
	POD_diablerie_gain_disciplines_effect = yes
	POD_bloodpotency_increase_effect = yes
	
	$VICTIM$ = {
		death = {
			death_reason = death_diablerie
			killer = scope:diablerist
		}
	}	

	if = {
		limit = { 
			NOT = { has_character_flag = POD_in_unconquered_soul_event } 
		}
		POD_diablerie_unconquered_soul_effect = yes
	}
}

POD_queue_diablerie_suspicion_event = {
	hidden_effect = {
		if = {
			limit = {
				$VICTIM$ = { is_vampire_trigger = yes } # safeguard
				NOT = { has_trait = diablerist } 
				NOT = { has_perk = fomori_deception_perk }
			}
			if = {
				limit = { NOT = { has_variable = diablere_sum } }
				set_variable = {
					name = diablere_sum
					value = 1
				}
			}
			else = {
				change_variable = {
					name = diablere_sum
					add = 1
				}
			}
			random = {
				chance = 40 
				
				trigger_event = {
					id = POD_diablerize.602
					days = 15
				}
			
				modifier = {
					add  = -20
					has_trait = obfuscateadvanced
				}
			}
		}
	}
}

POD_give_diablerist_secret_or_trait_effect = {
	if = {
		limit = {
			has_trait = vampire
			is_diablerist_trigger = no
		}
		add_secret = {
			type = secret_diablerist 
		}		
	}

    if = {
        limit = { POD_is_on_golconda_trigger = yes }
        custom_tooltip = POD_golconda_diablerie_alert
        POD_lose_golconda_effect = yes
    }
}

POD_diablerie_V5_effect = {
	if = {
		limit = {
			scope:victim = { has_trait = vampgeneration1 }
		}
		death = { death_reason = death_suicide }
		show_as_tooltip = {
			death = { death_reason = death_suicide }
			death = { death_reason = death_suicide }
			death = { death_reason = death_suicide }
			death = { death_reason = death_suicide }
			death = { death_reason = death_suicide }
			death = { death_reason = death_suicide }
		}
	}	

	else_if = {
		limit = {
			is_vampgeneration3_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 3 }
	}	
	
	else_if = {
		limit = {
			is_vampgeneration4_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 4 }
	}		

	else_if = {
		limit = {
			is_vampgeneration5_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 5 }
	}		

	else_if = {
		limit = {
			is_vampgeneration6_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 6 }
	}

	else_if = {
		limit = {
			is_vampgeneration7_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 7 }
	}	

	else_if = {
		limit = {
			is_vampgeneration8_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 8 }
	}	

	else_if = {
		limit = {
			is_vampgeneration9_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 9 }
	}
	
	else_if = {
		limit = {
			is_vampgeneration10_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 10 }
	}		

	else_if = {
		limit = {
			is_vampgeneration11_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 11 }
	}	

	else_if = {
		limit = {
			is_vampgeneration12_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 12 }
	}	

	else_if = {
		limit = {
			is_vampgeneration13_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 13 }
	}

	else_if = {
		limit = {
			is_vampgeneration14_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 14 }
	}

	else_if = {
		limit = {
			is_vampgeneration15_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 15 }
	}
	
	else_if = {
		limit = {
			is_vampgeneration16_trigger = yes
		}
		POD_diablerie_V5_gen_raise_effect = { GEN = 16 }
	}
}

POD_diablerie_V5_gen_raise_effect = {		
	if = {
		limit = {
			scope:victim = { 
				has_trait = vampgeneration
				has_trait_rank = {
					trait = vampgeneration
					rank < $GEN$
				}
			}
		}
		change_trait_rank = {
			trait = vampgeneration
			rank = -1
		}
	}
	POD_achiev_nomnom_check = yes
}

POD_diablerie_piety_loss_effect = {	
	if = {
		limit = {
			scope:victim = {	
				has_character_modifier = sentenced_court_blood_modifier
			}
		}
	}
	else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = sanctioned_diableries
			}
			scope:victim = {	
				OR = {
					has_trait = craven
					has_trait = arbitrary
					faith = {
						faith_hostility_level = {
						target = scope:diablerist.faith
						value = 3
						}
					}	
					}	
				}
			}
		add_piety = minor_piety_loss
	}

	else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = sanctioned_diableries
			}
			scope:victim = {	
				OR = {
					has_trait = just
					has_trait = brave
					faith = {
						faith_hostility_level = {
						target = scope:diablerist.faith
						value = 0
						}
					}	
					}	
				}
			}
		add_piety = massive_piety_loss
	}		
	
	else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = vampirediablerie_illegal
			}
		}
		add_piety = massive_piety_loss
	}
	
	else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = vampirediablerie_shunned
			}
		}
		add_piety = massive_piety_loss
	}	

	else_if = {
		limit = {
			faith = {
				has_doctrine_parameter = vampirediablerie_accepted
			}
		}
		add_piety = major_piety_loss
	}
	
}

POD_diablerie_gain_disciplines_effect = {
	if = {
		limit = { scope:diablerist = { POD_blocked_from_learning_trigger = no } }

		# Chance to learn Blood Sorcery Traditions if diablerist already knows Blood Sorcery
		if = {
			limit = {
				scope:diablerist = { has_bloodsorcery_trigger = yes }
				scope:victim = { has_bloodsorcery_trigger = yes }
			}

			scope:diablerist = {
				POD_learn_targets_known_bloodmagic_paths = {
					TARGET = scope:victim
					CHANCE = 10
				}
			}
		}

		# Chance to learn Necromancy paths if diablerist already knows Necromancy
		if = {
			limit = {
				scope:diablerist = { has_necromancy_trigger = yes }
				scope:victim = { has_necromancy_trigger = yes }
			}

			scope:diablerist = {
				POD_learn_targets_known_necromancy_paths = {
					TARGET = scope:victim
					CHANCE = 10
				}
			}
		}
		
		# Actual discipline assignment
		POD_trait_injector_disciplines = { EFFECT = POD_diablerie_roll_discipline }
	}
}

POD_diablerie_roll_discipline = {
	if = {
		limit = { scope:diablerist = { NOT = { has_trait = $TRAIT$discipline } } }
		
		if = {
			limit = { scope:victim = { has_trait = $TRAIT$ } }
			
			scope:diablerist = {
				POD_diablerie_gain_discipline = {
					CHANCE = 50
					TRAIT = $TRAIT$
				}
			}
		}
		
		if = {
			limit = { scope:victim = { has_trait = $TRAIT$advanced } }
			
			scope:diablerist = {
				POD_diablerie_gain_discipline = {
					CHANCE = 100
					TRAIT = $TRAIT$
				}
			}
		}
	}
}

POD_diablerie_gain_discipline = {
	random = {
		chance = $CHANCE$
		
		add_trait = $TRAIT$
		
		if = {
			limit = { trait:$TRAIT$ = trait:bloodsorcery }
			POD_learn_targets_known_bloodmagic_paths = {
				TARGET = scope:victim
				CHANCE = 100
			}
		}
		else_if = {
			limit = { trait:$TRAIT$ = trait:necromancy }
			POD_learn_targets_known_necromancy_paths = {
				TARGET = scope:victim
				CHANCE = 100
			}
		}
	}
}

POD_learn_targets_known_bloodmagic_paths = {
	if = {
		limit = {
			$TARGET$ = { has_thaumaturgy_bloodmagic_trigger = yes }
			has_thaumaturgy_bloodmagic_trigger = no
			can_learn_thaumaturgy_bloodmagic_trigger_visible = yes
		}
		random = {
			chance = $CHANCE$
			POD_learn_thaumaturgy_bloodmagic_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_dur_an_ki_bloodmagic_trigger = yes }
			has_dur_an_ki_bloodmagic_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_dur_an_ki_bloodmagic_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_akhu_bloodmagic_trigger = yes }
			has_akhu_bloodmagic_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_akhu_bloodmagic_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_sadhana_bloodmagic_trigger = yes }
			has_sadhana_bloodmagic_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_sadhana_bloodmagic_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_koldunic_bloodmagic_trigger = yes }
			has_koldunic_bloodmagic_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_koldunic_bloodmagic_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_sihr_bloodmagic_trigger = yes }
			has_sihr_bloodmagic_trigger = no
			can_learn_sihr_bloodmagic_trigger_visible = yes
		}
		random = {
			chance = $CHANCE$
			POD_learn_sihr_bloodmagic_effect = yes
		}
	}
}

POD_learn_targets_known_necromancy_paths = {
	if = {
		limit = {
			$TARGET$ = { has_cappadocian_necromancy_trigger = yes }
			has_cappadocian_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_cappadocian_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_giovanni_necromancy_trigger = yes }
			has_giovanni_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_giovanni_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_harbinger_necromancy_trigger = yes }
			has_harbinger_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_harbinger_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_impundulu_necromancy_trigger = yes }
			has_impundulu_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_impundulu_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_lamia_necromancy_trigger = yes }
			has_lamia_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_lamia_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_nagaraja_necromancy_trigger = yes }
			has_nagaraja_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_nagaraja_necromancy_effect = yes
		}
	}
	if = {
		limit = {
			$TARGET$ = { has_rosselini_necromancy_trigger = yes }
			has_rosselini_necromancy_trigger = no
		}
		random = {
			chance = $CHANCE$
			POD_learn_rosselini_necromancy_effect = yes
		}
	}
}