﻿namespace = QOL_surprise_war

#Events:
# 
# 0001 - I made a surprise attack
# 0002 - a neighboring ruler has waged a surprise war

QOL_surprise_war.0001 = {
	type = character_event
	title = QOL_surprise_war.0001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 1
					scope:actor_reaction = 1
				}
				desc = QOL_surprise_war.0001.angry_shame
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 2
					scope:actor_reaction = 1
				}
				desc = QOL_surprise_war.0001.fear_shame
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 3
					scope:actor_reaction = 1
				}
				desc = QOL_surprise_war.0001.shocked_shame
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 1
					scope:actor_reaction = 2
				}
				desc = QOL_surprise_war.0001.angry_opportunistic
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 2
					scope:actor_reaction = 2
				}
				desc = QOL_surprise_war.0001.fear_opportunistic
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 3
					scope:actor_reaction = 2
				}
				desc = QOL_surprise_war.0001.shocked_opportunistic
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 1
					scope:actor_reaction = 3
				}
				desc = QOL_surprise_war.0001.angry_ambitious
			}
			triggered_desc = {
				trigger = {
					scope:recipient_reaction = 2
					scope:actor_reaction = 3
				}
				desc = QOL_surprise_war.0001.fear_ambitious
			}
			desc = QOL_surprise_war.0001.shocked_ambitious
		}
		triggered_desc = {
			trigger = { exists = scope:angry_third_party }
			desc = {
				triggered_desc = {
					trigger = { scope:actor_reaction = 1 }
					desc = QOL_surprise_war.0001.sf
				}
				triggered_desc = {
					trigger = { scope:actor_reaction = 2 }
					desc = QOL_surprise_war.0001.of
				}
				triggered_desc = {
					trigger = { scope:actor_reaction = 3 }
					desc = QOL_surprise_war.0001.af
				}
				desc = QOL_surprise_war.0001.potential_foe
			}
		}
	}

	theme = war
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { scope:actor_reaction = 1 }
			animation = worry
		}
		triggered_animation = {
			trigger = { scope:actor_reaction = 2 }
			animation = thinking
		}
		animation = dismissal
	}
	right_portrait = {
		character = scope:recipient
		triggered_animation = {
			trigger = { scope:recipient_reaction = 1 }
			animation = anger
		}
		triggered_animation = {
			trigger = { scope:recipient_reaction = 2 }
			animation = fear
		}
		animation = shock
	}
	lower_right_portrait = {
		trigger = { exists = scope:angry_third_party }
		character = scope:angry_third_party
	}

	trigger = {
		exists = scope:actor
		exists = scope:recipient
		scope:actor = { is_landed = yes }
		scope:recipient = {  is_landed = yes }
		any_neighboring_and_across_water_top_liege_realm_owner = {
			ai_honor > 0
			NOR = {
				this = scope:actor
				this = scope:recipient
				has_trait = reclusive
				has_trait = shy
			}
		}
	}

	immediate = {
		# find a particularly disappointed ruler
		random_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				ai_honor > 0
				NOR = {
					this = scope:actor
					this = scope:recipient
					has_trait = reclusive
					has_trait = shy
				}
			}
			weight = {
				base = 0
				modifier = { always = yes add = ai_honor }
				modifier = {
					save_temporary_opinion_value_as = {
						name = opinion_of_offender
						target = root
					}
					always = yes
					add = {
						value = scope:opinion_of_offender
						multiply = -1
					}
				}
				modifier = {
					has_trait = ambitious
					factor = 0.5
				}
				modifier = {
					has_trait = greedy
					factor = 0.5
				}
				modifier = {
					has_trait = content
					factor = 1.2
				}
				modifier = {
					has_trait = just
					factor = 2
				}
				modifier = { # get a player involved as much as possible
					is_ai = no
					factor = 10
				}
			}
			save_scope_as = angry_third_party
		}
		# set up scopes for descs and animations
		scope:recipient = {
			if = {
				limit = {
					# max strength twice of your max strength
					max_military_strength > {
						value = root.max_military_strength
						multiply = 2
					}
					# and not so depleted to be challenged
					current_military_strength > {
						value = root.current_military_strength
						multiply = 0.4
					}
				}
				save_scope_value_as = {
					name = recipient_reaction
					value = 1
				}
			}
			else_if = {
				limit = {
					# has less than half of your strength
					current_military_strength < {
						value = root.current_military_strength
						multiply = 0.5
					}
				}
				save_scope_value_as = {
					name = recipient_reaction
					value = 2
				}
			}
			else = {
				# about your equal; shocked
				save_scope_value_as = {
					name = recipient_reaction
					value = 3
				}
			}
		}
		save_temporary_scope_value_as = {
			name = actor_honor_non_neg
			value = {
				value = ai_honor
				add = 100
			}
		}
		if = {
			limit = {
				# you're too honorable for this bs
				scope:actor_honor_non_neg > {
					value = ai_greed
					add = 100
					multiply = 1.5
				}
			}
			save_scope_value_as = {
				name = actor_reaction
				value = 1
			}
		}
		else_if = {
			limit = {
				# you have your reasons
				scope:actor_honor_non_neg > {
					value = ai_greed
					add = 100
					multiply = 0.8
				}
			}
			save_scope_value_as = {
				name = actor_reaction
				value = 2
			}
		}
		else = {
			# war is war
			save_scope_value_as = {
				name = actor_reaction
				value = 3
			}
		}
		# stress
		switch = {
			trigger = has_trait
			just = {
				add_stress = {
					value = ai_honor
					add = ai_compassion
					divide = 2
					ceiling = yes
					min = medium_stress_impact_gain
				}
			}
			content = {
				add_stress = {
					value = ai_honor
					min = medium_stress_impact_gain
				}
			}
			ambitious = {
				add_stress = {
					value = ai_greed
					divide = 1.5
					floor = yes
					max = minor_stress_impact_loss
				}
			}
			arrogant = {
				add_stress = {
					value = ai_boldness
					divide = 1.75
					floor = yes
					max = minor_stress_impact_loss
				}
			}
		}

		add_prestige_level = -1
	}

	option = {
		name = QOL_surprise_war.0001.shame
		trigger = { scope:actor_reaction = 1 }
		give_nickname = nick_the_foolish
		add_character_modifier = {
			modifier = waged_surprise_war
			years = 3
		}
		custom_tooltip = QOL_surprise_war.0001.might_join
	}
	option = {
		name = QOL_surprise_war.0001.opportunistic
		trigger = { scope:actor_reaction = 2 }
		give_nickname = nick_the_wicked
		add_character_modifier = {
			modifier = waged_surprise_war
			years = 4
		}
		custom_tooltip = QOL_surprise_war.0001.might_join
	}
	option = {
		name = QOL_surprise_war.0001.ambitious
		trigger = { scope:actor_reaction = 3 }
		give_nickname = nick_the_imperious
		add_character_modifier = {
			modifier = waged_surprise_war
			years = 5
		}
		custom_tooltip = QOL_surprise_war.0001.might_join
	}

	after = {
		scope:angry_third_party = {
			trigger_event = {
				id = QOL_surprise_war.0002
				days = { 2 6 }
			}
		}
	}
}


