﻿namespace = fp3_clan

# FP3: Additional Tax Collector Flavor Events
# by Chad Uhl

#####################################################################
# Worth more than Gold?												#
# Tax Collector learns of a secret held by one of their taxees		#
# by Chad Uhl														#
#####################################################################
fp3_clan.1000 = {
	type = character_event
	title = fp3_clan.1000.t
	desc = fp3_clan.1000.desc
	theme = realm
	
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:target_tax_collector
		animation = personality_dishonorable
	}
	lower_center_portrait = scope:secret_holder

	trigger = {
		has_fp3_dlc_trigger = yes
		is_valid_for_narrow_yearly_events = yes
		# Do any of their taxed vassals have a secret that you don't know about?
		any_tax_collector = {
			save_temporary_scope_as = temp_tax_collector
			tax_slot = {
				any_tax_slot_vassal = {
					# Don't let the tax collector tell on themself
					this != scope:temp_tax_collector
					# Ensure they have a secret that ROOT doesn't already know
					any_secret = {
						NOT = { is_known_by = root }
					}
				}
			}
		}
	}

	immediate = {
		random_tax_collector = {
			limit = {
				save_temporary_scope_as = temp_tax_collector
				tax_slot = {
					any_tax_slot_vassal = {
						# Don't let the tax collector tell on themself
						this != scope:temp_tax_collector
						# Ensure they have a secret that ROOT doesn't already know
						any_secret = {
							NOT = { is_known_by = root }
						}
					}
				}
			}
			weight = {
				base = 1
				modifier = { # Base tax collector weighting
					add = preferred_tax_collector_modifier
				}
				modifier = { # Diligent or Ambitious tax collectors are more likely
					add = 10
					OR = {
						has_trait = diligent
						has_trait = ambitious
					}
				}
				modifier = { # Being patient is also useful
					add = 5
					has_trait = patient
				}
				modifier = { # And so is being stubborn
					add = 5
					has_trait = stubborn
				}
				modifier = { # And so is being deceitful
					add = 5
					has_trait = deceitful
				}
			}
			save_scope_as = target_tax_collector
			tax_slot = {
				random_tax_slot_vassal = {
					limit = {
						any_secret = {
							NOT = { is_known_by = root }
						}
						this != scope:target_tax_collector
					}
					save_scope_as = secret_holder
					random_secret = {
						limit = {
							NOT = { is_known_by = root }
						}
						save_scope_as = target_secret
						reveal_to = root
						hidden_effect = { reveal_to = scope:target_tax_collector }
					}
				}
			}
		}
	}

	option = { # Some coin for your troubles
		name = fp3_clan.1000.a
		trigger = {
			short_term_gold > minor_gold_value
		}
		show_as_unavailable = {
			short_term_gold < minor_gold_value
		}
		pay_short_term_gold = {
			target = scope:target_tax_collector
			gold = minor_gold_value
		}
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = grateful_opinion
			opinion = 30
		}

		ai_chance = {
			base = 30	
		}

		stress_impact = {
			#paranoid = medium_stress_impact_loss
		}
	}
	
	option = { # take this artifact
		name = fp3_clan.1000.b
		trigger = {
			any_character_artifact = { }
		}
		show_as_unavailable = {
			any_character_artifact = {
				count < 1
			}
		}

		random_character_artifact = {
			save_scope_as = target_artifact
			set_owner = scope:target_tax_collector
			add_artifact_history = {
				type = given
				actor = root
				recipient = scope:target_tax_collector
			}
		}
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = grateful_opinion
			opinion = 40
		}

		ai_chance = {
			base = 30	
		}

		stress_impact = {
			#paranoid = medium_stress_impact_loss
		}
	}

	option = { # Wow thanks for this tasty info 
		name = fp3_clan.1000.c
		reverse_add_opinion = {
			target = scope:target_tax_collector
			# labelled spouse, but is generic and can work in this situation
			modifier = spouse_praised_me_opinion
		}

		ai_chance = {
			base = 30	
		}

		stress_impact = {
			paranoid = medium_stress_impact_loss
		}
	}
}

