예제 #1
0
        private void DoWork()
        {
            var ftl = MyAPIGateway.Entities.GetEntityById(FTLId) as IMyFunctionalBlock;

            if (ftl == null)        // Something happened
            {
                return;
            }

            var ftld = ftl.GetFTLData();

            var players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players, (x) => x.SteamUserId == SenderSteamId);
            ftld.jumpTargetGPS = FTLExtensions.GetGPSFromHash(GPSHash, players[0].IdentityId);

            if (GPSHash == 0 && Coords.HasValue)
            {
                ftld.jumpTargetGPS = MyAPIGateway.Session.GPS.Create("FTL Generated", string.Empty, Coords.Value, false, true);
            }

            if (ftld.jumpTargetGPS != null)
            {
                Logger.Instance.LogMessage(string.Format("Found GPS: " + ftld.jumpTargetGPS.Name));
            }
            else
            {
                Logger.Instance.LogMessage(string.Format("Cleared GPS"));
            }

            ftl.GameLogic.GetAs <FTLBase>().SaveTerminalValues();
        }
예제 #2
0
        static void FTLJumpDrive_PropertiesChanged(IMyTerminalBlock obj)
        {
            var hash = (obj.GetObjectBuilderCubeBlock() as MyObjectBuilder_JumpDrive).JumpTarget;
            var ftld = obj.GameLogic.GetAs <FTLBase>().Data;

            if (ftld.flags.HasFlag(JumpFlags.GPSWaypoint))  // One-time GPS coordinate
            {
                return;
            }

            if (hash != null)
            {
                ftld.jumpTargetGPS = FTLExtensions.GetGPSFromHash(hash.Value);
                return;
            }
            else
            {
                ftld.jumpTargetGPS = null;
                ftld.jumpDistance  = obj.GameLogic.GetAs <FTLJumpDrive>().ComputeMaxDistance();
            }
        }
        public override void UpdateBeforeSimulation10()
        {
            if (FTLAdmin.Configuration.BlockStockJump && (Entity as IMyJumpDrive).Enabled)
            {
                try
                {
                    float distance         = (Entity as IMyJumpDrive).GetValueFloat("JumpDistance");
                    var   reference        = (Entity as IMyFunctionalBlock).GetShipReference();
                    VRageMath.Vector3D pos = reference.Translation;

                    var   smaxdist = (Entity as IMyJumpDrive).DetailedInfo.Split(' ')[(Entity as IMyJumpDrive).DetailedInfo.Split(' ').Length - 2];
                    float maxdist  = 0;
                    if (float.TryParse(smaxdist, out maxdist))
                    {
                        // Found formula in workshop script: 479442492
                        // per = (Dist - 5) * (100/(Max-5))
                        // dist = (per / (100/(max-5))) + 5
                        distance = (distance / (100 / (maxdist - 5))) + 5;
                    }

                    distance *= 1000;           // Distance from jump drive is in km, convert to m
                    pos      += (reference.Forward * distance);

                    if (FTLExtensions.IsInhibited(Entity.GetPosition()) || FTLExtensions.IsInhibited(pos))
                    {
                        (Entity as IMyJumpDrive).RequestEnable(false);
                        (Entity as IMyFunctionalBlock).ShowMessageToUsersInRange("Jump drive disabled, interference detected", 5000, true);
                    }
                }
                catch (Exception)
                {
                    // Ignore exceptions for now, they occur during load
                    //Logger.Instance.LogException(ex);
                }
            }
        }