﻿#Effects relating to commanders

#get_valid_commander_list_effect: Creates a list of all valid commander characters called "valid_commanders"

get_valid_commander_list_effect = {
	every_vassal = {
		limit = {
			can_be_commander_now_trigger = { ARMY_OWNER = $ARMY_OWNER$ }
		}
		add_to_list = $LIST$
	}
	every_courtier = {
		limit = {
			can_be_commander_now_trigger = { ARMY_OWNER = $ARMY_OWNER$ }
		}
		add_to_list = $LIST$
	}
}

knight_increase_prowess_chance_effect = {
	random_list = {
		60 = {
			modifier = {
				add = {
					value = this.learning
					multiply = -1
					multiply = 2
				}
			}
			modifier = {
				factor = 0.5
				dynasty ?= {
					has_dynasty_perk = warfare_legacy_3
				}
			}
		}
		30 = {
			add_prowess_skill = 1
		}
		10 = {
			blademaster_lifestyle_rank_up_effect = yes
			modifier = {
				add = 5
				has_education_martial_trigger = yes
			}
			modifier = {
				add = 4
				has_trait = education_martial_prowess_1
			}
			modifier = {
				add = 8
				has_trait = education_martial_prowess_2
			}
			modifier = {
				add = 12
				has_trait = education_martial_prowess_3
			}
			modifier = {
				add = 16
				has_trait = education_martial_prowess_4
			}
			modifier = {
				add = 15
				has_trait = lifestyle_blademaster
			}
			modifier = {
				add = 10
				has_trait = shrewd
			}
			modifier = {
				add = 10
				has_trait = physique_good
			}
			modifier = {
				add = 5
				has_trait = intellect_good_1
			}
			modifier = {
				add = 15
				has_trait = intellect_good_2
			}
			modifier = {
				add = 30
				has_trait = intellect_good_3
			}
			modifier = {
				factor = 3
				culture = {
					has_cultural_parameter = blademaster_traits_more_common
				}
			}
			modifier = {
				factor = 0
				AND = {
					has_trait = lifestyle_blademaster
					has_trait_xp = {
						trait = lifestyle_blademaster
						value >= trait_third_level
					}
				}
			}
		}
	}

	#This effect is used when the knight does something "good", so let's save them for the player to perhaps reward in the future
	if = {
		limit = {
			liege ?= { is_ai = no }
			NOT = { has_character_flag = was_the_target_of_event_court_5060 }
		}
		if = {
			limit = {
				exists = var:number_of_impressive_knight_things
			}
			change_variable = {
				name = number_of_impressive_knight_things
				add = 1
			}
		}
		else = {
			set_variable = {
				name = number_of_impressive_knight_things
				value = 1
			}
		}

		# Maintenance of the variable
		if = {
			limit = {
				NOT = { has_character_flag = is_schedueled_for_court_5061_maintenance }
			}
			add_character_flag = {
				flag = is_schedueled_for_court_5061_maintenance
				years = 4
			}
			trigger_event = {
				id = court.5061
				years = 4
			}
		}
		liege = {
			add_to_variable_list = {
				name = impressive_knights
				target = prev
			}
		}
	}
}

berserker_kill_version_randomization_effect = {
	random_list = {
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_head_ripped_off
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v2"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_cloven_in_half
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v3"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_viciously_dismembered
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v4"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_ripped_apart_limb_by_limb
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v5"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_chopped_to_pieces
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v6"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_heart_ripped_out
					killer = root
				}
			}
		}
		1 = {
			trigger = {
				scope:enemy_knight = {
					NOT = {
						has_trait = brave
					}
				}
			}
			modifier = {
				add = 99
				scope:enemy_knight = {
					has_trait = craven
				}
			}
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v7"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_fear
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v8"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_skull_cracked_open
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "berserker_rage_killed_enemy_no_trait_v9"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_strangled_with_own_intestines
					killer = root
				}
			}
		}
	}
}

shieldmaiden_kill_version_randomisation_effect = {
	random_list = {
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "shieldmaiden_skill_killed_enemy_no_trait_v1"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_decapitated
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "shieldmaiden_skill_killed_enemy_no_trait_v2"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_cloven_in_half
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "shieldmaiden_skill_killed_enemy_no_trait_v3"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_viciously_dismembered
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "shieldmaiden_skill_killed_enemy_no_trait_v4"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_piteously_cut_down
					killer = root
				}
			}
		}
		10 = {
			scope:combat_side = {
				battle_event = {
					key = "shieldmaiden_skill_killed_enemy_no_trait_v5"
					left_portrait = root
					right_portrait = scope:enemy_knight
					type = death
					target_right = yes
				}
			}
			scope:enemy_knight = {
				death = {
					death_reason = death_chopped_to_pieces
					killer = root
				}
			}
		}
	}
}

