﻿namespace = holy_stuff_holy_land_relic_event

##################################################
# Holy Land Relic Events
##################################################

#Crusader trait gained during GHW.
#Fired on_army_enter_province
#Hidden first event fires for the owner of the army.
#root = owner of the army
#scope:army = the army itself.
holy_stuff_holy_land_relic_event.0001 = {
	hidden = yes
	
	trigger = {
                relic_hunter_is_valid_trigger = yes
		is_ai = no
		exists = root.faith.great_holy_war
		OR = { #Either army owner or one of his lieges is involved in a GHW.
			any_character_war = {
				OR = {
					using_cb = undirected_great_holy_war
					using_cb = directed_great_holy_war
				}
				is_attacker = root
			}
			any_liege_or_above = {
				faith = root.faith
				any_character_war = {
					OR = {
						using_cb = undirected_great_holy_war
						using_cb = directed_great_holy_war
					}
					is_attacker = root
				}
			}
		}
		scope:army = {
			exists = army_commander
			location = { save_temporary_scope_as = current_location }
		}
		root.faith.great_holy_war.ghw_target_title = { this = title:k_jerusalem  } 
		root.faith.great_holy_war.ghw_target_title = { #The dejure Kingdom targeted by the GHW
			any_in_de_jure_hierarchy = {
				tier = tier_barony
				title_province = { this = scope:current_location } #Any province within it.
				exists = holder
				holder = { #The province's owner must also be part of the GHW on the opposite side.
					OR = {
						any_character_war = {
							OR = {
								using_cb = undirected_great_holy_war
								using_cb = directed_great_holy_war
							}
							is_defender = prev
						}
						any_liege_or_above = {
							any_character_war = {
								OR = {
									using_cb = undirected_great_holy_war
									using_cb = directed_great_holy_war
								}
								is_defender = prev
							}
						}
					}
				}
			}
		}
	}

	immediate = {
		scope:army.location = { save_scope_as = current_location }
		faith = { save_scope_as = the_faith }
		faith.great_holy_war = { save_scope_as = scoped_ghw }
		faith.great_holy_war.ghw_target_title = { save_scope_as = target_kingdom }
		scope:army = {
			army_commander = { 
				random_list = {
					20 = {
						trigger_event = { 
                                                        id = holy_stuff_holy_land_relic_event.0002 #Holy Lance
							days = 40
							}
						}
					20 = {
						trigger_event = { 
                                                        id = holy_stuff_holy_land_relic_event.0003 #Holy Blood
							days = 40
							}
						}
					20 = {
						trigger_event = { 
                                                        id = holy_stuff_holy_land_relic_event.0004 #Holy Thorn
							days = 40
							}
						}
					20 = {
						trigger_event = { 
                                                        id = holy_stuff_holy_land_relic_event.0005 #Splinter of the True Cross
							days = 40
							}
						}
					20 = {
						trigger_event = { 
                                                        id = holy_stuff_holy_land_relic_event.0006 #Holy Tears
							days = 40
							}
						}
				}
			} 
		}
	}
}

holy_stuff_holy_land_relic_event.0002 = {
	title = holy_stuff_holy_land_relic_event.0002.t
	desc = holy_stuff_holy_land_relic_event.0002.desc
	theme = faith
	override_background = {
		reference = wilderness_scope
	}
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	
	trigger = {
		NOT = {
                         has_variable = holy_land_relic
		}
                relic_hunter_is_valid_trigger = yes
		root.faith = scope:the_faith
		exists = faith.great_holy_war
		OR = {
			is_commanding_army = yes
		}
	}

	immediate = {
		faith = {
			great_holy_war = {
				ghw_war = {
					primary_defender = {
						capital_province = {
							save_scope_as = background_wilderness_scope
						}
					}
				}
			}
		}
		play_music_cue = "mx_cue_epic_sacral_moment"
		root = {
			create_artifact_holy_lance_antiochia_effect = { OWNER = this }
		}
		set_variable = {
			name = holy_land_relic
		}
	}
	
	option = {
		name = holy_stuff_holy_land_relic_event.0002.a
	}
}

