﻿
namespace = feast_default_jason

# Legend
# involved_activity
# activity_host
# activity_location

scripted_trigger feast_default_jason_100_attending_soldier_trigger = {
	is_ai = yes
	NOT = {
		this = root
	}
	can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
	is_adult = yes
	NOT = {
		is_at_war_with = root
	}
}
scripted_trigger feast_default_jason_100_attending_ruler_trigger = {
	gold >= minor_gold_value
	is_ai = yes
	is_ruler = yes
	is_landed = yes
	NOT = {
		this = root
	}
	is_adult = yes
	NOR = {
		has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
		any_ally = {
			is_at_war_with = root
		}
		is_allied_to = root
		government_has_flag = government_is_herder
	}
	is_at_war = no
	opinion = {
		target = root
		value >= 0
	}
	trigger_if = {
		limit = {
			root = {
				highest_held_title_tier >= tier_empire
			}
		}
		highest_held_title_tier >= tier_duchy
	}
	trigger_else = {
		highest_held_title_tier >= tier_county
	}
	current_military_strength > 0
	NOR = {
		any_tributary = {
			is_at_war_with = root
		}
		suzerain ?= {
			is_at_war_with = root
		}
		top_suzerain ?= {
			is_at_war_with = root
		}
		any_liege_or_above = {
			is_at_war_with = root
			suzerain ?= {
				is_at_war_with = root
			}
		}
		any_vassal_or_below = {
			is_at_war_with = root
		}
		AND = {
			is_confederation_member = yes
			confederation = {
				is_house_based = no # any_confederation_member is not performant for house blocs
				any_confederation_member = {
					is_at_war_with = root
				}
			}
		}
	}
}

