5 using System.Collections.Generic;
6 using System.Collections.Immutable;
11 internal sealed
class CharacterAbilityUnlockApprenticeshipTalentTree : CharacterAbility
13 public override bool AllowClientSimulation =>
false;
15 public CharacterAbilityUnlockApprenticeshipTalentTree(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement) { }
17 public override void InitializeAbility(
bool addingFirstTime)
19 if (!addingFirstTime) {
return; }
22 if (GameMain.NetworkMember is { IsClient: true }) {
return; }
24 JobPrefab? apprentice = CharacterAbilityApplyStatusEffectsToApprenticeship.GetApprenticeJob(Character, JobPrefab.Prefabs.ToImmutableHashSet());
25 if (apprentice is
null)
27 DebugConsole.ThrowError($
"{nameof(CharacterAbilityUnlockApprenticeshipTalentTree)}: Could not find apprentice job for character {Character.Name}",
32 if (!TalentTree.JobTalentTrees.TryGet(apprentice.Identifier, out TalentTree? talentTree)) {
return; }
36 HashSet<ImmutableHashSet<Identifier>> talentsTrees =
new HashSet<ImmutableHashSet<Identifier>>();
37 foreach (TalentSubTree subTree
in talentTree.TalentSubTrees)
39 if (subTree.Type != TalentTreeType.Specialization) {
continue; }
41 HashSet<Identifier> identifiers =
new HashSet<Identifier>();
42 foreach (TalentOption option
in subTree.TalentOptionStages)
44 foreach (Identifier identifier
in option.TalentIdentifiers)
46 if (IsShowCaseTalent(identifier, option) || TalentTree.IsTalentLocked(identifier, characters)) {
continue; }
48 identifiers.Add(identifier);
51 foreach (var (_, value) in option.ShowCaseTalents)
53 var ids = value.Where(i => !TalentTree.IsTalentLocked(i, characters)).ToImmutableHashSet();
54 if (ids.Count is 0) {
continue; }
56 identifiers.Add(value.GetRandomUnsynced());
60 talentsTrees.Add(identifiers.ToImmutableHashSet());
63 ImmutableHashSet<Identifier>? selectedTalentTree = talentsTrees.GetRandomUnsynced();
64 if (selectedTalentTree !=
null)
66 foreach (Identifier identifier
in selectedTalentTree)
73 static bool IsShowCaseTalent(Identifier identifier, TalentOption option)
75 foreach (var (_, value) in option.ShowCaseTalents)
77 if (value.Contains(identifier)) {
return true; }
84 protected override void ApplyEffect(AbilityObject abilityObject)
CharacterTalent CharacterTalent
virtual void ApplyEffect()
static IEnumerable< Character > GetFriendlyCrew(Character character)
bool HasTalent(Identifier identifier)
bool GiveTalent(Identifier talentIdentifier, bool addingFirstTime=true)
readonly TalentPrefab Prefab
ContentPackage? ContentPackage