#Events handling Sway outcomes

namespace = sway_outcome

#Note: Outcome events for the Sway scheme are unusual. The default is simply a notification for success or failure

################################
# Standard outcomes
# 0000-0999
################################

#Standard success
	#by Petter Vilberg
sway_outcome.0001 = {
	hidden = yes

	immediate = {
		send_interface_message = {
			type = sway_good_message
			title = sway_sway_success_message
			left_icon = scope:target
			scope:target = {
				if = {
					limit = {
						is_alive = yes
						scope:owner = { is_alive = yes }
					}
					if = {
						limit = {
							any_character_struggle = {
								is_struggle_type = persian_struggle
								has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
							}
						}
						add_opinion = {
							target = scope:owner
							modifier = scheme_sway_and_compelled_to_submit_opinion
							opinion = sway_opinion_increase_per_success
						}
					}
					else = {
						add_opinion = {
							target = scope:owner
							modifier = scheme_sway_opinion
							opinion = sway_opinion_increase_per_success
						}
					}
					scope:owner = {
						if = {
							limit = {
								faith = { has_doctrine_parameter = sway_scheme_piety }
								OR = {
									liege ?= scope:target
									target_is_vassal_or_below = scope:target
								}
							}
							add_piety = minor_piety_gain
						}
					}
				}
			}
			sway_end_effect = yes
		}
	}
}

#Standard failure
	#by Petter Vilberg
sway_outcome.0002 = {
	hidden = yes

	immediate = {
		send_interface_message = {
			type = sway_bad_message
			title = sway_sway_failed_message
			left_icon = scope:target
			stress_impact = {
				gregarious = minor_stress_impact_gain
			}
			sway_end_effect = yes
		}
	}
}


#################################
# Positive Outcomes
# 1000-1999
#################################

#Diplomacy Duel to get an extra bonus
	#by Petter Vilberg
sway_outcome.1001 = {
	type = character_event
	title = sway_outcome.1001.t
	desc = sway_outcome.1001.desc
	theme = sway_scheme
	left_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { is_travelling_not_at_activity = yes }
		reference = terrain_travel
	}
	override_background = {
		trigger = { is_travelling_at_activity = yes }
		reference = ep2_activity
	}
	
	trigger = {
		NOT = {
			has_character_flag = had_event_sway_outcome_1001
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_sway_outcome_1001
			years = 5
		}
	}

	option = {
		name = sway_outcome.1001.a
		duel = {
			target = scope:target
			skill = diplomacy

			20 = {
				compare_modifier = {
					value = scope:duel_value
				}
				desc = sway_outcome.1001.a.success
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1001.a.success

					add_prestige = minor_prestige_gain

					scope:target = {
						if = {
							limit = {
								any_character_struggle = {
									is_struggle_type = persian_struggle
									has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
								}
							}
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_and_compelled_to_submit_opinion
								opinion = 50
							}
						}
						else = {
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_opinion
								opinion = 50
							}
						}
						scope:owner = {
							if = {
								limit = {
									faith = { has_doctrine_parameter = sway_scheme_piety }
									OR = {
										liege ?= scope:target
										target_is_vassal_or_below = scope:target
									}
								}
								add_piety = minor_piety_gain
							}
						}
					}
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				desc = sway_outcome.1001.a.failure
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1001.a.failure

					add_prestige = minor_prestige_loss
				}
			}
		}
		sway_end_effect = yes
	}

	option = {
		name = sway_outcome.1001.b
		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = scheme_sway_opinion
				opinion = 30
			}
		}
		scope:owner = {
			if = {
				limit = {
					faith = { has_doctrine_parameter = sway_scheme_piety }
					OR = {
						liege ?= scope:target
						target_is_vassal_or_below = scope:target
					}
				}
				add_piety = minor_piety_gain
			}
		}
		sway_end_effect = yes
	}
}

#Learning Duel to get an extra bonus
	#by Petter Vilberg
