﻿work_maintenance_pulse = {
	trigger = {
	  OR = {
			has_character_modifier = shop_assistant_modifier
			has_character_modifier = shop_keeper_modifier
			has_character_modifier = janitor_modifier
			has_character_modifier = royal_custodian_modifier
			has_character_modifier = beggar_modifier
			has_character_modifier = thief_modifier
		}
	}
	on_actions = {
		# Set up pulses with a consistent 120-day interval
		delay = { days = 120 }
		work_pulse
		delay = { days = 240 }
		work_pulse
		delay = { days = 360 }
		work_pulse
		delay = { days = 480 }
		work_pulse
	}
}

 
work_pulse = {
	trigger = {
		OR = {
			has_character_modifier = shop_assistant_modifier
			has_character_modifier = shop_keeper_modifier
			has_character_modifier = janitor_modifier
			has_character_modifier = royal_custodian_modifier
			has_character_modifier = beggar_modifier
			has_character_modifier = thief_modifier
		}
	}
	effect = {
		# Initialize total gold
		set_variable = {
			name = total_salary
			value = 0  
		}
		if = { limit = { NOT = { has_variable = shop_exp } } set_variable = { name = shop_exp value = 0 } }
		if = { limit = { NOT = { has_variable = janitor_exp } } set_variable = { name = janitor_exp value = 0 } }
		if = { limit = { NOT = { has_variable = beggar_exp } } set_variable = { name = beggar_exp value = 0 } }
		
		# Initialize job modifier variable

		# Check for each modifier and adjust total gold accordingly
		if = {
			limit = { has_character_modifier = shop_assistant_modifier }
			change_variable = {
				name = total_salary
				add = 1  # Add gold for shop assistant
			}
			change_variable = { name = shop_exp add = 50 }
		}
		if = {
			limit = { has_character_modifier = shop_keeper_modifier }
			change_variable = {
				name = total_salary
				add = 2  # Add gold for shop keeper
			}
		}
		if = {
			limit = { has_character_modifier = janitor_modifier }
			change_variable = {
				name = total_salary
				add = 1  # Add gold for janitor
			}
			change_variable = { name = janitor_exp add = 50 }
		}
		if = {
			limit = { has_character_modifier = royal_custodian_modifier }
			change_variable = {
				name = total_salary
				add = 2  # Add gold for royal custodian
			}
		}
		if = {
			limit = { has_character_modifier = beggar_modifier } # Beggar gets a random amount of gold
			random_list = {
				20 = { save_scope_value_as = { name = random_gold value = 1 } }  
				30 = { save_scope_value_as = { name = random_gold value = 2 } }   
				10 = { save_scope_value_as = { name = random_gold value = 3 } }   
			}
			change_variable = {
				name = total_salary
				add = scope:random_gold  # Add random gold to total
			}
			change_variable = { name = beggar_exp add = 50 }
		}
		if = {
			limit = { has_character_modifier = thief_modifier } # Thief can get random gold or get imprisoned
			random_list = {
				20 = { save_scope_value_as = { name = random_gold2 value = 2 } }  
				30 = { save_scope_value_as = { name = random_gold2 value = 5 } }  
				10 = { save_scope_value_as = { name = random_gold2 value = 10 } }  
				5 = { trigger_event = rtr.0006 }				
			}
			change_variable = {
				name = total_salary
				add = scope:random_gold2  # Add random gold to total
			}
		}
		if = {
			limit = { has_character_modifier = priviliged_peasants_modifier }
			change_variable = {
				name = total_salary
				add = 4  # Add gold for privilieged peasants
			}
		}

		# Now add total gold to the character
		add_gold = var:total_salary

		# Only send message if you actually made any money
		if = {
			limit = { var:total_salary > 0 }  
			send_interface_toast = {
				title = work_title
				custom_tooltip = work_tooltip
			}
		}
	}
		random_events = { # Oppressed modifier events + others
		 chance_to_happen = 50
		 80 = 0
		 20 = rtr.0017 # Populist oppression
		 20 = rtr.0018 # Peasant oppresssion
		 20 = rtr.0011
	    }
	on_actions = { promotion_on_action }
}
