#Build Pleasure Dome

### Devise Pleasure Dome ###
mpo_pleasure_dome_decision = {
    picture = {
        reference = "gfx/interface/illustrations/event_scenes/mpo_city_steppe.dds"
    }
	decision_group_type = nomad_minor
	sort_order = 80

	is_shown = {
		has_mpo_dlc_trigger = yes
        OR = {
	       	government_has_flag = government_is_nomadic
            has_trait = nomadic_philosophy
        }
        NOT = { has_global_variable = devised_pleasure_dome }
        culture = {
            OR = {
                has_cultural_pillar = heritage_mongolic
                has_cultural_pillar = heritage_turkic
            }
        }
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = mpo_pleasure_dome_no_barony_tt
			any_held_title = {
				tier = tier_barony
				title_province = {
                    has_special_building_slot = no
                }
				is_capital_barony = yes
				holder = root
				is_leased_out = no
                title_province = { geographical_region = world_steppe }
			}
		}
	}

	is_valid = {
		prestige_level >= very_high_prestige_level
		highest_held_title_tier = tier_empire
        trigger_if = {
            limit = {
                government_has_flag = government_is_nomadic
            }
            custom_tooltip = {
		    	text = dominate_title_trigger_dominance_4
		    	OR = {
		    		has_realm_law = nomadic_authority_5
		    		has_realm_law = nomadic_authority_4
		    	}
		    }
        }
		trigger_if = {
            limit = {
                government_has_flag = government_is_steppe_admin
            }
            custom_tooltip = {
		    	text = mpo_pleasure_dome_decision_steppe_admin
		    	OR = {
		    		has_realm_law = meritocratic_bureaucracy_2
		    		has_realm_law = meritocratic_bureaucracy_3
		    	}
		    }
        }
	}

	cost = {
		treasury_or_gold = {
			value = massive_treasury_or_gold_value
		}
		prestige = massive_prestige_value
		herd = {
            value = 0
            if = {
                limit = {
                    government_has_flag = government_is_nomadic
                }
                add = 2000
            }
        }
        influence = {
            value = 0
            if = {
                limit = {
                    government_has_flag = government_is_steppe_admin
                }
                add = 700
            }
        }
	}

    widget = {
        controller = create_holy_order
        barony_valid = {
            trigger_if = {
                limit = { exists = this }
                title_province = {
                    has_special_building_slot = no
                }
                is_capital_barony = yes
                holder = scope:ruler
                is_leased_out = no
            }
        }
    }
    effect = {
        send_interface_toast = {
            type = event_toast_effect_good
            title = mpo_pleasure_dome_slot_added.toast
            
            if = { 
                limit = { exists = scope:barony }
                custom_tooltip = {
                    text = mpo_add_pleasure_dome_effect_tt
                    scope:barony.title_province = { add_special_building = pleasure_dome }
                }
            }
        }
        custom_description_no_bullet = { text = mpo_pleasure_dome_barony_decision_tt }
        
        set_global_variable = {
            name = devised_pleasure_dome
            value = yes
        }
    }
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 60
		hegemony = 60
	}
    ai_potential = {
        is_at_war = no
		gold >= 1500
    }
    ai_will_do = {
        base = 100
    }
}

##Paiza decisions

#Starting decision, establish the system 
### Establish Paiza System ###
mpo_establish_paiza_system_decision = {
    picture = {
        reference = "gfx/interface/illustrations/event_scenes/mpo_rural_village_asian.dds"
    }
    decision_group_type = nomad_major
    sort_order = 80

    is_shown = {
		has_mpo_dlc_trigger = yes
        government_has_flag = government_is_nomadic
        NOT = { has_character_flag = established_paiza_system }
		exists = situation:the_great_steppe
		any_character_situation = {
			this = situation:the_great_steppe
		}
		OR = {
            has_realm_law = nomadic_authority_2
            has_realm_law = nomadic_authority_3
			has_realm_law = nomadic_authority_4
			has_realm_law = nomadic_authority_5
		}
    }

    is_valid = {
        culture ?= {
            has_innovation = innovation_ledger
        }
        is_independent_ruler = yes
        custom_tooltip = {
			text = mpo_establish_paiza_system_decision_is_gurkhan
			exists = situation:the_great_steppe
			this = situation:the_great_steppe.situation_top_herd
		}
		OR = {
			has_realm_law = nomadic_authority_4
			has_realm_law = nomadic_authority_5
		}    
    }

    is_valid_showing_failures_only = {
        trigger_if = {
            limit = {
                exists = global_var:global_established_paiza_system
            }
            custom_tooltip = {
                text = mpo_establish_paiza_system_decision.paiza_recently_established
                subject = global_var:global_established_paiza_system
                NAND = {  
                    global_var:global_established_paiza_system ?= {
                        is_alive = yes
                        has_realm_law = nomadic_authority_5
                    }
                }
            }
        }
    }

	cost = {
        gold = {
            value = 0
            if = {
                limit = {
                    has_treasury = no
                }
                add = massive_prestige_value
           }
        }

        treasury = {
            value = 0
            if = {
                limit = {
                    has_treasury = yes
                }
                add = 250
            }
        }

        herd = {
            value = 2000
        }
    }


    effect = {
        add_character_flag = established_paiza_system
        set_global_variable = {
            name = global_established_paiza_system
            value = root
            years = 8
        }
        custom_tooltip = mpo_establish_paiza_system_decision.grant_paiza_interaction_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.request_paiza_interaction_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.paiza_obedient
        custom_tooltip = mpo_establish_paiza_system_decision.call_for_merchants_decision_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.leverage_khan_authority_unlocked
        custom_tooltip = mpo_establish_paiza_system_decision.paiza_abuse_authority_unlocked

        if = { #populating the world with paizas
            limit = {
                is_ai = yes
            }
            ai_paiza_giveaway_effect = yes
            ai_paiza_giveaway_effect = yes
            ai_paiza_giveaway_effect = yes
            ai_paiza_giveaway_effect = yes
        }
        
        trigger_event = mpo_decisions_events.0099
    }
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 10
		empire = 10
		hegemony = 10
	}

    ai_will_do = { 
        base = 100
    }
}

