﻿namespace = bp1_yearly

##################################
# Revenge Memory                 #
# By Daniel Moore         		 #
##################################

bp1_yearly.7053 = { 
	type = character_event
	content_source = dlc_006
	id_override_priority = 100
	title = bp1_yearly.7053.t
	desc = bp1_yearly.7053.desc
	theme = murder_scheme
	override_background = { reference = gallows }
	left_portrait = {
		character = root
		animation = anger	
	}
	lower_right_portrait = {
		character = scope:bad_memory_participant
		animation = happiness 
	}
	cooldown = { years = 10 }
	trigger = {
		is_ai = no # Murder schemes are heavy for performance
		is_playable_character = yes
		is_available_at_peace_adult = yes
		has_bp1_dlc_trigger = yes
		any_memory = {
			has_memory_category = negative
			any_memory_participant = {
				save_temporary_scope_as = rival_character
				is_alive = yes
				NOR = {
					this = root
					has_relation_lover = root
					has_relation_friend = root
					root = {
						opinion = {
							target = scope:rival_character
							value >= -15
						}
					}
				}
				in_diplomatic_range = root
				root = {
					can_start_scheme = {
						type = murder
						target_character = scope:rival_character
					}
				}
			}
		}
		NOT = {
			has_trait = forgiving
		}
	}
	immediate = {
		random_memory = {
			limit = {
				has_memory_category = negative
				any_memory_participant = {
					this != root
					is_alive = yes
					root = {
						can_start_scheme = {
							type = murder
							target_character = prev
						}
					}
					NOR = {
						has_relation_lover = root
						has_relation_friend = root
						root = {
							opinion = {
								target = prev
								value >= -15
							}
						}
					}
					in_diplomatic_range = root
				}
			}
			#Used for loc
			save_scope_as = bad_memory
			#Find our participant
			random_memory_participant = {
				limit = {
					this != root
					is_alive = yes
					root = {
						can_start_scheme = {
							type = murder
							target_character = prev
						}
					}
					NOR = {
						has_relation_lover = root
						has_relation_friend = root
						root = {
							opinion = {
								target = prev
								value >= -15
							}
						}
					}
				}
				save_scope_as = bad_memory_participant
			}
		}
	}
	#Start revenge scheme or enhance existing scheme
	option = { 
		name = bp1_yearly.7053.a
		trigger = {
			can_start_scheme = {
				type = murder
				target_character = scope:bad_memory_participant
			}
		}
		#Do we already have a murder scheme against our rival?
		if = {
			limit = {
				NOT = {
					any_scheme = {
						type = murder
						scheme_target_character = scope:bad_memory_participant
					}
				}
			}
			start_scheme = {
				type = murder
				target_character = scope:bad_memory_participant
			}
		}
		custom_tooltip = diplomacy_family.2250.b.tt
		#Buff the scheme
		random_scheme = {
			type = murder
			limit = {
				scheme_target_character = scope:bad_memory_participant
			}
			add_scheme_modifier = {
				type = murder_memory_modifier
			}
		}
		stress_and_fulfillment_impact = {
			compassionate = major_stress_impact_gain
			honest = minor_stress_impact_gain
			just = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			wrathful = minor_stress_impact_loss
			vengeful = minor_stress_impact_loss
		}
		ai_chance = {
			base = 25
			modifier = {
				OR = {
					has_trait = eccentric
					has_trait = deceitful
					has_trait = wrathful
					has_trait = vengeful
				}
				add = 50
			}
			ai_value_modifier = {
				ai_vengefulness = 2
				ai_boldness = 2
				ai_honor = -2
				ai_compassion = -2
			}
		}
	} 
	#Forgive and Forget
	option = { 
		name = bp1_yearly.7053.b
		add_piety = minor_piety_value
		stress_and_fulfillment_impact = {
			eccentric = medium_stress_gain
			deceitful = medium_stress_gain
			wrathful = medium_stress_gain
			vengeful = major_stress_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = compassionate
					has_trait = honest
					has_trait = just
				}
				add = 50
			}
			ai_value_modifier = {
				ai_compassion = 2
				ai_honor = 2
				ai_rationality = 1
				ai_boldness = -2
				ai_vengefulness = -2
			}
		}
	}
}

##################################
# Dead Friends                   #
# By Daniel Moore                #
##################################