QOL_surprise_war.0002 = {
	type = character_event
	title = QOL_surprise_war.0002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:actor_reaction = 1 }
				desc = QOL_surprise_war.0002.regrettable
			}
			triggered_desc = {
				trigger = { scope:actor_reaction = 2 }
				desc = QOL_surprise_war.0002.detestable
			}
			desc = QOL_surprise_war.0002.punishable
		}
		desc = QOL_surprise_war.0002.decision
	}

	theme = court
	center_portrait = {
		character = root
		animation = thinking
	}
	lower_left_portrait = {
		character = scope:actor
	}
	lower_right_portrait = {
		character = scope:recipient
	}

	trigger = {
		exists = scope:actor
		exists = scope:recipient
		exists = scope:actor_reaction
	}

	immediate = {
		scope:recipient = {
			random_character_war = {
				limit = {
					is_defender = scope:recipient
					is_attacker = scope:actor
				}
				save_scope_as = scoped_war
			}
		}
	}

	option = {
		name = QOL_surprise_war.0002.join
		scope:scoped_war = {
			hidden_effect = {
				set_called_to = root
			}
			add_defender = root
		}
		add_character_modifier = {
			modifier = honorable_war_paragon
			years = 5
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_honor = 0.25
			}
			modifier = {
				exists = scope:actor_reaction
				add = {
					value = 10
					multiply = scope:actor_reaction
				}
			}
			modifier = {
				has_trait = wrathful
				add = 10
			}
			modifier = {
				exists = scope:recipient
				add = {
					value = 0
					if = {
						limit = { has_relation_friend = scope:recipient }
						add = 10
					}
					if = {
						limit = { has_relation_best_friend = scope:recipient }
						add = 30
					}
					if = {
						limit = { has_relation_lover = scope:recipient }
						add = 20
					}
					if = {
						limit = { has_relation_soulmate = scope:recipient }
						add = 100
					}
					if = { # no one messes with a child lord's love
						limit = {
							has_relation_crush = scope:recipient
							NOT = { has_trait = craven }
						}
						add = 80
					}
				}
			}
			modifier = {
				has_trait = craven
				factor = 0.5
			}
			modifier = {
				any_character_war = {} # already in a war
				factor = 0.2
			}
		}
	}
	option = {
		name = QOL_surprise_war.0002.prepare
		add_character_modifier = {
			modifier = preparing_against_surprise_wars
			years = 5
		}
		ai_chance = {
			base = 25
			ai_value_modifier = {
				ai_rationality = 0.25
			}
			modifier = {
				exists = scope:recipient
				add = {
					value = 0
					if = {
						limit = { has_relation_rival = scope:recipient }
						add = 20
					}
					if = {
						limit = { has_relation_nemesis = scope:recipient }
						add = 40
					}
				}
			}
			modifier = {
				has_trait = patient
				add = 20
			}
			modifier = {
				any_character_war = {} # already in a war
				factor = 1.5
			}
		}
	}
}