﻿bdp_battlefield_reputation_begin_duel_effect = {
	if = {
		limit = { exists = scope:bdp_battlefield_reputation_awarded }
		clear_saved_scope = bdp_battlefield_reputation_awarded
	}
	if = {
		limit = { exists = scope:bdp_battlefield_chronicle_recorded }
		clear_saved_scope = bdp_battlefield_chronicle_recorded
	}
	bdp_battlefield_chronicle_snapshot_duel_context_effect = yes
	# Save Stature before death weakens the character scope.
	save_scope_value_as = {
		name = bdp_battlefield_attacker_stature_snapshot
		value = scope:sc_attacker.bdp_battlefield_stature_value
	}
	save_scope_value_as = {
		name = bdp_battlefield_defender_stature_snapshot
		value = scope:sc_defender.bdp_battlefield_stature_value
	}
	save_scope_value_as = {
		name = bdp_battlefield_attacker_reputation_snapshot
		value = 0
	}
	if = {
		limit = { scope:sc_attacker = { has_variable = bdp_battlefield_reputation } }
		save_scope_value_as = {
			name = bdp_battlefield_attacker_reputation_snapshot
			value = scope:sc_attacker.var:bdp_battlefield_reputation
		}
	}
	save_scope_value_as = {
		name = bdp_battlefield_defender_reputation_snapshot
		value = 0
	}
	if = {
		limit = { scope:sc_defender = { has_variable = bdp_battlefield_reputation } }
		save_scope_value_as = {
			name = bdp_battlefield_defender_reputation_snapshot
			value = scope:sc_defender.var:bdp_battlefield_reputation
		}
	}
	save_scope_value_as = {
		name = bdp_battlefield_attacker_prowess_snapshot
		value = scope:sc_attacker.prowess
	}
	save_scope_value_as = {
		name = bdp_battlefield_defender_prowess_snapshot
		value = scope:sc_defender.prowess
	}
}

bdp_battlefield_reputation_clear_rank_modifiers_effect = {
	if = {
		limit = { has_character_modifier = bdp_battlefield_reputation_proven_modifier }
		remove_character_modifier = bdp_battlefield_reputation_proven_modifier
	}
	if = {
		limit = { has_character_modifier = bdp_battlefield_reputation_renowned_bronze_modifier }
		remove_character_modifier = bdp_battlefield_reputation_renowned_bronze_modifier
	}
	if = {
		limit = { has_character_modifier = bdp_battlefield_reputation_renowned_steel_modifier }
		remove_character_modifier = bdp_battlefield_reputation_renowned_steel_modifier
	}
	if = {
		limit = { has_character_modifier = bdp_battlefield_reputation_legendary_modifier }
		remove_character_modifier = bdp_battlefield_reputation_legendary_modifier
	}
}

bdp_battlefield_reputation_refresh_trait_effect = {
	# Reputation keeps climbing, but the trait bar stops at Legendary.
	if = {
		limit = {
			has_variable = bdp_battlefield_reputation
			var:bdp_battlefield_reputation >= 10
		}
		save_scope_as = bdp_battlefield_reputation_trait_holder
		if = {
			limit = { NOT = { has_trait = bdp_battlefield_reputation_trait } }
			add_trait = bdp_battlefield_reputation_trait
		}
		if = {
			limit = { var:bdp_battlefield_reputation >= 30 }
			add_trait_xp = {
				trait = bdp_battlefield_reputation_trait
				value = {
					value = var:bdp_battlefield_reputation
					multiply = 5
					divide = 3
					max = 100
					subtract = "scope:bdp_battlefield_reputation_trait_holder.has_trait_xp(bdp_battlefield_reputation_trait)"
				}
			}
		}
		else = {
			add_trait_xp = {
				trait = bdp_battlefield_reputation_trait
				value = {
					value = var:bdp_battlefield_reputation
					subtract = 10
					multiply = 5
					divide = 4
					add = 25
					subtract = "scope:bdp_battlefield_reputation_trait_holder.has_trait_xp(bdp_battlefield_reputation_trait)"
				}
			}
		}
	}
	else_if = {
		limit = { has_trait = bdp_battlefield_reputation_trait }
		remove_trait = bdp_battlefield_reputation_trait
	}
}

