auto_repair = {
    if = {
        limit = {
            OR = {
                exists = global_var:am_automation_repair_common
                exists = global_var:am_automation_repair_masterwork
                exists = global_var:am_automation_repair_famed
                exists = global_var:am_automation_repair_illustrious
            }
        }

		every_character_artifact = {
			limit = {
                OR = {
                    AND = {
                        rarity = common
                        exists = global_var:am_automation_repair_common
                    }
                    AND = {
                        rarity = masterwork
                        exists = global_var:am_automation_repair_masterwork
                    }
                    AND = {
                        rarity = famed
                        exists = global_var:am_automation_repair_famed
                    }
                    AND = {
                        rarity = illustrious
                        exists = global_var:am_automation_repair_illustrious
                    }
                }
			}
			save_scope_as = this_artifact
			if = { 
				limit ={
					exists = artifact_market_value
				}
				root = {
					remove_short_term_gold = {
						value = scope:this_artifact.repair_artifact_cost
					}
				}
			}
			else = {
				root = {
					remove_short_term_gold = {
						value = scope:this_artifact.artifact_wealth_quality_average_value
						multiply = 3.5
					}
				}
			}
            # repair this thing
            add_durability = artifact_max_durability
        }
    }
}

auto_vendor = {
    if = {
        limit = {
            OR = {
                exists = global_var:am_automation_vendor_common
                exists = global_var:am_automation_vendor_masterwork
                exists = global_var:am_automation_vendor_famed
                exists = global_var:am_automation_vendor_illustrious
            }
        }
        
		every_character_artifact = {
			limit = {
				is_equipped = no
                OR = {
                    AND = {
                        rarity = common
                        exists = global_var:am_automation_vendor_common
                    }
                    AND = {
                        rarity = masterwork
                        exists = global_var:am_automation_vendor_masterwork
                    }
                    AND = {
                        rarity = famed
                        exists = global_var:am_automation_vendor_famed
                    }
                    AND = {
                        rarity = illustrious
                        exists = global_var:am_automation_vendor_illustrious
                    }
                }
			}
			save_scope_as = this_artifact
			if = { 
				limit ={
					exists = artifact_market_value
				}
				root = {
					add_gold = {
						value = scope:this_artifact.artifact_market_value
					}
				}
			}
			else = {
				root = {
					add_gold = {
						value = scope:this_artifact.artifact_wealth_quality_average_value
						multiply = 3.5
					}
				}
			}
            destroy_artifact = scope:this_artifact
        }
    }
}