namespace = TUTOSOCI

########################JOINING############################

#From on_character_ask_to_join_society
character_event = {
    id = TUTOSOCI.100
	hide_window = yes
    is_triggered_only = yes
    trigger = {
    	FROM = { leader = { society_member_of = tutorial_society } }
    }
    immediate = {
    	FROM = { leader = { character_event = { id = TUTOSOCI.101 } } } #target is the leader of the society
    }
}

#Ping event
character_event = {
    id = TUTOSOCI.101
	hide_window = yes
    is_triggered_only = yes
    immediate = {
    	FROM = { letter_event = { id = TUTOSOCI.102 } } #send event back 
    }
}

#Welcome letter
letter_event = {
    id = TUTOSOCI.102
    desc = EVTDESC_TUTOSOCI_102
    border = GFX_event_letter_frame_war
	
    is_triggered_only = yes

    option = { #join the society
        name = EVTOPTA_TUTOSOCI_102
		FROM = { ROOT = { join_prev_tutorial_society_society = yes } } #call the scripted_effect to join the society you requested. (see tutorial_society_scripted_effects.txt)
		
		#you can make it simplier with this and not use the scripted_effect:
		
		# join_society = tutorial_society
    }
    option = { #don't
        name = EVTOPTB_TUTOSOCI_102
    }
}

########################AI JOIN AND AI RANK UP###########################

character_event = { #force the AI to join a society
	id = TUTOSOCI.110
	hide_window = yes
	
	only_rulers = yes #leave that unless you want random courtiers in the society
	is_triggered_only = yes
	
	immediate = {
		if = {
			limit = { #if he's already a member, will force a rank up 25% of the time
				ai = yes
				prisoner = no
				NOT = { trait = incapable }
				society_member_of = tutorial_society
				society_rank <= 3
				society_can_rank_up = yes
			}
			random_list = {
				75 = {}
				25 = {
					society_rank_up = 1					
				}
			}
		}
		# any_courtier = {  #if you want courtier in the society enable this part
			# limit = {
				# ai = yes
				# prisoner = no
				# NOT = { trait = incapable }
				# is_adult = yes
				# is_in_society = no
				# controls_religion = no
				# block_general_event_trigger = no
			# }
			# character_event = { id = TUTOSOCI.111 }
		# }
		if = { #force the joining event on AI
			limit = {
				ai = yes
				prisoner = no
				NOT = { trait = incapable }
				is_adult = yes
				is_in_society = no
				controls_religion = no
				block_general_event_trigger = no
			}
			character_event = { id = TUTOSOCI.111 }
		}
	}
}

character_event = { #AI join event
	id = TUTOSOCI.111
	hide_window = yes
	
	is_triggered_only = yes
	
	immediate = {
		random_list = {
			90 = { # do nothing
			}
			10 = { # try to join a society 10% of the time
				trigger = { #meet the requirement
					can_join_society = tutorial_society
				}
				modifier = { #things that will make that 10% of the time bigger, can be anything 
					factor = 2
					prestige = 200
				}
				join_society = tutorial_society #join the society
				random_list = { # Artificially increase society influence for balance purposes, not really useful in my opinion.
					75 = {
						modifier = {
							factor = 0
							society_influence >= 30
						}
						add_society_modifier = 	{ 
							modifier = tutorial_successful_mission
							years = 10
						}
					}
					25 = {
					}
				}
				if = { # Make grandmaster is there is none
					limit = {
						NOT = {
							society = {
								any_society_member = {
									is_society_grandmaster = yes
								}
							}
						}
					}
					set_society_grandmaster = yes
				}
			}
		}
	}
}

#######################Rank UP#############################

