Esempio n. 1
0
        private void InitEntities(bool fullInit)
        {
            ShieldEnt?.Close();
            _shellActive?.Close();
            _shellPassive?.Close();

            if (!fullInit)
            {
                if (Session.Enforced.Debug == 3)
                {
                    Log.Line($"InitEntities: mode: {ShieldMode}, remove complete - ShieldId [{Shield.EntityId}]");
                }
                return;
            }

            SelectPassiveShell();
            var parent = (MyEntity)MyGrid;

            if (!_isDedicated)
            {
                _shellPassive = Spawn.EmptyEntity("dShellPassive", $"{Session.Instance.ModPath()}{_modelPassive}", parent, true);
                _shellPassive.Render.CastShadows = false;
                _shellPassive.IsPreview          = true;
                _shellPassive.Render.Visible     = true;
                _shellPassive.Render.RemoveRenderObjects();
                _shellPassive.Render.UpdateRenderObject(true);
                _shellPassive.Render.UpdateRenderObject(false);
                _shellPassive.Save     = false;
                _shellPassive.SyncFlag = false;

                _shellActive = Spawn.EmptyEntity("dShellActive", $"{Session.Instance.ModPath()}{_modelActive}", parent, true);
                _shellActive.Render.CastShadows = false;
                _shellActive.IsPreview          = true;
                _shellActive.Render.Visible     = true;
                _shellActive.Render.RemoveRenderObjects();
                _shellActive.Render.UpdateRenderObject(true);
                _shellActive.Render.UpdateRenderObject(false);
                _shellActive.Save     = false;
                _shellActive.SyncFlag = false;
                _shellActive.SetEmissiveParts("ShieldEmissiveAlpha", Color.Transparent, 0f);
            }

            ShieldEnt = Spawn.EmptyEntity("dShield", null, parent);
            ShieldEnt.Render.CastShadows = false;
            ShieldEnt.Render.RemoveRenderObjects();
            ShieldEnt.Render.UpdateRenderObject(true);
            ShieldEnt.Render.Visible = true;
            ShieldEnt.Save           = false;
            _shieldEntRendId         = ShieldEnt.Render.GetRenderObjectID();
            _updateRender            = true;

            if (Icosphere == null)
            {
                Icosphere = new Icosphere.Instance(Session.Instance.Icosphere);
            }
            if (Session.Enforced.Debug == 3)
            {
                Log.Line($"InitEntities: mode: {ShieldMode}, spawn complete - ShieldId [{Shield.EntityId}]");
            }
        }
