﻿#From \common\casus_belli_types\01_ep1_wars.txt

artifact_war = {
	group = artifact
	ai_only_against_neighbors = yes
	
	allowed_for_character = {
		has_any_artifact_claim = yes
	}
	allowed_against_character = {
		scope:attacker = {
			OR = {
				any_personal_claimed_artifact = {
					artifact_owner = {
						is_ruler = yes
						target_is_same_character_or_above = scope:defender
					}
					#Modded so AI can only declare war for illustrious or famed artifacts it can use
					trigger_if = {
						limit = {
							scope:attacker = { is_ai = yes }
						}
						NOT = { has_variable = cursed_artifact }
						artifact_rarity >= 4 #More than masterwork
						scope:attacker = {
							can_benefit_from_artifact = prev
						}
					}
				}
				AND = {
					exists = scope:attacker.house
					house = {
						any_house_claimed_artifact = {
							trigger_if = {
								limit = {
									scope:attacker = { is_ai = yes }
								}
								NOT = { has_variable = cursed_artifact }
								artifact_rarity >= 4 #More than masterwork
								scope:attacker = {
									can_benefit_from_artifact = prev
								}
							}
							artifact_owner = {
								OR = {
									AND = { #Modded not the same Dynasty
										exists = scope:attacker.dynasty
										exists = dynasty
										NOT = {
											dynasty = scope:attacker.dynasty
										}
									}
									AND = { # Defender is lowborn
										exists = scope:attacker.house
										is_lowborn = yes
									}
								}
								is_ruler = yes
								target_is_same_character_or_above = scope:defender
							}
						}
					}
				}
			}
		}
	}
	
	on_declaration = {
		on_declared_war = yes
	}
	
	cost = {
		prestige = {
			value = 0
			add = {
				value = medium_prestige_value
				desc = CB_BASE_COST
			}

			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defender = { is_local_player = yes }
				}
				desc = artifact_war_victory_desc_defender
			}
			desc = artifact_war_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# transfer artifacts
		scope:attacker = {
			every_personal_claimed_artifact = {
				limit = {
					trigger_if = {
						limit = {
							scope:attacker = { is_ai = yes }
						}
						NOT = { has_variable = cursed_artifact }
						artifact_rarity >= 4 #More than masterwork
						scope:attacker = {
							can_benefit_from_artifact = prev
						}
					}
					artifact_owner = {
						is_ruler = yes
						target_is_same_character_or_above = scope:defender
					}
				}
				set_owner = {
					target = scope:attacker
					history = {
						type = conquest
						actor = scope:defender
						recipient = scope:attacker
					}
				}
				if = {
					limit = {
						NOT = { 
							scope:defender = { has_personal_artifact_claim = prev }
						}
					}
					scope:defender = { add_personal_artifact_claim = prev }
				}
			}
			if = {
				limit = {
					exists = scope:attacker.house
				}
				house = {
					every_house_claimed_artifact = {
						limit = {
							artifact_owner = {
								OR = {
									AND = { # Not the same House
										exists = house
										NOT = {
											house = scope:attacker.house
										}
									}
									AND = { # Defender is lowborn
										exists = scope:attacker.house
										is_lowborn = yes
									}
								}
								is_ruler = yes
								target_is_same_character_or_above = scope:defender
							}
							save_temporary_scope_as = temp_artifact_check
							NOT = {
								scope:attacker = {
									any_personal_claimed_artifact = {
										this = scope:temp_artifact_check
									}
								}
							}
						}
						set_owner = {
							target = scope:attacker
							history = {
								type = conquest
								actor = scope:attacker
								recipient = scope:defender
							}
						}
						if = {
							limit = {
								NOT = { 
									scope:defender = { has_personal_artifact_claim = prev }
								}
							}
							scope:defender = { add_personal_artifact_claim = prev }
						}
					}
				}
			}
		}
		
		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}
		
		# Truce
		add_truce_attacker_victory_effect = yes
	}

	on_white_peace_desc = {
		desc = artifact_war_white_peace_desc
	}
	
	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_white_peace_effect = yes
	}

	on_defeat_desc = {
		desc = artifact_war_defeat_desc
	}
	
	on_defeat = {
		scope:attacker = {
			show_pow_release_message_effect = yes

			every_personal_claimed_artifact = {
				limit = {
					artifact_owner = {
						is_ruler = yes
						target_is_same_character_or_above = scope:defender
					}
				}
				scope:attacker = { remove_personal_artifact_claim = prev }
			}
			if = {
				limit = {
					exists = scope:attacker.house
				}
				house = {
					every_house_claimed_artifact = {
						limit = {
							artifact_owner = {
								trigger_if = {
									limit = {
										exists = house
									}
									NOT = {
										house = scope:attacker.house
									}
								}
								is_ruler = yes
								target_is_same_character_or_above = scope:defender
							}
						}
						scope:attacker.house = { remove_house_artifact_claim = prev }
					}
				}
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Prestige for Defender
		scope:defender = {
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = major_prestige_value
			}
		}

		# Prestige for the attacker's war allies
		add_from_contribution_attackers = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Prestige for the defender's war allies
		add_from_contribution_defenders = {
			prestige = medium_prestige_value
			opinion = {
				modifier = contributed_in_war
			}
		}

		# Truce
		add_truce_attacker_defeat_effect = yes
	}
	
	should_invalidate = {
		NOT = {
			scope:attacker = {
				OR = {
					any_personal_claimed_artifact = {
						#Modded so AI can only declare war for illustrious or famed artifacts
						trigger_if = {
							limit = {
								scope:attacker = { is_ai = yes }
							}
							NOT = { has_variable = cursed_artifact }
							artifact_rarity >= 4 #More than masterwork
							scope:attacker = {
								can_benefit_from_artifact = prev
							}
						}
						artifact_owner = {
							is_ruler = yes
							target_is_same_character_or_above = scope:defender
						}
					}
					AND = {
						exists = scope:attacker.house
						house = {
							any_house_claimed_artifact = {
								#Modded so AI can only declare war for illustrious or famed artifacts
								trigger_if = {
									limit = {
										scope:attacker = { is_ai = yes }
									}
									NOT = { has_variable = cursed_artifact }
									artifact_rarity >= 4 #More than masterwork
									scope:attacker = {
										can_benefit_from_artifact = prev
									}
								}
								artifact_owner = {
									OR = {
										AND = { #Modded not the same Dynasty
											exists = scope:attacker.dynasty
											exists = dynasty
											NOT = {
												dynasty = scope:attacker.dynasty
											}
										}
										AND = { # Defender is lowborn
											exists = scope:attacker.house
											is_lowborn = yes
										}
									}
									is_ruler = yes
									target_is_same_character_or_above = scope:defender
								}
							}
						}
					}
				}
			}
		}
	}
	on_invalidated = {
	}
	
	on_invalidated_desc = {
		desc = artifact_war_invalidated_desc
	}
	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit
	
	transfer_behavior = transfer
	
	attacker_allies_inherit = yes
	defender_allies_inherit = yes
	
	war_name = "ARTIFACT_WAR_NAME"
	cb_name_no_target = "ARTIFACT_WAR_NAME_FALLBACK"
	
	interface_priority = 1000
	
	ticking_war_score_targets_entire_realm = yes
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
	attacker_ticking_warscore = 0
	attacker_wargoal_percentage = 0.8
	
	max_ai_diplo_distance_to_title = 500
	
	should_show_war_goal_subview = no
	
	ai_score = {
		value = artifact_war_ai_score_value
	}
}