﻿namespace = tour_grounds_events

############################
## Tour Mini-Activity: Tour Grounds
############################
## Vassal Events
## 7000-7999
## by Claudia Baldassi
############################
# tour_grounds_events.7000 - Liege: Vassal accidentally tours you past a room/building they didn't want you to see: it has all the nice things
# tour_grounds_events.7001 - Vassal: Try to keep your liege from your secret stash room

#####################################################################################

######################
## Vassal Events
## 7000-7999
## by Claudia Baldassi
######################

# Liege: Vassal accidentally tours you past a room/building they didn't want you to see: it has all the nice things they didn't want you to try and tax whilst you're here (e.g., their best horses)

scripted_trigger tour_grounds_has_artifacts_trigger = {
	any_character_artifact = {
		is_equipped = no
		exists = var:quality
		var:quality >= 40
		count >= 2
	}
}

scripted_trigger tour_grounds_has_food_trigger = {
	has_trait = gluttonous
	is_vegetarian_trigger = no
}

scripted_trigger tour_grounds_has_wine_trigger = {
	OR = {
		has_trait = drunkard
		has_trait = lifestyle_reveler
	}
	drinks_alcohol_trigger = yes
}

scripted_trigger tour_grounds_has_falcons_trigger = {
	OR = {
		AND = {
			has_trait = lifestyle_hunter
			has_trait_xp = {
				trait = lifestyle_hunter
				track = falconer
				value >= trait_second_level
			}
		}
		has_character_modifier = peregrine_falcon
	}
}

scripted_trigger tour_grounds_has_dogs_trigger = {
	OR = {
		has_trait = lifestyle_hunter
		house ?= { has_house_modifier = hold_court_8140_house_modifier }
	}
}

scripted_trigger tour_grounds_has_horses_trigger = {
	OR = {
		AND = {
			has_trait = tourney_participant
			has_trait_xp = {
				trait = tourney_participant
				track = horse
				value >= trait_second_level
			}
		}
		any_owned_story = {
			type = story_cycle_martial_lifestyle_warhorse
		}
		has_character_modifier = warfare_tamer_of_horses_modifier
		has_character_modifier = horse_story_modifier
	}
}

scripted_trigger tour_grounds_has_gold_trigger = {
	OR = {
		has_trait = greedy
		gold >= 300
	}
}

scripted_effect tour_grounds_tax_everything_effect = {
	pay_short_term_gold = {
		target = root
		gold = medium_gold_value
	}
	if = {
		limit = { vassal_contract_obligation_level_can_be_increased = feudal_government_taxes }
		vassal_contract_increase_obligation_level = feudal_government_taxes
	}
	else = {
		every_sub_realm_county = {
			add_county_modifier = {
				modifier = tour_liege_extra_taxation_county_modifier
				years = 10
			}
		}
	}
	add_opinion = {
		target = root
		modifier = annoyed_opinion
		opinion = -20
	}
}

