public InventoryEditorModel(MyObjectBuilder_Inventory inventory, float maxVolume, MyObjectBuilder_Character character = null)
        {
            _inventory = inventory;
            _maxVolume = maxVolume;
            _character = character;
            UpdateGeneralFromEntityBase();

            // Cube.InventorySize.X * CUbe.InventorySize.Y * CUbe.InventorySize.Z * 1000 * Sandbox.InventorySizeMultiplier;
            // or Cube.InventoryMaxVolume * 1000 * Sandbox.InventorySizeMultiplier;
            //Character.Inventory = 0.4 * 1000 * Sandbox.InventorySizeMultiplier;
        }
        public CharacterEntity(MyObjectBuilder_Character definition, Object backingObject)
            : base(definition, backingObject)
        {
            m_inventory = new InventoryEntity(definition.Inventory, InternalGetCharacterInventory());

            EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent();
            newEvent.type = EntityEventManager.EntityEventType.OnCharacterCreated;
            newEvent.timestamp = DateTime.Now;
            newEvent.entity = this;
            newEvent.priority = 1;
            EntityEventManager.Instance.AddEvent(newEvent);
        }
		public virtual void Init(MyObjectBuilder_Character characterBuilder)
		{
			if (characterBuilder == null)
				return;

			m_inertiaDampenersNotification = new MyHudNotification();
			m_jetpackToggleNotification = new MyHudNotification();

			CurrentAutoEnableDelay = characterBuilder.AutoenableJetpackDelay;

			if (ThrustComp != null)
				Character.Components.Remove<MyJetpackThrustComponent>();

		    var thrustProperties = Character.Definition.Jetpack.ThrustProperties;

		    FuelConverterDefinition = null;;
		    FuelConverterDefinition = !MyFakes.ENABLE_HYDROGEN_FUEL ? new MyFuelConverterInfo { Efficiency = 1.0f } : Character.Definition.Jetpack.ThrustProperties.FuelConverter;

		    MyDefinitionId fuelId = new MyDefinitionId();
		    if (!FuelConverterDefinition.FuelId.IsNull())
		        fuelId = thrustProperties.FuelConverter.FuelId;

		    MyGasProperties fuelDef = null;
            if (MyFakes.ENABLE_HYDROGEN_FUEL)
                MyDefinitionManager.Static.TryGetDefinition(fuelId, out fuelDef);

            FuelDefinition = fuelDef ?? new MyGasProperties // Use electricity by default
            {
                Id = MyResourceDistributorComponent.ElectricityId,
                EnergyDensity = 1f,
            };

            ForceMagnitude = thrustProperties.ForceMagnitude;
			MinPowerConsumption = thrustProperties.MinPowerConsumption;
			MaxPowerConsumption = thrustProperties.MaxPowerConsumption;
		    EffectivenessAtMinInfluence = thrustProperties.EffectivenessAtMinInfluence;
		    EffectivenessAtMaxInfluence = thrustProperties.EffectivenessAtMaxInfluence;

			MyEntityThrustComponent thrustComp = new MyJetpackThrustComponent();
			thrustComp.Init();

		    thrustComp.ResourceSink.TemporaryConnectedEntity = Character;

			Character.Components.Add(thrustComp);
			ThrustComp.DampenersEnabled = characterBuilder.DampenersEnabled;

			foreach (Vector3I direction in Base6Directions.IntDirections)
			{
				ThrustComp.Register(Character, direction);	// Preferably there should be a jetpack entity (equipment) that could hold the thrusts instead of the character
			}
            Character.SuitRechargeDistributor.AddSink(thrustComp.ResourceSink);
			TurnOnJetpack(characterBuilder.JetpackEnabled, true, true, true);
		}
 public CharacterEntity(MyObjectBuilder_Character definition)
     : base(definition)
 {
     m_inventory = new InventoryEntity(definition.Inventory);
 }
		public virtual void GetObjectBuilder(MyObjectBuilder_Character characterBuilder)
		{
			characterBuilder.DampenersEnabled = DampenersTurnedOn;
			characterBuilder.JetpackEnabled = TurnedOn;
			characterBuilder.AutoenableJetpackDelay = CurrentAutoEnableDelay;
		}
        public virtual void GetObjectBuilder(MyObjectBuilder_Character objectBuilder)
        {
            objectBuilder.OxygenLevel = SuitOxygenLevel;

            if (m_storedGases != null && m_storedGases.Length > 0)
            {
                if(objectBuilder.StoredGases == null)
                    objectBuilder.StoredGases = new List<MyObjectBuilder_Character.StoredGas>();

                foreach (var storedGas in m_storedGases)
                {
                    if (!objectBuilder.StoredGases.TrueForAll((obGas) => obGas.Id != storedGas.Id))
                        continue;

                    objectBuilder.StoredGases.Add(new MyObjectBuilder_Character.StoredGas { Id = storedGas.Id, FillLevel = storedGas.FillLevel });
                }
            }
        }