### Summon Wealthy Visitors: Paiza ###
mpo_call_for_merchants_decision = {
    picture = {
        reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
    }
    decision_group_type = nomad_major
    sort_order = 80

    is_shown = {
		has_mpo_dlc_trigger = yes
        government_has_flag = government_is_nomadic
        has_character_flag = established_paiza_system
    }

    is_valid = {
        custom_tooltip = {
			text = mpo_call_for_merchants_decision_is_gurkhan
			exists = situation:the_great_steppe
			this = situation:the_great_steppe.situation_top_herd
		}
        OR = {
			has_realm_law = nomadic_authority_4
			has_realm_law = nomadic_authority_5
		}
        trigger_if = {
            limit = {
                is_ai = no
            }
            domicile ?= {
                has_domicile_building_or_higher = trade_yurt_04
            }
        }
        trigger_else = {
            always = yes
        }
        gold >= 800
    }

    is_valid_showing_failures_only = {
        custom_tooltip = {
            text = mpo_call_for_merchants_decision.robbed_merchants
            NOT = {
                has_character_modifier = mpo_paiza_robbed_merchants
            }
        }
    }

    cost = {
        prestige = {
            value = major_prestige_value
        }
    }

    cooldown = { years = 4 }

    effect = {
        trigger_event = mpo_decisions_events.2139
        custom_tooltip = mpo_call_for_merchants_decision.merchant_will_arrive
        custom_tooltip = mpo_call_for_merchants_decision.gold_needed
        custom_tooltip = mpo_call_for_merchants_decision.buildings
    }
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 100
		kingdom = 100
		empire = 100
		hegemony = 100
	}

    ai_will_do = {
        base = 0
        modifier = {
            add = 8
            domicile ?= {
                has_domicile_building_or_higher = merchant_yurt_01
            }
        }
        modifier = {
            add = 8
            domicile ?= {
                has_domicile_building_or_higher = herd_trade_yurt_01
            }
        }
        modifier = {
            add = 8
            domicile ?= {
                has_domicile_building_or_higher = fertility_trade_yurt_01
            }
        }       
        modifier = {
            add = 8
            domicile ?= {
                has_domicile_building_or_higher = knight_trade_yurt_01
            }
        }
        modifier = {
            add = 20
            gold >= 2400
        }
    }

    ai_potential = {
        is_at_war = no
        ai_greed >= medium_positive_ai_value
    }
}