sway_outcome.1002 = {
	type = character_event
	title = sway_outcome.1002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { faith = scope:target.faith }
				desc = sway_outcome.1002.same_faith
			}
			desc = sway_outcome.1002.other_faith
		}
	}
	theme = sway_scheme
	left_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { scope:target = { is_travelling = yes } }
		reference = terrain_travel
	}
	
	trigger = {
		NOT = {
			has_character_flag = had_event_sway_outcome_1002
		}
	}

	weight_multiplier = {
		base = 0
		compare_modifier = {
			value = learning
			multiplier = 0.1
		}
		modifier = {
			add = 2
			scope:target = {
				is_landed = yes
				government_has_flag = government_is_theocracy
			}
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_sway_outcome_1002
			years = 5
		}
	}

	option = {
		name = sway_outcome.1002.a
		duel = {
			target = scope:target
			skill = learning

			20 = {
				compare_modifier = {
					value = scope:duel_value
					min = -18
					max = 20
				}
				desc = sway_outcome.1001.a.success
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1001.a.success

					add_prestige = minor_prestige_gain

					scope:target = {
						if = {
							limit = {
								any_character_struggle = {
									is_struggle_type = persian_struggle
									has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
								}
							}
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_and_compelled_to_submit_opinion
								opinion = 50
							}
						}
						else = {
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_opinion
								opinion = 50
							}
						}
						scope:owner = {
							if = {
								limit = {
									faith = { has_doctrine_parameter = sway_scheme_piety }
									OR = {
										liege ?= scope:target
										target_is_vassal_or_below = scope:target
									}
								}
								add_piety = minor_piety_gain
							}
						}
					}
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
					min = -18
					max = 20
				}
				desc = sway_outcome.1001.a.failure
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1001.a.failure

					add_prestige = minor_prestige_loss
				}
			}
		}
		sway_end_effect = yes
	}

	option = {
		name = sway_outcome.1002.b
		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = scheme_sway_opinion
				opinion = 30
			}
		}
		scope:owner = {
			if = {
				limit = {
					faith = { has_doctrine_parameter = sway_scheme_piety }
					OR = {
						liege ?= scope:target
						target_is_vassal_or_below = scope:target
					}
				}
				add_piety = minor_piety_gain
			}
		}
		sway_end_effect = yes
	}
}


#They're warming up to me, can I take it further?
	#by Linnéa Thimrén
sway_outcome.1003 = {
	type = character_event
	title = sway_outcome.1003.t
	desc = sway_outcome.1003.desc
	theme = sway_scheme
	left_portrait = scope:target
	right_portrait = scope:friend
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { is_travelling_not_at_activity = yes }
		reference = terrain_travel
	}
	override_background = {
		trigger = { is_travelling_at_activity = yes }
		reference = ep2_activity
	}
	
	trigger = {
		NOT = {
			has_character_flag = had_event_sway_outcome_1003
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_sway_outcome_1003
			years = 5
		}
		scope:target = {
			if = {
				limit = {
					any_character_struggle = {
						is_struggle_type = persian_struggle
						has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
					}
				}
				add_opinion = {
					target = scope:owner
					modifier = scheme_sway_and_compelled_to_submit_opinion
					opinion = 30
				}
			}
			else = {
				add_opinion = {
					target = scope:owner
					modifier = scheme_sway_opinion
					opinion = 30
				}
			}
			scope:owner = {
				if = {
					limit = {
						faith = { has_doctrine_parameter = sway_scheme_piety }
						OR = {
							liege ?= scope:target
							target_is_vassal_or_below = scope:target
						}
					}
					add_piety = minor_piety_gain
				}
			}
		}
		if = {
			limit = {
				any_relation = {
					type = friend
					diplomacy > root.diplomacy
				}
			}
			random_relation = {
				type = friend
				limit = {
					diplomacy > root.diplomacy
				}
				save_scope_as = friend
			}
		}
	}

	option = { #Gamble!
		name = sway_outcome.1003.a
		duel = {
			target = scope:target
			skill = diplomacy

			30 = {
				compare_modifier = {
					value = scope:duel_value
				}
				desc = sway_outcome.1003.a.success
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1003.a.success

					scope:target = {
						if = {
							limit = {
								any_character_struggle = {
									is_struggle_type = persian_struggle
									has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
								}
							}
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_and_compelled_to_submit_opinion
								opinion = 20
							}
						}
						else = {
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_opinion
								opinion = 20
							}
						}
					}
				}
			}
			20 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -1
				}
				desc = sway_outcome.1003.a.failure
				send_interface_toast = {
					left_icon = scope:target
					title = sway_outcome.1003.a.failure

					scope:target = {
						if = {
							limit = {
								any_character_struggle = {
									is_struggle_type = persian_struggle
									has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
								}
							}
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_and_compelled_to_submit_opinion
								opinion = -10
							}
						}
						else = {
							add_opinion = {
								target = scope:owner
								modifier = scheme_sway_opinion
								opinion = -10
							}
						}
					}
				}	
			}
		}
	}

	option = { #Gamble! Friend helps you out!
		name = sway_outcome.1003.a_friend
		trigger = {
			exists = scope:friend
		}
		scope:friend = {
			duel = {
				target = scope:target
				skill = diplomacy

				40 = {
					compare_modifier = {
						value = scope:duel_value
					}
					desc = sway_outcome.1003.a.success
					send_interface_toast = {
						left_icon = scope:target
						title = sway_outcome.1003.a.success

						scope:target = {
							if = {
								limit = {
									any_character_struggle = {
										is_struggle_type = persian_struggle
										has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
									}
								}
								add_opinion = {
									target = scope:owner
									modifier = scheme_sway_and_compelled_to_submit_opinion
									opinion = 15
								}
							}
							else = {
								add_opinion = {
									target = scope:owner
									modifier = scheme_sway_opinion
									opinion = 15
								}
							}
						}
					}
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					desc = sway_outcome.1003.a.failure
					send_interface_toast = {
						left_icon = scope:target
						title = sway_outcome.1003.a.failure

						scope:target = {
							if = {
								limit = {
									any_character_struggle = {
										is_struggle_type = persian_struggle
										has_struggle_phase_parameter = fp3_sway_vassals_removes_disloyalty
									}
								}
								add_opinion = {
									target = scope:owner
									modifier = scheme_sway_and_compelled_to_submit_opinion
									opinion = -10
								}
							}
							else = {
								add_opinion = {
									target = scope:owner
									modifier = scheme_sway_opinion
									opinion = -10
								}
							}
						}
					}
				}
			}
		}
	}

	option = { #Safe route
		name = sway_outcome.1003.b
		
	}

	after = {
		sway_end_effect = yes
	}
}

