﻿# Arrival in any province during travel
on_travel_plan_movement = {
	on_actions = {
		mbrxxx_coach_house_on_action_spy
		mbrxxx_coach_house_on_action_gamekeeper
		mbrxxx_coach_house_on_action_casino
		mbrxxx_warden_station_on_action_blademaster
	}
}

mbrxxx_coach_house_on_action_spy = {
	trigger = {
		current_travel_plan.current_location = {
			has_variable = mbrxxx_province_spy_story
			not = { root = county.holder }
		}
	}

	effect = {
		root = { save_scope_as = mbrxxx_coach_house_traveller }
		scope:mbrxxx_coach_house_traveller = {
			current_travel_plan.current_location.county.holder = { save_scope_as = mbrxxx_coach_house_patron }
			if = {
				limit = {
					not = { has_character_flag = mbrxxx_had_scheme_advance }
					scope:mbrxxx_coach_house_patron = {
						any_scheme = {
							scheme_target_character = scope:mbrxxx_coach_house_traveller
						}
					}
				}
				mbrxxx_advance_scheme_effect = yes
			}
			else_if = {
				limit = {
					not = { has_character_flag = mbrxxx_had_scheme_discovery }
					any_scheme = {
						mbrxxx_unexposed_hostile_scheme_target_charactering_patron_trigger = yes
					}
				}
				random = {
					chance = mbrxxx_coach_house_spy_chance

					mbrxxx_spy_uncover_scheme_effect = yes
				}
			}
			else_if = {
				limit = {
					not = { has_character_flag = mbrxxx_had_secret_discovery }
					has_any_secrets = yes
					any_secret = {
						not = { is_known_by = scope:mbrxxx_coach_house_patron }
					}
				}
				random = {
					chance = mbrxxx_coach_house_spy_chance

					mbrxxx_spy_learn_secrets_effect = yes
				}
			}
			else = {
			}
		}
	}
}

mbrxxx_coach_house_on_action_casino = {
	trigger = {
		not = { has_character_flag = mbrxxx_had_casino }
		current_travel_plan.current_location = {
			has_variable =  mbrxxx_province_casino_story
			not = { root = county.holder }
		}
	}
	
	effect = {
		root = { save_scope_as = mbrxxx_coach_house_traveller }
		scope:mbrxxx_coach_house_traveller = {
			current_travel_plan.current_location.county.holder = { save_scope_as = mbrxxx_coach_house_patron }
			if = {
				limit = {
					short_term_gold > 10
					scope:mbrxxx_coach_house_patron = { short_term_gold > 10 }
				}
				random_list = {
					50 = {
						modifier = {
							add = 25
							or = {
								has_trait = lifestyle_reveler
								has_trait = brave
								has_trait = gregarious
								has_trait = greedy
								has_trait = ambitious
								has_trait = fickle
								has_trait = arrogant
								has_trait = gluttonous
								ai_greed >= 25
								ai_boldness >= 25
							}
						}
						mbrxxx_casino_effect = yes
					}
					50 = {
						modifier = {
							add = 25
							has_trait = temperate
							has_trait = craven
							has_trait = content
							has_trait = shy
							has_trait = paranoid
							ai_greed < 25
							ai_boldness < 25
						}
					}
				}
			}
			else = {
			}
		}
	}
}

mbrxxx_coach_house_on_action_gamekeeper = {
	trigger = {
		not = { has_character_flag = mbrxxx_had_training_hunt }
		current_travel_plan.current_location = {
			has_variable =  mbrxxx_province_gamekeeper_story
		}
	}
	
	effect = {
		root = { save_scope_as = mbrxxx_coach_house_traveller }
		scope:mbrxxx_coach_house_traveller = {
			current_travel_plan.current_location.county.holder = { save_scope_as = mbrxxx_coach_house_patron }

			if = {
				limit = { has_trait = lifestyle_hunter }
				mbrxxx_gamekeeper_effect = yes
			}
		}
	}
}

mbrxxx_warden_station_on_action_blademaster = {
	trigger = {
		not = { has_character_flag = mbrxxx_had_training_blade }
		current_travel_plan.current_location = {
			has_variable =  mbrxxx_province_blademaster_story
		}
	}
	
	effect = {
		root = { save_scope_as = mbrxxx_warden_station_traveller }
		scope:mbrxxx_warden_station_traveller = {
			current_travel_plan.current_location.county.holder = { save_scope_as = mbrxxx_warden_station_patron }

			if = {
				limit = { has_trait = lifestyle_hunter }
				mbrxxx_blademaster_effect = yes
			}
		}
	}
}
