private void InitHudObjective()
        {
            IMyHudObjectiveLine objective = MyAPIGateway.Utilities.GetObjectiveLine();

            objective.Title = _track.Title;
            objective.Objectives.Clear();
            objective.Objectives.Add("");
            objective.Show();
        }
        public void ProcessPosition()
        {
            IMyHudObjectiveLine objective = MyAPIGateway.Utilities.GetObjectiveLine();

            if (_isTracking)
            {
                if (MyAPIGateway.Session.Player.Controller == null || MyAPIGateway.Session.Player.Controller.ControlledEntity == null || MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity == null)
                {
                    return;
                }

                if (!objective.Visible || objective.Title != _track.Title)
                {
                    _isTracking = false;
                    MyAPIGateway.Utilities.ShowNotification("Objective changed - tracking cancelled", 2500, MyFontEnum.Red);
                    return;
                }

                if (MyAPIGateway.Session.Player.Controller.ControlledEntity != _currentController)
                {
                    _isTracking = false;
                    MyAPIGateway.Utilities.ShowNotification("Cockpit changed - tracking cancelled", 2500, MyFontEnum.Red);
                    Unload();
                    CommandScan.ShipCache.Clear();
                    return;
                }

                //Vector3D position = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();
                if (objective.Title != _track.Title)
                {
                    objective.Title = _track.Title;
                }

                var playerPosition = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();
                var heading        = Support.GetRotationAngle(MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.WorldMatrix, _track.Position - playerPosition);
                var distance       = Math.Sqrt((playerPosition - _track.Position).LengthSquared());

                var pitchDirection = "Up";
                if (heading.Y < 0)
                {
                    pitchDirection = "Down";
                }

                var yawDirection = "Right";
                if (heading.X < 0)
                {
                    yawDirection = "Left";
                }

                objective.Objectives[_objectiveLine] = $"Range:{distance:N}m, Pitch {pitchDirection}:{Math.Abs(heading.Y):N}°, Yaw {yawDirection}:{Math.Abs(heading.X):N}°";
            }
        }
        private void Unload()
        {
            if (MyAPIGateway.Session != null)
            {
                try
                {
                    IMyHudObjectiveLine objective = MyAPIGateway.Utilities.GetObjectiveLine();

                    if (objective.Visible)
                    {
                        objective.Hide();
                    }
                }
                catch (Exception ex)
                {
                    MainChatCommandLogic.Instance.ClientLogger.WriteException(ex, "Exception caught during shutdown of mod.");
                    // catch and ignore issues during shutdown.
                }
            }
        }