bdp_battlefield_reputation_refresh_rank_modifier_effect = {
	bdp_battlefield_reputation_clear_rank_modifiers_effect = yes
	if = {
		limit = {
			has_variable = bdp_battlefield_reputation
			var:bdp_battlefield_reputation >= 60
		}
		add_character_modifier = { modifier = bdp_battlefield_reputation_legendary_modifier }
	}
	else_if = {
		limit = {
			has_variable = bdp_battlefield_reputation
			var:bdp_battlefield_reputation >= 45
		}
		add_character_modifier = { modifier = bdp_battlefield_reputation_renowned_steel_modifier }
	}
	else_if = {
		limit = {
			has_variable = bdp_battlefield_reputation
			var:bdp_battlefield_reputation >= 30
		}
		add_character_modifier = { modifier = bdp_battlefield_reputation_renowned_bronze_modifier }
	}
	else_if = {
		limit = {
			has_variable = bdp_battlefield_reputation
			var:bdp_battlefield_reputation >= 10
		}
		add_character_modifier = { modifier = bdp_battlefield_reputation_proven_modifier }
	}
	bdp_battlefield_reputation_refresh_trait_effect = yes
}

bdp_battlefield_reputation_finalise_duel_effect = {
	if = {
		limit = { NOT = { exists = scope:bdp_battlefield_reputation_awarded } }
		save_scope_value_as = {
			name = bdp_battlefield_reputation_awarded
			value = yes
		}
		if = {
			limit = { scope:sc_loser = scope:sc_attacker }
			save_scope_value_as = {
				name = bdp_battlefield_loser_stature_snapshot
				value = scope:bdp_battlefield_attacker_stature_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_loser_reputation_snapshot
				value = scope:bdp_battlefield_attacker_reputation_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_loser_prowess_snapshot
				value = scope:bdp_battlefield_attacker_prowess_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_victor_prowess_snapshot
				value = scope:bdp_battlefield_defender_prowess_snapshot
			}
		}
		else = {
			save_scope_value_as = {
				name = bdp_battlefield_loser_stature_snapshot
				value = scope:bdp_battlefield_defender_stature_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_loser_reputation_snapshot
				value = scope:bdp_battlefield_defender_reputation_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_loser_prowess_snapshot
				value = scope:bdp_battlefield_defender_prowess_snapshot
			}
			save_scope_value_as = {
				name = bdp_battlefield_victor_prowess_snapshot
				value = scope:bdp_battlefield_attacker_prowess_snapshot
			}
		}
		scope:sc_victor = {
			if = {
				limit = { is_ai = yes }
				bdp_battlefield_reputation_award_ai_stature_victory_effect = yes
			}
			else = {
				clear_saved_scope = bdp_battlefield_reputation_prowess_reward
				if = {
					limit = {
						OR = {
							AND = {
								scope:bdp_battlefield_loser_prowess_snapshot >= 50
								scope:bdp_battlefield_loser_reputation_snapshot < 60
							}
							AND = {
								scope:bdp_battlefield_loser_prowess_snapshot >= 36
								scope:bdp_battlefield_loser_reputation_snapshot < 45
							}
							AND = {
								scope:bdp_battlefield_loser_prowess_snapshot >= 26
								scope:bdp_battlefield_loser_reputation_snapshot < 30
							}
							AND = {
								scope:bdp_battlefield_loser_prowess_snapshot >= 16
								scope:bdp_battlefield_loser_reputation_snapshot < 10
							}
						}
					}
					save_scope_value_as = { name = bdp_battlefield_reputation_prowess_reward value = yes }
				}
				set_variable = {
					name = bdp_battlefield_reputation_prowess_gap
					value = {
						value = scope:bdp_battlefield_loser_prowess_snapshot
						subtract = scope:bdp_battlefield_victor_prowess_snapshot
					}
				}
				bdp_battlefield_reputation_award_duel_victory_effect = yes
				remove_variable = bdp_battlefield_reputation_prowess_gap
			}
		}
		if = {
			limit = { NOT = { exists = scope:bdp_battlefield_chronicle_recorded } }
			save_scope_value_as = {
				name = bdp_battlefield_chronicle_recorded
				value = yes
			}
			bdp_battlefield_chronicle_record_duel_effect = yes
		}
	}
}

bdp_battlefield_reputation_clear_opponent_record_effect = {
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_normal
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_normal
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_good
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_good
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_great
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_great
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_legendary
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_legendary
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_illustrious
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_illustrious
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_won_once
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_won_once
			target = scope:sc_loser
		}
	}
}

bdp_battlefield_reputation_clear_ai_opponent_record_effect = {
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_normal
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_normal
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_good
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_good
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_great
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_great
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_legendary
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_legendary
			target = scope:sc_loser
		}
	}
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_won_once
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_won_once
			target = scope:sc_loser
		}
	}
}

