﻿#Events handling Steal Back Artifact ongoing

namespace = smuggle_artifact_ongoing

######################
#
#	FREE-STANDING EVENTS
#	1000-4999
######################


# Bribing the antiquarian to purposefully lower security
	#by Bianca Savazzi

scripted_effect smuggle_artifact_ongoing_1001_effect = {
	random_list = {
		1 = {
			#Lustful characters likes beautiful people
			modifier = {
				add = 20
				scope:antiquarian = { has_trait = lustful }
				has_character_flag = chose_beauty_option_1001
			}
			# The random beauty's attractiveness makes the antiquarian more likely to agree
			modifier = {
				add = {
					value = scope:random_beauty.attraction 
				}
				has_character_flag = chose_beauty_option_1001
			}

			# Greedy characters far more likely to accept any bribe
			modifier = {
				add = {
					value = ai_greed
					if = {
						limit = {
							ai_greed > 0
						}
						multiply = 0.5
					}
				}
			}
			# Bonus for greedy characters recieving gold
			modifier = {
				add = 20
				scope:antiquarian = { has_trait = greedy }
				has_character_flag = chose_gold_option_1001
			}
							
			send_interface_toast = {
				title = smuggle_artifact_ongoing_notification.1001.success
				left_icon = scope:antiquarian
				scope:antiquarian = {
					add_opinion = {
						target = root
						modifier = gift_opinion
						opinion = 20
					}
				}
				scope:scheme = {
					add_scheme_progress = scheme_progress_gain
				}
			}	
		}
		1 = {
			# Honorful characters are less likely to accept bribes
			modifier = {
				add = {
					value = ai_honor
					if = {
						limit = {
							ai_honor > 0
						}
						multiply = 0.5
					}
				}
			}
			send_interface_toast = {
				title = smuggle_artifact_ongoing_notification.1001.failure
				left_icon = scope:antiquarian
				scope:antiquarian = {
					add_opinion = {
						target = root
						modifier = tried_to_bribe_opinion
						opinion = -25
					}
				}
				scope:scheme = {
					add_scheme_modifier = {
						type = scheme_modifier_failed_bribery
						years = 5
					}
				}
			}
		}
	}
	#Flag cleanup
	remove_character_flag = chose_gold_option_1001
	remove_character_flag = chose_beauty_option_1001
}


