
minor_sengoku_conquest = { 
	name = CB_NAME_GEKOKUJO
	war_name = WAR_NAME_GEKOKUJO
	sprite = 16
	truce_days = 365
	hostile_against_others = yes
	is_permanent = yes
	check_all_titles = yes # if permanent, setting this to true will check against all of someones titles, including vassal held titles
	press_claim = yes
	can_ask_to_join_war = yes
	max_defender_battle_score = 200
	max_attacker_battle_score = 200
	
	infamy_modifier = 0.85
	
	can_use_gui = {
		ROOT = {
			piety = 100
		}
	}
	
	on_add = {
		ROOT = { piety = -100 }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}
	
	can_use = {
		ROOT = {
			NOT = { is_liege_or_above = FROM }
			higher_tier_than = COUNT
			OR={
				religion = shinto
			}
		}
		ROOT = {
			capital_scope = {
				TECH_LEGALISM = 3
			}
		}
	}

	can_use_title = {
		tier = count
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
		
		NOT = {
			holder_scope = {
				is_liege_or_above = ROOT
			}
		}
		FROM = {
			NAND = {
				NOT = { num_of_count_titles = 2 }
			}
		}


		# The attacker needs a border or be at the most two sea zones away
		location = {
			any_neighbor_province = {
				OR = {
					AND = {
						has_owner = yes
						owner = {
							OR = {
								character = ROOT
								is_liege_or_above = ROOT
							}
						}
					}
					AND = {
						is_land = no
						any_neighbor_province = {
							OR = {
								AND = {
									has_owner = yes
									owner = {
										OR = {
											character = ROOT
											is_liege_or_above = ROOT
										}
									}
								}
								AND = {
									is_land = no
									any_neighbor_province = {
										owner = {
											OR = {
												character = ROOT
												is_liege_or_above = ROOT
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		holder_scope = {
			NOT = {
				has_landed_title = e_newjapan
			}
		}
		
	}

	is_valid_title = {
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	on_success_title = {
		if = {
			limit = {
				holder_scope = {
					tier = count
					NOT = { num_of_count_titles = 2 }
					lower_tier_than = ROOT
				}
			}

			holder_scope = {
				set_defacto_liege = ROOT
			}
		}

		if = {
			limit = {
				holder_scope = {
					OR = {
						higher_tier_than = count
						num_of_count_titles = 2
						NOT = { lower_tier_than = ROOT }
					}
				}
			}

			usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			any_de_jure_vassal_title = { # take all baronies under the one we're fighting for
				limit = {
					has_holder = yes
					NOT = {
						de_facto_liege = PREV
					}
					holder_scope = {
						OR = {
							character = FROM
							is_liege_or_above = FROM
						}
					}
				}

				usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
			}
		}
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 100
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	on_fail_title = {
		ROOT = {
			prestige = -100
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}
	
	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
		
		modifier = {
			factor = 0.9 # Prefer using CB's without on_add costs
		}
	}
}

sengoku_invasion = {
	name = CB_NAME_SENGOKU_INVASION
	war_name = WAR_SENGOKU_INVASION
	sprite = 8
	truce_days = 365
	hostile_against_others = yes
	is_permanent = yes
	can_ask_to_join_war = yes
	max_defender_battle_score = 200
	max_attacker_battle_score = 200
	check_de_jure_tier = DUKE # this scans all de jure duchy for the counties which are held by or vassals(or below) of selected character. Only valid if is_permanent = yes
	
	infamy_modifier = 0.85
	
	can_use_gui = {
		ROOT = {
			piety = 200
		}
	}
	
	on_add = {
		ROOT = { piety = -200 }
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	can_use = {		
		ROOT = {
			NOT = { same_realm = FROM }
			NOT = { is_liege_or_above = FROM }
			higher_tier_than = COUNT
			OR={
				religion = shinto
			}
		}
		ROOT = {
			capital_scope = {
				TECH_LEGALISM = 5
			}
		}
		FROM = {
			NOT = {
				OR = {
					is_merchant_republic = yes
				}
			}
		}
		
	}
	
	can_use_title = {
		# The attacker needs at least one county in the target kingdom, or a border, or be only two sea zones away from one of your counties		
		any_direct_de_jure_vassal_title = {
			OR = {
				holder_scope = {
					OR = {
						character = ROOT
						is_liege_or_above = ROOT
					}
				}
				location = {
					any_neighbor_province = {
						OR = {
							AND = {
								has_owner = yes
								owner = {
									OR = {
										character = ROOT
										is_liege_or_above = ROOT
									}
								}
							}
							AND = {
								is_land = no
								any_neighbor_province = {
									OR = {
										AND = {
											has_owner = yes
											owner = {
												OR = {
													character = ROOT
													is_liege_or_above = ROOT
												}
											}
										}
										AND = {
											is_land = no
											any_neighbor_province = {
												owner = {
													OR = {
														character = ROOT
														is_liege_or_above = ROOT
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		
		holder_scope = {
			NOT = {
				has_landed_title = e_newjapan
			}
		}
	}

	is_valid = {
		ROOT = {
			NOT = { same_realm = FROM }
		}
	}
	
	on_success = {
		ROOT = {
			prestige = 200
		}
		
		any_attacker = {
			limit = { character = ROOT }
			participation_scaled_prestige = 200
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { 
				participation_scaled_prestige = 200 
			}
		}
		FROM = {
			prestige = -200
		}
	}

	on_success_title = {
		
		if = {
			# Take the enemy's duchies within the target kingdom, if we are the same or lower tier
			limit = {
				ROOT = {
					NOT = { higher_tier_than = FROM }
				}
			}
			FROM = {
				any_demesne_title = {
					limit = {
						tier = DUKE
						OR = {
							title = PREVPREV
							de_jure_liege_or_above = PREVPREV
						}
					}
					ROOT = { usurp_title = { target = PREV type = invasion } }
				}
			}
		}
		
		# Have I become the vassal of the loser due to taking a duchy or kingdom?
		if = {
			limit = {
				ROOT = {
					is_liege_or_above = FROM	
				}
			}
			ROOT = {
				set_defacto_liege = ROOT
			}
		}
		
		# Vassalize the rest
		custom_tooltip = {
			text = pagan_subjugation_tip
			hidden_tooltip = {
				ROOT = {
					subjugate_or_take_under_title = { # If the target only has territory within the kingdom, he is simply vassalized
						title = PREV
						enemy = FROM
					}
				}
			}
		}
	}

	on_fail = {
		FROM = {
			prestige = 100
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 100
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		ROOT = {
			prestige = -200
		}
	}

	on_reverse_demand = {
		ROOT = {
			prestige = -200
			transfer_scaled_wealth = {
				to = FROM
				value = 4.0
			}
			decadence = 10
		}
		FROM = {
			prestige = 200
		}
		any_defender = {
			limit = { character = FROM }
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 200 }
		}
	}

	attacker_ai_victory_worth = {
		factor = 100
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 150
	}
}