bdp_battlefield_reputation_award_ai_stature_repeat_victory_effect = {
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_ai_opponents_won_once
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_ai_opponents_won_once
			target = scope:sc_loser
		}
		if = {
			limit = { scope:bdp_battlefield_loser_stature_snapshot >= 35 }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 5 }
			change_variable = { name = bdp_battlefield_reputation add = 5 }
		}
		else_if = {
			limit = { scope:bdp_battlefield_loser_stature_snapshot >= 18 }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 2 }
			change_variable = { name = bdp_battlefield_reputation add = 2 }
		}
		else_if = {
			limit = { scope:bdp_battlefield_loser_stature_snapshot >= 10 }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 1 }
			change_variable = { name = bdp_battlefield_reputation add = 1 }
		}
		else = { bdp_battlefield_reputation_send_exhausted_message_effect = yes }
	}
	else = { bdp_battlefield_reputation_send_exhausted_message_effect = yes }
}

bdp_battlefield_reputation_award_ai_stature_victory_effect = {
	if = {
		limit = { NOT = { has_variable = bdp_battlefield_reputation } }
		set_variable = { name = bdp_battlefield_reputation value = 0 }
	}
	if = {
		limit = { scope:bdp_battlefield_loser_stature_snapshot >= 35 }
		if = {
			limit = {
				NOT = {
					is_target_in_variable_list = {
						name = bdp_battlefield_reputation_ai_opponents_legendary
						target = scope:sc_loser
					}
				}
			}
			bdp_battlefield_reputation_clear_ai_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_legendary target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 10 }
			change_variable = { name = bdp_battlefield_reputation add = 10 }
		}
		else = { bdp_battlefield_reputation_award_ai_stature_repeat_victory_effect = yes }
	}
	else_if = {
		limit = { scope:bdp_battlefield_loser_stature_snapshot >= 18 }
		if = {
			limit = {
				OR = {
					NOR = {
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_good target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_great target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_legendary target = scope:sc_loser }
					}
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_good target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_ai_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_great target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 5 }
			change_variable = { name = bdp_battlefield_reputation add = 5 }
		}
		else = { bdp_battlefield_reputation_award_ai_stature_repeat_victory_effect = yes }
	}
	else_if = {
		limit = { scope:bdp_battlefield_loser_stature_snapshot >= 10 }
		if = {
			limit = {
				OR = {
					NOR = {
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_good target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_great target = scope:sc_loser }
						is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_legendary target = scope:sc_loser }
					}
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_ai_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_good target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 2 }
			change_variable = { name = bdp_battlefield_reputation add = 2 }
		}
		else = { bdp_battlefield_reputation_award_ai_stature_repeat_victory_effect = yes }
	}
	else = {
		if = {
			limit = {
				NOR = {
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_good target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_great target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_ai_opponents_legendary target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_ai_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_normal target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_ai_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 1 }
			change_variable = { name = bdp_battlefield_reputation add = 1 }
		}
		else = { bdp_battlefield_reputation_award_ai_stature_repeat_victory_effect = yes }
	}
	bdp_battlefield_reputation_refresh_rank_modifier_effect = yes
}

bdp_battlefield_reputation_send_exhausted_message_effect = {
	set_variable = { name = bdp_battlefield_reputation_last_award value = 0 }
	if = {
		limit = { is_ai = no }
		hidden_effect = {
			send_interface_message = {
				type = battlefield_duel_feed_neutral
				title = bdp_battlefield_reputation_gained_title
				desc = {
					first_valid = {
						triggered_desc = {
							trigger = { has_character_flag = trial_by_combat }
							desc = bdp_battlefield_reputation_exhausted_trial_desc
						}
						triggered_desc = {
							trigger = { exists = scope:task_contract }
							desc = bdp_battlefield_reputation_exhausted_contract_desc
						}
						desc = bdp_battlefield_reputation_exhausted_desc
					}
				}
				left_icon = scope:sc_victor
				right_icon = scope:sc_loser
			}
		}
	}
}

bdp_battlefield_reputation_add_underdog_bonus_effect = {
	if = {
		limit = { var:bdp_battlefield_reputation_prowess_gap >= 10 }
		change_variable = { name = bdp_battlefield_reputation add = 2 }
		change_variable = { name = bdp_battlefield_reputation_last_award add = 2 }
	}
	else_if = {
		limit = { var:bdp_battlefield_reputation_prowess_gap >= 5 }
		change_variable = { name = bdp_battlefield_reputation add = 1 }
		change_variable = { name = bdp_battlefield_reputation_last_award add = 1 }
	}
}