Example #7
0
        //Add switch case for CurrentPlayerState for each method below in this region only.
        //If CurrentPlayerState !=0 pass the stashed Player Entity - Needs to be written.
        public static string GetPlayerHealth(MyObjectBuilder_Character CharacterInfo)
        {
            float? percentFloat = null;
            if(CurrentPlayerState == 0)
            {
                if (!CharacterInfo.Health.HasValue)
                {
                    percentFloat = 100.00f;
                }
                else
                {
                    percentFloat = CharacterInfo.Health.Value;
                }
            }
            else
            {
                percentFloat = 666666;
            }

               return percentFloat.ToString();
        }
 public void ClearPilotAndAutopilot()
 {
     Pilot     = null;
     Autopilot = null;
 }
 public void ClearPilotAndAutopilot()
 {
     Pilot = null;
     Autopilot = null;
 }
        void SpawnSimpleSkinnedObject()
        {

            var skin = new MySkinnedEntity();

            MyObjectBuilder_Character ob = new MyObjectBuilder_Character();
            ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector);
            skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null);
            skin.Init(ob);

            MyEntities.Add(skin);

            var command = new MyAnimationCommand()
            {
                AnimationSubtypeName = "IdleBarbar",
                FrameOption = MyFrameOption.Loop,
                TimeScale = 1
            };
            skin.AddCommand(command);

            m_skins.Add(skin);
        }
Example #11
0
 public static string GetPlayerAntennaStatus(MyObjectBuilder_Character CharacterInfo)
 {
     bool BitVal = false;
     if (CurrentPlayerState == 0)
     {
         BitVal = CharacterInfo.EnableBroadcasting;
     }
     return BitVal.ToString();
 }
Example #12
0
 public static string GetPlayerSuitLightStatus(MyObjectBuilder_Character CharacterInfo)
 {
     bool BitVal = false;
     if (CurrentPlayerState == 0)
     {
         BitVal = CharacterInfo.LightEnabled;
     }
     return BitVal.ToString();
 }
Example #13
0
 public static string GetPlayerSpeed(MyObjectBuilder_Character CharacterInfo)
 {
     string StringVal = string.Empty;
     if (CurrentPlayerState == 0)
     {
     float Xvalue = CharacterInfo.LinearVelocity.X;
     float Yvalue = CharacterInfo.LinearVelocity.Y;
     float Zvalue = CharacterInfo.LinearVelocity.Z;
     Vector3 testVector = new Vector3(Xvalue, Yvalue, Zvalue);
     StringVal = testVector.Length().ToString() + " m/s";
     }
     return StringVal;
 }
Example #14
0
 public static string GetPlayerOxygen(MyObjectBuilder_Character CharacterInfo)
 {
     double percentDouble = 0;
     if (CurrentPlayerState == 0)
     {
          percentDouble = CharacterInfo.OxygenLevel * 10000f / 100;
     }
     return percentDouble.ToString();
 }
Example #15
0
        public static string GetPlayerHydrogen(MyObjectBuilder_Character CharacterInfo)
        {
            double percentDouble = 0;
            string currentamount = string.Empty;
            string id = string.Empty;
            if (CurrentPlayerState == 0)
            {
                //percentDouble = CharacterInfo.StoredGases..Capacity (* 10000f / 100);
                List<MyObjectBuilder_Character.StoredGas> StoredGases = CharacterInfo.StoredGases;
                foreach (MyObjectBuilder_Character.StoredGas gas in StoredGases)
                {
                     id = gas.Id.ToString();
                     if (id == "MyObjectBuilder_GasProperties/Hydrogen")
                     { percentDouble = gas.FillLevel *100; }
                     else { percentDouble = 0; }

                }
            }
            return percentDouble.ToString();
        }
 public void ClearPilotAndAutopilot()
 {
     Pilot            = null;
     Autopilot        = null;
     AttachedPlayerId = null;
 }
