Beispiel #1
0
        internal void CheckAutoTarget(BaseUnityPlugin plugin)
        {
            if (controllerOptions.danAutoTarget == ControllerOptions.AutoTarget.Off || !danTargetsValid)
            {
                return;
            }

            string targetTransform = BoneNames.BPKokanTarget;

            if (controllerOptions.danAutoTarget == ControllerOptions.AutoTarget.Oral)
            {
                targetTransform = BoneNames.HeadTarget;
            }
            else if (controllerOptions.danAutoTarget == ControllerOptions.AutoTarget.Anal)
            {
                targetTransform = BoneNames.AnaTarget;
            }

            var potentialTargets = FindObjectsOfType <Transform>().Where(x => x.name.Equals(targetTransform));

            if (potentialTargets == null)
            {
                return;
            }

            Transform autoTarget            = null;
            float     currentTargetDistance = danAgent.m_baseDanLength * 2.0f;

            foreach (var potentialTarget in potentialTargets)
            {
                if (potentialTarget.GetComponentInParent <ChaControl>() == danAgent.m_danCharacter)
                {
                    continue;
                }

                var potentialTargetDistance = Vector3.Distance(danAgent.m_danPoints.GetDanEndPosition(), potentialTarget.position);

                if (potentialTargetDistance >= currentTargetDistance)
                {
                    continue;
                }

                autoTarget            = potentialTarget;
                currentTargetDistance = potentialTargetDistance;
            }

            if (autoTarget == null)
            {
                return;
            }

            var collisionAgent = autoTarget.GetComponentInParent <ChaControl>();

            if (danEntryConstraint != null && danEntryConstraint.GetValue(1) != null &&
                danEntryConstraint.GetValue(1).ToString() == autoTarget.name &&
                collisionAgent == this.collisionAgent?.m_collisionCharacter)
            {
                return;
            }

            RemoveDanConstraints(plugin);
            RemoveCollisionAgent(isKokan, isAna);

            Transform danEntryParent = autoTarget;

            danEntryParentName = autoTarget.name;
            isKokan            = danEntryParentName.Contains("V****a");
            isAna  = danEntryParentName.Contains("Ana");
            isOral = danEntryParentName.Contains("Mouth");

            SetCollisionAgent(collisionAgent, isKokan, isAna, isOral);

#if AI || HS2
            Vector3 headOffset = new Vector3(0f, -0.05f, 0.02f);
#else
            Vector3 headOffset = new Vector3(0f, -0.01f, 0f);
#endif

            danEntryConstraint = new object[] {
                true,
                danEntryParent,
                danEntryChild,
                true,
                (danEntryParentName == BoneNames.HeadTarget)? headOffset: Vector3.zero,
                false,
                Quaternion.identity,
                false,
                Vector3.zero,
                $"{danAgent.m_danCharacter.fileParam.fullname} Penis First Target"
            };

            Transform danEndParent;
            if (danEntryParentName == BoneNames.HeadTarget)
            {
                danEndParent = Tools.GetTransformOfChaControl(collisionAgent, BoneNames.InnerHeadTarget);
            }
            else
            {
                danEndParent = Tools.GetTransformOfChaControl(collisionAgent, BoneNames.InnerTarget);
            }

            danEndParentName = danEndParent.name;

            danEndConstraint = new object[] {
                true,
                danEndParent,
                danEndChild,
                true,
                Vector3.zero,
                false,
                Quaternion.identity,
                false,
                Vector3.zero,
                $"{danAgent.m_danCharacter.fileParam.fullname} Penis Second Target"
            };

            AddDanConstraints(plugin, danEntryParent, danEndParent);
        }