﻿# The outcome of a agotma_revealbastard scheme

namespace = agotma_instigator_outcome

# NOTE: To set up a new scheme outcome, make sure that you make an event for the owner and one for the target, and add them to their relevant on_actions.



######################################################
# INSTIGATOR EVENTS
######################################################

#SCHEME READY
agotma_instigator_outcome.0001 = {
	type = character_event
	title = agotma_instigator_outcome.0001.t
	desc = {
		desc = agotma_instigator_outcome.0001.desc
		first_valid = {
			triggered_desc = {
				trigger = { scope:scheme.scheme_success_chance >= 60 }
				desc = agotma_instigator_outcome.0001.positive.desc
			}
			desc = agotma_instigator_outcome.0001.negative.desc
		}
	}
	theme = war

	override_background = {
		reference = courtyard
	}

	left_portrait = scope:owner
	right_portrait = scope:target
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}

	immediate = {
		scope:target = { liege = { save_scope_as = discoverer } }
	}

	option = {
		name = agotma_instigator_outcome.0001.a
		custom_tooltip = agotma_instigator_outcome.0001.a.tt
		trigger_event = agotma_instigator_outcome.0002

		stress_impact = {
			craven = minor_stress_impact_gain
		}
	}

	option = {
		name = agotma_instigator_outcome.0001.b
		scope:scheme = {
			end_scheme = yes
		}
	}
}




#STUFF
agotma_instigator_outcome.0002 = {
	type = character_event

	hidden = yes

	immediate = {
		if = {
			limit = { scope:target = { is_claimant = yes } }
			save_scope_as = cooking_the_war

		}
		if = {
			limit = {
				scope:target = { is_claimant = no }
			}
			save_scope_as = not_cooking_the_war
		}


		if = {
			limit = {
				scope:target = { is_claimant = yes }
			}
			scope:target = {
				every_claim = {
					limit = {
						exists = holder
						tier >= tier_duchy
					}
					add_to_list = agotma_claimed_lands
				}
				random_in_list = {
					list = agotma_claimed_lands
					weight = {
						base = 1

						modifier = {
							add = 999
							tier = tier_hegemony
						}

						modifier = {
							add = 199
							tier = tier_empire
						}

						modifier = {
							add = 49
							tier = tier_kingdom
						}

						modifier = {
							add = 1
							tier = tier_duchy
						}
					}
					save_scope_as = agotma_war_target_land
				}
				scope:agotma_war_target_land.holder = {	save_scope_as = wartargetperson }
			}

			scope:wartargetperson = {
				every_vassal_or_below = {
					limit = {
						highest_held_title_tier > tier_barony
					}

					add_to_list = agotma_landless_list
				}
				random_in_list = {
					list = agotma_landless_list

					save_scope_as = agotma_landless_random_holder
				}
			}
		}
		if = {
			limit = {
				exists = scope:target
				exists = scope:wartargetperson
			}
			scope:target = { save_scope_as = attacker }
			scope:wartargetperson = { save_scope_as = defender }
			if = {
				limit = { agot_mw_war_valid_during_megawar = yes }
				scope:owner = {	trigger_event = agotma_instigator_outcome.0003 }
			}
			else = { scope:owner = { trigger_event = agotma_buybetrothal_outcome.9999 } } #fail
		}
	}
}


#THE EDGE OF WAR
agotma_instigator_outcome.0003 = {
	type = character_event
	title = agotma_instigator_outcome.0003.t

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:cooking_the_war }
				desc = agotma_instigator_outcome.0003.success.desc
			}
			triggered_desc = {
				trigger = { exists = scope:not_cooking_the_war }
				desc = agotma_instigator_outcome.0003.failure.desc
			}
		}
	}


	theme = war

	override_background = {
		reference = army_camp
	}

	left_portrait = {
		character = scope:target
		animation = thinking
	}
	right_portrait = scope:wartargetperson
	lower_right_portrait = scope:owner

	#CHOSE THE TARGET
	option = {
		name = agotma_instigator_outcome.0003.a.success
		trigger = { exists = scope:cooking_the_war }
		show_as_tooltip = {	custom_tooltip = agotma_instigator_outcome.0003.a.tt }

		scope:target = { trigger_event = agotma_instigator_outcome.0030 }
	}
}

