Beispiel #1
0
        //DataTypes:
        //0 = Bool
        //1 = Float
        //2 = Int
        private static void ShowPlayerData()
        {
            //Temporary Arduino Values
            int ComPortNumber = 6;
            int BaudRate      = 115200;
            MyObjectBuilder_Character CharacterInfo = (MyObjectBuilder_Character)MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetObjectBuilder();
            MySerialOut MessageOut = new MySerialOut();
            bool        result     = false;
            Dictionary <int, SerialVars> SerialOutValues = new Dictionary <int, SerialVars>();

            #region object gathering

            //SerialVars PlayerHealth = new SerialVars()
            //{
            //    ItemID = 0,
            //    ItemName = "PlayerHealth",
            //    CurrentValue = (int)(float.Parse(SerialCommsOut.Script.GetPlayerHealth(CharacterInfo)) * 100.0f),
            //    MaxValue = "100",
            //    DataType = "1"
            //};
            SerialVars PlayerEnergy = new SerialVars()
            {
                ItemID       = 1,
                ItemName     = "PlayerEnergy",
                CurrentValue = (int)(CharacterInfo.Battery.CurrentCapacity * 100),
                MaxValue     = "100",
                DataType     = "1",
                lastState    = "LastPlayerEnergyUpdate"
            };
            SerialVars PlayerOxygen = new SerialVars()
            {
                ItemID       = 2,
                ItemName     = "PlayerOxygen",
                CurrentValue = (int)(CharacterInfo.OxygenLevel * 100),
                MaxValue     = "100",
                DataType     = "1",
                lastState    = "LastPlayerOxygenUpdate"
            };
            ////SerialVars PlayerHydrogen = new SerialVars()
            ////{
            ////    ItemID = 3,
            ////    ItemName = "PlayerHydrogen",
            ////    CurrentValue = SerialCommsOut.Script.GetPlayerHydrogen(CharacterInfo),
            ////    MaxValue = "100",
            ////    DataType = "Double"
            ////};
            //SerialVars PlayerDampers = new SerialVars()
            //{
            //    ItemID = 4,
            //    ItemName = "PlayerDampers",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerDamperStatus(CharacterInfo)),
            //    MaxValue = "1",
            //    DataType = "0"
            //};
            //SerialVars PlayerJetPack = new SerialVars()
            //{
            //    ItemID = 5,
            //    ItemName = "PlayerJetPack",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerJetPackStatus(CharacterInfo)),
            //    MaxValue = "1",
            //    DataType = "0"
            //};
            //SerialVars PlayerSuitLight = new SerialVars()
            //{
            //    ItemID = 6,
            //    ItemName = "PlayerSuitLight",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerSuitLightStatus(CharacterInfo)),
            //    MaxValue = "1",
            //    DataType = "0"
            //};
            //SerialVars PlayerSpeed = new SerialVars()
            //{
            //    ItemID = 7,
            //    ItemName = "PlayerSpeed",
            //    CurrentValue = (int)(float.Parse(SerialCommsOut.Script.GetPlayerSpeed(CharacterInfo)) * 100.0f),
            //    MaxValue = "0",
            //    DataType = "1"
            //};
            //SerialVars PlayerCurrentInventory = new SerialVars()
            //{
            //    ItemID = 8,
            //    ItemName = "PlayerCurrentInventory",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerCurrentInventory()),
            //    MaxValue = "0",
            //    DataType = "2"
            //};
            //SerialVars PlayerMaxInventory = new SerialVars()
            //{
            //    ItemID = 9,
            //    ItemName = "PlayerMaxInventory",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerMaxInventory()),
            //    MaxValue = "0",
            //    DataType = "2"
            //};
            //SerialVars PlayerAntenna = new SerialVars()
            //{
            //    ItemID = 10,
            //    ItemName = "PlayerAntenna",
            //    CurrentValue = Convert.ToInt16(SerialCommsOut.Script.GetPlayerAntennaStatus(CharacterInfo)),
            //    MaxValue = "1",
            //    DataType = "0"
            //};
            //Should Ship data ItemID always come after player data?
            //Should we break this API script into 2 Scripts one for Player and one for Ship?
            //A ship only script would be easier to attach to a programmable block until Ondrej enables local scripts

            /*SerialVars ShipDamage = new SerialVars()
             * {
             *  ItemID = 100,
             *  ItemName = "ShipDamage",
             *  CurrentValue = "50",
             *  MaxValue = "100",
             *  DataType = "Double"
             * };*/
            #endregion

            //Add all Desired Objects here with "SerialOutValues.Add"

            SerialOutValues.Clear();
            //SerialOutValues.Add(PlayerHealth.ItemID, PlayerHealth);
            SerialOutValues.Add(PlayerEnergy.ItemID, PlayerEnergy);
            SerialOutValues.Add(PlayerOxygen.ItemID, PlayerOxygen);
            //SerialOutValues.Add(PlayerHydrogen.ItemID, PlayerHydrogen);
            //SerialOutValues.Add(PlayerDampers.ItemID, PlayerDampers);
            //SerialOutValues.Add(PlayerJetPack.ItemID, PlayerJetPack);
            //SerialOutValues.Add(PlayerSuitLight.ItemID, PlayerSuitLight);
            //SerialOutValues.Add(PlayerSpeed.ItemID, PlayerSpeed);
            //SerialOutValues.Add(PlayerCurrentInventory.ItemID, PlayerCurrentInventory);
            //SerialOutValues.Add(PlayerMaxInventory.ItemID, PlayerMaxInventory);
            //SerialOutValues.Add(PlayerAntenna.ItemID, PlayerAntenna);

            foreach (SerialVars serialVars in SerialOutValues.Values)      //.OrderBy()
            {
                //        ScreenData += (String.Format("ItemID = {0}, ItemName = {1}, CurrentValue = {2}, MaxValue = {3}, DataType = {4}", serialVars.ItemID, serialVars.ItemName, serialVars.CurrentValue, serialVars.MaxValue, serialVars.DataType)) + "/\n";
                // MessageOut = (serialVars.DataType, serialVars.ItemName, serialVars.CurrentValue, serialVars.MaxValue );
                IMySerialOutAccess OutData     = MessageOut;
                string             tempMessage = serialVars.DataType + "," + serialVars.ItemID.ToString() + "," + serialVars.CurrentValue.ToString() + "," + serialVars.MaxValue;
                if (LastStates.GetCurrentLasState(serialVars))    // if true send message
                {
                    result = OutData.SendMessageToSerial(tempMessage, ComPortNumber, BaudRate);
                    MyAPIGateway.Utilities.ShowNotification(tempMessage, 3000, MyFontEnum.Green);
                }
            }

            //MyAPIGateway.Utilities.ShowMissionScreen("Serial Out Data", DateTime.Now.ToString(), "Values:", ScreenData, null, "Hide Screen");

            /*if (CurrentPlayerState != 0)
             * {
             *  SerialOutValues.Add(ShipDamage.ItemID, ShipDamage);
             * }*/
            //call SerialCommsOut_SerialCommsOut SerialCommsOut.Script ShowSerialVars
        }