bp1_yearly.7029 = {
	hidden = yes
	id_override_priority = 100
	
	trigger = {
		is_adult = yes
		is_landed = yes
		has_bp1_dlc_trigger = yes
		exists = scope:dead_friend_spouse
		exists = scope:dead_friend
		scope:dead_friend_spouse = {
			is_available_ai_adult = yes
			is_eunuch_trigger = no
			num_of_relation_lover < 1
			NOR = {
				has_trait = infirm
				is_malformed_trigger = yes
				is_involved_in_any_romantic_scheme = yes
				has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
			}
			trigger_if = {
				limit = {
					root = {
						is_female = yes
						age < 25
					}
				}
				age <= root.age_plus_25
				age >= root.age_minus_10
			}
			trigger_else_if = {
				limit = {
					root = {
						is_female = yes
						age >= 25
					}
				}
				age <= root.age_plus_10
				age >= root.age_minus_10
			}
			trigger_else = {
				age <= root.age_plus_5
				age >= root.age_minus_25
			}
			might_cheat_on_every_partner_trigger = yes
			willing_to_take_character_as_lover = { LOVER = root }
		}

		accepts_incest_with_each_other_trigger = {
			CHARACTER_1 = root
			CHARACTER_2 = scope:dead_friend_spouse
		}

		matching_gender_and_sexuality_trigger = {
			CHARACTER_1 = root
			CHARACTER_2 = scope:dead_friend_spouse
		}
	}

	immediate = {
		random_memory = {
			memory_type = friend_died
			limit = {
				any_memory_participant = {
					this = scope:dead_friend
				}
			}
			save_scope_as = dead_friend_memory
		}

		random_list = {
			1 = { #Small chance to fire this when your friend dies.
				modifier = {
					add = 20
					scope:dead_friend_spouse = {
						likely_to_take_lover_trigger = yes
					}
				}
				modifier = {
					add = 20
					has_focus_or_focus_trait_trigger = { FOCUS = intrigue_temptation_focus }
				}
				trigger_event = {
					id = bp1_yearly.7030
					days = { 10 20 }
				}
			}

			14 = { #Empty chance to make the other chance rarer.

			}
		}
	}
}

bp1_yearly.7030 = {
	type = character_event
	content_source = dlc_006
	id_override_priority = 100
	title = bp1_yearly.7030.t
	desc = bp1_yearly.7030.desc
	theme = seduction

    override_background = {
		reference = bedchamber
	}
	left_portrait = {
		character = root
		animation = disbelief
	}

	right_portrait = {
		character = scope:dead_friend_spouse
		animation = flirtation  
	}


    trigger = {
		is_available_adult = yes
		is_playable_character = yes
		has_bp1_dlc_trigger = yes
		exists = scope:dead_friend_spouse
		
		accepts_incest_with_each_other_trigger = {
			CHARACTER_1 = root
			CHARACTER_2 = scope:dead_friend_spouse
		}
		
		matching_gender_and_sexuality_trigger = {
			CHARACTER_1 = root
			CHARACTER_2 = scope:dead_friend_spouse
		}
		might_cheat_on_every_partner_trigger = yes

		scope:dead_friend_spouse = {
			is_available_ai_adult = yes
			might_cheat_on_every_partner_trigger = yes
			num_of_relation_lover < 1
			NOR = {
				has_trait = infirm
				is_malformed_trigger = yes
				is_involved_in_any_romantic_scheme = yes
				has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
			}
			trigger_if = {
				limit = {
					root = {
						is_female = yes
						age < 25
					}
				}
				age <= root.age_plus_25
				age >= root.age_minus_10
			}
			trigger_else_if = {
				limit = {
					root = {
						is_female = yes
						age >= 25
					}
				}
				age <= root.age_plus_10
				age >= root.age_minus_10
			}
			trigger_else = {
				age <= root.age_plus_5
				age >= root.age_minus_25
			}
			willing_to_take_character_as_lover = { LOVER = root }
		}
	}


    immediate = {
        scope:dead_friend_spouse = {
            add_character_flag = single_combat_stripped_to_waist
			add_character_flag = no_hat
        }
		add_character_flag = no_sex_stress_loss
    }

    on_trigger_fail = {
    	trigger_event = {
    		id = bp1_yearly.7030
    		days = 100
    	}
    }

    option = {
        name = bp1_yearly.7030.a
        had_sex_with_effect = { CHARACTER = scope:dead_friend_spouse PREGNANCY_CHANCE = pregnancy_chance }

        scope:dead_friend_spouse = {
            add_opinion = {
                modifier = pleased_opinion
                target = root
                opinion = 20
            }
            if = {
				limit = {
					can_set_relation_potential_lover_trigger = { CHARACTER = root }
				}
				set_relation_potential_lover = root
			}
        }
		
		stress_and_fulfillment_impact = {
			lustful = medium_stress_impact_loss
			rakish = minor_stress_impact_loss
			disloyal = medium_stress_impact_loss
			chaste = major_stress_impact_gain
			celibate = major_stress_impact_gain
			content = medium_stress_impact_gain
			loyal = medium_stress_impact_gain
			temperate = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			callous = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				OR = {
					has_trait = chaste
					has_trait = celibate
					has_trait = content
					has_trait = loyal
				}
			}
			modifier = {
				factor = 0.5
				scope:dead_friend_spouse = { is_unattractive_trigger = yes }
			}
			modifier = {
				factor = 0
				OR = {
					might_cheat_on_every_partner_trigger = no
					NOT = {
						willing_to_take_character_as_lover = { LOVER = scope:dead_friend_spouse }
					}
				}
			}
		}
    }

    option = { 
        name = bp1_yearly.7030.b

        add_piety = 100
        scope:dead_friend_spouse = {
            add_opinion = {
                modifier = rejected_opinion
                target = root
                opinion = -50
            }
        }
		
		stress_and_fulfillment_impact = {
			lustful = major_stress_impact_gain
			rakish = major_stress_impact_gain
			trusting = medium_stress_impact_gain
			fickle = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0.1
				OR = {
					likely_to_take_lover_trigger = yes
					has_trait = trusting
					has_trait = fickle
				}
			}
		}
    }

    after = {
   		scope:dead_friend_spouse = {
        	remove_character_flag = single_combat_stripped_to_waist
			remove_character_flag = no_hat
        }
		remove_character_flag = no_sex_stress_loss
    }
}