recruit_terrain_specialist_effect = {
	if = {
		limit = {
			exists = root.capital_province
			any_pool_character = {
				is_adult = yes
				province = root.capital_province
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				martial >= medium_skill_rating
				culture = root.culture
				opinion = { # Just to make sure you don't pull in rivals or similar
					value >= -30
					target = root
				}
			}
		}
		random_pool_character = {
			province = root.capital_province
			limit = {
				is_adult = yes
				can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				martial >= medium_skill_rating
				culture = root.culture
				opinion = { # Just to make sure you don't pull in rivals or similar
					value >= -30
					target = root
				}
			}
			if = {
				limit = {
					NOT = {
						has_trait = $SPECIALIST_TRAIT$
					}
				}
				add_trait = $SPECIALIST_TRAIT$
			}
			random = {
				chance = 50
				wanderer_give_random_commander_trait_effect = yes
			}
			save_scope_as = new_commander
		}
	}
	else = {
		create_character = {
			employer = root
			template = $SPECIALIST_TEMPLATE_CHARACTER$
			faith = root.faith
			culture = root.culture
			gender_female_chance = {
				if = {
					limit = { root.culture = { has_cultural_parameter = martial_custom_male_only_combatant } }
					add = 0
				}
				else_if = {
					limit = { root.culture = { has_cultural_parameter = martial_custom_female_only_combatant } }
					add = 100
				}
				else = {
					add = 50
				}
			}
			save_scope_as = new_commander
		}
	}
	if = { # Error suppression
		limit = {
			exists = scope:new_commander
		}
		scope:new_commander = {
			add_character_flag = {
				flag = blocked_from_leaving
				years = 25
			}
		}
		if = {
			limit = {
				scope:new_commander = {
					NOT = {
						is_courtier_of = root
					}
				}
			}
			add_courtier = scope:new_commander
		}
		send_interface_toast = {
			title = commander_recruited.t
			left_icon = scope:new_commander
			custom_tooltip = commander_recruited.desc
		}
	}
}

recruit_three_nomadic_capital_characters_effect = {
	save_scope_as = root_scope
	create_character = {
		employer = scope:root_scope
		template = $NOMAD_TEMPLATE_CHARACTER$
		faith = domicile.domicile_faith
		culture = domicile.domicile_culture
		save_scope_as = new_commander
	}
	if = { # Error suppression
		limit = {
			exists = scope:new_commander
		}
		scope:new_commander = {
			assign_random_nickname_effect = yes
			add_character_flag = {
				flag = blocked_from_leaving
				years = 25
			}
		}
		if = {
			limit = {
				scope:new_commander = {
					NOT = {
						is_courtier_of = scope:root_scope
					}
				}
			}
			add_courtier = scope:new_commander
		}
		send_interface_message = {
			title = nomad_character_recruited.t
			left_icon = scope:new_commander
			custom_tooltip = commander_recruited.desc
		}
	}
	create_character = {
		employer = scope:root_scope
		template = $NOMAD_TEMPLATE_CHARACTER$
		faith = domicile.domicile_faith
		culture = domicile.domicile_culture
		save_scope_as = new_commander
	}
	if = { # Error suppression
		limit = {
			exists = scope:new_commander
		}
		scope:new_commander = {
			assign_random_nickname_effect = yes
			add_character_flag = {
				flag = blocked_from_leaving
				years = 25
			}
		}
		if = {
			limit = {
				scope:new_commander = {
					NOT = {
						is_courtier_of = scope:root_scope
					}
				}
			}
			add_courtier = scope:new_commander
		}
		send_interface_message = {
			title = nomad_character_recruited.t
			left_icon = scope:new_commander
			custom_tooltip = commander_recruited.desc
		}
	}
	create_character = {
		employer = scope:root_scope
		template = $NOMAD_TEMPLATE_CHARACTER$
		faith = domicile.domicile_faith
		culture = domicile.domicile_culture
		save_scope_as = new_commander
	}
	if = { # Error suppression
		limit = {
			exists = scope:new_commander
		}
		scope:new_commander = {
			assign_random_nickname_effect = yes
			add_character_flag = {
				flag = blocked_from_leaving
				years = 25
			}
		}
		if = {
			limit = {
				scope:new_commander = {
					NOT = {
						is_courtier_of = scope:root_scope
					}
				}
			}
			add_courtier = scope:new_commander
		}
		send_interface_message = {
			title = nomad_character_recruited.t
			left_icon = scope:new_commander
			custom_tooltip = commander_recruited.desc
		}
	}
}

commander_trait_lvling_ai_effect = {
	save_scope_as = root_scope
	random_list = {
		1 = {
			trigger = { has_trait = logistician }
			add_trait_xp = {
				trait = logistician
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(logistician)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = military_engineer }
			add_trait_xp = {
				trait = military_engineer
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(military_engineer)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = aggressive_attacker }
			add_trait_xp = {
				trait = aggressive_attacker
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(aggressive_attacker)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = unyielding_defender }
			add_trait_xp = {
				trait = unyielding_defender
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(unyielding_defender)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = forder }
			add_trait_xp = {
				trait = forder
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(forder)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = flexible_leader }
			add_trait_xp = {
				trait = flexible_leader
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(flexible_leader)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = desert_warrior }
			add_trait_xp = {
				trait = desert_warrior
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(desert_warrior)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = jungle_stalker }
			add_trait_xp = {
				trait = jungle_stalker
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(jungle_stalker)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = reaver }
			add_trait_xp = {
				trait = reaver
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(reaver)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = reckless }
			add_trait_xp = {
				trait = reckless
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(reckless)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = holy_warrior }
			add_trait_xp = {
				trait = holy_warrior
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(holy_warrior)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = open_terrain_expert }
			add_trait_xp = {
				trait = open_terrain_expert
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(open_terrain_expert)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = rough_terrain_expert }
			add_trait_xp = {
				trait = rough_terrain_expert
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(rough_terrain_expert)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = forest_fighter }
			add_trait_xp = {
				trait = forest_fighter
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(forest_fighter)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = cautious_leader }
			add_trait_xp = {
				trait = cautious_leader
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(cautious_leader)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = organizer }
			add_trait_xp = {
				trait = organizer
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(organizer)"
					divide = 100
				}
			}
		}
		1 = {
			trigger = { has_trait = winter_soldier }
			add_trait_xp = {
				trait = winter_soldier
				value = {
					value = 100
					subtract = "scope:root_scope.has_trait_xp(winter_soldier)"
					divide = 100
				}
			}
		}
	}
}