#####################################################################
# GetHerHis Cup Runneth Over										#
# Tax Collector is embezzling money									#
# by Chad Uhl														#
#####################################################################
fp3_clan.1010 = {
	type = character_event
	title = fp3_clan.1010.t
	desc = fp3_clan.1010.desc
	theme = realm
		
	left_portrait = {
		character = scope:steward
		animation = thinking
	}
	right_portrait = {
		character = scope:target_tax_collector
		animation = shame
	}

	trigger = {
		has_fp3_dlc_trigger = yes
		is_valid_for_narrow_yearly_events = yes
		# Check that tax collector is not trustworthy
		exists = cp:councillor_steward
		any_tax_collector = {
			NOT = { this = root.cp:councillor_steward }
			root = {
				NOT = { has_imprisonment_reason = prev }
			}
		}
	}

	cooldown = { years = 10 }

	immediate = {
		cp:councillor_steward = { save_scope_as = steward }
		random_tax_collector = {
			limit = {
				this != scope:steward
			}
			weight = {
				base = 1
				modifier = { # Base tax collector weighting
					add = preferred_tax_collector_modifier
				}
				modifier = { # Deceitful or Ambitious tax collectors are more likely
					add = 10
					OR = {
						has_trait = deceitful
						has_trait = ambitious
					}
				}
				modifier = { # And so is being stubborn
					add = 5
					has_trait = stubborn
				}
			}
			save_scope_as = target_tax_collector
		}
		# Give valid imprisonment reason
		add_opinion = {
			target = scope:target_tax_collector
			modifier = embezzled_opinion
		}
		# Determine how much money they embezzled
		set_variable = {
			name = embezzled_gold
			value = {
				value = 10
				multiply = root.primary_title.tier
				# Mult the number of vassals they have in that tax slot
				multiply = {
					value = 1
					scope:target_tax_collector.tax_slot = {
						every_tax_slot_vassal = {
							add = 1
						}
					}
					divide = 2
					min = 1
				} 
			}
		}
	}

	option = { # Demand your money back 
		name = fp3_clan.1010.a
		# Skill challenge
		duel = {
			skills = { stewardship diplomacy }
			target = scope:target_tax_collector
			# Success: you get your money back
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = fp3_clan.1010.a.success
				send_interface_toast = {
					title = fp3_clan.1010.a.success
					left_icon = root
					right_icon = scope:target_tax_collector
					# Apply success effects
					# you get the gold; wahoo
					add_treasury_or_gold = root.var:embezzled_gold
				}
			}
			# Failure: lower opinion from tax collector
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = fp3_clan.1010.a.failure
				send_interface_toast = {
					title = fp3_clan.1010.a.failure
					left_icon = root
					right_icon = scope:target_tax_collector
					# Apply failure effects
					# Lower opinion to affect tax collector aptitude
					reverse_add_opinion = {
						target = scope:target_tax_collector
						modifier = was_scolded_opinion
					}
				}
			}
		}

		ai_chance = {
			base = 33 
			modifier = {
				has_trait = greedy 
				add = 50 
			}
		}

		stress_impact = {
			greedy = minor_stress_impact_loss
		}
	}

	option = { # Opportunity plus instinct equals profit
		name = fp3_clan.1010.b
		flavor = fp3_clan.1010.b.flavor
		# Opinion gain to make the tax collector better at their job
		reverse_add_opinion = {
			modifier = grateful_opinion
			opinion = 35
			target = scope:target_tax_collector
		}
		add_character_modifier = {
			modifier = fp3_cunning_tax_collectors
			years = 30
		}

		ai_chance = {
			base = 33 
			modifier = {
				has_trait = generous 
				add = 50 
			}
		}
	}
	
	option = { # Don't let it happen again
		name = fp3_clan.1010.c
		# Lower opinion to affect tax collector aptitude
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = whipped_me_opinion
		}
		add_dread = medium_dread_gain

		ai_chance = {
			base = 33
			modifier = {
				OR = {
					has_trait = sadistic
					has_trait = wrathful
					has_trait = vengeful
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = calm
					has_trait = content 
					has_trait = generous
					has_trait = forgiving
					has_trait = compassionate
				}
				factor = 0 
			}
			modifier = {
				dread >= 50
				add = -30
			}
		}

		stress_impact = {
			calm = minor_stress_impact_gain
			content = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
		}
	}

	after = {
		# Variable cleanup
		remove_variable = embezzled_gold
	}
}