#TARGET DECIDES
agotma_instigator_outcome.0030 = {
	type = character_event
	title = agotma_instigator_outcome.0030.t

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:cooking_the_war }
				desc = agotma_instigator_outcome.0030.success.desc
			}
			triggered_desc = {
				trigger = { exists = scope:not_cooking_the_war }
				desc = agotma_instigator_outcome.0030.failure.desc
			}
		}
	}


	theme = war

	override_background = {
		reference = army_camp
	}

	left_portrait = {
		character = scope:target
		animation = thinking
	}
	right_portrait = scope:wartargetperson
	lower_right_portrait = scope:owner

	#IT'S WAR
	option = {
		ai_chance = { base = 999 }
		name = agotma_instigator_outcome.0030.a.success
		trigger = { exists = scope:cooking_the_war }
		show_as_tooltip = {	custom_tooltip = agotma_instigator_outcome.0030.a.tt }


		scope:target = {

			#ENEMY IS DUCHY TIER

			if = {
				limit = {
					NOT = { is_playable_character = yes }
				}

				setup_agotma_rebel_title_effect = yes

				setup_agotma_rebel_army_spawner = yes

			}

			else_if = {
				limit = {
					is_claimant = yes
					is_playable_character = yes
					scope:wartargetperson.primary_title.tier = tier_duchy
				}
				if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_1
							has_trait = education_martial_1
							has_trait = education_stewardship_1
							has_trait = education_intrigue_1
							has_trait = education_learning_1
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 2
						}
						men_at_arms = {
							type = light_footmen
							stacks = 4
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_2
							has_trait = education_martial_2
							has_trait = education_stewardship_2
							has_trait = education_intrigue_2
							has_trait = education_learning_2
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 3
						}
						men_at_arms = {
							type = light_footmen
							stacks = 6
						}
						men_at_arms = {
							type = bowmen
							stacks = 1
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_3
							has_trait = education_martial_3
							has_trait = education_stewardship_3
							has_trait = education_intrigue_3
							has_trait = education_learning_3
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 6
						}
						men_at_arms = {
							type = light_footmen
							stacks = 12
						}
						men_at_arms = {
							type = bowmen
							stacks = 2
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_4
							has_trait = education_martial_4
							has_trait = education_stewardship_4
							has_trait = education_intrigue_4
							has_trait = education_learning_4
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 9
						}
						men_at_arms = {
							type = light_footmen
							stacks = 18
						}
						men_at_arms = {
							type = bowmen
							stacks = 3
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_5
							has_trait = education_martial_5
							has_trait = education_stewardship_5
							has_trait = education_intrigue_5
							has_trait = education_learning_5
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 12
						}
						men_at_arms = {
							type = light_footmen
							stacks = 24
						}
						men_at_arms = {
							type = bowmen
							stacks = 4
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
			}

			#ENEMY IS KING OR EMPIRE TIER

			else_if = {
				limit = {
					is_claimant = yes
					is_playable_character = yes
					scope:wartargetperson.primary_title.tier > tier_duchy
				}
				if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_1
							has_trait = education_martial_1
							has_trait = education_stewardship_1
							has_trait = education_intrigue_1
							has_trait = education_learning_1
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 9
						}
						men_at_arms = {
							type = light_footmen
							stacks = 18
						}
						men_at_arms = {
							type = bowmen
							stacks = 3
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_2
							has_trait = education_martial_2
							has_trait = education_stewardship_2
							has_trait = education_intrigue_2
							has_trait = education_learning_2
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 18
						}
						men_at_arms = {
							type = light_footmen
							stacks = 36
						}
						men_at_arms = {
							type = bowmen
							stacks = 6
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_3
							has_trait = education_martial_3
							has_trait = education_stewardship_3
							has_trait = education_intrigue_3
							has_trait = education_learning_3
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 30
						}
						men_at_arms = {
							type = light_footmen
							stacks = 60
						}
						men_at_arms = {
							type = bowmen
							stacks = 10
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_4
							has_trait = education_martial_4
							has_trait = education_stewardship_4
							has_trait = education_intrigue_4
							has_trait = education_learning_4
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 45
						}
						men_at_arms = {
							type = light_footmen
							stacks = 90
						}
						men_at_arms = {
							type = bowmen
							stacks = 15
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
				else_if = {
					limit = {
						OR = {
							has_trait = education_diplomacy_5
							has_trait = education_martial_5
							has_trait = education_stewardship_5
							has_trait = education_intrigue_5
							has_trait = education_learning_5
						}
					}
					spawn_army = {
						levies = 0
						men_at_arms = {
							type = armored_footmen
							stacks = 60
						}
						men_at_arms = {
							type = light_footmen
							stacks = 120
						}
						men_at_arms = {
							type = bowmen
							stacks = 20
						}
						inheritable = no
						location = scope:target.capital_province
						name = agotma_spawn_army_name
					}
				}
			}
		}


		hidden_effect = {
			every_ruler = {
				limit = {
					NOT = { this = scope:owner }
					scope:owner = { is_playable_character = yes }
				}
				add_opinion = {
					target = scope:owner
					modifier = agotma_instigator_provoked_war
				}
			}

			scope:owner = {
				add_character_modifier = {
					modifier = agotma_instigator_final_modifier
					years = 15
				}
			}
		}
		if = {
			limit = {
				scope:wartargetperson = {
					OR = {
						highest_held_title_tier >= tier_kingdom
						is_independent_ruler = yes
					}
				}
			}
			if = {
				limit = {
					OR = {
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_dorne }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_crownlands }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_iron_islands }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_north }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_reach }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_riverlands }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_stormlands }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_vale }
						scope:wartargetperson.capital_province = { geographical_region = world_westeros_the_westerlands }
					}
				}
				title:h_the_iron_throne = {
					every_de_jure_county_holder = {
						add_to_list = agotma_the_world_instigator
					}
				}
			}
			if = {
				limit = {
					OR = {
						scope:wartargetperson.capital_province = { geographical_region = world_stepstones }
						scope:wartargetperson.capital_province = { geographical_region = world_essos_tyrosh }
						scope:wartargetperson.capital_province = { geographical_region = world_essos_lys }
						scope:wartargetperson.capital_province = { geographical_region = world_essos_disputed_lands }
						scope:wartargetperson.capital_province = { geographical_region = world_essos_myr }
					}
				}
				title:e_three_daughters = {
					every_de_jure_county_holder = {
						add_to_list = agotma_the_world_instigator
					}
				}
			}
			if = {
				limit = {
					OR = {
						scope:wartargetperson.capital_province = { geographical_region = world_essos_andalos }
						scope:wartargetperson.capital_province = { geographical_region = world_essos_pentos }
					}
				}
				title:e_pentos = {
					every_de_jure_county_holder = {
						add_to_list = agotma_the_world_instigator
					}
				}
			}
		}
		else = {
			scope:wartargetperson.liege = {
				every_vassal_or_below = {
					limit = { highest_held_title_tier >= tier_county }
					add_to_list = iron_throne_realm
				}
			}
		}

		#LET THE REALM KNOW
		every_in_list = {
			list = agotma_the_world_instigator
			trigger_event = {
				id = agotma_instigator_outcome.0004
				days = 1
			}
		}
		scope:scheme = {
			end_scheme = yes
		}


		#TRIGGER THE WAR
		if = {
			limit = {
				scope:target = {
					is_claimant = yes
					is_playable_character = yes
				}
			}
			scope:target = {
				start_war = {
					cb = claim_cb
					target = scope:agotma_war_target_land.holder
					claimant = scope:target
					target_title = scope:agotma_war_target_land
				}
			}
		}
	}

	#IDUNWANIT
	option = {
		ai_chance = { base = 1 }
		name = agotma_instigator_outcome.0030.a.failure
		trigger = { exists = scope:cooking_the_war }
		show_as_tooltip = {	custom_tooltip = agotma_instigator_outcome.0030.b.tt }

		scope:owner = {
			trigger_event = agotma_instigator_outcome.0031
		}
	}
}