bdp_battlefield_reputation_send_first_victory_message_effect = {
	if = {
		limit = { is_ai = no }
		if = {
			limit = { exists = scope:bdp_battlefield_reputation_prowess_reward }
			if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 50 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_extraordinary_prowess_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_extraordinary_prowess_contract_desc }
								desc = bdp_battlefield_reputation_gained_extraordinary_prowess_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 36 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_fearsome_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_fearsome_contract_desc }
								desc = bdp_battlefield_reputation_gained_fearsome_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 26 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_formidable_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_formidable_contract_desc }
								desc = bdp_battlefield_reputation_gained_formidable_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else = {
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_capable_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_capable_contract_desc }
								desc = bdp_battlefield_reputation_gained_capable_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
		}
		else = {
			if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 60 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_legendary_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_legendary_contract_desc }
								desc = bdp_battlefield_reputation_gained_legendary_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 45 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_illustrious_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_illustrious_contract_desc }
								desc = bdp_battlefield_reputation_gained_illustrious_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 30 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_great_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_great_contract_desc }
								desc = bdp_battlefield_reputation_gained_great_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 10 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_good_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_good_contract_desc }
								desc = bdp_battlefield_reputation_gained_good_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else = {
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_gained_normal_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_gained_normal_contract_desc }
								desc = bdp_battlefield_reputation_gained_normal_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
		}
	}
}

bdp_battlefield_reputation_send_repeat_victory_message_effect = {
	if = {
		limit = { is_ai = no }
		if = {
			limit = { exists = scope:bdp_battlefield_reputation_prowess_reward }
			if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 50 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_extraordinary_prowess_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_extraordinary_prowess_contract_desc }
								desc = bdp_battlefield_reputation_reduced_extraordinary_prowess_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 36 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_fearsome_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_fearsome_contract_desc }
								desc = bdp_battlefield_reputation_reduced_fearsome_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_prowess_snapshot >= 26 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_formidable_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_formidable_contract_desc }
								desc = bdp_battlefield_reputation_reduced_formidable_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else = {
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_capable_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_capable_contract_desc }
								desc = bdp_battlefield_reputation_reduced_capable_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
		}
		else = {
			if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 60 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_legendary_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_legendary_contract_desc }
								desc = bdp_battlefield_reputation_reduced_legendary_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 45 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_illustrious_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_illustrious_contract_desc }
								desc = bdp_battlefield_reputation_reduced_illustrious_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 30 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_great_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_great_contract_desc }
								desc = bdp_battlefield_reputation_reduced_great_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else_if = {
				limit = { scope:bdp_battlefield_loser_reputation_snapshot >= 10 }
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_good_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_good_contract_desc }
								desc = bdp_battlefield_reputation_reduced_good_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
			else = {
				hidden_effect = {
					send_interface_message = {
						type = battlefield_duel_feed_prowess_good
						title = bdp_battlefield_reputation_gained_title
						desc = {
							first_valid = {
								triggered_desc = { trigger = { has_character_flag = trial_by_combat } desc = bdp_battlefield_reputation_reduced_normal_trial_desc }
								triggered_desc = { trigger = { exists = scope:task_contract } desc = bdp_battlefield_reputation_reduced_normal_contract_desc }
								desc = bdp_battlefield_reputation_reduced_normal_desc
							}
						}
						left_icon = scope:sc_victor
						right_icon = scope:sc_loser
					}
				}
			}
		}
	}
}