smuggle_artifact_ongoing.1001 = {
	type = character_event
	title = smuggle_artifact_ongoing.1001.t
	desc = smuggle_artifact_ongoing.1001.desc
	theme = generic_intrigue_scheme
	left_portrait = scope:antiquarian
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		exists = scope:scheme 
		scope:scheme = {
			NOT = { has_variable = had_event_smuggle_artifact_ongoing_1001 }
		}
		scope:target = {
			employs_court_position = antiquarian_court_position
			any_court_position_holder = {
		        type = antiquarian_court_position
				is_available_healthy_ai_adult = yes
			}
		}
	}

	immediate = {
		scope:scheme = {
			set_variable = {	
				name = had_event_smuggle_artifact_ongoing_1001
				value = yes
				days = 3650
			}
		}
		scope:target = {
			random_court_position_holder = {
				type = antiquarian_court_position
				limit = { is_available_ai_adult = yes }
				save_scope_as = antiquarian
			}
		}

		# Saving the scope of a random artifact for option B 
		if = {
			limit = {
				any_character_artifact = {
					count > 0
					ep1_artifact_durability_higher_equal_percent_trigger = { PERCENT = 0.51 } #don't give something that's too crummy
				}
			}
			random_character_artifact = {
				limit = {
					ep1_artifact_durability_higher_equal_percent_trigger = { PERCENT = 0.51 } 
				}
				save_scope_as = artifact_to_trade
			}
		}

		# Saving the scope of a random beauty for option C 
		if = {
			limit = {
				scope:scheme = { 
					any_scheme_agent_character = {
						is_ai = yes
						has_trait = beauty_good
						scope:antiquarian = { is_attracted_to_gender_of = prev }
					}
				}
			}
			scope:scheme = { 
				random_scheme_agent_character = {
					limit = {
						is_adult = yes
						has_trait = beauty_good
						scope:antiquarian = { is_attracted_to_gender_of = prev }
					}
					save_scope_as = random_beauty
				}
			}
		}
		else_if = { # courtier back-up to make the option more often available 
			limit = {
				any_courtier = {
					is_ai = yes
					has_trait = beauty_good
					scope:antiquarian = { is_attracted_to_gender_of = prev }
				}
			}
			random_courtier = {
				limit = {
					is_adult = yes
					has_trait = beauty_good
					scope:antiquarian = { is_attracted_to_gender_of = prev }
				}
				save_scope_as = random_beauty
			}
		}
	}

	option = { #Gold
		name = smuggle_artifact_ongoing.1001.a
		custom_tooltip = smuggle_artifact_ongoing.1001.a.tt
		remove_short_term_gold = medium_gold_value

		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {
				add = -45
				has_trait = greedy
			}
		}
		hidden_effect = {
			add_character_flag = {
				flag = chose_gold_option_1001
			}
			smuggle_artifact_ongoing_1001_effect = yes
		}
	}

	option = { #artifact
		name = smuggle_artifact_ongoing.1001.b
		trigger = {
			exists = scope:artifact_to_trade
		}
		custom_tooltip = smuggle_artifact_ongoing.1001.b.tt

		scope:artifact_to_trade = { 
			set_owner = scope:antiquarian
		}

		send_interface_toast = {
			title = smuggle_artifact_ongoing_notification.1001.success
			left_icon = scope:antiquarian
			scope:antiquarian = {
				add_opinion = {
					target = root
					modifier = gift_opinion
					opinion = 20
				}
			}
			scope:scheme = {
				add_scheme_progress = scheme_progress_gain
			}
		}

		ai_chance = {
			base = 10
			modifier = {
				add = 100
				has_trait = just
			}
		}
	}

	option = { #beautiful person
		name = smuggle_artifact_ongoing.1001.c
		trigger = {
			exists = scope:random_beauty
		}
		custom_tooltip = smuggle_artifact_ongoing.1001.c.tt

		ai_chance = {
			base = 0
			modifier = {
				add = 50
				scope:target = { has_trait = lustful }
			}
		}

		# Random beauty's reaction to being thrust into seducing the target
		if = {
			limit = {
				scope:random_beauty = {
					OR = {
						has_trait = seducer 
						has_trait = lustful
						scope:antiquarian.attraction >= medium_positive_attraction 
					}
					is_attracted_to_gender_of = scope:antiquarian 
				}
			}
			# Minor penalty, like a "ugh" reaction from someone used to seduce people or that the target is attractive
			scope:random_beauty = {
				add_opinion = {
					modifier = annoyed_opinion
					target = root
					opinion = -10
				}
			}
		}
		else = {
			# Penalty for not finding the target attractive and not being the type to seduce on command
			scope:random_beauty = {
				add_opinion = {
					modifier = disgusted_opinion
					target = root
					opinion = -30
				}
				# Grossed out and leaves your court if courtier
				if = {
					limit = {
						is_courtier_of = root
						is_landed = no
						NOT = { scheme_is_character_agent = this }
					}
					select_and_move_to_pool_effect = yes
				}
			}
		}

		#Scheme might be revealed as a consequence
		if = {
			limit = {
				scope:scheme = { 
					root = { 
						NOT = { is_agent_exposed_in_scheme = scope:scheme } 
					} 
				}
			}
			random_list = {
				1 = {
					# Scheme owner is exposed
					scope:scheme = {
						expose_scheme_agent = root
					}
				}
				1 = {
					# Agent is exposed (only if not already exposed)
					trigger = {
						scope:scheme = { 
							NOT = { scheme_is_character_agent = scope:random_beauty }
							scope:random_beauty = { 
								NOT = { is_agent_exposed_in_scheme = scope:scheme } 
							}
						}
					}
					scope:scheme = {
						expose_scheme_agent = scope:random_beauty
					}
				}
				1 = {
					# Nothing happens (based on the intrigue of the agent)
					modifier = {
						add = {
							value = scope:random_beauty.intrigue
							multiply = 5 # High since its an AI character that the player have most likely not invested in 
						}
					}
				}
			}
		}

		hidden_effect = {
			add_character_flag = {
				flag = chose_beauty_option_1001
			}
			smuggle_artifact_ongoing_1001_effect = yes
		}
	}

	option = { #do nothing
		name = smuggle_artifact_ongoing.1001.d
		
		ai_chance = {
			base = 10
		}
	}
}
