public WorldResource ClosestResourceOfInterest(List <WorldResource> _ResourceToFind, Vector3 VillagerPosition, GameObject Villager)
    {
        float         ClosestDistance  = 50;
        WorldResource _ClosestResource = null;

        foreach (WorldResource _Supply in _ResourceToFind)
        {
            if (_Supply != null)
            {
                float Distance = Vector3.Distance(VillagerPosition, _Supply.transform.position);
                if (Distance < ClosestDistance)
                {
                    if (_Supply._SupplyBeingTaken == true)
                    {
                        continue;
                    }
                    else
                    {
                        ClosestDistance  = Distance;
                        _ClosestResource = _Supply;
                    }
                }
            }
        }
        return(_ClosestResource);
    }
예제 #2
0
 public override void FinishedTargetLocation(Tile targetTile, WorldResource targetResource)
 {
     if (grown)
     {
         Harvest();
     }
 }
 public void DeleteWorldResource(WorldResource _Resource)
 {
     if (_WoodSupplies.Contains(_Resource))
     {
         _WoodSupplies.Remove(_Resource);
     }
 }
예제 #4
0
 public Target(Vector3 location, bool callWhenDone)
 {
     this.location       = location;
     this.targetTile     = null;
     this.targetResource = null;
     this.anim           = null;
     this.duration       = 0f;
     this.callWhenReach  = false;
     this.callWhenDone   = callWhenDone;
     this.dist           = 0.5f;
 }
예제 #5
0
 public Target(Vector3 location, Tile targetTile, WorldResource targetResource, Animation anim, float duration, bool callWhenReach, bool callWhenDone)
 {
     this.location       = location;
     this.targetTile     = targetTile;
     this.targetResource = targetResource;
     this.anim           = anim;
     this.duration       = duration;
     this.callWhenReach  = callWhenReach;
     this.callWhenDone   = callWhenDone;
     this.dist           = 0.5f;
 }
예제 #6
0
    private void AddNetworkedWorldResource(WorldResource worldResource, Vector2 terrainChunkCoord)
    {
        if (worldResource == null)
        {
            throw new MissingComponentException("No WorldResource component attached to the given prefab.");
        }

        if (!networkedWorldResources.ContainsKey(worldResource.Id))
        {
            photonView.RPC(nameof(RPC_AddNetworkedWorldResource), PhotonTargets.All, worldResource.Id, terrainChunkCoord, worldResource.MaxHealth);
        }
    }
예제 #7
0
    private IEnumerator PlayDepletedAnimation(WorldResource worldResource, Vector2 terrainChunkCoord)
    {
        if (worldResource.Animator != null)
        {
            worldResource.Animator.SetBool("isDepleted", true);
            yield return(new WaitForSeconds(worldResource.Animator.GetCurrentAnimatorClipInfo(0).Length + 1f));
        }

        worldResource.ItemsToDrop?.SpawnItemsOnDepleted();

        photonView.RPC(nameof(RPC_RemoveNetworkedWorldResource), PhotonTargets.All, worldResource.Id, terrainChunkCoord);
    }
예제 #8
0
    public void DecreaseHealth(WorldResource worldResource, TerrainChunk terrainChunk, float amount)
    {
        if (!networkedWorldResources.ContainsKey(worldResource.Id))
        {
            AddNetworkedWorldResource(worldResource, terrainChunk.Coord);
        }

        if (networkedWorldResources[worldResource.Id].Health > 0)
        {
            photonView.RPC(nameof(RPC_DecreaseHealth), PhotonTargets.All, worldResource.Id, amount);

            if (networkedWorldResources[worldResource.Id].Health <= 0)
            {
                StartCoroutine(PlayDepletedAnimation(worldResource, terrainChunk.Coord));
            }
        }
    }
예제 #9
0
 public override void FinishedTargetLocation(Tile targetTile, WorldResource targetResource)
 {
     GameObject.Destroy(targetResource.GetResourceObject());
     resourcesLeft--;
     if (resourcesLeft == 0)
     {
         // Change tile back to Grass Tile
         GrassTile gT = new GrassTile(mapLoc, worldLoc, type, tileObj);
         mapScript.SetTileFromMapPos((int)mapLoc.x, (int)mapLoc.y, gT);
     }
     if (isTrees)
     {
         tm.AddResource(woodRes);
     }
     else
     {
         tm.AddResource(stoneRes);
     }
 }