#####################################################################
# Practical Learning												#
# Your tax collector improves skill on the job 						#
# by Chad Uhl														#
#####################################################################
fp3_clan.1020 = {
	type = character_event
	title = fp3_clan.1020.t
	desc = {
		desc = fp3_clan.1020.desc
		first_valid = {
			triggered_desc = {
				trigger = { var:skill_to_increase = flag:stewardship }
				desc = fp3_clan.1020.stewardship
			}
			triggered_desc = {
				trigger = { var:skill_to_increase = flag:intrigue }
				desc = fp3_clan.1020.intrigue
			}
			triggered_desc = {
				trigger = { var:skill_to_increase = flag:diplomacy }
				desc = fp3_clan.1020.diplomacy
			}
		}
		desc = fp3_clan.1020.outro
	}
	theme = realm
	
	left_portrait = {
		character = scope:steward
		animation = personality_content
	}
	right_portrait = {
		character = scope:target_tax_collector
		animation = happiness
	}

	cooldown = { years = 5 }

	trigger = {
		has_fp3_dlc_trigger = yes
		is_valid_for_narrow_yearly_events = yes
		exists = cp:councillor_steward
		employs_tax_collector = yes
		any_tax_collector = {
			NOT = { this = root.cp:councillor_steward }
		}
	}

	immediate = {
		cp:councillor_steward = { save_scope_as = steward }
		random_tax_collector = {
			limit = { this != scope:steward }
			weight = {
				base = 1
				modifier = { # Base tax collector weighting
					add = preferred_tax_collector_modifier
				}
				modifier = {
					add = 10
					has_trait = diligent
				}
				modifier = {
					add = 10
					has_trait = ambitious
				}
				modifier = {
					add = 5
					has_trait = stubborn
				}
			}
			save_scope_as = target_tax_collector
		}
		random_list = {
			1 = {
				set_variable = {
					name = skill_to_increase
					value = flag:stewardship
				}
			}
			1 = {
				set_variable = {
					name = skill_to_increase
					value = flag:intrigue
				}
			}
			1 = {
				set_variable = {
					name = skill_to_increase
					value = flag:diplomacy
				}
			}
		}
	}

	option = { # Well done!
		name = fp3_clan.1020.a
		reverse_add_opinion = {
			modifier = spouse_praised_me_opinion
			target = scope:target_tax_collector
		}
		scope:target_tax_collector = { increase_tax_collector_skill = yes } 

		ai_chance = {
			base = 30 
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = generous
					has_trait = gregarious
					has_trait = humble 
					has_trait = just
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = arrogant
					has_trait = callous
				}
				factor = 0
			}
		}

		stress_impact = {
			arrogant = minor_stress_impact_gain
			callous = minor_stress_impact_gain
			generous = minor_stress_impact_loss
			compassionate = minor_stress_impact_loss
		}
	}

	option = { # Teach the others your skills
		name = fp3_clan.1020.b
		trigger = {
			any_tax_collector = {
				count >= 2
			}
		}
		scope:target_tax_collector = { increase_tax_collector_skill = yes } 
		every_tax_collector = {
			custom = fp3_clan.1020.every_tax_collector
			limit = {
				this != scope:target_tax_collector
			}
			random = {
				chance = 30
				increase_tax_collector_skill = yes
				root = {
					add_to_variable_list = {
						name = improved_tax_collectors
						target = prev
					}
				}
			}
		}
		hidden_effect = {
			if = { # If any tax collectors were improved, send a toast
				limit = {
					any_in_list = {
						variable = improved_tax_collectors
						count >= 1
					}
				}
				every_in_list = {
					variable = improved_tax_collectors
					root = {
						if = {
							limit = {
								NOT = { has_variable = num_improved_tax_collectors }
							}
							set_variable = {
								name = num_improved_tax_collectors
								value = 0
							}
						}
						change_variable = {
							name = num_improved_tax_collectors
							add = 1
						}
					}
				}
				send_interface_toast = {
					title = fp3_clan.1020.b.improved_tax_collectors
					left_icon = scope:target_tax_collector
					custom_tooltip = fp3_clan.1020.b.improved_tax_collectors.desc
				}
			}
			else = {
				send_interface_toast = {
					title = fp3_clan.1020.b.none_improved
					left_icon = scope:target_tax_collector
					custom_tooltip = fp3_clan.1020.b.none_improved.desc
				}
			}
		}

		ai_chance = {
			base = 40 
		}
	}
	
	option = { # Deny recognition
		name = fp3_clan.1020.c
		scope:target_tax_collector = { increase_tax_collector_skill = yes }
		reverse_add_opinion = {
			modifier = neglected_opinion
			target = scope:target_tax_collector
			opinion = -10
		}
		add_prestige = medium_prestige_gain

		ai_chance = {
			base = 30 
			modifier = {
				OR = {
					has_trait = callous 
					has_trait = arrogant
				}
				add = 50 
			}
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = generous
					has_trait = gregarious
					has_trait = humble 
					has_trait = just
				}
				factor = 0 
			}
		}

		stress_impact = {
			arrogant = minor_stress_impact_loss
			callous = minor_stress_impact_loss
			compassionate = minor_stress_impact_gain
		}
	}

	after = {
		remove_variable = skill_to_increase
		remove_variable = improved_tax_collectors
		if = {
			limit = { exists = var:num_improved_tax_collectors }
			remove_variable = num_improved_tax_collectors
		}
	}
}

