﻿action_regula_make_paelex = {
    combine_into_one = yes
    priority = 700

    check_create_action = {
        if = {
            limit = { 
                has_trait = magister_trait_group
                has_trait_rank = {
                    trait = magister_trait_group 
                    rank >= 2
                }
                # NOT = { global_var:action_regula_make_paelex_value = flag:direct }
                # NOT = { global_var:action_regula_make_paelex_value = flag:none }
            }
        }
        every_vassal = {
            limit = {
                has_trait = mulsa
                is_imprisoned = no
                highest_held_title_tier >= tier_county
            }
            try_create_important_action = {
                important_action_type = action_regula_make_paelex
                actor = global_var:magister_character
                recipient = this
            }
        }
    }

    effect = {
        open_interaction_window = {
            interaction = regula_make_paelex_interaction
            actor = scope:actor
            recipient = scope:recipient
        }
    }
}

# action_regula_make_paelex_direct_vassals = {
#     combine_into_one = yes
#     priority = 700

#     check_create_action = {
#         if = {
#             limit = { 
#                 has_trait = magister_trait_group
#                 has_trait_rank = {
#                     trait = magister_trait_group 
#                     rank >= 2
#                 }
#                 exists = global_var:action_regula_make_paelex_value
#                 global_var:action_regula_make_paelex_value = flag:direct
#             }
#         }
#         every_vassal = {
#             limit = {
#                 has_trait = mulsa
#                 is_imprisoned = no
#                 highest_held_title_tier >= tier_county
#             }
#             try_create_important_action = {
#                 important_action_type = action_regula_make_paelex
#                 actor = global_var:magister_character
#                 recipient = this
#             }
#         }
#     }

#     effect = {
#         open_interaction_window = {
#             interaction = regula_make_paelex_interaction
#             actor = scope:actor
#             recipient = scope:recipient
#         }
#     }
# }

action_regula_take_orba = {
    combine_into_one = yes
    priority = 600
 
    
    check_create_action = {
        if = {
            limit = { 
                has_trait = magister_trait_group
                has_trait_rank = {
                    trait = magister_trait_group 
                    rank >= 2
                } 
            }
        }
        every_vassal_or_below = {
            limit = {
                has_trait = orba
                is_imprisoned = no
            }
            try_create_important_action = {
                important_action_type = action_regula_take_orba
                actor = root
                recipient = this
            }
        }
    }

    effect = {
        open_interaction_window = {
            interaction = regula_take_orba_interaction
            actor = scope:actor
            recipient = scope:recipient
        }
    }
}

action_regula_potestas_non_transfunde = {
    combine_into_one = yes
    priority = 950
 
    
    check_create_action = {
        if = {
            limit = { 
                is_ai = no
                exists = faith.religious_head
                root = faith.religious_head
                faith = {
                    has_doctrine = tenet_regula_devoted
                }
                has_trait = magister_trait_group
                has_trait_rank = {
                    trait = magister_trait_group 
                    rank >= 2
                } 
            }
            every_neighboring_and_across_water_top_liege_realm_owner = {
                limit = {
                    faith = root.faith
                    is_independent_ruler = yes
                    is_male = no
                    age >= 16
                    highest_held_title_tier < root.highest_held_title_tier
                    is_diplomatically_available = yes
                    save_temporary_scope_as = transfunde_target
                    root = {
                        prestige >= scope:transfunde_target.regula_potestas_non_transfunde_cost
                    }
                }
                try_create_important_action = {
                    important_action_type = action_regula_potestas_non_transfunde
                    actor = root
                    recipient = this
                }
            }
        }
    }

    effect = {
        open_interaction_window = {
            interaction = regula_potestas_non_transfunde_interaction
            actor = scope:actor
            recipient = scope:recipient
        }
    }
}

# suggestion_regula_potesas_non_transfunde = {  ### UPDATE - Actually make this.

# 	weight = {
# 		base = 0

# 		modifier = { #Is the suggestion available at all?
# 			add = 0.5
# 			any_neighboring_and_across_water_top_liege_realm = {
# 				AND = {
#                     is_independent_ruler = yes
# 					faith.religious_head = global_var:magister_character
# 					is_at_war = no
# 				}
# 			}
# 		}

# 		modifier = { #Less likely if you're bankrupt
# 			add = -0.75
# 			gold < 0
# 		}

# 		modifier = { #More likely if you're famous.
# 			add = 0.25
# 			prestige > monumental_prestige_value
# 		}
# 	}

# 	check_create_suggestion = {
# 		every_directly_owned_province = {
# 			limit = {
# 				has_free_building_slot = yes
# 			}

# 			try_create_suggestion = {
# 				suggestion_type = suggestion_regula_postesas_non_transfunde
# 				potestas_recipient = recipient
# 			}
# 		}
# 	}
# 	effect = {
# 		scope:recipient = {
# 			open_view_data = {
# 				view = character
# 			}
# 		}
# 	}

# 	score = {
# 		base = 100
# 		modifier = {
# 			add = {
# 				value = -10
# 				multiply = scope:recipient.highest_held_title_tier
# 				# Larger realms are less cost-efficient to vassalize. 
# 				}
# 			}
# 		}
# 	}
# 	### UPDATE - Will this work?
# 	is_valid = {
# 		prestige >= regula_potestas_non_transfunde_cost
# 	}	
# }

}