static bool Prefix(AbilityData __instance, TargetWrapper target, ref bool __result)
        {
            foreach (IAbilityTargetChecker targetChecker in __instance.Blueprint.TargetCheckers)
            {
                if (!targetChecker.CanTarget(__instance.Caster.Unit, target))
                {
                    __result = false;
                    return(false);
                }
            }

            if ((__instance.Caster.Buffs.HasFact(SharedSpells.can_only_target_self_buff) && Common.isPersonalSpell(__instance) ||
                 __instance.HasMetamagic((Metamagic)MetamagicFeats.MetamagicExtender.ImprovedSpellSharing)) &&
                target.Unit != __instance.Caster.Unit)
            {
                __result = false;
                return(false);
            }


            if (!__instance.Blueprint.CanTargetSelf && target.Unit == __instance.Caster.Unit)
            {
                __result = false;
                return(false);
            }

            if (__instance.TargetAnchor == AbilityTargetAnchor.Unit && __instance.Blueprint.Range == AbilityRange.Personal && !__instance.AlchemistInfusion)
            {//if spell was orginally personal - check validity of sharing it with target
                __result = SharedSpells.isValidShareSpellTarget(target.Unit, __instance.Caster);
                return(false);
            }

            switch (__instance.TargetAnchor)
            {
            case AbilityTargetAnchor.Owner:
                if (target.IsUnit)
                {
                    __result = target.Unit == __instance.Caster.Unit;
                }
                break;

            case AbilityTargetAnchor.Unit:
                __result = target.IsUnit && (__instance.Blueprint.CanTargetFriends || target.Unit.IsPlayerFaction || __instance.Caster.Unit.CanAttack(target.Unit));
                break;

            case AbilityTargetAnchor.Point:
                __result = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(false);
        }
        static bool Prefix(AbilityData __instance, ref AbilityTargetAnchor __result)
        {
            if ((UnityEngine.Object)__instance.SourceItemUsableBlueprint != (UnityEngine.Object)null && __instance.SourceItemUsableBlueprint.Type == UsableItemType.Potion && !__instance.PotionForOther || __instance.IsAlchemistSpell && !__instance.AlchemistInfusion)
            {
                __result = AbilityTargetAnchor.Owner;
            }
            else if (__instance.Blueprint.Range == AbilityRange.Personal)
            {
                __result = __instance.AlchemistInfusion || SharedSpells.canShareSpell(__instance) ? AbilityTargetAnchor.Unit : AbilityTargetAnchor.Owner;
            }
            else if (!__instance.Blueprint.CanTargetFriends && !__instance.Blueprint.CanTargetEnemies && !__instance.Blueprint.CanTargetPoint)
            {
                __result = __instance.AlchemistInfusion ? AbilityTargetAnchor.Unit : AbilityTargetAnchor.Owner;
            }
            else
            {
                __result = __instance.Blueprint.CanTargetPoint ? AbilityTargetAnchor.Point : AbilityTargetAnchor.Unit;
            }

            return(false);
        }