Example #17
0
        public static void SendCharacterCreated(MyObjectBuilder_Character character, MyCockpit cockpit)
        {
            MySyncCreate.SendEntityCreated(character);

            AttachToCockpitMsg msg = new AttachToCockpitMsg();
            msg.CharacterEntityId = character.EntityId;
            msg.CockpitEntityId = cockpit.EntityId;

            Sync.Layer.SendMessageToAll(ref msg);
        }
        public virtual void Init(MyObjectBuilder_Character characterOb)
        {
            if (MySession.Static.SurvivalMode)
            {
                m_suitOxygenAmount = characterOb.OxygenLevel * Definition.OxygenCapacity;
            }
            else
            {
                m_suitOxygenAmount = Definition.OxygenCapacity;
            }
            m_oldSuitOxygenLevel = SuitOxygenLevel;

            m_gasIdToIndex = new Dictionary<MyDefinitionId, int>(); 
            if (MyFakes.ENABLE_HYDROGEN_FUEL && Definition.SuitResourceStorage != null)
            {
                m_storedGases = new GasData[Definition.SuitResourceStorage.Count];
                for(int gasIndex = 0; gasIndex < m_storedGases.Length; ++gasIndex)
                {
                    var gasInfo = Definition.SuitResourceStorage[gasIndex];
                    m_storedGases[gasIndex] = new GasData
                    {
                        Id = gasInfo.Id,
                        FillLevel = 1f,
                        MaxCapacity = gasInfo.MaxCapacity,
                        Throughput = gasInfo.Throughput
                    };
                    m_gasIdToIndex.Add(gasInfo.Id, gasIndex);
                }

                if (characterOb.StoredGases != null)
                {
                    foreach (var gasInfo in characterOb.StoredGases)
                    {
                        int gasIndex;
                        if (!m_gasIdToIndex.TryGetValue(gasInfo.Id, out gasIndex))
                            continue;
                        m_storedGases[gasIndex].FillLevel = gasInfo.FillLevel;
                    }
                }
            }
            if(m_storedGases == null)
                m_storedGases = new GasData[0];

            m_oxygenBottleRefillNotification = new MyHudNotification(text: MySpaceTexts.NotificationBottleRefill, level: MyNotificationLevel.Important);
            m_lowOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenLow, font: MyFontEnum.Red, level: MyNotificationLevel.Important);
            m_criticalOxygenNotification = new MyHudNotification(text: MySpaceTexts.NotificationOxygenCritical, font: MyFontEnum.Red, level: MyNotificationLevel.Important);
            m_helmetToggleNotification = m_helmetToggleNotification ?? new MyHudNotification(); // Init() is called when toggling helmet so this check is required

            m_needsOxygen = Definition.NeedsOxygen;

            NeedsUpdateBeforeSimulation100 = true;
        }