#TARGET DECLINED
agotma_instigator_outcome.0031 = {
	type = character_event
	title = agotma_instigator_outcome.0031.t

	desc = {
		desc = agotma_instigator_outcome.0031.desc
	}


	theme = court

	override_background = {
		reference = courtyard
	}

	left_portrait = scope:owner
	right_portrait = scope:target

	option = {
		name = agotma_instigator_outcome.0031.a.failure
		trigger = { exists = scope:cooking_the_war }
		show_as_tooltip = {	custom_tooltip = agotma_instigator_outcome.0031.b.tt }

		scope:scheme = {
			end_scheme = yes
		}
	}
}

#REALMWIDE MESSAGE
agotma_instigator_outcome.0004 = {
	type = character_event
	title = agotma_instigator_outcome.0004.t

	desc = {
		desc = agotma_instigator_outcome.0004.desc
	}

	theme = war

	override_background = {
		reference = battlefield
	}

	left_portrait = {
		character = scope:target
		animation = war_attacker
	}
	right_portrait = {
		character = scope:wartargetperson
		animation = worry
	}
	lower_right_portrait = scope:owner



	option = {
		name = agotma_instigator_outcome.0004.a
		ai_chance = {
			base = 75
			modifier = {
				add = 100
				has_trait = honest
			}
		}
	}

	option = {
		name = agotma_instigator_outcome.0004.b
		ai_chance = {
			base = 25
			modifier = {
				add = 50
				has_trait = deceitful
			}
			modifier = {
				add = 50
				has_trait = humble
			}
		}
	}
}




#target died
agotma_instigator_outcome.0006 = {
	type = character_event
	title = agotma_instigator_outcome.0006.t
	desc = agotma_instigator_outcome.0006.desc

	theme = court
	left_portrait = scope:target
	#No scheme, no widget

	option = {
		name = agotma_instigator_outcome.0006.a
	}
}

#already revealed
agotma_instigator_outcome.0007 = {
	type = character_event
	title = agotma_instigator_outcome.0007.t
	desc = agotma_instigator_outcome.0007.desc

	theme = court
	left_portrait = scope:target
	#No scheme, no widget

	option = {
		name = agotma_instigator_outcome.0007.a
	}
}

