﻿demand_payment_interaction = {
	category = interaction_category_friendly
	icon = icon_gold

	auto_accept = yes
	use_diplomatic_range = yes
	interface_priority = 35

	desc = demand_payment_interaction_desc

	is_shown = {
		scope:actor = {
			OR = {
				# SAS Change
				AND = {
					OR = {
						has_game_rule = sas_all_modified_perks
						has_game_rule = spy_and_interactions
					}
					exists = court_position:smuggler_court_position
				}
				AND = {
					OR = {
						has_game_rule = spy_perks_only
						has_game_rule = spy_and_intrigue_buffs
					}
					has_perk = golden_obligations_perk
				}		
				# SAS Change End
				AND = {
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = unlocks_demand_payments_for_all
						is_secondary_character_involvement_either_trigger = {
							CHAR = scope:recipient
						}
					}
				}
			}
		}
		scope:recipient = {
			is_ai = yes
		}
		scope:recipient != scope:actor
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_physically_able_adult = yes
			NOT = {
				is_at_war_with = scope:recipient
			}
		}
		scope:recipient = {
			is_imprisoned = no
		}
		scope:recipient = {
			custom_description = {
				text = demand_payment_too_little_gold
				gold >= 1
			}
		}
	}

	is_valid = {
		scope:actor = {
			has_usable_hook = scope:recipient
		}
	}

	is_highlighted = {
		scope:actor = {
			has_usable_hook = scope:recipient
		}
	}

	on_accept = {
		if = {
			limit = {
				scope:recipient.gold < scope:recipient.golden_obligation_value
			}
			custom_tooltip = demand_payment_too_little_gold_tt
		}
		scope:actor = {
			send_interface_toast = {
				title = demand_payment_interaction_message
				left_icon = scope:recipient

				scope:actor = {
					use_hook = scope:recipient
				}
				scope:recipient = {
					if = {
						pay_short_term_gold = {
							target = scope:actor
							gold = golden_obligation_value
						}
						limit = {
							gold > golden_obligation_value
						}
					}
					else = {
						pay_short_term_gold = {
							target = scope:actor
							gold = {
								value = scope:recipient.gold
								floor = yes
							}
						}
					}
				}
			}
			stress_impact = {
				generous = medium_stress_impact_gain
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_demand_payment.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
	
	ai_potential = {
		NOT = {
			has_trait = generous
		}
		OR = {
			ai_greed >= low_positive_ai_value
			is_at_war = yes
		}
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}
	
	ai_targets = {
		ai_recipients = hooked_characters
	}
	
	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 12
		empire = 6
		hegemony = 6
	}
	
	ai_will_do = {
		base = 100

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = -100
		}

		modifier = { #ai won't use the interaction if they'll get nothing out of it
			factor = 0
			scope:recipient.gold < 8
		}
		
		modifier = {
			factor = 0
			scope:actor = {
				OR = {
					has_relation_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_soulmate = scope:recipient
				}
			}
		}
	}
}