#A disloyal vassal can be compelled to reconsider during the Anarchy at Samarra Struggle 
	#by Ola Jentzsch

sway_outcome.1004 = {
	type = character_event
	title = sway_outcome.1004.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = {
						ai_vengefulness >= medium_positive_ai_value
					}
				}
				desc = sway_outcome_grudgingly.1004.desc
			}
			random_valid = {
				desc = sway_outcome_magnanimity.1004.desc
				desc = sway_outcome_blessed.1004.desc
				triggered_desc = {
					trigger = {
						scope:target = {
							NOR = {
								has_trait = stubborn
								has_trait = arrogant 
								has_trait = august
								has_trait = callous 
							}
						}
					}
					desc = sway_outcome_flattery.1004.desc 
				}
				triggered_desc = {
					trigger = {
						AND = {
							scope:target = {
								AND = {
									OR = {
										has_religion = religion:buddhism_religion
										has_religion = religion:jainism_religion
										has_religion = religion:hinduism_religion
									}
									ai_zeal >= low_positive_ai_value
								}
							}
							scope:owner = {
								OR = {
									has_religion = religion:buddhism_religion
									has_religion = religion:jainism_religion
									has_religion = religion:hinduism_religion
								} 
							}
						}
					}
					desc = sway_outcome_dharmic.1004.desc 
				}
				triggered_desc = {
					trigger = {
						scope:target = {
							has_religion = religion:islam_religion
							ai_zeal >= low_positive_ai_value
							exists = faith.religious_head 
							faith.religious_head = { this = root }
						}
					}
					desc = sway_outcome_caliph.1004.desc 		
				}				
			}
		}
	}
	theme = sway_scheme
	left_portrait = {
		character = scope:owner
		triggered_animation = {
			trigger = {
				has_trait = callous
				has_trait = vengeful
				has_trait = sadistic
			}
			animation = personality_callous
		}
		animation = personality_bold 
	}
	right_portrait = {
		character = scope:target
		animation = throne_room_bow_1
	}

	trigger = {

		any_character_struggle = {
			is_struggle_type = persian_struggle
			has_struggle_phase_parameter = fp3_sway_scheme_more_powerful
		}

		scope:target = { 
			AND = {
				is_vassal_of = scope:owner 
				has_trait = disloyal
			}
			NOT = {
				has_relation_rival = scope:owner
			}
		}
	}

	weight_multiplier = { #more likely to trigger if the target likes you, or has a flexible personality
		base = 1
		modifier = { 
			add = 0.5
			scope:target = { has_trait = fickle } #They're flexible 
		}
		modifier = { 
			add = 0.5
			scope:target = { has_trait = trusting } #They trust you
		}
		modifier = { 
			add = -0.7
			scope:target = { has_trait = stubborn } #They are not prone to change their ways
		}
		modifier = { 
			add = -0.3
			scope:target = { has_trait = vengeful } #They are not soon to forgive slights, real or imagined
		}
	}

	immediate = {

		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = scheme_sway_opinion
				opinion = 20
			}
			remove_trait = disloyal 
		}
		scope:owner = {
			if = {
				limit = {
					faith = { has_doctrine_parameter = sway_scheme_piety }
					OR = {
						liege ?= scope:target
						target_is_vassal_or_below = scope:target
					}
				}
				add_piety = minor_piety_gain
			}
		}
	}

	option = {
		name = sway_outcome.1004.a 

		trigger = {
			OR = {
				has_trait = vengeful
				has_trait = arrogant
				has_trait = paranoid
			}
		}

		scope:scheme = {
			end_scheme = yes
		}
	}

	option = {
		name = sway_outcome.1004.b 

		trigger = {
			NOR = {
				has_trait = vengeful
				has_trait = arrogant
				has_trait = paranoid
			}
		}

		scope:scheme = {
			end_scheme = yes
		}
	}
}


