Ejemplo n.º 1
0
            public static bool ChangeWarpSpeed(PlayerMove_Sail __instance, long timei)
            {
                Console.WriteLine($"Warp speed is: {__instance.player.mecha.maxWarpSpeed}");

                __instance.player.mecha.maxWarpSpeed = getNewWarpSpeed();

                Console.WriteLine($"New warp speed is: {__instance.player.mecha.maxWarpSpeed}");

                return(true);
            }
Ejemplo n.º 2
0
        private bool NeedLocalLongDistanceNavigate(PlayerMove_Sail __instance)
        {
            double distance = (target.TargetPlanet.uPosition - __instance.player.uPosition).magnitude;

            bool localWarpable = (enableLocalWrap &&
                                  distance > localWrapMinDistance &&
                                  distance > (target.TargetPlanet.realRadius + longNavUncoverRange));

            return(localWarpable || target.IsLocalStarPlanet == false);
        }
Ejemplo n.º 3
0
            public static bool TryLeaveWarp(PlayerMove_Sail __instance)
            {
                if (__instance.player.warping)
                {
                    __instance.player.warpCommand = false;
                    VFAudio.Create("warp-end", __instance.player.transform, Vector3.zero, true);

                    return(true);
                }

                return(false);
            }
Ejemplo n.º 4
0
            public static bool TryEnterWarp(PlayerMove_Sail __instance)
            {
                if (!__instance.player.warping && __instance.player.mecha.UseWarper())
                {
                    __instance.player.warpCommand = true;
                    VFAudio.Create("warp-begin", __instance.player.transform, Vector3.zero, true);
                    //GameMain.gameScenario.NotifyOnWarpModeEnter();

                    return(true);
                }

                return(false);
            }
Ejemplo n.º 5
0
        public void PlanetNavigation(PlayerMove_Sail __instance)
        {
            ModDebug.Assert(IsCurNavPlanet());
            player = __instance.player;

            if (IsCurNavPlanet())
            {
                double distance = (target.TargetPlanet.uPosition - __instance.player.uPosition).magnitude;

                if ((enableLocalWrap &&
                     distance > localWrapMinDistance &&
                     distance > (target.TargetPlanet.realRadius + longNavUncoverRange))
                    ||
                    target.IsLocalStarPlanet() == false)
                {
                    PlanetData localPlanet = GameMain.localPlanet;
                    if (localPlanet != null &&
                        target.TargetPlanet != null &&
                        localPlanet.id != target.TargetPlanet.id)
                    {
#if DEBUG
                        ModDebug.Log("Leave Local Planet");
#endif
                        VectorLF3 dir = (__instance.player.uPosition - localPlanet.uPosition).normalized;
                        Sail.SetDir(__instance, dir);
                    }
                    else
                    {
#if DEBUG
                        ModDebug.Log("Local Long Distance Navigation");
#endif
                        LongDistanceNavigate(__instance);
                    }
                }
                else
                {
#if DEBUG
                    ModDebug.Log("Local Short Distance Navigation");
#endif
                    ShortDistanceNavigate(__instance);
                }
            }
            else
            {
                Arrive();
#if DEBUG
                ModDebug.Error("PlanetNavigation - No Target");
#endif
            }
        }
