public override void Process(Action _action, Track _track, int _localTime)
        {
            base.Process(_action, _track, _localTime);
            if (!this.triggerActor || !this.targetActor || (this.moveSpeed == 0 && this.acceleration == 0))
            {
                return;
            }
            if (this.done_)
            {
                return;
            }
            VInt3 location = this.triggerActor.get_handle().location;
            VInt3 vInt     = this.targetActor.get_handle().location;
            int   num      = _localTime - this.lastTime_;

            this.lastTime_ = _localTime;
            VInt3 vInt2 = vInt - location;
            long  num2  = (long)this.curSpeed * (long)num + (long)this.acceleration * (long)num * (long)num / 2L / 1000L;

            this.curSpeed     = Mathf.Min(this.curSpeed + this.acceleration * num / 1000, this.maxMoveSpeed);
            this.curLerpSpeed = this.curSpeed;
            num2 /= 1000L;
            if (num2 >= (long)(vInt2.get_magnitude() - this.lastDistance))
            {
                num2       = (long)Mathf.Max(vInt2.get_magnitude() - this.lastDistance, 0);
                this.done_ = true;
                vInt       = location + vInt2.NormalizeTo((int)num2);
                if (!PathfindingUtility.IsValidTarget(this.triggerActor.get_handle(), vInt))
                {
                    bool  flag  = false;
                    VInt3 vInt3 = PathfindingUtility.FindValidTarget(this.triggerActor.get_handle(), vInt, this.triggerActor.get_handle().location, 10000, out flag);
                    VInt  vInt4 = 0;
                    PathfindingUtility.GetGroundY(vInt3, out vInt4);
                    vInt3.y = vInt4.i;
                    vInt    = vInt3;
                    vInt2   = vInt - this.triggerActor.get_handle().location;
                    num2    = (long)vInt2.get_magnitude();
                }
            }
            this.dir = vInt2;
            if (vInt2 != VInt3.zero)
            {
                this.triggerActor.get_handle().rotation = Quaternion.LookRotation((Vector3)vInt2);
            }
            this.triggerActor.get_handle().location += vInt2.NormalizeTo((int)num2);
        }
        private bool TargetMoveDirectionFilter(ref PoolObjHandle <ActorRoot> soucreActor, ref PoolObjHandle <ActorRoot> targetActor)
        {
            if (!this.bFilterMoveDirection || !soucreActor || !targetActor || this.Angle <= 0)
            {
                return(false);
            }
            VInt3 vInt    = soucreActor.get_handle().location - targetActor.get_handle().location;
            VInt3 forward = targetActor.get_handle().forward;

            if (vInt.get_magnitude() == 0 || forward.get_magnitude() == 0)
            {
                return(false);
            }
            VFactor vFactor  = VInt3.AngleInt(vInt, forward);
            VFactor vFactor2 = VFactor.pi * (long)(this.Angle / 2) / 180L;

            return(vFactor > vFactor2);
        }
示例#3
0
    private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result, bool checkAnotherEdge = true)
    {
        DebugHelper.Assert(edge >= 0 && edge <= 2);
        VInt3 vertex  = node.GetVertex(edge);
        VInt3 vertex2 = node.GetVertex((edge + 1) % 3);
        VInt3 vInt    = destLoc - srcLoc;

        vInt.y = 0;
        VInt3 vInt2 = vertex2 - vertex;

        vInt2.y = 0;
        vInt2.NormalizeTo(1000);
        int num;

        if (state != null)
        {
            num = vInt.get_magnitude2D() * 1000;
            VInt3 vInt3 = (!state.enabled) ? vInt : state.firstAdjDir;
            if (VInt3.Dot(ref vInt2, ref vInt3) < 0)
            {
                num   = -num;
                vInt3 = -vInt2;
            }
            else
            {
                vInt3 = vInt2;
            }
            if (!state.enabled)
            {
                state.enabled     = true;
                state.firstAdjDir = VInt3.Lerp(vInt, vInt3, 1, 3);
                state.firstDir    = state.curDir;
                state.adjDir      = vInt3;
            }
            else if (VInt3.Dot(ref state.adjDir, ref vInt3) >= 0)
            {
                state.adjDir = vInt3;
            }
            else
            {
                num = 0;
            }
            state.applied = true;
        }
        else
        {
            num = vInt2.x * vInt.x + vInt2.z * vInt.z;
        }
        bool  flag;
        VInt3 vInt4 = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, ref flag);

        if (!flag)
        {
            if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc))
            {
                result = srcLoc;
                return;
            }
            if (num >= 0)
            {
                int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z);
                int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z);
                vInt4 = ((num2 <= num3) ? vertex2 : destLoc);
                DebugHelper.Assert(num2 >= 0 && num3 >= 0);
            }
            else
            {
                int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z);
                int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z);
                vInt4 = ((Mathf.Abs(num4) <= Mathf.Abs(num5)) ? vertex : destLoc);
                DebugHelper.Assert(num4 >= 0 && num5 >= 0);
            }
        }
        int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(vInt4) * 1000000L);
        int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(vInt4) * 1000000L);

        if (num >= num6 && num <= num7)
        {
            result = IntMath.Divide(vInt2, (long)num, 1000000L) + vInt4;
            if (!node.ContainsPoint(result))
            {
                Vector3 vector = (Vector3)(vertex2 - vertex);
                vector.y = 0f;
                vector.Normalize();
                VInt3 vInt5 = vertex2 - vertex;
                vInt5.y = 0;
                vInt5  *= 10000;
                long    num8    = (long)vInt5.get_magnitude();
                VFactor vFactor = default(VFactor);
                vFactor.nom = (long)num;
                vFactor.den = num8 * 1000L;
                int num9;
                int num10;
                PathfindingUtility.getMinMax(out num9, out num10, (long)vInt5.x, ref vFactor);
                int num11;
                int num12;
                PathfindingUtility.getMinMax(out num11, out num12, (long)vInt5.z, ref vFactor);
                if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc))
                {
                    result = srcLoc;
                }
            }
            if (PathfindingUtility.MoveAxisY)
            {
                PathfindingUtility.CalculateY(ref result, node);
            }
        }
        else
        {
            int   num13;
            int   num14;
            VInt3 vInt6;
            if (num < num6)
            {
                num13 = num - num6;
                num14 = (edge + 2) % 3;
                vInt6 = vertex;
            }
            else
            {
                num13 = num - num7;
                num14 = (edge + 1) % 3;
                vInt6 = vertex2;
            }
            VInt3            vInt7 = vInt2 * num13 / 1000000f;
            int              startEdge;
            TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num14, ref startEdge);
            if (neighborByEdge != null)
            {
                PathfindingUtility.checkedNodes.Add(node);
                PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt6, vInt7 + vInt6, state, out result);
            }
            else
            {
                if (checkAnotherEdge)
                {
                    VInt3 vertex3 = node.GetVertex((edge + 2) % 3);
                    VInt3 vInt8   = (vertex3 - vInt6).NormalizeTo(1000);
                    if (VInt3.Dot(vInt8, vInt7) > 0)
                    {
                        PathfindingUtility.checkedNodes.Add(node);
                        PathfindingUtility.MoveAlongEdge(node, num14, vInt6, vInt7 + vInt6, state, out result, false);
                        return;
                    }
                }
                result = vInt6;
            }
        }
    }