#################################
# Negative Outcomes
# 2000-2999
#################################

#Diplomatic misunderstanding
	#by Petter Vilberg
sway_outcome.2001 = {
	type = character_event
	title = sway_outcome.2001.t
	desc = {
		desc = sway_outcome.2001.opening
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:target = {
						OR = {
							is_of_major_interest_to_root_trigger = yes
							is_of_minor_interest_to_root_trigger = yes
						}
						NOT = {
							has_relation_rival = root
						}
					}
				}
				desc = sway_outcome.2001.not_interested_relation
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						possibly_interested_in_character_trigger = {
							CHARACTER = root
						}
					}
				}
				desc = sway_outcome.2001.not_interested_romantically
			}
			random_valid = {
				desc = sway_outcome.2001.not_interested_horses
				desc = sway_outcome.2001.not_interested_toll_exemptions
				desc = sway_outcome.2001.not_interested_friend
				triggered_desc = {
					trigger = {
						OR = { religion = religion:eastern_orthodox_religion religion = religion:catholic_religion religion = religion:protestant_religion }
						OR = { scope:target.religion = religion:eastern_orthodox_religion scope:target.religion = religion:catholic_religion scope:target.religion = religion:protestant_religion }
					}
					desc = sway_outcome.2001.not_interested_relics
				}
			}
		}
		desc = sway_outcome.2001.end
	}
	theme = sway_scheme
	left_portrait = {
		character = scope:target
		animation = eyeroll
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { is_travelling_not_at_activity = yes }
		reference = terrain_travel
	}
	override_background = {
		trigger = { is_travelling_at_activity = yes }
		reference = ep2_activity
	}
	
	trigger = {
		NOT = {
			has_character_flag = had_event_sway_outcome_2001
		}
		NOR = {
			has_relation_lover = scope:target
			has_relation_friend = scope:target
			any_consort = {
				this = scope:target
			}
			betrothed ?= scope:target

		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_sway_outcome_2001
			years = 5
		}
	}

	option = {
		name = sway_outcome.2001.a
		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = sway_blocker_opinion
				opinion = -10
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}
}


#They think you're plotting against them
	#by Linnéa Thimrén
sway_outcome.2002 = {
	type = character_event
	title = sway_outcome.2002.t
	desc = sway_outcome.2002.desc
	theme = sway_scheme
	left_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	override_background = {
		trigger = { is_travelling_not_at_activity = yes }
		reference = terrain_travel
	}
	override_background = {
		trigger = { is_travelling_at_activity = yes }
		reference = ep2_activity
	}
	
	trigger = {
		NOT = {
			has_character_flag = had_event_sway_outcome_2002
		}
	}

	weight_multiplier = {
		base = 0.75
		modifier = {
			add = 0.75
			has_trait = paranoid
		}
	}

	immediate = {
		add_character_flag = {
			flag = had_event_sway_outcome_2002
			years = 5
		}
	}

	option = {
		name = sway_outcome.2002.a
		scope:target = {
			add_opinion = {
				target = scope:owner
				modifier = sway_blocker_opinion
				opinion = -10
			}
			add_character_modifier = {
				modifier = more_vigilant_recistance_modifier
				years = 5
			}
		}
		scope:scheme = {
			end_scheme = yes
		}
	}
}