#####################################################################
# Tax Dispute														#
# Tax collector in conflict with vassal, you can choose sides		#
# by Chad Uhl														#
#####################################################################
scripted_trigger is_valid_vassal_1030_trigger = {
	is_available_ai_adult = yes
	# we wanna dunk on them, not their diarch
	has_active_diarchy = no 
}

fp3_clan.1030 = {
	type = character_event
	title = fp3_clan.1030.t
	desc = fp3_clan.1030.desc
	theme = realm
	
	left_portrait = {
		character = scope:target_taxed_vassal
		animation = anger
	}
	right_portrait = {
		character = scope:target_tax_collector
		animation = disapproval
	}

	trigger = {
		has_fp3_dlc_trigger = yes
		is_valid_for_narrow_yearly_events = yes
		# ensure we have a proper vassal to pull in 
		any_tax_collector = {
			save_temporary_scope_as = temp_tax_collector
			tax_slot = {
				any_tax_slot_vassal = {
					is_valid_vassal_1030_trigger = yes
					faith = {
						this != scope:temp_tax_collector.faith
						faith_hostility_level = {
							target = scope:temp_tax_collector.faith
							value > faith_fully_accepted_level
						}
					}
				}
			}
		}
	}

	immediate = {
		random_tax_collector = {
			limit = {
				save_temporary_scope_as = temp_tax_collector
				tax_slot = {
					any_tax_slot_vassal = {
						is_valid_vassal_1030_trigger = yes 
						faith = {
							this != scope:temp_tax_collector.faith
							faith_hostility_level = {
								target = scope:temp_tax_collector.faith
								value > faith_fully_accepted_level
							}
						}
					}
				}
			}
			save_scope_as = target_tax_collector
			tax_slot = {
				random_tax_slot_vassal = {
					limit = {
						is_valid_vassal_1030_trigger = yes
						faith = {
							this != scope:target_tax_collector.faith
							faith_hostility_level = {
								target = scope:target_tax_collector.faith
								value > faith_fully_accepted_level
							}
					}
					}
					weight = { # Grab the tax slot vassal with the worst stewardship
						base = 1
						modifier = {
							add = {
								value = stewardship
								multiply = -1
							}
						}
					}
					save_scope_as = target_taxed_vassal
				}
			}
		}
	}

	option = { # Side with the vassal 
		name = fp3_clan.1030.a
		fire_tax_collector = scope:target_tax_collector
		reverse_add_opinion = {
			target = scope:target_taxed_vassal
			modifier = feast_sided_with_me_in_my_fight_opinion
		}
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = feast_sided_against_me_in_my_fight_opinion
		}
		if = { # add a favor hook if we can 
			limit = {
				can_add_hook = {
					target = scope:target_taxed_vassal
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:target_taxed_vassal
				type = favor_hook
				years = 3
			}
		}
		add_character_modifier = {
			modifier = fp3_sided_with_different_faith_vassal_tax_dispute
			years = 10
		}
		scope:target_taxed_vassal.faith = {
			change_fervor = {
				# Since this event is fired repeatedly, the miniscule value is halved
				value = {
					value = miniscule_fervor_gain
					divide = 2
				}
				desc = tax_collector_fired_on_religious_grounds
			}
		}

		ai_chance = {
			base = 50
			modifier = {
				root.faith = scope:target_taxed_vassal.faith 
				add = 50
			}
		}

		stress_impact = {
			base = minor_stress_impact_gain
		}
	}

	option = { # Side with the tax collector 
		name = fp3_clan.1030.b
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = feast_sided_with_me_in_my_fight_opinion
		}
		reverse_add_opinion = {
			target = scope:target_taxed_vassal
			modifier = feast_sided_against_me_in_my_fight_opinion
		}
		if = { # add a favor hook if we can 
			limit = {
				can_add_hook = {
					target = scope:target_tax_collector
					type = favor_hook
				}
			}
			add_hook = {
				target = scope:target_tax_collector
				type = favor_hook
				years = 3
			}
		}
		add_character_modifier = {
			modifier = fp3_sided_with_tax_collector_tax_dispute
			years = 10
		}

		ai_chance = {
			base = 50 
		}
	}
	
	option = { # Resolve it yourselves
		name = fp3_clan.1030.c
		reverse_add_opinion = {
			target = scope:target_taxed_vassal
			modifier = neglected_opinion
			opinion = -10
		}
		reverse_add_opinion = {
			target = scope:target_tax_collector
			modifier = neglected_opinion
			opinion = -10
		}

		ai_chance = {
			base = 10 
			modifier = {
				has_trait = lazy 
				add = 100
			}
		}

		stress_impact = {
			base = minor_stress_impact_loss
			lazy = medium_stress_impact_loss
		}
	}
}