### Summon Wealthy Visitors: Local Offers ###
mpo_call_for_merchants_small_decision = {
    picture = {
        reference = "gfx/interface/illustrations/decisions/fp3_decision_tax_collector.dds"
    }
    decision_group_type = nomad_minor
    sort_order = 80

    is_shown = {
        has_mpo_dlc_trigger = yes
        government_has_flag = government_is_nomadic
        NOT = {
            has_character_flag = established_paiza_system
        }   
    }

    is_valid = {
        domicile ?= {
            has_domicile_building_or_higher = trade_yurt_01
        }
        gold >= 400
    }

    is_valid_showing_failures_only = {
        custom_tooltip = {
            text = mpo_call_for_merchants_decision.robbed_merchants
            NOT = {
                has_character_modifier = mpo_paiza_robbed_merchants
            }
        }
        
    }

    cost = {
        prestige = {
            value = major_prestige_value
        }
    }

    cooldown = { years = 8 }

    effect = {
        trigger_event = mpo_decisions_events.2139
        custom_tooltip = mpo_call_for_merchants_decision.merchant_will_arrive_smol
        custom_tooltip = mpo_call_for_merchants_decision.gold_needed_smol
        custom_tooltip = mpo_call_for_merchants_decision.buildings
    }
	
	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 100
		kingdom = 100
		empire = 100
		hegemony = 100
	}

    ai_will_do = {
        base = 0
        modifier = {
            add = 4
            domicile ?= {
                has_domicile_building_or_higher = merchant_yurt_01
            }
        }
        modifier = {
            add = 4
            domicile ?= {
                has_domicile_building_or_higher = herd_trade_yurt_01
            }
        }
        modifier = {
            add = 4
            domicile ?= {
                has_domicile_building_or_higher = fertility_trade_yurt_01
            }
        }       
        modifier = {
            add = 4
            domicile ?= {
                has_domicile_building_or_higher = knight_trade_yurt_01
            }
        }
        modifier = {
            add = 20
            gold >= 1200
        }
    }

    ai_potential = {
        is_at_war = no
        ai_greed >= medium_positive_ai_value
    }
}

### Abuse Gurkhan's Authority ###
mpo_abuse_authority_paiza_decision = {
    picture = {
        reference = "gfx/interface/illustrations/event_scenes/mpo_camp_steppe.dds"
    }

    decision_group_type = nomad_major
    sort_order = 80

    is_shown = {
		has_mpo_dlc_trigger = yes
        is_imprisoned = no
        any_character_artifact = {
            root = { can_benefit_from_artifact = prev }
            exists = var:paiza_patron 
            NOT = {
                root = var:paiza_patron
                var:paiza_patron = {
                    is_at_war_with = root
                }
            }                    
        }
    }

    is_valid = {
        prestige_level >= 2
        trigger_if = {
            limit = {
                has_character_flag = no_more_paiza_abuse
            }
            custom_tooltip = {
                text = mpo_abuse_authority_paiza_decision.no_more_paiza_abuse
                NOT = {
                    has_character_flag = no_more_paiza_abuse
                }
            }
        }      
    }

    is_valid_showing_failures_only = {
        custom_tooltip = {
            text = mpo_abuse_authority_paiza_decision.paiza_patron_not_topdog
            any_character_artifact = {
                root = { can_benefit_from_artifact = prev }
                exists = var:paiza_patron
                var:paiza_patron ?= {
                    is_gurkhan = yes
                }    
            }
        }
        custom_tooltip = {
            text = mpo_abuse_authority_paiza_decision.nothing_to_abuse
            location ?= {
                duchy ?= {
                    any_de_jure_county = {
                        county_ready_for_abuse_trigger = yes             
                    }
                }
            }
        }
    }

    effect = {
        trigger_event = mpo_decisions_events.0110
        show_as_tooltip = {
            mpo_abuse_authority_county_effect = yes
            random_character_artifact = {
                limit = {
                    root = { can_benefit_from_artifact = prev }
                    exists = var:paiza_patron
                }        
                var:paiza_patron ?= {
                    save_temporary_scope_as = paiza_patron
                }
                root = {
                    mpo_paiza_abuse_counter_effect = {
                        PAIZA_PATRON = scope:paiza_patron
                        PAIZA_ABUSER = root
                    }
                }   
            }       
        }
    }

    cooldown = { years = 2 }

    cost = {
        prestige = {
            value = major_prestige_value
        }
    }

	ai_check_interval_by_tier = {
		barony = 0
		county = 100
		duchy = 10
		kingdom = 10
		empire = 10
		hegemony = 10
	}

    ai_will_do = {
        base = -20

        modifier = {
            add = 10
            has_trait = greedy
        }
        modifier = {
            add = 10
            has_trait = wrathful
        }
        modifier = {
            add = 10
            has_trait = ambitious
        }
        modifier = {
            add = {
                value = max_herd
                subtract = herd
                divide = max_herd
                multiply = 20
            }
            domicile ?= {
                herd <= max_herd
            }
        }

        modifier = {
            add = -25
            var:paiza_patron ?= {
                domicile ?= { has_domicile_parameter = nomad_yurt_paiza_abuse_less_likely_lvl_3 }
            }
        }

        modifier = {
            add = -15
            var:paiza_patron ?= {
                domicile ?= { has_domicile_parameter = nomad_yurt_paiza_abuse_less_likely_lvl_2 }
            }
        }

        modifier = {
            add = -10
            var:paiza_patron ?= {
                domicile ?= { has_domicile_parameter = nomad_yurt_paiza_abuse_less_likely_lvl_1 }
            }
        }
    }
}