# Hidden start: Send the rank-up request to the current Grandmaster (delayed event on self, from decision to rank up)
character_event = {
	id = TUTOSOCI.120

	hide_window = yes

	trigger = { #has pressed the button
		has_character_flag = has_sent_request_to_rank_up
	}
	
	is_triggered_only = yes

	immediate = {
		if = { #if he's still a member
			limit = { is_in_society = yes }
			random_society_member = { #will send the request to a random top rank member of the same society
				limit = {
					is_society_grandmaster = yes
					same_society_as = ROOT
				}
				character_event = { id = TUTOSOCI.121 } # send request to Grand Master.
			}
		}
		if = { #if he's not a member
			limit = { is_in_society = no }
			clr_character_flag = has_sent_request_to_rank_up
		}
	}
}

# Grandmaster gets the rank-up request
character_event = {
	id = TUTOSOCI.121
	
	hide_window = yes

	is_triggered_only = yes

	immediate = {
		event_target:rank_up_target = { letter_event = { id = TUTOSOCI.122 } } #send it back
	}
}

#Grand master approves my request
letter_event = {
	id = TUTOSOCI.122
	desc = EVTDESC_TUTOSOCI_122
	border = GFX_event_letter_frame_war

	trigger = {
		society_rank < 4 #cannot rank up past 4
		has_character_flag = has_sent_request_to_rank_up
	}
	
	is_triggered_only = yes

	#Rank up approved
	option = {
		name = EVTOPTA_TUTOSOCI_122
		if = { limit = { society_rank < 4 } #if not max rank, rank up
			society_rank_up = 1
		}
		clr_character_flag = has_sent_request_to_rank_up
	}
}

#################################MISSIONS######################################

#Mission tombola, this is where an hidden event choose a quest. I have made only one quest, do look for other mission tombola in the vanilla files for more example.
character_event = {
    id = TUTOSOCI.130
    hide_window = yes

    is_triggered_only = yes
    
	is_in_society = yes

	trigger = {
		society_member_of = tutorial_society
		has_any_quest = no #cannot have more than 1 shown
		NOT = { has_character_modifier = quest_cooldown_timer } #to avoid spam and delay it for people who refused a quest.
		NOT = { is_inaccessible_trigger = yes }
		prisoner = no
		society = { #look if there is a close member to give you the quest
			any_society_member = {
				NOT = { character = ROOT }
				prisoner = no
				is_within_diplo_range = ROOT
				opinion = { who = ROOT value = 0 }
			}
		}
	}

    immediate = {
    	#Picks out mission giver
    	random_list = {
    		20 = { #International society member
    			society = {
    				random_society_member = {
    					limit = { 	
							NOT = { character = ROOT }
							prisoner = no
    						is_within_diplo_range = ROOT
							opinion = { who = ROOT value = 0 }
    					}
    					save_event_target_as = quest_collaborator
    				}
    			}
    		}
    		40 = { #Realm society member is there is any
    			trigger = {
    				society = {
    					any_society_member = {
    						NOT = { character = ROOT }
    						prisoner = no
    						is_within_diplo_range = ROOT
							opinion = { who = ROOT value = 0 }
							same_realm = ROOT
    					}
    				}
    			}
    			society = {
    				random_society_member = {
    					limit = { 	
    						NOT = { character = ROOT }
    						prisoner = no
    						is_within_diplo_range = ROOT
							opinion = { who = ROOT value = 0 }
							same_realm = ROOT
    					}
    					save_event_target_as = quest_collaborator
    				}
    			}
    		}
    	}

    	#Randomizes mission
		#Has I have only 1 mission this random_list is unnecessary, but you will need it if you make more than one mission.
    	random_list = {
			100 = { #press the button, the mission
				event_target:quest_collaborator = { character_event = { id = TUTOSOCI.140 days = 7 random = 7 } } #will send the quest to the quest_collaborator, which will offer it back to you.
			}
			
			50 = { # AI bypasses missions at times and goes directly to success/failure, increase the 50% if you add more mission to balance or you could delete this whole { } if you want the AI to do real missions
				modifier = {
					factor = 0
					ai = no
				}
				random_list = {
					70 = { #success, harder the more influencial the society is
						modifier = {
							factor = 0.9
							society_influence >= 30
						}
						modifier = {
							factor = 0.9
							society_influence >= 40
						}
						modifier = {
							factor = 0.8
							society_influence >= 50
						}
						modifier = {
							factor = 0.7
							society_influence >= 70
						}
						modifier = {
							factor = 0.6
							society_influence >= 80
						}
						modifier = {
							factor = 0.5
							society_influence >= 90
						}
						add_society_modifier = 	{
							modifier = tutorial_successful_mission
							years = 10
						}
					}
					30 = { #failure
						add_society_modifier = 	{
							modifier = tutorial_failed_mission
							years = 10
						}
					}
				}
			}
			
			100 = { #AI refuse mission
				modifier = {
					factor = 0
					ai = no
				}
			}
    	}
    }
}