Ejemplo n.º 6
0
            public static bool HasWrapChance(AutoStellarNavigation self, PlayerMove_Sail __instance)
            {
                bool LocalPlanetWarp()
                {
                    if (GameMain.localPlanet != null && self.target.TargetPlanet.id == GameMain.localPlanet.id)
                    {
                        return(false);
                    }
                    else if ((__instance.player.uPosition - self.target.TargetPlanet.uPosition).magnitude < (self.localWrapMinDistance))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }

                if (self.IsCurNavStar() || LocalPlanetWarp())
                {
                    if (__instance.player.mecha.thrusterLevel >= 3)
                    {
                        if (__instance.mecha.coreEnergy > __instance.mecha.warpStartPowerPerSpeed * (double)__instance.mecha.maxWarpSpeed)
                        {
                            if (GetWraperCount(__instance) <= 0)
                            {
                                return(false);
                            }
                            else
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
Ejemplo n.º 7
0
            private static void Postfix(PlayerMove_Sail __instance)
            {
                // Sail 默认不加速
                s_NavigateInstance.sailSpeedUp = false;

                if (!s_NavigateInstance.enable)
                {
                    return;
                }

                if (GameMain.localPlanet != null ||
                    s_NavigateInstance.target.IsVaild())
                {
                    __instance.sailPoser.targetURot = oTargetURot;
                    s_NavigateInstance.HandlePlayerInput();
                }
            }
Ejemplo n.º 8
0
            private static void Prefix(PlayerMove_Sail __instance)
            {
                if (autoNav.enable && (__instance.player.sailing || __instance.player.warping))
                {
                    ++__instance.controller.input0.y;
                    oTargetURot = __instance.sailPoser.targetURot;

                    if (autoNav.IsCurNavStar())
                    {
                        autoNav.StarNavigation(__instance);
                    }
                    else if (autoNav.IsCurNavPlanet())
                    {
                        autoNav.PlanetNavigation(__instance);
                    }
                }
            }
Ejemplo n.º 9
0
        public void PlanetNavigation(PlayerMove_Sail __instance)
        {
            ModDebug.Assert(IsCurNavPlanet);
            player = __instance.player;

            if (!IsCurNavPlanet)
            {
                Arrive();
#if DEBUG
                ModDebug.Error("Planet navigation - Error target");
#endif
                return;
            }

            if (NeedLocalLongDistanceNavigate(__instance))
            {
                PlanetData localPlanet = GameMain.localPlanet;
                if (localPlanet != null &&
                    target.TargetPlanet != null &&
                    localPlanet.id != target.TargetPlanet.id)
                {
#if DEBUG
                    ModDebug.Log("Leave Local Planet");
#endif
                    VectorLF3 dir = (__instance.player.uPosition - localPlanet.uPosition).normalized;
                    Sail.SetDir(__instance, dir);
                }
                else
                {
#if DEBUG
                    ModDebug.Log("Local Long Distance Navigation");
#endif
                    LongDistanceNavigate(__instance);
                }

                return;
            }

#if DEBUG
            ModDebug.Log("Local Short Distance Navigation");
#endif
            ShortDistanceNavigate(__instance);
        }
Ejemplo n.º 10
0
        public void StarNavigation(PlayerMove_Sail __instance)
        {
            ModDebug.Assert(IsCurNavStar());
            player = __instance.player;

            if (IsCurNavStar())
            {
                PlanetData localPlanet = GameMain.localPlanet;
                if (localPlanet != null)
                {
#if DEBUG
                    ModDebug.Log("Leave Local Planet");
#endif
                    VectorLF3 dir = (__instance.player.uPosition - localPlanet.uPosition).normalized;
                    Sail.SetDir(__instance, dir);
                    return;
                }
                else
                {
                    if (DetermineArrive() && IsCloseToNearStar(__instance))
                    {
#if DEBUG
                        ModDebug.Log("StarNavigation Arrive");
#endif
                        Arrive();
                        Warp.TryLeaveWarp(__instance);
                        return;
                    }
                    else
                    {
                        LongDistanceNavigate(__instance);
                        return;
                    }
                }
            }
            else
            {
                Arrive();
#if DEBUG
                ModDebug.Error("StarNavigation - No Target");
#endif
            }
        }
Ejemplo n.º 11
0
            private static void Prefix(PlayerMove_Sail __instance)
            {
                if (!s_NavigateInstance.enable)
                {
                    return;
                }

                if (!__instance.player.sailing && !__instance.player.warping)
                {
                    return;
                }

                ++__instance.controller.input0.y;
                oTargetURot = __instance.sailPoser.targetURot;

                if (s_NavigateInstance.IsCurNavStar)
                {
                    s_NavigateInstance.StarNavigation(__instance);
                }
                else if (s_NavigateInstance.IsCurNavPlanet)
                {
                    s_NavigateInstance.PlanetNavigation(__instance);
                }
            }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取当前星系最近行星距离
        /// </summary>
        private double NearestPlanetDistance(PlayerMove_Sail __instance)
        {
            StarData localStar = GameMain.localStar;
            double   distance  = (localStar.planets[0].uPosition - __instance.player.uPosition).magnitude;

            //Distance set negative when local star is null
            if (localStar == null)
            {
                return(-10.0);
            }

            for (int index = 0; index < localStar.planetCount; ++index)
            {
                PlanetData planet    = localStar.planets[index];
                double     magnitude = (planet.uPosition - __instance.player.uPosition).magnitude;

                if (magnitude < distance)
                {
                    distance = magnitude;
                }
            }

            return(distance);
        }
Ejemplo n.º 13
0
 public static void SetDir(PlayerMove_Sail __instance, VectorLF3 dir) =>
 __instance.sailPoser.targetURot = Quaternion.LookRotation(dir);
Ejemplo n.º 14
0
        public bool AdvisePointIfOcclusion(PlayerMove_Sail __instance, ref VectorLF3 advisePoint, double radiusOffest)
        {
            bool navPlanet = false;
            bool navStar   = false;

            StarData  localStar = GameMain.localStar;
            VectorLF3 srcPoint  = __instance.player.uPosition;
            VectorLF3 dstPoint  = VectorLF3.zero;

            if (IsCurNavStar)
            {
                navStar  = true;
                dstPoint = target.TargetStar.uPosition;
            }
            else if (IsCurNavPlanet)
            {
                navPlanet = true;
                dstPoint  = target.TargetPlanet.uPosition;
            }
            else
            {
                ModDebug.Error("AdvisePointIfOcclusion When No Navigate!!!");
                return(false);
            }

            bool hit = false;

            Math.Line3D hitPlaneVertical = new Math.Line3D();
            double      uncoverRadius    = 0;

            Math.Line3D  line  = new Math.Line3D(srcPoint, dstPoint);
            Math.Plane3D plane = new Math.Plane3D();
            plane.normal = line.dir;

            if (localStar != null)
            {
                //Planet occlusion
                for (int index = 0; index < localStar.planetCount; ++index)
                {
                    PlanetData planet = localStar.planets[index];
                    plane.ponit = planet.uPosition;

                    if (plane.IsParallel(line) == false)
                    {
                        //Target planet
                        if (navPlanet && planet.id == target.TargetPlanet.id)
                        {
                            continue;
                        }

                        VectorLF3 intersection = plane.GetIntersection(line);

                        double minHitRange = planet.realRadius + radiusOffest;

                        if (intersection.Distance(planet.uPosition) < minHitRange &&
                            intersection.Distance(srcPoint) + intersection.Distance(dstPoint) <= (dstPoint.Distance(srcPoint) + 0.1))
                        {
                            hit = true;

                            //Maximum radius plane
                            if (minHitRange > uncoverRadius)
                            {
                                uncoverRadius        = minHitRange;
                                hitPlaneVertical.src = planet.uPosition;

                                if (planet.uPosition != intersection)
                                {
                                    hitPlaneVertical.dst = intersection;
                                }
                                //Rare case
                                else
                                {
                                    hitPlaneVertical.dst = plane.GetAnyPoint();
                                }
                            }
                        }
                    }
                }

                ///Star occlusion
                StarData star = localStar;
                plane.ponit = star.uPosition;

                //Target star
                if (navStar && star.id == target.TargetStar.id)
                {
                }
                else
                {
                    if (plane.IsParallel(line) == false)
                    {
                        VectorLF3 intersection = plane.GetIntersection(line);

                        double minHitRange = star.physicsRadius + radiusOffest;
                        if (intersection.Distance(star.uPosition) < minHitRange)
                        {
                            hit = true;

                            //Maximum radius plane
                            if (minHitRange > uncoverRadius)
                            {
                                uncoverRadius        = minHitRange;
                                hitPlaneVertical.src = star.uPosition;

                                if (star.uPosition != intersection)
                                {
                                    hitPlaneVertical.dst = intersection;
                                }
                                //Rare case
                                else
                                {
                                    hitPlaneVertical.dst = plane.GetAnyPoint();
                                }
                            }
                        }
                    }
                }
            }

            if (hit)
            {
#if DEBUG
                ModDebug.Log("AdvisePointIfOcclusion Hit");
#endif
                VectorLF3   uncoverOrbitPoint = hitPlaneVertical.src + (hitPlaneVertical.dir * (uncoverRadius + 10));
                Math.Line3D uncoverLine       = new Math.Line3D(dstPoint, uncoverOrbitPoint);
                plane.normal = uncoverLine.dir;
                plane.ponit  = srcPoint;

                advisePoint = plane.GetIntersection(uncoverLine);
            }

            return(hit);
        }
Ejemplo n.º 15
0
 public static int GetWarperCount(PlayerMove_Sail __instance)
 {
     return(__instance.player.mecha.warpStorage.GetItemCount(1210));
 }
Ejemplo n.º 16
0
 public static bool HasWarper(PlayerMove_Sail __instance) =>
 GetWarperCount(__instance) > 0;
Ejemplo n.º 17
0
        private void LongDistanceNavigate(PlayerMove_Sail __instance)
        {
            VectorLF3 dir = target.GetDirection(__instance.player);

            Sail.SetDir(__instance, dir);

            VectorLF3 advisePoint = VectorLF3.zero;

            if (AdvisePointIfOcclusion(__instance, ref advisePoint, longNavUncoverRange))
            {
#if DEBUG
                ModDebug.Log("LongDistanceNavigate - ToAdvisePoint:" + advisePoint);
#endif

                dir = (advisePoint - __instance.player.uPosition).normalized;
                Sail.SetDir(__instance, dir);
                Sail.TrySpeedUp(this, __instance);
            }
            else if (Target.IsFocusingNormalized(dir, __instance.player.uVelocity.normalized) && !__instance.player.warping)
            {
                if (__instance.player.mecha.coreEnergy >= wrapEnergylimit && Warp.TryWrap(this, __instance))
                {
#if DEBUG
                    ModDebug.Log("Enter Wrap");
#endif
                    return;
                }
                else if (IsCurNavPlanet && target.IsLocalStarPlanet == true)
                {
#if DEBUG
                    ModDebug.Log("Local Planet Navigate No Wrap Chance SpeedUp");
#endif
                    Sail.TrySpeedUp(this, __instance);
                    return;
                }
                else if (LongDistanceNavigateNeedSpeedUp())
                {
#if DEBUG
                    ModDebug.Log("Long Distance Navigate Need SpeedUp");
#endif
                    Sail.TrySpeedUp(this, __instance);
                }
                else
                {
#if DEBUG
                    ModDebug.Log("Long Distance Navigate No SpeedUp And Warp");
#endif
                }
            }

            bool LongDistanceNavigateNeedSpeedUp()
            {
                if (__instance.player.mecha.coreEnergy >= speedUpEnergylimit)
                {
                    if (__instance.player.mecha.thrusterLevel < THRUSTER_LEVEL_WARP)
                    {
                        return(true);
                    }
                    //else if (Warp.GetWarperCount(__instance) <= 0)
                    else if (!Warp.HasWarper(__instance))
                    {
                        return(true);
                    }
                    return(true);
                }
                //Prepare warp
                if (__instance.player.mecha.coreEnergy < wrapEnergylimit)
                {
                    return(false);
                }
                return(false);
            }
        }