bdp_battlefield_reputation_award_repeat_victory_effect = {
	if = {
		limit = {
			is_target_in_variable_list = {
				name = bdp_battlefield_reputation_opponents_won_once
				target = scope:sc_loser
			}
		}
		remove_list_variable = {
			name = bdp_battlefield_reputation_opponents_won_once
			target = scope:sc_loser
		}

		if = {
			limit = {
				OR = {
					scope:bdp_battlefield_loser_reputation_snapshot >= 60
					scope:bdp_battlefield_loser_prowess_snapshot >= 50
				}
			}
			set_variable = { name = bdp_battlefield_reputation_last_award value = 5 }
			change_variable = { name = bdp_battlefield_reputation add = 5 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_repeat_victory_message_effect = yes
		}
		else_if = {
			limit = {
				OR = {
					scope:bdp_battlefield_loser_reputation_snapshot >= 45
					scope:bdp_battlefield_loser_prowess_snapshot >= 36
				}
			}
			set_variable = { name = bdp_battlefield_reputation_last_award value = 4 }
			change_variable = { name = bdp_battlefield_reputation add = 4 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_repeat_victory_message_effect = yes
		}
		else_if = {
			limit = {
				OR = {
					scope:bdp_battlefield_loser_reputation_snapshot >= 30
					scope:bdp_battlefield_loser_prowess_snapshot >= 26
				}
			}
			set_variable = { name = bdp_battlefield_reputation_last_award value = 3 }
			change_variable = { name = bdp_battlefield_reputation add = 3 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_repeat_victory_message_effect = yes
		}
		else_if = {
			limit = {
				OR = {
					scope:bdp_battlefield_loser_reputation_snapshot >= 10
					scope:bdp_battlefield_loser_prowess_snapshot >= 16
				}
			}
			set_variable = { name = bdp_battlefield_reputation_last_award value = 2 }
			change_variable = { name = bdp_battlefield_reputation add = 2 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_repeat_victory_message_effect = yes
		}
		else = {
			set_variable = { name = bdp_battlefield_reputation_last_award value = 1 }
			change_variable = { name = bdp_battlefield_reputation add = 1 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_repeat_victory_message_effect = yes
		}
	}
	else = { bdp_battlefield_reputation_send_exhausted_message_effect = yes }
}

bdp_battlefield_reputation_award_duel_victory_effect = {
	if = {
		limit = { NOT = { has_variable = bdp_battlefield_reputation } }
		set_variable = { name = bdp_battlefield_reputation value = 0 }
	}

	if = {
		limit = {
			OR = {
				scope:bdp_battlefield_loser_reputation_snapshot >= 60
				scope:bdp_battlefield_loser_prowess_snapshot >= 50
			}
		}
		if = {
			limit = {
				NOT = {
					is_target_in_variable_list = {
						name = bdp_battlefield_reputation_opponents_legendary
						target = scope:sc_loser
					}
				}
			}
			bdp_battlefield_reputation_clear_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_legendary target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 10 }
			change_variable = { name = bdp_battlefield_reputation add = 10 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_first_victory_message_effect = yes
		}
		else = { bdp_battlefield_reputation_award_repeat_victory_effect = yes }
	}
	else_if = {
		limit = {
			OR = {
				scope:bdp_battlefield_loser_reputation_snapshot >= 45
				scope:bdp_battlefield_loser_prowess_snapshot >= 36
			}
		}
		if = {
			limit = {
				NOR = {
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_illustrious target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_legendary target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_illustrious target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 8 }
			change_variable = { name = bdp_battlefield_reputation add = 8 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_first_victory_message_effect = yes
		}
		else = { bdp_battlefield_reputation_award_repeat_victory_effect = yes }
	}
	else_if = {
		limit = {
			OR = {
				scope:bdp_battlefield_loser_reputation_snapshot >= 30
				scope:bdp_battlefield_loser_prowess_snapshot >= 26
			}
		}
		if = {
			limit = {
				NOR = {
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_great target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_illustrious target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_legendary target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_great target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 6 }
			change_variable = { name = bdp_battlefield_reputation add = 6 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_first_victory_message_effect = yes
		}
		else = { bdp_battlefield_reputation_award_repeat_victory_effect = yes }
	}
	else_if = {
		limit = {
			OR = {
				scope:bdp_battlefield_loser_reputation_snapshot >= 10
				scope:bdp_battlefield_loser_prowess_snapshot >= 16
			}
		}
		if = {
			limit = {
				NOR = {
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_good target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_great target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_illustrious target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_legendary target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_good target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 4 }
			change_variable = { name = bdp_battlefield_reputation add = 4 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_first_victory_message_effect = yes
		}
		else = { bdp_battlefield_reputation_award_repeat_victory_effect = yes }
	}
	else = {
		if = {
			limit = {
				NOR = {
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_normal target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_good target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_great target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_illustrious target = scope:sc_loser }
					is_target_in_variable_list = { name = bdp_battlefield_reputation_opponents_legendary target = scope:sc_loser }
				}
			}
			bdp_battlefield_reputation_clear_opponent_record_effect = yes
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_normal target = scope:sc_loser }
			add_to_variable_list = { name = bdp_battlefield_reputation_opponents_won_once target = scope:sc_loser }
			set_variable = { name = bdp_battlefield_reputation_last_award value = 2 }
			change_variable = { name = bdp_battlefield_reputation add = 2 }
			bdp_battlefield_reputation_add_underdog_bonus_effect = yes
			bdp_battlefield_reputation_send_first_victory_message_effect = yes
		}
		else = { bdp_battlefield_reputation_award_repeat_victory_effect = yes }
	}
	bdp_battlefield_reputation_refresh_rank_modifier_effect = yes
}
