3 using System.Collections.Generic;
11 private enum WeaponType
21 private static readonly List<WeaponType> WeaponTypeValues = Enum.GetValues(typeof(WeaponType)).Cast<WeaponType>().ToList();
23 private readonly
string itemIdentifier;
24 private readonly Identifier[] tags;
25 private readonly WeaponType weapontype;
26 private readonly
bool ignoreNonHarmfulAttacks;
28 private readonly
bool ignoreOwnAttacks;
32 itemIdentifier = conditionElement.
GetAttributeString(nameof(itemIdentifier),
string.Empty);
34 ignoreNonHarmfulAttacks = conditionElement.
GetAttributeBool(nameof(ignoreNonHarmfulAttacks),
false);
35 ignoreOwnAttacks = conditionElement.
GetAttributeBool(nameof(ignoreOwnAttacks),
false);
38 if (!Enum.TryParse(weaponTypeStr, ignoreCase:
true, out weapontype))
40 DebugConsole.ThrowError($
"Error in talent \"{characterTalent.DebugIdentifier}\": \"{weaponTypeStr}\" is not a valid weapon type.",
49 if (ignoreOwnAttacks && attackData.Attacker ==
character) {
return false; }
51 if (ignoreNonHarmfulAttacks && attackData.SourceAttack !=
null)
53 if (attackData.SourceAttack.Stun <= 0.0f && (attackData.SourceAttack.Afflictions?.All(a => a.Key.Prefab.IsBuff) ??
true))
59 Item item = attackData?.SourceAttack?.SourceItem;
61 if (!
string.IsNullOrEmpty(itemIdentifier))
71 if (!tags.All(t => item?.
HasTag(t) ??
false))
77 if (weapontype != WeaponType.Any)
79 foreach (WeaponType wt
in WeaponTypeValues)
81 if (wt == WeaponType.Any || !weapontype.HasFlag(wt)) {
continue; }
84 case WeaponType.Melee:
86 if (item?.GetComponent<Projectile>() is { IsActive:
true }) {
continue; }
87 if (item?.GetComponent<MeleeWeapon>() !=
null) {
return true; }
89 case WeaponType.Ranged:
91 if (item?.GetComponent<MeleeWeapon>() is { Hitting:
true }) {
continue; }
92 if (item?.GetComponent<Projectile>() !=
null) {
return true; }
94 case WeaponType.HandheldRanged:
96 var projectile = item?.GetComponent<
Projectile>();
97 if (projectile?.Launcher?.GetComponent<Holdable>() !=
null) {
return true; }
100 case WeaponType.Turret:
102 var projectile = item?.GetComponent<
Projectile>();
103 if (projectile?.Launcher?.GetComponent<Turret>() !=
null) {
return true; }
106 case WeaponType.NoWeapon:
107 if (item ==
null) {
return true; }
AbilityConditionAttackData(CharacterTalent characterTalent, ContentXElement conditionElement)
override bool MatchesConditionSpecific(AbilityObject abilityObject)
void LogAbilityConditionError(AbilityObject abilityObject, Type expectedData)
CharacterTalent characterTalent
string? GetAttributeString(string key, string? def)
Identifier[] GetAttributeIdentifierArray(Identifier[] def, params string[] keys)
ContentPackage? ContentPackage
bool GetAttributeBool(string key, bool def)
bool HasTag(Identifier tag)
readonly Identifier Identifier