﻿on_game_start = {
	on_actions = {
		brus_immediate_action
	}
}

brus_immediate_action = {
	events = {
		rus_invasion.4
	}
	effect = {
		# Add the Familial Principalities tradition to Rus for 1066
		if = {
			limit = {
				current_date >= 1000.1.1
			}
			culture:russian = {
				add_culture_tradition = tradition_brus_rurikid
			}
		}
		# Enable Lestvitsa for the Kievian princes
		if = {
			limit = {
				current_date >= 1016.1.1
			}
			every_independent_ruler = {
				limit = {
					culture = culture:russian
				}
				every_held_title = {
					limit = {
						tier = prev.primary_title.tier
						tier >= tier_duchy
						NOT = { has_title_law = brus_lestvitsa_succession_law }
					}
					add_title_law = brus_lestvitsa_succession_law
				}
			}
			title:d_kiev = {
				add_title_law = brus_lestvitsa_succession_law
			}
		}
		if = { # Some historical setup for 1066 characters
			limit = {
				current_date >= 1066.1.1
			}
			character:650 = { # Spawn a modest amount of events troops for Vseslav of Polotsk for his historical military adventures
				spawn_army = {
					name = event_troop_default_name
					men_at_arms = {
						type = druzhina
						stacks = 8
					}	
					location = character:650.capital_province
					uses_supply = no
					inheritable = no
				}
			}	
			character:670 = { # Rostislav is an adventurer-type character and this is a pretty bad position, so let's give him a boost
				trigger_event = {
					id = kiev_rus_events.1
					days = { 30 50 }
				}
				spawn_army = {
					name = event_troop_default_name
					men_at_arms = {
						type = druzhina
						stacks = 5
					}
					levies = 500
					location = character:670.capital_province
					uses_supply = no
					inheritable = no
				}
				add_gold = 120
			}
			character:652 = { # Honestly, he just dies too much right at the start. I think it may be from raids.
				add_character_modifier = {
					modifier = strong_willed_modifier
					years = 5
				}
				add_prowess_skill = 8
			}
		}
	}
}

on_death = {
	on_actions = {
		brus_on_death
	}
}
# on_title_gained = {
# 	on_actions = {
# 		brus_on_title_gain
# 	}
# }
# # Give new titles lestvitsa if already have it
# brus_on_title_gain = {
# 	effect = {
# 		if = {
# 			limit = {
# 				root = {
# 					primary_title = { has_title_law = brus_lestvitsa_succession_law }
# 					scope:title.tier = primary_title.tier
# 				}
# 				scope:transfer_type = flag:created
# 			}
# 			scope:title = {
# 				add_title_law = brus_lestvitsa_succession_law
# 			}
# 		}
# 	}
# }

#Transfer Rus invasion to player heir
brus_on_death = {
	effect = {
		if = {
			limit = { 
				has_character_flag = undertaking_rus_invasion 
				# Only inheritable once
				NOT = { has_character_flag = inherited_rus_invasion }
				is_ai = yes
			}
			# Inherit the flag and make sure it doesn't happen again
			player_heir = {
				add_character_flag = undertaking_rus_invasion
				add_character_flag = inherited_rus_invasion
			}
		}
	}
}

three_year_playable_pulse = { 
	on_actions = { 
		brus_random_triyearly_action
	} 
}

brus_random_triyearly_action = {
	effect = {
		# Check for Mother of Rus Cities Event
		root = {
			if = {
				limit = {
					is_independent_ruler = yes
					OR = {
						culture = { has_cultural_pillar = heritage_east_slavic }
						AND = {
							culture = { has_cultural_pillar = heritage_north_germanic }
							primary_title.empire = title:e_russia
						}
					}
					title:c_kiev = {
						exists = holder
						holder = {
							is_vassal_or_below_of = root
							NOT = {
								is_allied_to = root
								dynasty = root.dynasty
							}
						}
						county_controller = title:c_kiev.holder
					}
					NOR = {
						is_target_in_global_variable_list = {
							name = unavailable_unique_decisions
							target = flag:flag_founded_capital_of_rus
						}
						has_character_flag = had_kiev_event
					}
				}
				trigger_event = rus_invasion.5 # Mother for Rus Cities
			}
		}
	}
}