Esempio n. 2
0
        public override void UpdateBeforeSimulation()
        {
            // Ignore damaged or build progress hyper_blocks. Ignore ghost grids (projections).
            if (!hyperDriveBlock.IsFunctional || hyperDriveBlock.CubeGrid.Physics == null)
            {
                return;
            }
            _ticks++;
            _tick++;
            if (!firstrun)
            {
                if (_ticks > 12)
                {
                    MyAPIGateway.Parallel.StartBackground(HyperFunctions.BackGroundChecks);
                    //HyperFunctions._powerPercent = (HyperFunctions._maxPower * 0.6f);
                    HyperFunctions.UpdateGridPower();
                    HyperFunctions.ResourceSink.Update();
                    hyperDriveBlock.RefreshCustomInfo();
                    _ticks = 0;
                }
                if (MyAPIGateway.Session.IsServer)
                {
                    if (!_shellBool)
                    {
                        try
                        {
                            var parent = (MyEntity)hyperDriveBlock.CubeGrid;
                            Spawn._emptyGridShell = Spawn.EmptyEntity("dShellPassive2", $"{Session.Instance.ModPath()}{Spawn._modelShell}", parent, true);
                            Spawn._emptyGridShell.Render.CastShadows = false;
                            Spawn._emptyGridShell.IsPreview          = true;
                            Spawn._emptyGridShell.Render.Visible     = true;
                            Spawn._emptyGridShell.Render.RemoveRenderObjects();
                            Spawn._emptyGridShell.Render.UpdateRenderObject(true);
                            Spawn._emptyGridShell.Render.UpdateRenderObject(false);
                            Spawn._emptyGridShell.Save     = false;
                            Spawn._emptyGridShell.SyncFlag = false;
                            try
                            {
                                Session.Instance.CreateMobileShape();
                                Spawn._emptyGridShell.PositionComp.LocalMatrix = Matrix.Zero;  // Bug - Cannot just change X coord, so I reset first.
                                Spawn._emptyGridShell.PositionComp.LocalMatrix = Spawn._shieldShapeMatrix;
                            }
                            catch
                            {
                                Logging.Logging.Instance.WriteLine("CreateMobileShape() Failure");
                            }
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("emptyGrid Failure");
                        }

                        _shellBool = true;
                    }
                    if (HyperFunctions.ResourceSink.IsPowerAvailable(HyperFunctions._electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed        = true;
                        _bubbleNotification = true;
                    }
                    else if (!HyperFunctions.ResourceSink.IsPowerAvailable(HyperFunctions._electricity, HyperFunctions.PowerConsumption()))
                    {
                        BubbleFormed = false;
                    }
                    if (_tick > 10000)
                    {
                        _tick   = 0;
                        msgSent = false;
                    }
                    if (HyperFunctions.IsWorking() && HyperEngaged)
                    {
                        hyper = true;
                        //var grid = hyperDriveBlock.CubeGrid;
                        if (BubbleFormed && hyperDriveBlock.CubeGrid.Physics != null && hyperDriveBlock.CubeGrid.WorldMatrix != null && hyperDriveBlock.CubeGrid.WorldMatrix.Translation != null && warpTimer < 120)
                        {
                            HyperFunctions.Warp();
                            warpTimer = (warpTimer + 1);

                            if (warpTimer > 95 && fade)
                            {
                                fade = false;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    //MyVisualScriptLogicProvider.ShowNotification("Jump Initialisation Success: " + "Maybe", 9500, "White", id);
                                    MyVisualScriptLogicProvider.ScreenColorFadingStart(0.25f, true);
                                }
                                lastPos         = hyperDriveBlock.CubeGrid.GetPosition();
                                from            = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward;// * 1d;
                                to              = hyperDriveBlock.WorldMatrix.Translation + hyperDriveBlock.WorldMatrix.Forward * 2001d;
                                destination     = from - to;
                                hyperSpaceTimer = 7200;
                                //hyperSpaceTimer = (hyperSpaceTimer + distanceVar);
                                jumpOut = true;
                                HyperFunctions.HyperJump();
                            }
                        }
                        else
                        {
                            hyper     = false;
                            warpTimer = 0;
                            fade      = true;
                            if (jumpOut)
                            {
                                var realPlayerIds = new List <long>();
                                jumpOut = false;
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    //MyVisualScriptLogicProvider.ShowNotification("Jump Time: " + "Time to Jump to HyperSpace", 9500, "White", id);
                                    MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(0.25f);
                                }
                                hyperSpace   = true;
                                HyperEngaged = false;
                                HyperSpaceParticle();
                            }
                        }
                    }
                    if (hyperSpace)
                    {
                        hyperSpaceTimer = (hyperSpaceTimer - 1);

                        try
                        {
                            Session.Instance.ShellVisibility(true);
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("ShellVisibility(true) Failure");
                        }

                        if (hyperSpaceTimer >= 0)
                        {
                            hyperDriveBlock.CubeGrid.Physics.AngularVelocity = Vector3D.Zero;
                            hyperDriveBlock.CubeGrid.Physics.LinearVelocity  = Vector3D.Zero;

                            if (!ExitWarning10 && hyperSpaceTimer <= 600)
                            {
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ShowNotification("10 Seconds to Normal Space", 9600, "White", id);
                                }
                                ExitWarning10 = true;
                            }
                            else if (!ExitWarning60 && hyperSpaceTimer <= 3600)
                            {
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ShowNotification("60 Seconds to Normal Space", 9600, "White", id);
                                }
                                ExitWarning60 = true;
                            }
                        }
                        else if (ExitWarning10 && ExitWarning60)
                        {
                            warpTimer = (warpTimer + 1);
                            if (warpTimer < 25 && fade)
                            {
                                fade = false;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ScreenColorFadingStart(0.25f, true);
                                }
                            }
                            else
                            {
                                HyperFunctions.HyperJumpDestination(destination, lastPos);
                                hyperSpace    = false;
                                jumpIn        = true;
                                warpTimer     = 0;
                                ExitWarning10 = false;
                                ExitWarning60 = false;
                                //hyperSpaceTimer = 7200;
                                HyperSpaceParticleStop();
                            }
                        }
                    }
                    else if (!hyperSpace && !jumpIn)
                    {
                        if (!BubbleFormed && hyperDriveBlock.Enabled && _tick > 16)
                        {
                            hyper = false;
                            hyperDriveBlock.Enabled = false;
                        }
                        if (!HyperFunctions.IsWorking() && hyper)
                        {
                            hyper = false;
                            HyperFunctions.EmergencyStop();
                        }
                        if (!hyper)
                        {
                            HyperFunctions.emitter.StopSound(false, true);
                            HyperEngaged = false;
                        }
                    }
                    if (jumpIn)
                    {
                        warpTimer = (warpTimer + 1);
                        HyperFunctions.Warp();
                        try
                        {
                            Session.Instance.ShellVisibility(false);
                        }
                        catch
                        {
                            Logging.Logging.Instance.WriteLine("ShellVisibility(false) Failure");
                        }
                        if (warpTimer > 30)
                        {
                            if (!fade)
                            {
                                fade = true;
                                var realPlayerIds = new List <long>();
                                DsUtilsStatic.GetRealPlayers(hyperDriveBlock.PositionComp.WorldVolume.Center, 500f, realPlayerIds);
                                foreach (var id in realPlayerIds)
                                {
                                    MyVisualScriptLogicProvider.ScreenColorFadingStartSwitch(0.04f);
                                }
                            }
                            if (warpTimer > 120)
                            {
                                warpTimer    = 0;
                                jumpIn       = false;
                                HyperEngaged = false;
                            }
                        }
                    }
                }
            }
        }