#You are stressed at the feast and your realm is at war
feast_default_jason.100 = {
	type = activity_event
	title = feast_default_jason.100.t
	desc = feast_default_jason.100.desc
	theme = feast_activity

	left_portrait = {
		character = root
		animation = stress
	}
	center_portrait = {
		character = scope:soldier
		animation = inspect_weapon
		camera = camera_event_center_pointing_forward
	}
	right_portrait = {
		character = scope:other_ruler
		animation = debating
		camera = camera_event_very_right
	}
	lower_right_portrait = scope:foe
	cooldown = { years = 10 }
	
	trigger = {
		has_raised_armies = yes
		is_landed = yes
		stress_level >= 1
		is_at_war = yes
		any_character_war = {
			NOR = {
				using_cb = undirected_great_holy_war
				using_cb = directed_great_holy_war
			}
			OR = {
				AND = {
					primary_defender = root
					defender_war_score <= 10
				}
				AND = {
					primary_attacker = root
					attacker_war_score <= 10
				}
			}
		}
		scope:activity = {
			any_attending_character = {
				feast_default_jason_100_attending_soldier_trigger = yes
				save_temporary_scope_as = soldier_temp
			}
			any_attending_character = {
				feast_default_jason_100_attending_ruler_trigger = yes
				NOT = {
					this = scope:soldier_temp
				}
			}
		}
	}
	weight_multiplier = {
		base = 1
		modifier = {
			stress_level >= 2
			add = 1
		}
		modifier = {
			stress_level >= 3
			add = 1
		}
	}

	immediate = {
		
		scope:activity = {
			ordered_attending_character = {
				order_by = martial
				limit = {
					feast_default_jason_100_attending_soldier_trigger = yes
				}
				save_scope_as = soldier
			}
			#Try to save valid supporter if host of coronation
			if = {
				limit = {
					activity_host = root
					has_activity_type = activity_coronation
				} 
				ordered_guest_subset = {
					name = supporter
					order_by = {
						value = "opinion(root)"
					}
					limit = {
						feast_default_jason_100_attending_ruler_trigger = yes
						NOT = {
							this = scope:soldier
						}
					}
					save_scope_as = other_ruler
				}
			}
			if = {
				limit = {
					NOT = {
						exists = scope:other_ruler
					}
				}
				ordered_attending_character = {
					order_by = {
						value = "opinion(root)"
					}
					limit = {
						feast_default_jason_100_attending_ruler_trigger = yes
						NOT = {
							this = scope:soldier
						}
					}
					save_scope_as = other_ruler
				}
			}
		}
		random_character_war = {
			limit = {
				NOR = {
					using_cb = undirected_great_holy_war
					using_cb = directed_great_holy_war
				}
				OR = {
					AND = {
						primary_defender = root
						defender_war_score <= 10
					}
					AND = {
						primary_attacker = root
						attacker_war_score <= 10
					}
				}
			}
			save_scope_as = war
			if = {
				limit = {
					primary_defender = root
				}
				primary_attacker = {
					save_scope_as = foe
				}
			}
			else = {
				primary_defender = {
					save_scope_as = foe
				}
			}
		}
		ordered_army = {
			order_by = army_size
			save_scope_as = army
			location = {
				save_scope_as = army_location
			}
		}
	}
	#Add ruler to war
	option = {
		trigger = {
			#I seek advancement!
			trigger_if = {
				limit = {
					involved_activity = {
						NOT = { activity_host = root }
						has_activity_type = activity_coronation
					}
					scope:war = {
						primary_attacker = root
					}
				}
				has_activity_intent = coronation_seize_advantages
			}
			#I seek aid for my people
			trigger_else_if = {
				limit = {
					involved_activity = {
						NOT = { activity_host = root }
						has_activity_type = activity_coronation
					}
					scope:war = {
						primary_defender = root
					}
				}
				has_activity_intent = coronation_advocate_domain
			}
			trigger_else_if = {
				limit = {
					involved_activity = {
						activity_host = root
						has_activity_type = activity_coronation
					}
					has_activity_intent = coronation_embrace_supporters
				}
				has_activity_intent = coronation_embrace_supporters
			}
			trigger_else = {
				diplomacy >= high_skill_rating
			}
		}
		show_as_unavailable = {
			always = yes
		}
		name = feast_default_jason.100.a
		if = {
			limit = {
				scope:war = {
					primary_defender = root
				}
			}
			scope:war = {
				add_defender = scope:other_ruler
			}
		}
		else = {
			scope:war = {
				add_attacker = scope:other_ruler
			}
		}
		scope:other_ruler = {
			if = {
				limit = {
					NOR = {
						is_liege_or_above_of = root
						is_allied_to = root
						highest_held_title_tier > root.highest_held_title_tier
					}
				}
				add_prestige = medium_prestige_gain
			}
			else = {
				add_prestige = minor_prestige_gain
			}
		}
		hidden_effect = {
			add_opinion = {
				modifier = grateful_opinion
				target = scope:other_ruler
				opinion = 30
			}
			
		}
		
		stress_impact = {
			base = minor_stress_impact_loss
			stubborn = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			craven = minor_stress_impact_loss
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_boldness = -0.5
				ai_rationality = 0.5
			}
			modifier = {
				factor = 5
				OR = {
					scope:war = {
						primary_defender = root
						attacker_war_score >= 40
					}
					scope:war = {
						primary_attacker = root
						defender_war_score >= 40
					}
					scope:war = {
						primary_defender = root
						primary_attacker = {
							current_military_strength > root.current_military_strength
							
						}
					}
					scope:war = {
						primary_attacker = root
						primary_defender = {
							current_military_strength > root.current_military_strength
						}
					}
				}
			}
			modifier = {
				factor = 2
				has_trait = craven
				scope:war = {
					primary_defender = root
				}
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = stubborn
					has_trait = arrogant

					scope:war = {
						primary_defender = root
						primary_attacker = {
							current_military_strength < root.current_military_strength
							
						}
					}
					scope:war = {
						primary_attacker = root
						primary_defender = {
							current_military_strength < root.current_military_strength
						}
					}
				}
			}
		}
	}
	#Spend the rest of the feast speaking of victory
	option = {
		name = feast_default_jason.100.b
		if = {
			limit = {
				involved_activity = {
					has_activity_type = activity_coronation
				}
				this = involved_activity.activity_host
			}
			custom_tooltip = coronation_tt_positive_tiny
			involved_activity = { activity_special_type_progression_tiny = yes }
			coronation_add_magnificence_log_effect = {
        	    VALUE = flag:positive_tiny
        	    CHAR = root
        	}
		}
		else = {
			add_prestige = miniscule_prestige_gain
		}
		if = {
			limit = {
				has_activity_intent = coronation_exalt_crown
			}
			add_character_modifier = {
				modifier = boasted_of_victories_modifier
				years = 5
				desc = victories_reduce_stress_add_prestige_desc
			}
		}
		else = {
			add_character_modifier = {
				modifier = boasted_of_victories_modifier
				years = 3
				desc = victories_reduce_stress_add_prestige_desc
			}
		}
		custom_tooltip = victories_reduce_stress_add_prestige_tt
		if = {
			limit = {
				has_activity_intent = coronation_exalt_crown
			}
			custom_tooltip = feast_default_jason.100.b_exalt_the_crown
		}
		stress_impact = {
			arrogant = minor_stress_impact_loss
			ambitious = miniscule_stress_impact_loss
			humble = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_energy = 0.5
			}
			modifier = {
				factor = 5
				
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = arrogant
					has_trait = ambitious
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = humble
					scope:war = {
						primary_defender = root
						attacker_war_score >= 30
					}
					scope:war = {
						primary_attacker = root
						defender_war_score >= 30
					}
					scope:war = {
						primary_defender = root
						primary_attacker = {
							current_military_strength > root.current_military_strength
							
						}
					}
					scope:war = {
						primary_attacker = root
						primary_defender = {
							current_military_strength > root.current_military_strength
						}
					}
				}
			}
		}
	}
	#Another round!
	option = {
		name = {
			trigger = {
				drinks_alcohol_trigger = yes
				NOR = {
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
			text = feast_default_jason.100.c
		}
		name = {
			trigger = {
				OR = {
					drinks_alcohol_trigger = no
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
			text = feast_default_jason.100.c_hungee
		}
		#Alcohol stress loss
		if = {
			limit = {
				drinks_alcohol_trigger = yes
				NOR = {
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = drunkard 
					}
				}
				random = {
					chance = 5
					add_trait = drunkard
				}
			}
			stress_impact = {
				base = medium_stress_impact_loss
				temperate = medium_stress_impact_gain
				diligent = miniscule_stress_impact_gain
				vengeful = miniscule_stress_impact_gain
				drunkard = medium_stress_impact_loss
				lifestyle_reveler = medium_stress_impact_loss
				gregarious = miniscule_stress_impact_loss
				content = minor_stress_impact_loss
				lazy = minor_stress_impact_loss
				fickle = miniscule_stress_impact_loss
				calm = miniscule_stress_impact_loss
				patient = miniscule_stress_impact_loss
			}
		}
		#Food stress loss
		if = {
			limit = {
				OR = {
					drinks_alcohol_trigger = no
					has_trait = comfort_eater
					has_trait = gluttonous
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = comfort_eater 
					}
				}
				random = {
					chance = 5
					add_trait = comfort_eater
				}
			}
			stress_impact = {
				base = medium_stress_impact_loss
				temperate = medium_stress_impact_gain
				diligent = miniscule_stress_impact_gain
				vengeful = miniscule_stress_impact_gain
				gluttonous = medium_stress_impact_loss
				comfort_eater = medium_stress_impact_loss
				gregarious = miniscule_stress_impact_loss
				content = minor_stress_impact_loss
				lazy = minor_stress_impact_loss
				fickle = miniscule_stress_impact_loss
				calm = miniscule_stress_impact_loss
				patient = miniscule_stress_impact_loss
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -0.5
				ai_energy = -0.5
			}
			modifier = {
				factor = 2
				OR = {
					has_trait = gluttonous
					has_trait = drunkard
					has_trait = comfort_eater
					has_trait = lifestyle_reveler
					has_trait = content
					has_trait = lazy
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = temperate
					has_trait = diligent
					has_trait = vengeful
				}
			}
		}
	}
}
