﻿#Player may manually remove the Obscured trait
remove_obscure_trait = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	icon = icon_contract_modification_single
	common_interaction = yes
	
	desc = remove_obscure_trait_desc

	is_shown = {
		scope:recipient = {
			has_trait = acotw_obscured
		}
		NOT = { scope:recipient = scope:actor }
	}

	send_option = {
		flag = remove_ruler_trait
		localization = remove_ruler_trait_only
	}
	
	send_option = {
		is_shown = {
			scope:recipient = {
				any_courtier = {
					is_alive = yes
				}
			}
		}
		flag = remove_ruler_and_courtiers_traits
		localization = remove_ruler_and_courtiers_trait_only
	}
	
	send_option = {
		is_shown = {
			scope:recipient = {
				is_ruler = yes
				any_vassal = {
					is_alive = yes
				}
			}
		}
		flag = remove_ruler_courtiers_vassals_traits
		localization = remove_ruler_vassals_courtiers_trait_only
	}
	
	send_option = {
		is_shown = {
			scope:recipient = {
				top_liege = this
			}
		}
		flag = remove_realm_traits
		localization = remove_all_traits
	}

	#send_options_exclusive = no

	ai_frequency = 0

	on_accept = {
		scope:recipient = {
			if = {
				limit = { scope:remove_ruler_trait ?= yes }
				
				actow_olympia_remove_culling_trait_and_modifiers = yes
				add_character_flag = acotw_do_not_obscure
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_removed_obscurity.t
						desc = olympia_removed_obscurity_desc
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
			else_if = {
				limit = { scope:remove_ruler_and_courtiers_traits ?= yes }
				
				actow_olympia_remove_culling_trait_and_modifiers = yes
				add_character_flag = acotw_do_not_obscure
				every_courtier_or_guest = {
					actow_olympia_remove_culling_trait_and_modifiers = yes
				}
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_removed_obscurity.t
						desc = olympia_removed_obscurity_desc.court
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
			else_if = {
				limit = { scope:remove_ruler_courtiers_vassals_traits ?= yes }
				
				actow_olympia_remove_culling_trait_and_modifiers = yes
				add_character_flag = acotw_do_not_obscure
				every_courtier_or_guest = {
					actow_olympia_remove_culling_trait_and_modifiers = yes
				}
				
				every_vassal_or_below = {
					actow_olympia_remove_culling_trait_and_modifiers = yes
				}
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_removed_obscurity.t
						desc = olympia_removed_obscurity_desc.vassals
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
			else_if = {
				limit = { scope:remove_realm_traits ?= yes }
				
				olympia_purge_obscured_from_realm = yes
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_removed_obscurity.t
						desc = olympia_removed_obscurity_desc.realm
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
		}
	}

	auto_accept = yes
}

#Player may manually add back the Obscured trait
add_obscure_trait = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes
	icon = icon_contract_modification_single
	common_interaction = yes
	
	desc = remove_obscure_trait_desc

	is_shown = {
		scope:recipient = {
			NOT = { has_trait = acotw_obscured }
			NOT = {
				any_player = {
					in_diplomatic_range = scope:recipient
				}
			}
			NOT = { is_at_war_with = scope:actor }	#No adding it back when you're at war
		}
	}

	send_option = {
		flag = add_ruler_trait
		localization = add_ruler_trait_only
	}
	
	send_option = {
		is_shown = {
			scope:recipient = {
				is_ruler = yes
				any_vassal = {
					is_alive = yes
				}
			}
		}
		flag = add_ruler_courtiers_vassals_traits
		localization = add_ruler_vassals_courtiers_trait_only
	}
	
	send_option = {
		is_shown = {
			scope:recipient = {
				top_liege = this
			}
		}
		flag = add_realm_traits
		localization = add_all_traits
	}

	#send_options_exclusive = no

	ai_frequency = 0

	on_accept = {
		scope:recipient = {
			if = {
				limit = { scope:add_ruler_trait ?= yes }
				
				add_trait = acotw_obscured
				actow_olympia_add_ruler_modifiers = yes
				actow_olympia_add_health_modifiers = yes
				remove_character_flag = acotw_do_not_obscure
				
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_added_obscurity.t
						desc = olympia_added_obscurity_desc
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
			else_if = {
				limit = { scope:add_ruler_courtiers_vassals_traits ?= yes }
				
				add_trait = acotw_obscured
				actow_olympia_add_ruler_modifiers = yes
				actow_olympia_add_health_modifiers = yes
				remove_character_flag = acotw_do_not_obscure
				
				every_courtier_or_guest = {
					add_trait = acotw_obscured
					actow_olympia_add_health_modifiers = yes
					remove_character_flag = acotw_do_not_obscure
				}
				
				every_vassal_or_below = {
					add_trait = acotw_obscured
					actow_olympia_add_ruler_modifiers = yes
					actow_olympia_add_health_modifiers = yes
					remove_character_flag = acotw_do_not_obscure
				}
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_added_obscurity.t
						desc = olympia_added_obscurity_desc.vassals
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
			else_if = {
				limit = { scope:add_realm_traits ?= yes }
				
				#If they are obscured but haven't yet got the modifiers particularly if they just inherited the title
				add_trait = acotw_obscured
				actow_olympia_add_ruler_modifiers = yes
				actow_olympia_add_health_modifiers = yes
				remove_character_flag = acotw_do_not_obscure
				
				#Add traits and modifiers to all courtiers and guests
				every_courtier_or_guest = {
					limit = { acotw_character_can_be_obscured = yes }
					add_trait = acotw_obscured
					actow_olympia_add_health_modifiers = yes
					remove_character_flag = acotw_do_not_obscure
				}
				
				#Add traits to every vassal
				every_vassal_or_below = {
					limit = { acotw_character_can_be_obscured = yes }
					add_trait = acotw_obscured
					actow_olympia_add_ruler_modifiers = yes
					actow_olympia_add_health_modifiers = yes
					remove_character_flag = acotw_do_not_obscure
				}
				
				#Add traits to every vassal's courtiers and guests
				every_vassal_or_below = {				
					every_courtier_or_guest = {
						limit = { acotw_character_can_be_obscured = yes }
						add_trait = acotw_obscured
						actow_olympia_add_health_modifiers = yes
						remove_character_flag = acotw_do_not_obscure
					}
				}
				
				every_player = {
					#Alert all players useful for multiplayer
					send_interface_message = {
						type = olympia_removed_obscurity
						title = olympia_added_obscurity.t
						desc = olympia_added_obscurity_desc.realm
						left_icon = scope:recipient
						right_icon = scope:actor
					}
				}
			}
		}
	}

	auto_accept = yes
}

#A manual way of checking to ensure that all realms have the correct obscurity status
acotw_check_for_obscurity = {
	category = interaction_category_diplomacy
	icon = icon_contract_modification_single
	interface_priority = 0
	cooldown = { days = 90 }
	
	desc = acotw_check_for_obscurity_desc
	
	auto_accept = yes

	is_shown = {						#Can only target yourself
		scope:recipient = scope:actor
	}
	
	is_valid_showing_failures_only = {
		scope:actor = {
		}
	}
	
	send_option = {
		flag = check_obscurity
		localization = acotw_check_obscurity_localization
	}
	
	#Landed Rulers
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					has_character_modifier = acotw_olympia_adjust_diplomatic_range_75
					has_character_modifier = acotw_olympia_adjust_diplomatic_range_50
					has_character_modifier = acotw_olympia_adjust_diplomatic_range_25
				}
				is_landless_ruler = no
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_100
		localization = acotw_adjust_diplomatic_range_100_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_olympia_adjust_diplomatic_range_25 }
				is_landless_ruler = no
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_25
		localization = acotw_adjust_diplomatic_range_25_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_olympia_adjust_diplomatic_range_50 }
				is_landless_ruler = no
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_50
		localization = acotw_adjust_diplomatic_range_50_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_olympia_adjust_diplomatic_range_75 }
				is_landless_ruler = no
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_75
		localization = acotw_adjust_diplomatic_range_75_localization
	}
	
	#Landless Rulers
	send_option = {
		is_shown = {
			scope:actor = {
				OR = {
					has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_75
					has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_50
					has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_25
				}
				is_landless_ruler = yes
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_100_landless
		localization = acotw_landless_adjust_diplomatic_range_100_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_25 }
				is_landless_ruler = yes
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_25_landless
		localization = acotw_landless_adjust_diplomatic_range_25_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_50 }
				is_landless_ruler = yes
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_50_landless
		localization = acotw_landless_adjust_diplomatic_range_50_localization
	}
	
	send_option = {
		is_shown = {
			scope:actor = {
				NOT = { has_character_modifier = acotw_landless_olympia_adjust_diplomatic_range_75 }
				is_landless_ruler = yes
			}
			has_game_rule = acotw_player_dynamic_diplomacy_range_on
		}
		
		flag = adjust_diplomatic_range_75_landless
		localization = acotw_landless_adjust_diplomatic_range_75_localization
	}
	
	on_accept = {
		scope:recipient = {
			
			#Landed
			if = {
				limit = { scope:adjust_diplomatic_range_75 ?= yes }
				olympia_acotw_add_75_range_adjustment = yes
			}
			
			else_if = {
				limit = { scope:adjust_diplomatic_range_50 ?= yes }
				
				olympia_acotw_add_50_range_adjustment = yes
			}
			
			else_if = {
				limit = { scope:adjust_diplomatic_range_25 ?= yes }
				
				olympia_acotw_add_25_range_adjustment = yes
			}
			
			else_if = {
				limit = { scope:adjust_diplomatic_range_100 ?= yes }
				
				olympia_acotw_add_100_range_adjustment = yes
			}

			else = {
				limit = { scope:check_obscurity ?= yes }
				
				custom_tooltip = CHECK_FOR_OBSCURED_STATUS
				
				trigger_event = {
					id = olympia_culling.1008
					days = 1
				}
			}
			
			#Landless
			else_if = {
				limit = { scope:adjust_diplomatic_range_100_landless ?= yes }
				
				olympia_acotw_landless_add_100_range_adjustment = yes
			}
			else_if = {
				limit = { scope:adjust_diplomatic_range_50_landless ?= yes }
				
				olympia_acotw_landless_add_50_range_adjustment = yes
			}
			
			else_if = {
				limit = { scope:adjust_diplomatic_range_25_landless ?= yes }
				
				olympia_acotw_landless_add_25_range_adjustment = yes
			}
			
			else_if = {
				limit = { scope:adjust_diplomatic_range_75_landless ?= yes }
				
				olympia_acotw_landless_add_75_range_adjustment = yes
			}
			
			else = {
				limit = { scope:check_obscurity ?= yes }
				
				custom_tooltip = CHECK_FOR_OBSCURED_STATUS
				
				trigger_event = {
					id = olympia_culling.1008
					days = 1
				}
			}
		}
	}
	
	auto_accept = yes
}