Beispiel #1
0
    protected VInt3 CaculateDir(VInt3 currentPosition)
    {
        if (this.path == null || this.path.vectorPath == null || this.path.vectorPath.get_Count() == 0)
        {
            return(VInt3.zero);
        }
        List <VInt3> vectorPath = this.path.vectorPath;

        if (vectorPath.get_Count() == 1)
        {
            vectorPath.Insert(0, currentPosition);
        }
        if (this.currentWaypointIndex >= vectorPath.get_Count())
        {
            this.currentWaypointIndex = vectorPath.get_Count() - 1;
        }
        if (this.currentWaypointIndex <= 1)
        {
            this.currentWaypointIndex = 1;
        }
        while (this.currentWaypointIndex < vectorPath.get_Count() - 1)
        {
            long num = vectorPath.get_Item(this.currentWaypointIndex).XZSqrMagnitude(currentPosition);
            if (num != 0L)
            {
                if (num < (long)this.pickNextWaypointDist * (long)this.pickNextWaypointDist)
                {
                    VInt3 vInt  = vectorPath.get_Item(this.currentWaypointIndex - 1);
                    VInt3 vInt2 = vectorPath.get_Item(this.currentWaypointIndex);
                    VInt3 vInt3 = vInt2 - vInt;
                    long  num2  = (long)vInt3.get_magnitude2D();
                    long  num3  = VInt3.DotXZLong(currentPosition - vInt, vInt3.NormalizeTo(1000));
                    if (num3 >= num2 * 1000L)
                    {
                        this.lastFoundWaypointPosition = currentPosition;
                        this.lastFoundWaypointTime     = Time.time;
                        this.currentWaypointIndex++;
                        continue;
                    }
                }
IL_184:
                this.targetPoint       = this.CalculateTargetPoint(currentPosition, vectorPath.get_Item(this.currentWaypointIndex - 1), vectorPath.get_Item(this.currentWaypointIndex));
                this.targetDirection   = this.targetPoint - currentPosition;
                this.targetDirection.y = 0;
                return(this.targetDirection.NormalizeTo(1000));
            }
            this.lastFoundWaypointPosition = currentPosition;
            this.lastFoundWaypointTime     = Time.time;
            this.currentWaypointIndex++;
        }
        goto IL_184;
    }
Beispiel #2
0
 public void Enter(Action _action)
 {
     this.skillContext = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext");
     this.lastTime     = 0;
     this.lastVelocity = (this.lastLerpVelocity = this.velocity);
     this.stopCondtion = false;
     this.moveActor    = _action.GetActorHandle(this.targetId);
     if (!this.moveActor)
     {
         return;
     }
     this.gravityControler = new AccelerateMotionControler();
     this.moveActor.get_handle().ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp));
     if (this.MoveType == ActorMoveType.Target)
     {
         this.tarActor = _action.GetActorHandle(this.destId);
         if (!this.tarActor)
         {
             return;
         }
         this.destPosition = this.tarActor.get_handle().location;
         CActorInfo charInfo = this.tarActor.get_handle().CharInfo;
         if (charInfo != null)
         {
             this.hitHeight = charInfo.iBulletHeight;
             VInt3 vInt = this.moveActor.get_handle().location - this.destPosition;
             vInt.y             = 0;
             vInt               = vInt.NormalizeTo(1000);
             this.destPosition += IntMath.Divide(vInt, (long)charInfo.iCollisionSize.x, 1000L);
         }
         this.destPosition.y = this.destPosition.y + this.hitHeight;
     }
     else if (this.MoveType == ActorMoveType.Directional)
     {
         VInt3 vInt2 = VInt3.one;
         if (this.skillContext == null)
         {
             return;
         }
         PoolObjHandle <ActorRoot> originator = this.skillContext.Originator;
         if (!originator)
         {
             return;
         }
         if (this.bBulletUseDir)
         {
             _action.refParams.GetRefParam("_BulletUseDir", ref vInt2);
         }
         else if (this.bUseIndicatorDir)
         {
             SkillUseContext refParamObject = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext");
             VInt3           vInt3;
             if (refParamObject != null && refParamObject.CalcAttackerDir(out vInt3, originator))
             {
                 vInt2 = vInt3;
             }
             else
             {
                 vInt2 = originator.get_handle().forward;
             }
         }
         else
         {
             vInt2 = originator.get_handle().forward;
         }
         vInt2 = vInt2.RotateY(this.offsetDir.y);
         if (this.bResetMoveDistance)
         {
             int num = 0;
             _action.refParams.GetRefParam("_BulletRealFlyingTime", ref num);
             int num2 = num * this.velocity / 1000;
             this.distance = ((num2 <= 0) ? this.distance : num2);
         }
         this.destPosition   = this.moveActor.get_handle().location + vInt2.NormalizeTo(this.distance);
         this.destPosition.y = this.moveActor.get_handle().location.y;
     }
     else if (this.MoveType == ActorMoveType.Position)
     {
         if (this.bReachDestStop)
         {
             this.destPosition = this.targetPosition;
         }
         else
         {
             VInt3 vInt4 = this.targetPosition - this.moveActor.get_handle().location;
             vInt4.y           = 0;
             vInt4             = vInt4.NormalizeTo(1000);
             this.destPosition = this.moveActor.get_handle().location + vInt4 * (this.length * this.velocity / 1000);
             VInt vInt5;
             if (PathfindingUtility.GetGroundY(this.destPosition, out vInt5))
             {
                 this.destPosition.y = vInt5.i;
             }
         }
     }
     if (this.bAdjustSpeed)
     {
         VInt3 vInt6 = this.destPosition - this.moveActor.get_handle().location;
         int   num3  = this.length - 100;
         num3          = ((num3 > 0) ? num3 : this.length);
         this.velocity = (int)IntMath.Divide((long)vInt6.get_magnitude2D() * 1000L, (long)num3);
     }
     if (this.gravity < 0)
     {
         if (this.velocity == 0)
         {
             this.stopCondtion = true;
             return;
         }
         VInt3 vInt7 = this.destPosition - this.moveActor.get_handle().location;
         int   num4;
         if (!this.shouldUseAcceleration)
         {
             num4 = (int)IntMath.Divide((long)vInt7.get_magnitude2D() * 1000L, (long)this.velocity);
         }
         else
         {
             long num5 = (long)this.velocity;
             long num6 = (long)this.acceleration;
             long num7 = (long)vInt7.get_magnitude2D();
             long num8 = num5 * num5 + 2L * num6 * num7;
             num4 = (int)IntMath.Divide(((long)IntMath.Sqrt(num8) - num5) * 1000L, num6);
             this.lastVelocity = (this.lastLerpVelocity = this.velocity);
         }
         if (num4 == 0)
         {
             this.stopCondtion = true;
             return;
         }
         VInt vInt8;
         if (PathfindingUtility.GetGroundY(this.destPosition, out vInt8))
         {
             this.gravityControler.InitMotionControler(num4, vInt8.i - this.moveActor.get_handle().location.y, this.gravity);
         }
         else
         {
             this.gravityControler.InitMotionControler(num4, 0, this.gravity);
         }
     }
 }
Beispiel #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;
            }
        }
    }