﻿namespace = jason_first_race_event


##################################################
# A Mess of Legs
# by Jason Cantalini
# 4700
##################################################

scripted_trigger jason_first_race_event_1_opponent_trigger = {
	is_ai = yes
	exists = var:contest_aptitude
	this != root
	OR = {
		is_lowborn = no
		is_landed = no
	}
}

#Two racers collide with each other
jason_first_race_event.1 = {
	type = activity_event
	title = jason_first_race_event.1.t
	desc = {
		desc = jason_first_race_event.1.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						has_trait = paranoid
						has_trait = vengeful
						has_trait = wrathful
						has_relation_rival = scope:opponent
						has_relation_nemesis = scope:opponent
					}
					NOR = {
						has_trait = trusting
						has_trait = forgiving
						has_trait = compassionate
					}
				}
				desc = jason_first_race_event.1.desc.suspicious
			}
			triggered_desc = {
				trigger = {
					OR = {
						has_trait = trusting
						has_trait = forgiving
						has_trait = compassionate
					}
				}
				desc = jason_first_race_event.1.desc.sympathetic
			}
		}
	}
	theme = tournament_contest
	window = widget_activity_locale_fullscreen_event
	left_portrait = {
		character = root
		animation = disbelief
	}
	right_portrait = {
		character = scope:opponent
		animation = fear
	}

	trigger = {
		exists = var:contest_aptitude
		scope:activity = {
			any_guest_subset_current_phase = {
				name = qualified
				this = root
			}
			any_guest_subset_current_phase = {
				name = qualified
				jason_first_race_event_1_opponent_trigger = yes
			}
			NOT = { 
				any_attending_character = {
					is_ai = no
					this != root
				}
			}
			# Only one event removing competitors should occur
			any_guest_subset_current_phase = {
				name = qualified
				count >= 8
			}
		}
		#Standard checks.
		NOT = { has_character_flag = horse_race_contest_event_cooldown }
	}

	immediate = {
		tournament_pivotal_flavor_variable_effect = { CONTEST = horse_race ID = 10 }
		add_character_flag = {
			flag = horse_race_contest_event_cooldown
			years = 1
		}
		tournament_horse_race_fetch_horse_effect = yes
		scope:activity = {
			random_guest_subset_current_phase = {
				name = qualified
				limit = {
					jason_first_race_event_1_opponent_trigger = yes
				}
				weight = {
					base = 1
					activity_recurring_character_weight_modifier = { VALUE = 100 }
				}
				save_scope_as = opponent
				try_to_create_recurring_character_effect = { CHARACTER = root }
			}
		}
		scope:opponent = {
			tournament_horse_race_fetch_horse_effect = yes
			activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
		}
		root.var:horse_race_jockey = { save_scope_as = jockey }
		activity_tournament_change_contestant_score_effect = { SCORE = decrease_minor }
	}

	# Accuse the other horse's owner of sabotaging you
	option = {
		name = jason_first_race_event.1.a
		flavor = jason_first_race_event.1.a.tt
		
		progress_towards_rival_effect = {
			CHARACTER = scope:opponent
			REASON = rival_race_sabotage_accusation
			OPINION = -40
		}

		duel = {
			skills = { diplomacy intrigue }
			value = 10
			#You convince everyone that this affront merits a restart
			45 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					add = 20
					dread > medium_dread
				}
				modifier = {
					add = 40
					dread > high_dread
				}
				modifier = {
					add = 50
					scope:host = {
						this = root
					}
				}
				modifier = {
					add = 25
					highest_held_title_tier = tier_kingdom
				}
				modifier = {
					add = 50
					highest_held_title_tier = tier_empire
				}
				send_interface_toast = {
					title = jason_first_race_event.1.a.tt.win
					left_icon = root
					right_icon = scope:opponent

					tournament_contest_knocked_out_effect = { CHARACTER = scope:opponent }
				}

				desc = jason_first_race_event.1.a.tt.win
			}
			#You sound petty and no one listens
			55 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					title = jason_first_race_event.1.a.tt.lose
					left_icon = root
					right_icon = scope:opponent

					scope:activity = {
						add_activity_log_entry = {
							key = contest_horse_race_collision_log
							tags = { contest bad }
							score = 30
							character = root
							target = scope:opponent
						}
						every_attending_character = {
							limit = {
								NOR = {
									this = root
									this = scope:opponent
								}
							}
							custom = every_tournament_attendee_tt
							add_opinion = {
	 							target = root
	 							modifier = contempt_opinion
	 							opinion = -10
	 						}
						}
					}
				}
				desc = jason_first_race_event.1.a.tt.lose
			}
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			trusting = minor_stress_impact_gain
			compassionate = miniscule_stress_impact_gain
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
			callous = miniscule_stress_impact_loss
			sadistic = miniscule_stress_impact_loss
		}

		ai_chance = {

			base = 100

			modifier = {
				factor = 0
				OR = {
					has_trait = forgiving
					has_trait = trusting
				}
			}
			modifier = {
				add = -50
				OR = {
					has_trait = compassionate
					has_trait = honest
					has_trait = shy
					has_trait = content
					has_trait = calm
				}
			}
			modifier = {
				add = -50
				OR = {
					diplomacy <= low_skill_rating
					intrigue <= low_skill_rating
				}
			}
			modifier = {
				add = -25
				OR = {
					diplomacy < medium_skill_rating
					intrigue < medium_skill_rating
				}
			}
			modifier = {
				add = -50
				diplomacy <= decent_skill_rating
				intrigue <= decent_skill_rating
			}
			modifier = {
				add = 100
				OR = {
					diplomacy >= high_skill_rating
					prowess >= high_skill_rating
				}
			}
			modifier = {
				add = 100
				OR = {
					has_trait = vengeful
					has_trait = arbitrary
					has_trait = deceitful
					has_trait = paranoid
					has_trait = greedy
				}
			}
			modifier = {
				add = 50
				highest_held_title_tier = tier_kingdom
			}
			modifier = {
				add = 100
				highest_held_title_tier = tier_empire
			}
			modifier = {
				add = 150
				scope:host = {
					this = root
				}
			}
			modifier = {
				add = 75
				dread > medium_dread
			}	
		}
	}
	# Console your opponent and apologize
	option = {
		trigger = {
			OR = {
				NOR = {
					has_relation_rival = scope:opponent
					has_relation_nemesis = scope:opponent
					has_trait = paranoid
					has_trait = vengeful
					has_trait = wrathful
					has_trait = sadistic
				}
				OR = {
					has_relation_rival = scope:opponent
					has_relation_nemesis = scope:opponent
					OR = {
						has_trait = trusting
						has_trait = forgiving
						has_trait = compassionate
					}
				}
			}
		}
		name = jason_first_race_event.1.b
		flavor = jason_first_race_event.1.b.tt
		scope:activity = {
			add_activity_log_entry = {
				key = contest_horse_race_collision_log
				tags = { contest bad }
				score = 30
				character = root
				target = scope:opponent

				# Effect
				root = {
				 	progress_towards_friend_effect = {
						CHARACTER = scope:opponent
						REASON = friend_shared_disappointment
						OPINION = 40
					}
				}
			}
		}
		stress_impact = {
			forgiving = minor_stress_impact_loss
			wrathful = major_stress_impact_gain
			sadistic = major_stress_impact_gain
			paranoid = major_stress_impact_gain
			vengeful = major_stress_impact_gain
			callous = medium_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			
			modifier = {
				factor = 0
				OR = {				
					has_trait = wrathful
					has_trait = sadistic
					has_trait = paranoid
					has_trait = vengeful
					has_trait = callous
				}
			}
			modifier = {
				add = -50
				has_trait = arrogant

			}
			modifier = {
				add = 100
				has_trait = forgiving

			}
		}
	}
	# Try to encourage your jockey
	option = {
		name = jason_first_race_event.1.c
		flavor = jason_first_race_event.1.c.tt

		duel = {
			skill = diplomacy
			value = 10
			#Your jockey gets back on track
			45 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					has_trait_xp = {
						trait = tourney_participant
						track = horse
						value >= 20
					}
					add = 20
				}
				modifier = {
					has_trait_xp = {
						trait = tourney_participant
						track = horse
						value >= 50
					}
					add = 30
				}
				modifier = {
					has_trait_xp = {
						trait = tourney_participant
						track = horse
						value >= 80
					}
					add = 50
				}
				send_interface_toast = {
					title = jason_first_race_event.1.c.tt.win
					left_icon = root
					right_icon = scope:opponent
					desc = jason_first_race_event.1.c.tt.lose

					create_character_memory = {
						type = successful_race_rescue
					}

					activity_tournament_change_contestant_score_effect = { SCORE = increase_minor }

					# add horsemanship tournament skill XP
					if = {
						limit = {
							has_trait = tourney_participant
						}
						add_trait_xp = {
							trait = tourney_participant
							track = horse
							value = tournament_hastiludes_xp_gain_medium_value
						}
					}
				}

				desc = jason_first_race_event.1.c.tt.win
			}
			#Your jockey can't hear you
			55 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}

				send_interface_toast = {
					title = jason_first_race_event.1.c.tt.lose
					left_icon = root
					right_icon = scope:opponent
					scope:activity = {
						add_activity_log_entry = {
							key = contest_horse_race_collision_log
							tags = { contest bad }
							score = 30
							character = root
							target = scope:opponent
						}
					}
					activity_tournament_change_contestant_score_effect = { SCORE = decrease_miniscule }
				}
				desc = jason_first_race_event.1.c.tt.lose
				create_character_memory = {
					type = trampled_during_race_rescue
				}
			}
		}
		stress_impact = {
			craven = major_stress_impact_gain
			sadistic = medium_stress_impact_gain
			lazy = medium_stress_impact_gain
			callous = medium_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			
			modifier = {
				factor = 0
				OR = {			
					has_trait = sadistic
					has_trait = lazy
					has_trait = craven
					has_trait = callous
				}
			}
			modifier = {
				add = -50
				has_trait = vengeful

			}
			modifier = {
				add = -50
				OR = {
					diplomacy < mediocre_skill_rating
					prowess < mediocre_skill_rating
				}
			}
			modifier = {
				add = -25
				OR = {
					diplomacy < mediocre_skill_rating
					prowess < mediocre_skill_rating
				}
			}
			modifier = {
				add = -50
				diplomacy <= medium_skill_rating
				prowess <= medium_skill_rating
			}

			modifier = {
				add = -50
				highest_held_title_tier = tier_empire
			}
			modifier = {
				add = 75
				OR = {
					has_trait = compassionate
					has_trait = brave
				}
			}
			modifier = {
				add = 25
				has_trait_xp = {
					trait = tourney_participant
					track = horse
					value >= 50
				}
			}
			modifier = {
				add = 50
				has_trait_xp = {
					trait = tourney_participant
					track = horse
					value >= 100
				}
			}
			modifier = {
				add = 50
				OR = {
					diplomacy >= very_high_skill_rating
					prowess >= very_high_skill_rating
				}
			}
		}
	}
	# Accept this unfortunate loss
	option = {
		name = jason_first_race_event.1.d
		flavor = jason_first_race_event.1.d.tt
		scope:activity = {
			add_activity_log_entry = {
				key = contest_horse_race_collision_log
				tags = { contest bad }
				score = 30
				character = root
				target = scope:opponent
			}
		}

		stress_impact = {
			wrathful = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			compassionate = minor_stress_impact_gain
			stubborn = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}

		ai_chance = {
			base = 100
			
			modifier = {
				factor = 0
				OR = {
					has_trait = wrathful
					has_trait = paranoid
				}
			}
			modifier = {
				add = -50
				OR = {				
					has_trait = compassionate
					has_trait = stubborn
					has_trait = greedy
				}
			}
			modifier = {
				add = 50
				OR = {
						has_trait = calm
						has_trait = shy
					}
			}
		}
	}
}


