﻿
send_child_to_holy_order_effect = {
	$GRANDMASTER$ = {
		add_courtier = scope:recipient
		if = {
            limit = {
                scope:recipient = {
                    is_close_family_of = scope:actor
                    NOT = {
                    	has_trait = bastard
                    }
                }
            }
            add_opinion = {
                target = scope:actor
                modifier = pleased_opinion
                opinion = 25
            }
        }
        else_if = {
            limit = {
                scope:recipient = {
                    is_close_family_of = scope:actor
                }
            }
            add_opinion = {
                target = scope:actor
                modifier = pleased_opinion
                opinion = 15
            }
        }
	}
	scope:recipient = {
		add_trait = order_member
		add_piety_level = 1
		if = {
			limit = { is_ruler = yes }
			depose = yes
		}
		if = {
			limit = {
				faith != $GRANDMASTER$.faith
			}
			set_character_faith = $GRANDMASTER$.faith
			set_character_rite = $GRANDMASTER$.rite
		}
		if = {
			limit = {
				is_married = yes
			}
			every_spouse = {
				divorce = scope:recipient
			}
		}
		if = {
			limit = {
				exists = betrothed
			}
			break_betrothal = betrothed
			if = {
				limit = {
					has_been_promised_grand_wedding = yes
				}
				break_grand_wedding_betrothal_effect = yes
			}
		}
		if = {
			limit = {
				is_concubine = yes
			}
			this.concubinist = {
				remove_concubine = scope:recipient
			}
		}
		if = {
			limit = {
				number_of_concubines > 0
			}
			every_concubine = {
				scope:recipient = {
					remove_concubine = prev
				}
			}
		}
		create_character_memory = {
			type = lmf_memory_sent_to_holy_order
			participants = {
				sender = scope:actor
			}
		}
		scope:new_memory = {
			set_variable = {
				name = new_order
				value = $GRANDMASTER$.primary_title
			}
			if = {
				limit = { exists = var:sender_title }
				#To prevent 'unused except in loc' errors :catto:
			}
		}
	}
	take_vows_faith_opinion_effect = yes
	if = {
		limit = {
			$GRANDMASTER$ = {
				has_realm_law = cultural_holy_order_succession_law
				NOT = {
					culture = {
						has_same_culture_heritage = scope:recipient.culture
					}
				}
			}
		}
		$GRANDMASTER$ = { save_scope_as = grandmaster }
		custom_tooltip = military_order_wrong_culture_tt
	}
}

send_child_to_clergy_effect = {
	scope:recipient = {
		if = {
			limit = {
				NOT = { has_character_flag = pam_simony_paid_vows }
			}
			if = {
				limit = {
					OR = {
						scope:demand ?= yes
						AND = {
							is_imprisoned_by = scope:puppet_or_actor
							OR = {
								is_heir_of = scope:puppet_or_actor
								any_claim = {
									exists = this
								}
							}
						}
					}
				}
				add_opinion = {
					modifier = forced_taking_vows
					target = scope:puppet_or_actor
				}
			}
			else = {
				add_opinion = {
					modifier = demanded_taking_vows
					target = scope:puppet_or_actor
				}
			}
		}
		create_character_memory = {
			type = lmf_memory_sent_to_be_devoted
			participants = {
				sender = scope:puppet_or_actor
			}
		}
		scope:new_memory = {
			set_variable = {
				name = devoted_faith
				value = scope:recipient.faith
			}
			set_variable = {
				name = sender_title
				value = scope:puppet_or_actor.primary_title
			}
		}
		simplified_clergy_effect = { RECIPIENT = scope:recipient }
	}
	scope:puppet_or_actor = {
		#Spiritual fulfillment gain
   		if = {
   			limit = {
   				scope:recipient = {
    	            is_child_of = scope:puppet_or_actor
    	            NOT = {
    	        		has_trait = bastard
    	        	}
    	        }
   			}
   			change_spiritual_fulfillment = {
   				value = medium_spiritual_fulfillment_value
   				if = {
   					limit = {
   						scope:recipient = {
   							is_imprisoned = yes
   						}
   					}
   					multiply = 0.5
   				}
   			}
   		}
   		else_if = {
   			limit = {
   				scope:recipient = {
    	            trigger_if = {
    	            	limit = {
    	            		has_trait = bastard
    	            	}
    	            	is_child_of = scope:puppet_or_actor
    	            }
    	            OR = {
    	            	house ?= scope:puppet_or_actor.house
    	            	is_close_family_of = scope:puppet_or_actor
    	            }
    	        }
   			}
   			change_spiritual_fulfillment = {
   				value = minor_spiritual_fulfillment_value
   				if = {
   					limit = {
   						scope:recipient = {
   							is_imprisoned = yes
   						}
   					}
   					multiply = 0.5
   				}
   			}
   		}
   		else_if = {
   			limit = {
   				scope:recipient = {
    	            trigger_if = {
    	            	limit = {
    	            		has_trait = bastard
    	            	}
    	            	OR = {
    	            		house ?= scope:puppet_or_actor.house
    	            		is_close_family_of = scope:puppet_or_actor
    	           		}
    	            }
    	            trigger_else = {
    	            	OR = {
    	            		dynasty ?= scope:puppet_or_actor.dynasty
    	            		is_close_or_extended_family_of = scope:puppet_or_actor
    	            	}
    	            }
    	        }
   			}
   			change_spiritual_fulfillment = {
   				value = miniscule_spiritual_fulfillment_value
   				if = {
   					limit = {
   						scope:recipient = {
   							is_imprisoned = yes
   						}
   					}
   					multiply = 0.5
   				}
   			}
   		}
   		else = {
   			change_spiritual_fulfillment = {
   				value = miniscule_spiritual_fulfillment_value
   				multiply = 0.5
   				if = {
   					limit = {
   						scope:recipient = {
   							is_imprisoned = yes
   						}
   					}
   					multiply = 0.5
   				}
   			}
   		}
	}
}