예제 #10
0
파일: Map.cs 프로젝트: JKneedler/Polis
    public List <WorldResource> GenerateResources(TempTile tile, Vector2 tileWorldPos, bool trees)
    {
        int resourceAmt = tile.numRes;
        List <WorldResource> tileResources = new List <WorldResource>();

        for (int i = 0; i < resourceAmt; i++)
        {
            //Get Random Position on Tile
            float      posX    = Random.Range(tileWorldPos.x, tileWorldPos.x + 1);
            float      posY    = Random.Range(tileWorldPos.y, tileWorldPos.y + 1);
            float      randRot = Random.Range(0, 360);
            Quaternion resRot  = Quaternion.Euler(0, randRot, 0);
            //Determine Amount of Trees on Tile
            int resourceSize = 0;
            if (trees)
            {
                resourceSize = Mathf.CeilToInt(Random.Range(0f, 1f) * ((float)resourceAmt / (float)maxTrees) * 3) - 1;
            }
            if (!trees)
            {
                resourceSize = Mathf.CeilToInt(Random.Range(0f, 1f) * ((float)resourceAmt / (float)maxRocks) * 3) - 1;
            }
            int        treeType   = Random.Range(0, 2);
            GameObject modelToUse = rockModels[0];
            if (trees)
            {
                modelToUse = treeModels[resourceSize + (3 * treeType)];
            }
            if (!trees)
            {
                modelToUse = rockModels[resourceSize];
            }
            GameObject resourceObj = (GameObject)Instantiate(modelToUse, new Vector3(posX, 0.05f, posY), resRot);
            resourceObj.transform.parent = resourceParent;
            WorldResource res = new WorldResource(resourceObj);
            tileResources.Add(res);
        }
        return(tileResources);
    }
예제 #11
0
 public override void ReachedTargetLocation(Tile targetTile, WorldResource targetResource)
 {
 }