#This is the quest_collaborator receiving the mission and giving it back to you.
character_event = {
    id = TUTOSOCI.140
    hide_window = yes #instant event, no need to show it
    is_triggered_only = yes
    immediate = { FROM = { society_quest_event = { id = TUTOSOCI.141 days = 7 random = 7 } } }
}

#This event is set as a society_quest_event, not character_event. This is the accept or refuse the quest event, the next parts of the quest use the regular character_event.
society_quest_event = {
    id = TUTOSOCI.141
    desc = EVTDESC_TUTOSOCI_141

    is_triggered_only = yes
   
    option = { 
		name = ACCEPT

		set_quest = quest_tutorial_quest_1 #use this if the quest has no real target, look at other quests made by Paradox if you want something more complicated that target someone/something

	}

	option = {
		name = DECLINE
		custom_tooltip = { text = decline_quest_tooltip }

		add_character_modifier = { #will delay the next quest for a while
			name = quest_cooldown_timer
			hidden = yes
			days = 1000
		}

		ai_chance = { factor = 0 }
	}
}

#Training quest, start of the flavor event chain, the quest_collaborator/training_partner receive from the decision
character_event = {
    id = TUTOSOCI.142
    desc = EVTDESC_TUTOSOCI_142
    picture = GFX_evt_throne_room
    border = GFX_event_normal_frame_war

    is_triggered_only = yes

    option = { #Quest will success
        name = EVTOPTA_TUTOSOCI_142
		
		clr_quest = quest_tutorial_quest_1 #remove the quest
		# add_mission_succeed_influence_effect = yes #quest add society influence
		
		#I prefer to directly use the modifiers instead of using "add_mission_succeed_influence_effect = yes", specially if you try to balance the influence given by the event MNM.6666 that flood your society with mission success.
		add_society_modifier = 	{
			modifier = tutorial_successful_mission #this is not the vanilla modifier, I prefer the controle of making my owns
			years = 10
		}
		change_society_currency = 100 #reward
    }
    option = { #Quest will failed
        name = EVTOPTB_TUTOSOCI_142
		
		clr_quest = quest_tutorial_quest_1 #remove the quest
		# add_mission_fail_influence_effect = yes #quest remove society influence
		add_society_modifier = 	{
			modifier = tutorial_failed_mission #this is not the vanilla modifier, I prefer the controle of making my owns
			years = 10
		}
		change_society_currency = -100 #penalty
    }
}

#Society only quest that trigger every 2 years
character_event = {
    id = TUTOSOCI.150
    desc = EVTDESC_TUTOSOCI_150
    picture = GFX_evt_throne_room
    border = GFX_event_normal_frame_war

    is_triggered_only = yes

	trigger = {
		society_member_of = tutorial_society #Use this to limit events and decisions to your society with trigger
		#you can also use this scripted_trigger to check several societies if you made one. (see tutorial_society_scripted_triggers.txt)
		#	is_tutorial_society_trigger = yes 
	}
	
    option = {
        name = EVTOPTA_TUTOSOCI_150
    }
    option = {
        name = EVTOPTB_TUTOSOCI_150
    }
}