tour_grounds_events.7000 = {
	type = activity_event
	title = tour_grounds_events.7000.t
	desc = {
		desc = tour_grounds_events.7000.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_artifacts_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_artifacts
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_food_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_pantry
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_wine_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_cellar
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_falcons_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_falcons
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_dogs_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_dogs
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_horses_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_horses
			}
			triggered_desc = {
				trigger = {
					scope:stop_host_scope = {
						tour_grounds_has_gold_trigger = yes
					}
				}
				desc = tour_grounds_events.7000.desc_gold
			}
			desc = tour_grounds_events.7000.desc_fallback
		}
	}
	theme = tour_grounds
	cooldown = { years = 1 }
	left_portrait = {
		character = root
		animation = shock
	}
	right_portrait = {
		character = scope:stop_host_scope
		animation = shame
	}
	override_background = { reference = corridor_day }

	immediate = {
		if = {
			limit = {
				scope:stop_host_scope = {
					tour_grounds_has_artifacts_trigger = yes
				}
			}
			scope:stop_host_scope = {
				random_character_artifact = {
					limit = {
						is_equipped = no
						exists = var:quality
						var:quality >= 40
					}
					save_scope_as = this_artifact
				}
			}
		}
	}

	# Option A: tax EVERYTHING
	option = {
		name = tour_grounds_events.7000.a
		scope:stop_host_scope = {
			send_interface_toast = {
				title = tour_grounds_events.7000.a.tt
				left_icon = root
				tour_grounds_tax_everything_effect = yes
			}
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
			}
			modifier = {
				has_trait = compassionate
				add = -50
			}
		}
	}

	# Option B: commandeer all
	option = {
		name = tour_grounds_events.7000.b
		trigger = {
			OR = {
				has_trait = greedy
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_intimidation
					}
				}
			}
		}
		scope:stop_host_scope = {
			send_interface_toast = {
				title = tour_grounds_events.7000.b.tt
				left_icon = root
				if = {
					limit = {
						exists = scope:this_artifact
					}
					pay_short_term_gold = {
						target = root
						gold = major_gold_value
					}
					scope:this_artifact = {
						set_owner = root
					}

				}
				else_if = {
					limit = {
						OR = {
							tour_grounds_has_food_trigger = yes
							tour_grounds_has_wine_trigger = yes
							tour_grounds_has_falcons_trigger = yes
							tour_grounds_has_dogs_trigger = yes
							house ?= { has_house_modifier = hold_court_8140_house_modifier }
							tour_grounds_has_horses_trigger = yes
						}
					}
					pay_short_term_gold = {
						target = root
						gold = major_gold_value
					}
					custom_tooltip = tour_grounds_events.7000.b.tt.2
				}
				else = {
					scope:stop_host_scope = {
						pay_short_term_gold = {
							target = root
							gold = massive_gold_value
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:stop_host_scope = {
					OR = {
						tour_grounds_has_food_trigger = yes
						tour_grounds_has_wine_trigger = yes
					}
				}
			}
			add_character_modifier = {
				modifier = tours_grounds_luxury_dining_modifier
				years = 15
			}
		}
		else_if = {
			limit = {
				scope:stop_host_scope = {
					OR = {
						tour_grounds_has_falcons_trigger = yes
						tour_grounds_has_dogs_trigger = yes
					}
				}
			}
			add_character_modifier = {
				modifier = tours_grounds_hunting_companions_modifier
				years = 15
			}
			if = {
				limit = {
					scope:stop_host_scope = {
						has_character_modifier = peregrine_falcon
					}
				}
				add_character_modifier = peregrine_falcon
			}
			else_if = {
				limit = {
					scope:stop_host_scope = {
						house ?= { has_house_modifier = hold_court_8140_house_modifier }
					}
				}
				house = { add_house_modifier = { modifier = hold_court_8140_house_modifier years = 30 } }
			}
		}
		else_if = {
			limit = {
				scope:stop_host_scope = {
					tour_grounds_has_horses_trigger = yes
				}
			}
			add_character_modifier = {
				modifier = tours_grounds_excellent_horses_modifier
				years = 15
			}
		}
		scope:stop_host_scope = {
			add_opinion = {
				target = root
				modifier = insult_opinion
				opinion = -40
			}
		}
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_intimidation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 1 }
		}
		else_if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = tour_type_taxation
					}
				}
			}
			increase_tour_success_effect = { POINTS = 2 }
		}
		stress_impact = {
			generous = major_stress_impact_gain
			compassionate = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 2
			}
			modifier = {
				has_trait = compassionate
				add = -75
			}
		}
	}

	# Option C: common interest
	option = {
		name = tour_grounds_events.7000.c
		trigger = {
			trigger_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_food_trigger = yes
					}
				}
				tour_grounds_has_food_trigger = yes
			}
			trigger_else_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_wine_trigger = yes
					}
				}
				tour_grounds_has_food_trigger = yes
			}
			trigger_else_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_falcons_trigger = yes
					}
				}
				tour_grounds_has_falcons_trigger = yes
			}
			trigger_else_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_dogs_trigger = yes
					}
				}
				OR = {
					tour_grounds_has_dogs_trigger = yes
					any_owned_story = { type = story_cycle_pet_dog }
				}
			}
			trigger_else_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_horses_trigger = yes
					}
				}
				tour_grounds_has_horses_trigger = yes
			}
			trigger_else_if = {
				limit = {
					scope:stop_host_scope = {
						tour_grounds_has_gold_trigger = yes
					}
				}
				has_trait = greedy
			}
			trigger_else = {
				always = no
			}
		}
		scope:stop_host_scope = {
			send_interface_toast = {
				title = tour_grounds_events.7000.c.tt
				left_icon = root
				custom_tooltip = tour_grounds_events.7000.c.tt.2
				add_character_modifier = {
					modifier = tours_grounds_sharing_tips_with_friend_modifier
					years = 10
				}
			}
		}
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:stop_host_scope }
			}
			set_relation_friend = { reason = friend_common_interests target = scope:stop_host_scope }
		}
		add_character_modifier = {
			modifier = tours_grounds_sharing_tips_with_friend_modifier
			years = 15
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			shy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -75
			}
			modifier = {
				has_trait = shy
				add = -50
			}
			modifier = {
				has_trait = gregarious
				add = 100
			}
		}
	}

	# Option D: you saw nothing
	option = {
		name = tour_grounds_events.7000.d
		reverse_add_opinion = {
			target = scope:stop_host_scope
			modifier = grateful_opinion
			opinion = 30
		}
		scope:stop_host_scope = {
			send_interface_toast = {
				title = tour_grounds_events.7000.d.tt
				left_icon = root
				if = {
					limit = {
						root = {
							can_add_hook = {
								target = scope:stop_host_scope
									type = favor_hook
							}
						}
					}
					root = {
						add_hook = {
							target = scope:stop_host_scope
								type = favor_hook
						}
					}
				}
			}
		}
		stress_impact = {
			greedy = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = greedy
				add = -100
			}
		}
	}
}