Beispiel #2
0
        private static void ShowPlayerData()
        {
            MyObjectBuilder_Character CharacterInfo = (MyObjectBuilder_Character)MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetObjectBuilder();

            Dictionary<int, SerialVars> SerialOutValues = new Dictionary<int, SerialVars>();

            #region object gathering

            SerialVars PlayerHealth = new SerialVars()
            {
                Priority = 0,
                ItemName = "PlayerHealth",
                CurrentValue = SerialCommsOut.Script.GetPlayerHealth(CharacterInfo),
                MaxValue = "100",
                DataType = "Float"
            };
            SerialVars PlayerEnergy = new SerialVars()
            {
                Priority = 1,
                ItemName = "PlayerEnergy",
                CurrentValue = SerialCommsOut.Script.GetPlayerEnergy(CharacterInfo),
                MaxValue = "100",
                DataType = "Double"
            };
            SerialVars PlayerOxygen = new SerialVars()
            {
                Priority = 2,
                ItemName = "PlayerOxygen",
                CurrentValue = SerialCommsOut.Script.GetPlayerOxygen(CharacterInfo),
                MaxValue = "100",
                DataType = "Double"
            };
            SerialVars PlayerHydrogen = new SerialVars()
            {
                Priority = 3,
                ItemName = "PlayerHydrogen",
                CurrentValue = SerialCommsOut.Script.GetPlayerHydrogen(CharacterInfo),
                MaxValue = "100",
                DataType = "Double"
            };
            SerialVars PlayerDampers = new SerialVars()
            {
                Priority = 4,
                ItemName = "PlayerDampers",
                CurrentValue = SerialCommsOut.Script.GetPlayerDamperStatus(CharacterInfo),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerJetPack = new SerialVars()
            {
                Priority = 5,
                ItemName = "PlayerJetPack",
                CurrentValue = SerialCommsOut.Script.GetPlayerJetPackStatus(CharacterInfo),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerSuitLight = new SerialVars()
            {
                Priority = 6,
                ItemName = "PlayerSuitLight",
                CurrentValue = SerialCommsOut.Script.GetPlayerSuitLightStatus(CharacterInfo),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerSpeed = new SerialVars()
            {
                Priority = 7,
                ItemName = "PlayerSpeed",
                CurrentValue = SerialCommsOut.Script.GetPlayerSpeed(CharacterInfo),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerCurrentInventory = new SerialVars()
            {
                Priority = 8,
                ItemName = "PlayerCurrentInventory",
                CurrentValue = SerialCommsOut.Script.GetPlayerCurrentInventory(),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerMaxInventory = new SerialVars()
            {
                Priority = 9,
                ItemName = "PlayerMaxInventory",
                CurrentValue = SerialCommsOut.Script.GetPlayerMaxInventory(),
                MaxValue = "true",
                DataType = "Bit"
            };
            SerialVars PlayerAntenna = new SerialVars()
            {
                Priority = 10,
                ItemName = "PlayerAntenna",
                CurrentValue = SerialCommsOut.Script.GetPlayerAntennaStatus(CharacterInfo),
                MaxValue = "true",
                DataType = "Bit"
            };
            //Should Ship data priority always come after player data?
            //Should we break this API script into 2 Scripts one for Player and one for Ship?
            //A ship only script would be easier to attach to a programmable block until Ondrej enables local scripts

            /*SerialVars ShipDamage = new SerialVars()
            {
                Priority = 100,
                ItemName = "ShipDamage",
                CurrentValue = "50",
                MaxValue = "100",
                DataType = "Double"
            };*/
            #endregion

            //Add all Desired Objects here with "SerialOutValues.Add"

                SerialOutValues.Clear();
                SerialOutValues.Add(PlayerHealth.Priority, PlayerHealth);
                SerialOutValues.Add(PlayerEnergy.Priority, PlayerEnergy);
                SerialOutValues.Add(PlayerOxygen.Priority, PlayerOxygen);
                SerialOutValues.Add(PlayerHydrogen.Priority, PlayerHydrogen);
                SerialOutValues.Add(PlayerDampers.Priority, PlayerDampers);
                SerialOutValues.Add(PlayerJetPack.Priority, PlayerJetPack);
                SerialOutValues.Add(PlayerSuitLight.Priority, PlayerSuitLight);
                SerialOutValues.Add(PlayerSpeed.Priority, PlayerSpeed);
                SerialOutValues.Add(PlayerCurrentInventory.Priority, PlayerCurrentInventory);
                SerialOutValues.Add(PlayerMaxInventory.Priority, PlayerMaxInventory);
                SerialOutValues.Add(PlayerAntenna.Priority, PlayerAntenna);
                string ScreenData = string.Empty;
                foreach (SerialVars serialVars in SerialOutValues.Values)  //.OrderBy()
                {
                    ScreenData += (String.Format("Priority = {0}, ItemName = {1}, CurrentValue = {2}, MaxValue = {3}, DataType = {4}", serialVars.Priority, serialVars.ItemName, serialVars.CurrentValue, serialVars.MaxValue, serialVars.DataType)) + "/\n";
                }

            MyAPIGateway.Utilities.ShowMissionScreen("Serial Out Data", DateTime.Now.ToString(), "Values:", ScreenData, null, "Hide Screen");
            ScreenData = String.Empty;

            /*if (CurrentPlayerState != 0)
            {
                SerialOutValues.Add(ShipDamage.Priority, ShipDamage);
            }*/
            //call SerialCommsOut_SerialCommsOut SerialCommsOut.Script ShowSerialVars
        }