﻿royalcampaign_effect = {
	if = {
		limit = {
			NOT = { has_trait = lifestyle_royalcampaign }
			AND = {
				is_at_war = yes
				is_commanding_army = yes
				highest_held_title_tier >= tier_kingdom
			}
		}
		royalcampaign_set_up_effects = yes
	}
	else_if = {
		limit = {
			has_trait = lifestyle_royalcampaign
			has_trait_xp = {
				trait = lifestyle_royalcampaign
				value < 100
			}
		}
		royalcampaign_xp_effects = yes
	}
}

royalcampaign_set_up_effects = {
	add_trait = lifestyle_royalcampaign
}

royalcampaign_xp_effects = {
	if = {
		limit = {
			has_trait = lifestyle_royalcampaign
			is_at_war = yes
			is_commanding_army = yes
			highest_held_title_tier > tier_kingdom
		}
		add_trait_xp = {
			trait = lifestyle_royalcampaign
			value = {
				integer_range = {
					min = 2
					max = 6
				}
			}
		}
	}
	if = {
		limit = {
			has_trait = lifestyle_royalcampaign
			is_at_war = yes
			is_commanding_army = yes
			highest_held_title_tier = tier_kingdom
		}
		add_trait_xp = {
			trait = lifestyle_royalcampaign
			value = {
				integer_range = {
					min = 2
					max = 5
				}
			}
		}
	}
}


###########War and Peace############

warandpeace_effect = {
	if = {
		limit = {
                NOR = { 
				has_trait = lifestyle_warandpeace 
				has_government = theocracy_government
				has_government = landless_adventurer_government
			}
			AND = {
				is_landed = yes
				highest_held_title_tier >= tier_duchy
			}
		}
		warandpeace_set_up_effects = yes
	}
	else_if = {
		limit = {
			has_trait = lifestyle_warandpeace
		}
		warandpeace_xp_effects = yes
	}
}

warandpeace_set_up_effects = {
	add_trait = lifestyle_warandpeace
}

warandpeace_xp_effects = {
	if = {
		limit = {
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			has_trait = lifestyle_warandpeace
			is_at_war = yes
			is_ai = yes
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = war
			value = {
				integer_range = {
					min = 6
					max = 12
				}
			}
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = peace
			value = {
				integer_range = {
					min = -10
					max = -5
				}
			}
		}
	}
	if = {
		limit = {
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			has_trait = lifestyle_warandpeace
			OR = {
			is_at_war = no
			}
			is_ai = yes
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = peace
			value = {
				integer_range = {
					min = 6
					max = 12
				}
			}
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = war
			value = {
				integer_range = {
					min = -10
					max = -5
				}
			}
		}
	}
	if = {
		limit = {
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			has_trait = lifestyle_warandpeace
			is_at_war = yes
			is_ai = no
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = war
			value = {
				integer_range = {
					min = 6
					max = 10
				}
			}
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = peace
			value = {
				integer_range = {
					min = -10
					max = -5
				}
			}
		}
	}
	if = {
		limit = {
			is_landed = yes
			highest_held_title_tier >= tier_duchy
			has_trait = lifestyle_warandpeace
			OR = {
			is_at_war = no
			}
			is_ai = no
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = peace
			value = {
				integer_range = {
					min = 6
					max = 10
				}
			}
		}
		add_trait_xp = {
			trait = lifestyle_warandpeace
			track = war
			value = {
				integer_range = {
					min = -10
					max = -5
				}
			}
		}
	}
}



########House modifiers###########

royalcampaignactive_effect = {
	if = {
		limit = {
			AND = {
				has_trait = lifestyle_royalcampaign
				has_trait_xp = {
					trait = lifestyle_royalcampaign
					value >= 80
				}
			}
		}
		save_scope_as = royalcampaignactive
		house = {
			add_house_modifier = {
				modifier = royalcampaignactive_modifier
				desc = royalcampaignactive_modifier_custom_desc
				years = 2
			}
		}
	}
}

royalcampaigndeath_effect = {
	if = {
		limit = {
			AND = {
				has_trait = lifestyle_royalcampaign
				is_at_war = yes
				is_commanding_army = yes
				highest_held_title_tier >= tier_kingdom
				prestige_level >= 2
			}
		}
		house = {
			add_house_modifier = {
				modifier = sl_kingdiedinbattle_modifier
				desc = sl_kingdiedinbattle_modifier_custom_desc
				years = 10
			}
			every_house_member = {
				limit = { is_ai = no }
				send_interface_message = {
					type = notable_has_died
					title = house_sl_kingdiedinbattle_modifier
					desc = house_sl_kingdiedinbattle_modifier_desc
					left_icon = scope:dead_character
					right_icon = scope:title
				}
			}
		}
	}
}

everycommander_effect = {
	scope:army.army_commander ?= {
		if = {
			limit = {
				OR = { 
					liege = { is_at_war = yes }
					is_at_war = yes
				}
				#NOT = { has_character_modifier = callofduty_modifier }
			}
			add_character_modifier = {
				modifier = callofduty_modifier
				months = 2
			}
		}
		if = {
			limit = {
				OR = { 
					liege = { is_at_war = yes }
					is_at_war = yes
				}
			}
			add_character_modifier = {
				modifier = battlesense_modifier
				months = 5
			}
		}			
	}
}


########M/A#########

royalcampaigncleaner_effect = {
	if = {
		limit = {
			OR = {
				has_government = landless_adventurer_government
				has_government = theocracy_government
				highest_held_title_tier <= tier_county
				is_landed = no
			}
			has_trait = lifestyle_warandpeace
		}
		remove_trait = lifestyle_warandpeace
	}
}