Example #19
0
        public static string RepairSandBox(WorldResource world)
        {
            var str = new StringBuilder();
            var statusNormal = true;
            var missingFiles = false;
            var saveAfterScan = false;

            // repair will use the WorldResource, thus it won't have access to the wrapper classes.
            // Any repair must be on the raw XML or raw serialized classes.

            var repairWorld = world;
            repairWorld.LoadCheckpoint();

            var xDoc = repairWorld.LoadSectorXml();

            if (xDoc == null)
            {
                str.AppendLine("! Sector file is missing or broken.");
                str.AppendLine("! Unable to repair.");
                missingFiles = true;
            }
            else
            {
                var nsManager = xDoc.BuildXmlNamespaceManager();
                var nav = xDoc.CreateNavigator();

                #region Updates the Group Control format.

                var shipNodes = nav.Select("MyObjectBuilder_Sector/SectorObjects/MyObjectBuilder_EntityBase[@xsi:type='MyObjectBuilder_CubeGrid']", nsManager);
                while (shipNodes.MoveNext())
                {
                    var groupBlocksNode = shipNodes.Current.SelectSingleNode("BlockGroups/MyObjectBuilder_BlockGroup/Blocks", nsManager);
                    if (groupBlocksNode != null)
                    {
                        var entityIdNodes = groupBlocksNode.Select("long", nsManager);
                        var removeNodes = new List<XPathNavigator>();
                        while (entityIdNodes.MoveNext())
                        {
                            var entityId = Convert.ToInt64(entityIdNodes.Current.Value);
                            var node = shipNodes.Current.SelectSingleNode(string.Format("CubeBlocks/*[./EntityId='{0}']", entityId), nsManager);
                            if (node != null)
                            {
                                var x = node.ToValue<string>("Min/@x");
                                var y = node.ToValue<string>("Min/@y");
                                var z = node.ToValue<string>("Min/@z");

                                entityIdNodes.Current.InsertBefore(string.Format("<Vector3I><X>{0}</X><Y>{1}</Y><Z>{2}</Z></Vector3I>", x, y, z));
                                removeNodes.Add(entityIdNodes.Current.Clone());
                                str.AppendLine("* Replaced BlockGroup item.");
                                saveAfterScan = true;
                                statusNormal = false;
                            }
                        }

                        foreach (var node in removeNodes)
                        {
                            node.DeleteSelf();
                        }
                    }
                }

                //<BlockGroups>
                //<MyObjectBuilder_BlockGroup>
                //    <Name>Open</Name>
                //    <Blocks>
                //    <long>-2287829012813351669</long>
                //    <long>-1828477283611406765</long>
                //    <long>73405095007807299</long>
                //    <long>-8785290580748247313</long>
                //    </Blocks>
                //</MyObjectBuilder_BlockGroup>
                //</BlockGroups>

                //<BlockGroups>
                //<MyObjectBuilder_BlockGroup>
                //    <Name>Open</Name>
                //    <Blocks>
                //    <Vector3I>
                //        <X>-1</X>
                //        <Y>2</Y>
                //        <Z>-4</Z>
                //    </Vector3I>
                //    <Vector3I>
                //        <X>-1</X>
                //        <Y>7</Y>
                //        <Z>2</Z>
                //    </Vector3I>
                //    <Vector3I>
                //        <X>-1</X>
                //        <Y>8</Y>
                //        <Z>-9</Z>
                //    </Vector3I>
                //    <Vector3I>
                //        <X>-1</X>
                //        <Y>13</Y>
                //        <Z>-3</Z>
                //    </Vector3I>
                //    </Blocks>
                //</MyObjectBuilder_BlockGroup>
                //</BlockGroups>

                if (saveAfterScan)
                {
                    repairWorld.SaveSectorXml(true, xDoc);
                    str.AppendLine("* Saved changes.");
                }

                #endregion
            }

            repairWorld.LoadDefinitionsAndMods();
            repairWorld.LoadSector();

            if (repairWorld.Checkpoint == null)
            {
                statusNormal = false;
                str.AppendLine("! Checkpoint file is missing or broken.");
                str.AppendLine("! Unable to repair.");
                missingFiles = true;
            }

            if (repairWorld.SectorData == null)
            {
                statusNormal = false;
                str.AppendLine("! Sector file is missing or broken.");
                str.AppendLine("! Unable to repair.");
                missingFiles = true;
            }

            if (!missingFiles)
            {
                MyObjectBuilder_Character character;

                saveAfterScan = false;

                Dictionary<long, long> idReplacementTable = new Dictionary<long, long>();
                if (repairWorld.Checkpoint.Identities != null)
                {
                    foreach(var identity in repairWorld.Checkpoint.Identities)
                    {
                        if (!SpaceEngineersApi.ValidateEntityType(IDType.IDENTITY, identity.IdentityId))
                        {
                            identity.IdentityId = MergeId(identity.IdentityId, IDType.IDENTITY, ref idReplacementTable);

                            statusNormal = false;
                            str.AppendLine("! Fixed player identity.");
                            saveAfterScan = true;
                        }
                    }
                }

                if (repairWorld.Checkpoint.AllPlayersData != null)
                {
                    foreach (var player in repairWorld.Checkpoint.AllPlayersData.Dictionary)
                    {
                        if (!SpaceEngineersApi.ValidateEntityType(IDType.IDENTITY, player.Value.IdentityId))
                        {
                            player.Value.IdentityId = MergeId(player.Value.IdentityId, IDType.IDENTITY, ref idReplacementTable);

                            statusNormal = false;
                            str.AppendLine("! Fixed player identity.");
                            saveAfterScan = true;
                        }
                    }
                }

                if (saveAfterScan)
                {
                    repairWorld.SaveCheckPointAndSector(true);
                    str.AppendLine("* Saved changes.");
                }

                if (world.SaveType == SaveWorldType.Local)
                {
                    var player = repairWorld.FindPlayerCharacter();

                    if (player == null)
                    {
                        statusNormal = false;
                        str.AppendLine("! No active Player in Save content.");

                        character = repairWorld.FindAstronautCharacter();
                        if (character != null)
                        {
                            repairWorld.Checkpoint.ControlledObject = character.EntityId;
                            repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.Entity;
                            repairWorld.Checkpoint.CameraEntity = character.EntityId;
                            str.AppendLine("* Found and Set new active Player.");
                            repairWorld.SaveCheckPointAndSector(true);
                            str.AppendLine("* Saved changes.");
                        }
                        else
                        {
                            var cockpit = repairWorld.FindPilotCharacter();
                            if (cockpit != null)
                            {
                                repairWorld.Checkpoint.ControlledObject = cockpit.EntityId;
                                repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.ThirdPersonSpectator;
                                repairWorld.Checkpoint.CameraEntity = 0;
                                str.AppendLine("* Found and Set new active Player.");
                                repairWorld.SaveCheckPointAndSector(true);
                                str.AppendLine("* Saved changes.");
                            }
                            else
                            {
                                str.AppendLine("! Could not find any Player Characters.");
                                character = new MyObjectBuilder_Character();
                                character.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.IDENTITY);
                                character.PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene;
                                character.PositionAndOrientation = new MyPositionAndOrientation(VRageMath.Vector3D.Zero, VRageMath.Vector3.Forward, VRageMath.Vector3.Up);
                                character.CharacterModel = SpaceEngineersCore.Resources.Definitions.Characters[0].Name;
                                character.ColorMaskHSV = new SerializableVector3(0, -1, 1); // White
                                character.Battery = new MyObjectBuilder_Battery { CurrentCapacity = 0.5f };
                                character.LightEnabled = false;
                                character.HeadAngle = new VRageMath.Vector2();
                                character.LinearVelocity = new VRageMath.Vector3();
                                character.AutoenableJetpackDelay = -1;
                                character.JetpackEnabled = true;
                                character.Inventory = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_Inventory>();

                                // Add default items to Inventory.
                                MyObjectBuilder_InventoryItem item;
                                MyObjectBuilder_EntityBase gunEntity;

                                character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                item.Amount = 1;
                                item.ItemId = 0;
                                item.Content = new MyObjectBuilder_Welder();
                                gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_Welder>();
                                gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                ((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;

                                character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                item.Amount = 1;
                                item.ItemId = 1;
                                item.Content = new MyObjectBuilder_AngleGrinder();
                                gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AngleGrinder>();
                                gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                ((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;

                                character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                item.Amount = 1;
                                item.ItemId = 2;
                                item.Content = new MyObjectBuilder_HandDrill();
                                gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_HandDrill>();
                                gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                ((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;

                                character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                item.Amount = 1;
                                item.ItemId = 3;
                                item.Content = new MyObjectBuilder_AutomaticRifle();
                                gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AutomaticRifle>();
                                gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                ((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;

                                repairWorld.Checkpoint.ControlledObject = character.EntityId;
                                repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.Entity;
                                repairWorld.Checkpoint.CameraEntity = character.EntityId;

                                repairWorld.SectorData.SectorObjects.Add(character);

                                str.AppendLine("* Created new active Player.");
                                repairWorld.SaveCheckPointAndSector(true);
                                str.AppendLine("* Saved changes.");
                            }
                        }
                    }

                    saveAfterScan = false;

                    // Make sure the character in a locally saved world has all tools.
                    // SubtypeNames for required tools.
                    var requiredItems = new[] { 
                        "WelderItem", "AngleGrinderItem", "HandDrillItem" };

                    character = repairWorld.FindAstronautCharacter()
                        ?? repairWorld.FindPilotCharacter().Pilot;

                    MyObjectBuilder_Inventory inventory = character.Inventory;
                    requiredItems.ForEach(
                        delegate(string subtypeName)
                        {
                            if (!inventory.Items.Any(i =>
                                i.PhysicalContent != null &&
                                i.PhysicalContent.SubtypeName == subtypeName))
                            {
                                statusNormal = false;
                                str.AppendLine("! Replaced astronaut's missing " + subtypeName + ".");
                                saveAfterScan = true;
                                inventory.Items.Add(new MyObjectBuilder_InventoryItem
                                {
                                    Amount = 1,
                                    Content = new MyObjectBuilder_PhysicalGunObject { SubtypeName = subtypeName },
                                    ItemId = inventory.nextItemId
                                });
                                inventory.nextItemId++;
                            }
                        });
                }

                // Scan through all items.
                foreach (var entity in repairWorld.SectorData.SectorObjects)
                {
                    if (entity is MyObjectBuilder_CubeGrid)
                    {
                        var cubeGrid = (MyObjectBuilder_CubeGrid)entity;

                        var list = cubeGrid.CubeBlocks.Where(c => c is MyObjectBuilder_Ladder).ToArray();

                        for (var i = 0; i < list.Length; i++)
                        {
                            var c = new MyObjectBuilder_Passage
                            {
                                EntityId = list[i].EntityId,
                                BlockOrientation = list[i].BlockOrientation,
                                BuildPercent = list[i].BuildPercent,
                                ColorMaskHSV = list[i].ColorMaskHSV,
                                IntegrityPercent = list[i].IntegrityPercent,
                                Min = list[i].Min,
                                SubtypeName = list[i].SubtypeName
                            };
                            cubeGrid.CubeBlocks.Remove(list[i]);
                            cubeGrid.CubeBlocks.Add(c);
                        }

                        if (list.Length > 0)
                        {
                            // MyObjectBuilder_Ladder/MyObjectBuilder_Passage convert.
                            statusNormal = false;
                            str.AppendLine("! 'Ladder' no longer supported in game.");
                            str.AppendLine(string.Format("! {0} 'Ladder' converted to 'Passage'.", list.Length));
                            saveAfterScan = true;
                        }

                        list = cubeGrid.CubeBlocks.OfType<MyObjectBuilder_Cockpit>().ToArray();
                        for (var i = 0; i < list.Length; i++)
                        {
                            if (((MyObjectBuilder_Cockpit)list[i]).Pilot != null)
                            {
                                character = ((MyObjectBuilder_Cockpit)list[i]).Pilot;

                                if (!SpaceEngineersCore.Resources.Definitions.Characters.Any(c => c.Model == character.CharacterModel))
                                {
                                    character.CharacterModel = SpaceEngineersCore.Resources.Definitions.Characters[0].Model;
                                    statusNormal = false;
                                    str.AppendLine("! Fixed astronaut's CharacterModel.");
                                    saveAfterScan = true;
                                }
                            }
                        }

                        // TODO: search for cubeblocks that don't exist in the definitions.
                        //var definition = SpaceEngineersAPI.GetCubeDefinition(block.GetType(), CubeGrid.GridSizeEnum, block.SubtypeName);
                    }

                    character = entity as MyObjectBuilder_Character;
                    if (character != null)
                    {
                        if (!SpaceEngineersCore.Resources.Definitions.Characters.Any(c => c.Model == character.CharacterModel))
                        {
                            character.CharacterModel = SpaceEngineersCore.Resources.Definitions.Characters[0].Model;
                            statusNormal = false;
                            str.AppendLine("! Fixed astronaut's CharacterModel.");
                            saveAfterScan = true;
                        }
                    }
                }

                //if (world.Checkpoint.Players != null)
                //{
                //    foreach (var item in world.Checkpoint.Players.Dictionary)
                //    {
                //        if (!SpaceEngineersCore.Resources.Definitions.Characters.Any(c => c.Name == item.Value.PlayerModel))
                //        {
                //            item.Value.PlayerModel = SpaceEngineersCore.Resources.Definitions.Characters[0].Name;
                //            statusNormal = false;
                //            str.AppendLine("! Fixed astronaut's CharacterModel.");
                //            saveAfterScan = true;
                //        }

                //        // AllPlayers is obsolete.
                //        //if (item.Value.PlayerId == 0)
                //        //{
                //        //    item.Value.PlayerId = SpaceEngineersApi.GenerateEntityId();
                //        //    world.Checkpoint.AllPlayers.Add(new MyObjectBuilder_Checkpoint.PlayerItem(item.Value.PlayerId, "Repair", false, item.Value.SteamID, null));
                //        //    statusNormal = false;
                //        //    str.AppendLine("! Fixed corrupt or missing Player defitinion.");
                //        //    saveAfterScan = true;
                //        //}
                //    }
                //}

                if (saveAfterScan)
                {
                    repairWorld.SaveCheckPointAndSector(true);
                    str.AppendLine("* Saved changes.");
                }
            }

            if (statusNormal)
            {
                str.AppendLine("Detected no issues.");
            }

            return str.ToString();
        }
Example #20
0
 public static string GetPlayerEnergy(MyObjectBuilder_Character CharacterInfo)
 {
     double percentDouble = 0;
     if (CurrentPlayerState == 0)
     {
         percentDouble = CharacterInfo.Battery.CurrentCapacity * 10000000f;
     }
     return percentDouble.ToString();
 }