예제 #12
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
                            {
                                // The game is sucessfully generating new characters now, so this code shouldn't be requried any more.

                                /*
                                 * 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 = Sandbox.Game.Entities.Character.MyCharacter.DefaultModel;
                                 * 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;
                                 * gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_Welder>();
                                 * gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                 * gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                 * item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject {GunEntity = gunEntity};
                                 *
                                 * character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                 * item.Amount = 1;
                                 * item.ItemId = 1;
                                 * gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AngleGrinder>();
                                 * gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                 * gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                 * item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { GunEntity = gunEntity };
                                 *
                                 * character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                 * item.Amount = 1;
                                 * item.ItemId = 2;
                                 * gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_HandDrill>();
                                 * gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                 * gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                 * item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { GunEntity = gunEntity };
                                 *
                                 * character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
                                 * item.Amount = 1;
                                 * item.ItemId = 3;
                                 * gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AutomaticRifle>();
                                 * gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
                                 * gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
                                 * item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { 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;

                    var inventoryBase = character.ComponentContainer.Components.FirstOrDefault(e => e.TypeId == "MyInventoryBase");
                    MyObjectBuilder_Inventory inventory = inventoryBase == null ? null : inventoryBase.Component as MyObjectBuilder_Inventory;

                    if (inventory != null)
                    {
                        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,
                                    PhysicalContent = 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.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 || c.Name == character.CharacterModel))
                                {
                                    character.CharacterModel = Sandbox.Game.Entities.Character.MyCharacter.DefaultModel;
                                    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 || c.Name == character.CharacterModel))
                        {
                            character.CharacterModel = Sandbox.Game.Entities.Character.MyCharacter.DefaultModel;
                            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());
        }
예제 #13
0
 public void AddResource(WorldResource res)
 {
     resources.Add(res);
 }
예제 #14
0
        public static string RepairSandBox(WorldResource world)
        {
            var    str           = new StringBuilder();
            var    statusNormal  = true;
            var    missingFiles  = false;
            var    saveAfterScan = false;
            string errorInformation;

            // 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;

            if (!repairWorld.LoadCheckpoint(out errorInformation))
            {
                statusNormal = false;
                str.AppendLine(errorInformation);
                missingFiles = true;
            }

            var xDoc = repairWorld.LoadSectorXml();

            if (xDoc == null)
            {
                str.AppendLine(Res.ClsRepairSectorBroken);
                str.AppendLine(Res.ClsRepairUnableToRepair);
                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(Res.ClsRepairReplacedBlockGroup);
                                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(Res.ClsRepairSavedChanges);
                }

                #endregion
            }

            repairWorld.LoadDefinitionsAndMods();

            if (!repairWorld.LoadSector(out errorInformation))
            {
                statusNormal = false;
                str.AppendLine(errorInformation);
                missingFiles = true;
            }

            if (repairWorld.Checkpoint == null)
            {
                statusNormal = false;
                str.AppendLine(Res.ClsRepairCheckpointBroken);
                str.AppendLine(Res.ClsRepairUnableToRepair);
                missingFiles = true;
            }

            if (repairWorld.SectorData == null)
            {
                statusNormal = false;
                str.AppendLine(Res.ClsRepairSectorBroken);
                str.AppendLine(Res.ClsRepairUnableToRepair);
                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(Res.ClsRepairFixedPlayerIdentity);
                            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(Res.ClsRepairFixedPlayerIdentity);
                            saveAfterScan = true;
                        }
                    }
                }

                if (saveAfterScan)
                {
                    repairWorld.SaveCheckPointAndSector(true);
                    str.AppendLine(Res.ClsRepairSavedChanges);
                }

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

                    if (player == null)
                    {
                        statusNormal = false;
                        str.AppendLine(Res.ClsRepairNoPlayerFound);

                        character = repairWorld.FindAstronautCharacter();
                        if (character != null)
                        {
                            repairWorld.Checkpoint.ControlledObject = character.EntityId;
                            repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.Entity;
                            repairWorld.Checkpoint.CameraEntity     = character.EntityId;
                            str.AppendLine(Res.ClsRepairFoundSetPlayer);
                            repairWorld.SaveCheckPointAndSector(true);
                            str.AppendLine(Res.ClsRepairSavedChanges);
                        }
                        else
                        {
                            var cockpit = repairWorld.FindPilotCharacter();
                            if (cockpit != null)
                            {
                                repairWorld.Checkpoint.ControlledObject = cockpit.EntityId;
                                repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.ThirdPersonSpectator;
                                repairWorld.Checkpoint.CameraEntity     = 0;
                                str.AppendLine(Res.ClsRepairFoundSetPlayer);
                                repairWorld.SaveCheckPointAndSector(true);
                                str.AppendLine(Res.ClsRepairSavedChanges);
                            }
                        }
                    }

                    saveAfterScan = false;
                }

                // 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.OfType <MyObjectBuilder_Cockpit>().ToArray();
                        for (var i = 0; i < list.Length; i++)
                        {
                            character = (list[i]).GetHierarchyCharacters().FirstOrDefault();
                            if (character != null)
                            {
                                if (!SpaceEngineersCore.Resources.CharacterDefinitions.Any(c => c.Model == character.CharacterModel || c.Name == character.CharacterModel))
                                {
                                    character.CharacterModel = Sandbox.Game.Entities.Character.MyCharacter.DefaultModel;
                                    statusNormal             = false;
                                    str.AppendLine(Res.ClsRepairFixedCharacterModel);
                                    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.CharacterDefinitions.Any(c => c.Model == character.CharacterModel || c.Name == character.CharacterModel))
                        {
                            character.CharacterModel = Sandbox.Game.Entities.Character.MyCharacter.DefaultModel;
                            statusNormal             = false;
                            str.AppendLine(Res.ClsRepairFixedCharacterModel);
                            saveAfterScan = true;
                        }
                    }
                }

                //if (world.Checkpoint.Players != null)
                //{
                //    foreach (var item in world.Checkpoint.Players.Dictionary)
                //    {
                //        if (!SpaceEngineersCore.Resources.CharacterDefinitions.Any(c => c.Name == item.Value.PlayerModel))
                //        {
                //            item.Value.PlayerModel = SpaceEngineersCore.Resources.CharacterDefinitions[0].Name;
                //            statusNormal = false;
                //            str.AppendLine(Res.ClsRepairFixedCharacterModel);
                //            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(Res.ClsRepairSavedChanges);
                }
            }

            if (statusNormal)
            {
                str.AppendLine(Res.ClsRepairNoIssues);
            }

            return(str.ToString());
        }
예제 #15
0
 public virtual void FinishedTargetLocation(Tile targetTile, WorldResource targetResource)
 {
 }