#####################################################################
# Mismanaged Land													#
# Tax collector makes you aware of someone mismanaging their lands	#
# by Chad Uhl														#
#####################################################################
fp3_clan.1040 = {
	type = character_event
	title = fp3_clan.1040.t
	desc = fp3_clan.1040.desc
	theme = realm
	
	left_portrait = {
		character = root
		animation = thinking
	}
	right_portrait = {
		character = scope:target_tax_collector
		animation = happiness
	}
	lower_center_portrait = scope:target_taxed_vassal

	trigger = {
		has_fp3_dlc_trigger = yes
		is_valid_for_narrow_yearly_events = yes 
		# ensure we have a proper vassal to pull in 
		any_tax_collector = {
			tax_slot = {
				any_tax_slot_vassal = {
					is_valid_vassal_1030_trigger = yes
				}
			}
		}
	}

	cooldown = { years = 10 }

	immediate = {
		random_tax_collector = {
			limit = {
				tax_slot = {
					any_tax_slot_vassal = {
						is_valid_vassal_1030_trigger = yes 
					}
				}
			}
			save_scope_as = target_tax_collector
			tax_slot = {
				random_tax_slot_vassal = {
					limit = { is_valid_vassal_1030_trigger = yes }
					weight = { # Grab the tax slot vassal with the worst stewardship
						base = 1
						modifier = {
							add = {
								value = stewardship
								multiply = -1
							}
						}
					}
					save_scope_as = target_taxed_vassal
				}
			}
		}
	}

	option = { # Educate everyone on your next round
		name = fp3_clan.1040.a
		add_character_modifier = {
			modifier = fp3_tax_collector_become_teacher
			years = 10
		}

		ai_chance = {
			base = 60
		}
	}

	option = { # I'll go help them myself
		name = fp3_clan.1040.b
		# Skill challenge
		duel = {
			skill = stewardship
			value = {
				value = 0 
				if = { # easier if you have the stewardship lifestyle selected
					limit = { has_lifestyle = stewardship_lifestyle }
					add = medium_skill_rating
				}
				else = {
					add = high_skill_rating
				}
			}
			# Success: they improve their skill and you get some money/xp
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				desc = fp3_clan.1040.b.success
				send_interface_toast = {
					title = fp3_clan.1040.b.success
					left_icon = scope:target_tax_collector
					right_icon = scope:target_taxed_vassal
					# Apply success effects
					add_treasury_or_gold = medium_treasury_or_gold_value
					scope:target_taxed_vassal = { add_stewardship_skill = 1 }
					if = {
						limit = {
							has_lifestyle = stewardship_lifestyle
						}
						add_stewardship_lifestyle_xp = medium_lifestyle_xp
					}
					reverse_add_opinion = {
						target = scope:target_tax_collector
						modifier = respect_opinion
						opinion = 15
					}
				}
			}
			# Failure: lower opinion from tax collector
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				desc = fp3_clan.1040.b.failure
				send_interface_toast = {
					title = fp3_clan.1040.b.failure
					left_icon = scope:target_tax_collector
					right_icon = scope:target_taxed_vassal
					# Apply failure effects
					if = {
						limit = {
							has_lifestyle = stewardship_lifestyle
						}
						add_stewardship_lifestyle_xp = minor_lifestyle_xp
					}
					reverse_add_opinion = {
						target = scope:target_tax_collector
						modifier = disappointed_opinion
						opinion = -15
					}
				}
			}
		}
		ai_chance = {
			base = 0
		}
	}
	
	option = { # Perhaps a physical reminder of my authority is needed
		name = fp3_clan.1040.c
		reverse_add_opinion = {
			modifier = whipped_me_opinion
			target = scope:target_taxed_vassal
		}
		add_dread = medium_dread_gain

		ai_chance = {
			base = 50
			modifier = {
				OR = {
					has_trait = sadistic
					has_trait = wrathful
					has_trait = vengeful
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = calm
					has_trait = content 
					has_trait = generous
					has_trait = forgiving
					has_trait = compassionate
				}
				factor = 0 
			}
			modifier = {
				dread >= 50
				add = -30
			}
		}

		stress_impact = {
			calm = minor_stress_impact_gain
			content = minor_stress_impact_gain
			generous = minor_stress_impact_gain
			forgiving = medium_stress_impact_gain
			compassionate = medium_stress_impact_gain
			sadistic = minor_stress_impact_loss
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
		}
	}
}
