############################################################
##          Elite Recruitment Chancellor Helpers          ##
############################################################
##                                                        ##
## Chancellor helper effects to add flavor to the Elite   ##
## Recruitment mod.                                       ##
##                                                        ##
############################################################

# Create male chancellor in your culture and religion with dynasty lottery
create_male_chancellor_dynasty_lottery_effect = {
  random_list = {
    # New random house
    33 = { create_random_diplomat = {
      dynasty = random
      female = no
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }

    # Lowborn
    33 = { create_random_diplomat = {
      dynasty = none
      female = no
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }

    # Random existing house matching your culture
    33 = { create_random_diplomat = {
      dynasty = actually_culture
      female = no
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }
  }
}

# Create female chancellor in your culture and religion with dynasty lottery
create_female_chancellor_dynasty_lottery_effect = {
  random_list = {
    # New random house
    33 = { create_random_diplomat = {
      dynasty = random
      female = yes
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }

    # Lowborn
    33 = { create_random_diplomat = {
      dynasty = none
      female = yes
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }

    # Random existing house matching your culture
    33 = { create_random_diplomat = {
      dynasty = actually_culture
      female = yes
      random_traits = yes
      age = 16
      religion = ROOT
      culture = ROOT
    } }
  }
}

# Assign the base chancellor attributes to the base character
assign_chancellor_base_attributes_effect = {
  change_diplomacy = 12
  change_learning = 4
  change_stewardship = 4
  change_intrigue = 4
  change_martial = 4
}

# Assign the chancellor traits to the base character (orchestrator)
assign_chancellor_traits_effect = {
  remove_chancellor_negative_traits_effect = yes
  set_elite_chancellor_education_effect = yes
  assign_chancellor_flavor_effect = yes
  assign_religion_traits_effect = yes

  set_character_flag = elite_recruit_chancellor
  save_event_target_as = invited_character
}

# Remove social and physical drawbacks unbecoming of an elite chancellor. An envoy is the
# realm's face abroad, so frailty, cowardice, and abrasive or off-putting manners are
# stripped (the imposing giant is the one deliberate exception below).
remove_chancellor_negative_traits_effect = {
  # Incompetence / frailty
  remove_trait = weak
  remove_trait = slow
  remove_trait = imbecile
  remove_trait = dull
  remove_trait = inbred
  remove_trait = dwarf
  # giant not stripped -- net-positive opinion for an envoy
  remove_trait = hunchback
  remove_trait = clubfooted
  remove_trait = craven
  remove_trait = paranoid

  # Speech defects -- an envoy is the realm's voice
  remove_trait = harelip
  remove_trait = lisp
  remove_trait = stutter

  # Off-putting manners, unbecoming of a diplomat
  remove_trait = shy
  remove_trait = cruel
  remove_trait = envious
  remove_trait = slothful

  remove_lifestyle_trait_effect = yes
}

# Guaranteed top diplomacy education
set_elite_chancellor_education_effect = {
  clear_education_trait = yes
  add_trait = grey_eminence
}

# Weighted "flavor" roll: usually a small, fitting bonus, rarely something bigger
assign_chancellor_flavor_effect = {
  random_list = {
    5 = {
      add_trait = shrewd
    }
    5 = {
      add_trait = quick
    }
    20 = {
      assign_elite_beauty_trait_effect = yes
    }
    20 = {
      change_diplomacy = 2
    }
    10 = {
      change_diplomacy = 4
    }
    10 = {
      add_trait = gregarious
    }
    10 = {
      add_trait = socializer
    }
    10 = {
      add_trait = kind
    }
    5 = {
      add_trait = honest
    }
    5 = {
      add_trait = genius
    }
  }
}
