Example #1
0
        private void handleRemoveInteriorBtn()
        {
            var confirmResult = System.Windows.Forms.MessageBox.Show("Are you sure to delete the interior?", "Confirm Delete!", System.Windows.Forms.MessageBoxButtons.YesNo);

            if (confirmResult == System.Windows.Forms.DialogResult.Yes)
            {
                Interior interior = SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID);

                if (interior.WorldLinks == null || interior.WorldLinks.Count == 0)
                {
                    SimulationGame.Player.UpdatePosition(new WorldPosition(0, 0, Interior.Outside));
                }

                // Check if durable entities are inside besides player
                if (interior.ContainedObjects != null)
                {
                    foreach (var containedObject in interior.ContainedObjects)
                    {
                        if (containedObject is DurableEntity && containedObject is Player == false)
                        {
                            System.Windows.Forms.MessageBox.Show("Cannot delete interior because a durable entity is inside");
                            return;
                        }
                    }
                }

                // Delete all WorldLinks
                if (interior.WorldLinks != null)
                {
                    bool playerTeleported = false;

                    WorldLink[] wordLinks = new WorldLink[interior.WorldLinks.Count];
                    interior.WorldLinks.Values.CopyTo(wordLinks, 0);

                    foreach (var worldLink in wordLinks)
                    {
                        if (playerTeleported == false)
                        {
                            SimulationGame.Player.UpdatePosition(worldLink.ToRealWorldPositionTo());
                            playerTeleported = true;
                        }

                        try
                        {
                            SimulationGame.World.UpdateWorldLink(worldLink);
                        }
                        catch (Exception e)
                        {
                            System.Windows.Forms.MessageBox.Show("Couldn't delete WorldLink: " + e.Message);
                        }
                    }
                }

                // Unload and Erase File
                SimulationGame.World.InteriorManager.RemoveChunk(interior.ID);
                WorldLoader.EraseInterior(interior);
            }
        }