# Vassal: Try to keep your liege from your secret stash room

tour_grounds_events.7001 = {
	type = activity_event
	title = tour_grounds_events.7000.t
	desc = {
		desc = tour_grounds_events.7001.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					tour_grounds_has_artifacts_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_artifacts
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_food_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_pantry
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_wine_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_cellar
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_falcons_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_falcons
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_dogs_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_dogs
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_horses_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_horses
			}
			triggered_desc = {
				trigger = {
					tour_grounds_has_gold_trigger = yes
				}
				desc = tour_grounds_events.7001.desc_gold
			}
			desc = tour_grounds_events.7001.desc_fallback
		}
		desc = tour_grounds_events.7001.desc_conclusion
	}
	theme = tour_grounds
	left_portrait = {
		character = root
		animation = shame
	}
	right_portrait = {
		character = scope:visiting_liege
		animation = shock
	}
	override_background = { reference = corridor_day }

	trigger = {
		NOT = { has_character_flag = was_extorted_by_visiting_liege }
	}

	weight_multiplier = {
		base = 1
		modifier = {
			OR = {
				tour_grounds_has_artifacts_trigger = yes
				tour_grounds_has_food_trigger = yes
				tour_grounds_has_wine_trigger = yes
			}
			add = 1
		}
		modifier = {
			OR = {
				tour_grounds_has_falcons_trigger = yes
				tour_grounds_has_dogs_trigger = yes
				tour_grounds_has_horses_trigger = yes
			}
			add = 2
		}
	}

	immediate = {
		add_character_flag = {
			flag = was_extorted_by_visiting_liege
			days = 30 #Only once per visit
		}
	}

	#Option A: try to distract
	option = {
		name = tour_grounds_events.7001.a
		duel = {
			skills = { diplomacy intrigue }
			target = scope:visiting_liege
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = tour_grounds_events.7001.a.success
				send_interface_toast = {
					title = tour_grounds_events.7001.a.success.tt
					left_icon = scope:visiting_liege
					add_character_modifier = {
						modifier = tour_grounds_hidden_assets_modifier
						years = 15
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = tour_grounds_events.7001.a.failure
				custom_tooltip = tour_grounds_events.7001_followup
				scope:visiting_liege = { trigger_event = tour_grounds_events.7000 }
				send_interface_toast = {
					title = tour_grounds_events.7001.a.failure.tt
					left_icon = scope:visiting_liege
				}
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = deceitful
				add = 100
			}
		}
	}

	#Option B: Bribe
	option = {
		name = tour_grounds_events.7001.b
		duel = {
			skills = { stewardship intrigue }
			target = scope:visiting_liege
			60 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					scope:visiting_liege = { has_trait = greedy }
					add = 20
				}
				desc = tour_grounds_events.7001.b.success
				send_interface_toast = {
					title = tour_grounds_events.7001.b.success.tt
					left_icon = scope:visiting_liege
					add_character_modifier = {
						modifier = tour_grounds_hidden_assets_modifier
						years = 15
					}
					pay_short_term_gold = {
						target = scope:visiting_liege
						gold = major_gold_value
					}
				}
				scope:visiting_liege = {
					if = {
						limit = {
							is_ai = no
						}
						send_interface_toast = {
							title = tour_grounds_events.7001.b.tt
							custom_tooltip = tour_grounds_events.7001.b.tt.2
							show_as_tooltip = {
								root = {
									pay_short_term_gold = {
										target = scope:visiting_liege
										gold = major_gold_value
									}
								}
							}
						}
					}
					else = {
						add_opinion = {
							target = root
							modifier = grateful_opinion
							opinion = 30
						}
					}
				}
			}
			40 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = tour_grounds_events.7001.a.failure
				scope:visiting_liege = { trigger_event = tour_grounds_events.7000 }
				custom_tooltip = tour_grounds_events.7001_followup
				send_interface_toast = {
					title = tour_grounds_events.7001.a.failure.tt
					left_icon = scope:visiting_liege
				}
			}
		}
		
		ai_chance = {
			base = 100
		}
	}

	#Option C: I was JUST about to take you there!
	option = {
		name = tour_grounds_events.7001.c
		scope:visiting_liege = { trigger_event = tour_grounds_events.7000 }
		custom_tooltip = tour_grounds_events.7001_followup
		if = {
			limit = {
				scope:visiting_liege = { is_ai = yes }
				can_add_hook = {
					target = scope:visiting_liege
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:visiting_liege
				type = favor_hook
			}
		}
		ai_chance = {
			base = 100
			modifier = {
				has_trait = honest
				add = 100
			}
		}
	}
}