holy_stuff_holy_land_relic_event.0003 = {
	title = holy_stuff_holy_land_relic_event.0003.t
	desc = holy_stuff_holy_land_relic_event.0003.desc
	theme = faith
	override_background = {
		reference = wilderness_scope
	}
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	
	trigger = {
		NOT = {
                         has_variable = holy_land_relic
		}
                relic_hunter_is_valid_trigger = yes
		root.faith = scope:the_faith
		exists = faith.great_holy_war
		OR = {
			is_commanding_army = yes
		}
	}

	immediate = {
		faith = {
			great_holy_war = {
				ghw_war = {
					primary_defender = {
						capital_province = {
							save_scope_as = background_wilderness_scope
						}
					}
				}
			}
		}
		play_music_cue = "mx_cue_epic_sacral_moment"
		root = {
			create_artifact_holy_blood_effect = { OWNER = this }
		}
		set_variable = {
			name = holy_land_relic
		}
	}
	
	option = {
		name = holy_stuff_holy_land_relic_event.0003.a
	}
}

holy_stuff_holy_land_relic_event.0004 = {
	title = holy_stuff_holy_land_relic_event.0004.t
	desc = holy_stuff_holy_land_relic_event.0004.desc
	theme = faith
	override_background = {
		reference = wilderness_scope
	}
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	
	trigger = {
		NOT = {
                         has_variable = holy_land_relic
		}
                relic_hunter_is_valid_trigger = yes
		root.faith = scope:the_faith
		exists = faith.great_holy_war
		OR = {
			is_commanding_army = yes
		}
	}

	immediate = {
		faith = {
			great_holy_war = {
				ghw_war = {
					primary_defender = {
						capital_province = {
							save_scope_as = background_wilderness_scope
						}
					}
				}
			}
		}
		play_music_cue = "mx_cue_epic_sacral_moment"
		root = {
			create_artifact_holy_thorn_effect = { OWNER = this }
		}
		set_variable = {
			name = holy_land_relic
		}
	}
	
	option = {
		name = holy_stuff_holy_land_relic_event.0004.a
	}
}

holy_stuff_holy_land_relic_event.0005 = {
	title = holy_stuff_holy_land_relic_event.0005.t
	desc = holy_stuff_holy_land_relic_event.0005.desc
	theme = faith
	override_background = {
		reference = wilderness_scope
	}
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	
	trigger = {
		NOT = {
                         has_variable = holy_land_relic
		}
                relic_hunter_is_valid_trigger = yes
		root.faith = scope:the_faith
		exists = faith.great_holy_war
		OR = {
			is_commanding_army = yes
		}
	}

	immediate = {
		faith = {
			great_holy_war = {
				ghw_war = {
					primary_defender = {
						capital_province = {
							save_scope_as = background_wilderness_scope
						}
					}
				}
			}
		}
		play_music_cue = "mx_cue_epic_sacral_moment"
		root = {
			create_artifact_splinter_of_the_true_cross_effect = { OWNER = this }
		}
		set_variable = {
			name = holy_land_relic
		}
	}
	
	option = {
		name = holy_stuff_holy_land_relic_event.0005.a
	}
}

holy_stuff_holy_land_relic_event.0006 = {
	title = holy_stuff_holy_land_relic_event.0006.t
	desc = holy_stuff_holy_land_relic_event.0006.desc
	theme = faith
	override_background = {
		reference = wilderness_scope
	}
	left_portrait = {
		character = root
		animation = personality_zealous
	}
	
	trigger = {
		NOT = {
                         has_variable = holy_land_relic
		}
                relic_hunter_is_valid_trigger = yes
		root.faith = scope:the_faith
		exists = faith.great_holy_war
		OR = {
			is_commanding_army = yes
		}
	}

	immediate = {
		faith = {
			great_holy_war = {
				ghw_war = {
					primary_defender = {
						capital_province = {
							save_scope_as = background_wilderness_scope
						}
					}
				}
			}
		}
		play_music_cue = "mx_cue_epic_sacral_moment"
		root = {
			create_artifact_holy_tears_effect = { OWNER = this }
		}
		set_variable = {
			name = holy_land_relic
		}
	}
	
	option = {
		name = holy_stuff_holy_land_relic_event.0006.a
	}
}