예제 #4
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (MyAPIGateway.Session == null)
                {
                    return;
                }

                _updateCount++;

                if (!_init)
                {
                    Initialize();
                }

                if (!_playerInit && MyAPIGateway.Session?.Player?.Character != null)
                {
                    _playerInit = true;
                    if (MyAPIGateway.Utilities.FileExistsInLocalStorage("Ship.bin", typeof(LinkModCore)))
                    {
                        BinaryReader reader = MyAPIGateway.Utilities.ReadBinaryFileInLocalStorage("Ship.bin", typeof(LinkModCore));
                        int          count  = reader.ReadInt32();
                        byte[]       bytes  = reader.ReadBytes(count);

                        Logging.Instance.WriteLine($"Sending grid parts: {count} bytes.");

                        Communication.SegmentAndSend(Communication.MessageType.ServerGridPart, bytes, MyAPIGateway.Session.Player.SteamUserId);
                    }
                    else
                    {
                        var character = MyAPIGateway.Session.Player.Character;
                        var pos       = Utilities.RandomPositionFromPoint(character.GetPosition(), 500000);
                        var newPos    = MyAPIGateway.Entities.FindFreePlace(pos, 5f);
                        character.SetPosition(newPos ?? pos);
                    }
                    //if (!MyAPIGateway.Utilities.FileExistsInLocalStorage("Greeting.cfm", typeof(LinkModCore)))
                    //{
                    //    MyAPIGateway.Utilities.ShowMissionScreen("ServerLink",
                    //                                             "",
                    //                                             null,
                    //                                             "Welcome to the server link demo! Important rules and explanations:\r\n" +
                    //                                             "Pistons and rotors are prohibited.\r\n" +
                    //                                             "Grids are limited to 5k blocks.\r\n" +
                    //                                             "Grids in the hub will always be static, and all weapons are disabled.\r\n" +
                    //                                             "Grids in the hub MUST be owned! Unowned grids and grids beloning to offline players will be deleted every 10 minutes.\r\n\r\n" +
                    //                                             "Hub server provided by Neimoh of Galaxy Strike Force\r\n" +
                    //                                             "Match server #1 provided by Franky500 of Frankys Space\r\n" +
                    //                                             "Be sure to visit their regular servers!\r\n" +
                    //                                             "All other servers provided by X_Wing_Ian\r\n\r\n" +
                    //                                             "Use !join to get a list of servers you can join. Use !help for a full list of commands you can use.\r\n\r\n\r\n" +
                    //                                             "Enjoy!\r\n" +
                    //                                             "-rexxar",
                    //                                             null,
                    //                                             "Close");
                    //    var w = MyAPIGateway.Utilities.WriteFileInLocalStorage("Greeting.cfm", typeof(LinkModCore));
                    //    w.Write("true");
                    //    w.Flush();
                    //    w.Close();
                    //}
                    //else if (!Settings.Instance.Hub && !Exempt.Contains(MyAPIGateway.Session.Player.SteamUserId))
                    //{
                    //    MyAPIGateway.Utilities.ShowMessage("System", "You shouldn't be here!");
                    //    Communication.RedirectClient(MyAPIGateway.Session.Player.SteamUserId, Utilities.ZERO_IP);
                    //}
                }

                if (MyAPIGateway.Session.Player != null)
                {
                    if (LobbyTime.HasValue && LobbyTime > DateTime.UtcNow)
                    {
                        IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine();
                        line.Title = "Match starting in:";
                        line.Objectives.Clear();
                        line.Objectives.Add((DateTime.UtcNow - LobbyTime.Value).ToString(@"mm\:ss"));
                        if (_countdown && !line.Visible)
                        {
                            line.Show();
                        }
                    }
                    else
                    {
                        if (MatchTime.HasValue && MatchTime >= DateTime.UtcNow)
                        {
                            IMyHudObjectiveLine line = MyAPIGateway.Utilities.GetObjectiveLine();
                            line.Title = "Match ending in:";
                            line.Objectives.Clear();
                            line.Objectives.Add((DateTime.UtcNow - MatchTime.Value).ToString(@"mm\:ss"));
                            if (_countdown && !line.Visible)
                            {
                                line.Show();
                            }
                        }
                    }
                }

                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    if (Settings.Instance == null)
                    {
                        MyAPIGateway.Utilities.ShowMessage("LinkMod", "Settings not defined on this server! Link mod will not work!");
                        MyAPIGateway.Utilities.SendMessage("Settings not defined on this server! Link mod will not work!");
                        return;
                    }

                    if (Settings.Instance.Hub)
                    {
                        if (_updateCount % 10 == 0)
                        {
                            ProcessEnforcement();
                        }
                    }
                    else
                    {
                        if (_updateCount % 120 == 0)
                        {
                            ProcessCleanup();
                        }
                        if (_lobbyRunning)
                        {
                            var entities = new HashSet <IMyEntity>();
                            MyAPIGateway.Entities.GetEntities(entities);
                            foreach (var entity in entities)
                            {
                                var grid = entity as IMyCubeGrid;
                                if (grid?.Physics != null)
                                {
                                    entity.Physics.LinearVelocity = Vector3D.ClampToSphere(entity.Physics.LinearVelocity, 10);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine($"Exception during update:\r\n{ex}");
            }
        }
예제 #5
0
        /// <summary>
        /// Displays the current hud information.
        /// It should not contain any complex calculation, merly update the Hud as fast as possible.
        /// </summary>
        private static void DisplayHud()
        {
            ClientConfig clientConfig = EconomyScript.Instance.ClientConfig;

            // client config has not been received from server yet.
            if (clientConfig == null)
                return;

            if (clientConfig.ClientHudSettings.ShowHud)
            {
                IMyHudObjectiveLine objective = MyAPIGateway.Utilities.GetObjectiveLine();

                //Hud, displays users balance, trade network name, and optionally faction and free storage space (% or unit?) in cargo and/or inventory
                //may also eventually be used to display info about completed objectives in missions/jobs/bounties/employment etc
                //needs to call this at init (working), and at each call to message handling(working), and on recieving any notification of payment.
                //since other balance altering scenarios such as selling stock requires a command or prompt by player calling this
                //at message handler should update in those scenarios automatically. That should avoid need for a timing loop and have no obvious sim impact

                /* We need a routine populating a field similar the the below regularly, which pushes
                 * updates to the x y z location readout if it is enabled
                 * this will also be critical for checking against mission conditions
                 * once missions are functional, that require a user travelling to a location
                
                 * something like this can be used to populate the trade region part of the hud as well
                 * where we find ourself in a trade region
                 * it could probably hang off the timer code that updates lcds
                 var position = ((IMyEntity)character).WorldMatrix.Translation;
                 var markets = MarketManager.FindMarketsFromLocation(position);
                 */

                //use title here that frees up mission line for actual missions - cargo should list total and used space or just empty space?

                string readout = null;
                if (clientConfig.HudReadout != null)
                {
                    // if the player does not have a controlable body yet, no point displaying a hud.
                    if (MyAPIGateway.Session.Player.Controller?.ControlledEntity?.Entity != null)
                    {
                        Vector3D position = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetPosition();

                        readout = string.Format(clientConfig.HudReadout,
                            clientConfig.BankBalance,
                            clientConfig.ServerConfig.CurrencyName,
                            position.X,
                            position.Y,
                            position.Z,
                            clientConfig.FactionName,
                            clientConfig.TradeZoneName);
                    }
                }

                if (clientConfig.ClientHudSettings.ShowFaction)
                {
                    if (objective.Objectives.Count < 1)
                        objective.Objectives.Add(clientConfig.HudObjective);
                    else if (objective.Objectives[0] != clientConfig.HudObjective)
                    {
                        // if we wanted a 2nd mission add it like this MyAPIGateway.Utilities.GetObjectiveLine().Objectives.Add("Mission");
                        //MyAPIGateway.Utilities.GetObjectiveLine().Objectives.Add(ClientConfig.LazyMissionText); //testing if my global is available
                        objective.Objectives[0] = clientConfig.HudObjective;
                    }
                }

                if (objective.Title != readout)
                {
                    objective.Title = readout;
                }
            }
            //MyAPIGateway.Utilities.GetObjectiveLine().Objectives[0] = readout;  //using title not mission text now
        }