Beispiel #1
0
        public static void SaveWorldGridChunk(int chunkX, int chunkY, WorldGridChunk chunk)
        {
            var chunkPathPersistent = Path.Combine(Util.Util.GetWorldSavePath(), persistentIdentifier + (chunkX < 0 ? "m" + Math.Abs(chunkX) : "" + chunkX) + "_" + (chunkY < 0 ? "m" + Math.Abs(chunkY) : "" + chunkY));
            var chunkPath           = Path.Combine(Util.Util.GetWorldSavePath(), (chunkX < 0 ? "m" + Math.Abs(chunkX) : "" + chunkX) + "_" + (chunkY < 0 ? "m" + Math.Abs(chunkY) : "" + chunkY));

            fileLocks.Enter(chunkPath);

            try
            {
                var savePath = chunk.IsPersistent ? chunkPathPersistent : chunkPath;

                using (var stream = File.OpenWrite(savePath))
                    using (var writer = new BsonWriter(stream))
                    {
                        WorldGridChunkSerializer.Serialize(chunk).WriteTo(writer);
                    }

                // We delete the other chunk
                var deletePath = chunk.IsPersistent ? chunkPath : chunkPathPersistent;

                if (File.Exists(deletePath))
                {
                    File.Delete(deletePath);
                }
            }
            finally
            {
                fileLocks.Exit(chunkPath);
            }
        }
Beispiel #2
0
        public static WorldGridChunk Deserialize(JObject jObject)
        {
            WorldGridChunk worldGridChunk = ReflectionUtils.CallPrivateConstructor <WorldGridChunk>();

            Deserialize(ref jObject, worldGridChunk);

            return(worldGridChunk);
        }
Beispiel #3
0
        public static JObject Serialize(WorldGridChunk worldGridChunk)
        {
            var retObject = new JObject();

            SerializationUtils.SerializeType(worldGridChunkType, ref retObject);
            Serialize(worldGridChunk, ref retObject);

            return(retObject);
        }
        public static bool IsHitableBlockHitted(Rect hitboxBounds, string interiorID = null)
        {
            ThreadingUtils.assertMainThread();

            if (interiorID == Interior.Outside)
            {
                // Check if blocks are of type blocking
                Point topLeft     = GeometryUtils.GetChunkPosition(hitboxBounds.Left, hitboxBounds.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
                Point bottomRight = GeometryUtils.GetChunkPosition(hitboxBounds.Right, hitboxBounds.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                for (int blockX = topLeft.X; blockX <= bottomRight.X; blockX++)
                {
                    for (int blockY = topLeft.Y; blockY <= bottomRight.Y; blockY++)
                    {
                        Point          chunkPos       = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                        WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkPos.X, chunkPos.Y);

                        int blockType = worldGridChunk.GetBlockType(blockX, blockY);

                        if (IsBlockHitable(blockType))
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                Interior interior = SimulationGame.World.InteriorManager.Get(interiorID);

                // Check if blocks are of type blocking
                Point topLeft     = GeometryUtils.GetChunkPosition(hitboxBounds.Left, hitboxBounds.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
                Point bottomRight = GeometryUtils.GetChunkPosition(hitboxBounds.Right, hitboxBounds.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                for (int blockX = topLeft.X; blockX <= bottomRight.X; blockX++)
                {
                    for (int blockY = topLeft.Y; blockY <= bottomRight.Y; blockY++)
                    {
                        int blockType = interior.GetBlockType(blockX, blockY);

                        if (IsBlockHitable(blockType))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #5
0
        // Create WorldGridChunks
        public void Build()
        {
            //ElevationGenerator.PrintHeightMap(this);

            for (int i = 0; i < WorldSegmentChunkSize.X; i++)
            {
                for (int j = 0; j < WorldSegmentChunkSize.Y; j++)
                {
                    var worldGridChunkExists = WorldLoader.DoesWorldGridChunkExist(startChunkPosition.X + i, startChunkPosition.Y + j);

                    if (worldGridChunkExists == true)
                    {
                        continue;
                    }

                    if (Blocks[i * WorldGrid.WorldChunkBlockSize.X, j *WorldGrid.WorldChunkBlockSize.Y].BlockId == BlockType.Invalid)
                    {
                        continue;
                    }

                    var chunkBlockPosition = new Point(startBlockPosition.X + i * WorldGrid.WorldChunkBlockSize.X, startBlockPosition.Y + j * WorldGrid.WorldChunkBlockSize.Y);

                    WorldGridChunk    worldGridChunk    = new WorldGridChunk(WorldGrid.BlockSize.X * chunkBlockPosition.X, WorldGrid.BlockSize.Y * chunkBlockPosition.Y);
                    WalkableGridChunk walkableGridChunk = WalkableGridChunk.CreateEmpty(startChunkPosition.X + i, startChunkPosition.Y + j);

                    worldGridChunk.SetBiomeType(Biome);

                    for (int x = 0; x < WorldGrid.WorldChunkBlockSize.X; x++)
                    {
                        for (int y = 0; y < WorldGrid.WorldChunkBlockSize.Y; y++)
                        {
                            var blockPosition        = new Point(chunkBlockPosition.X + x, chunkBlockPosition.Y + y);
                            var worldSegmentPosition = new Point(i * WorldGrid.WorldChunkBlockSize.X + x, j * WorldGrid.WorldChunkBlockSize.Y + y);

                            worldGridChunk.SetBlockType(blockPosition.X, blockPosition.Y, Blocks[worldSegmentPosition.X, worldSegmentPosition.Y].BlockId);

                            if (CollisionUtils.IsBlockBlocking(Blocks[worldSegmentPosition.X, worldSegmentPosition.Y].BlockId))
                            {
                                walkableGridChunk.SetWalkable(blockPosition.X, blockPosition.Y, false);
                            }
                        }
                    }

                    WorldLoader.SaveWorldGridChunk(startChunkPosition.X + i, startChunkPosition.Y + j, worldGridChunk);
                    WorldLoader.SaveWalkableGridChunk(startChunkPosition.X + i, startChunkPosition.Y + j, walkableGridChunk);
                }
            }
        }
        public static bool IsBlockHitable(int blockX, int blockY, string interiorID)
        {
            if (interiorID == Interior.Outside)
            {
                Point          chunkPos       = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkPos.X, chunkPos.Y);
                int            blockType      = worldGridChunk.GetBlockType(blockX, blockY);

                return(IsBlockHitable(blockType));
            }
            else
            {
                Interior interior  = SimulationGame.World.InteriorManager.Get(interiorID);
                int      blockType = interior.GetBlockType(blockX, blockY);

                return(IsBlockHitable(blockType));
            }
        }
Beispiel #7
0
        private static void drawOutside(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Point topLeft     = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Left, SimulationGame.VisibleArea.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
            Point bottomRight = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Right, SimulationGame.VisibleArea.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

            for (int blockX = topLeft.X; blockX < bottomRight.X; blockX++)
            {
                for (int blockY = topLeft.Y; blockY < bottomRight.Y; blockY++)
                {
                    Point          worldGridChunkPosition = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                    WorldGridChunk worldGridChunk         = SimulationGame.World.GetFromChunkPoint(worldGridChunkPosition.X, worldGridChunkPosition.Y);

                    BlockRenderer.Draw(spriteBatch, blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, worldGridChunk.GetBlockType(blockX, blockY));
                }
            }

            Point chunkTopLeft     = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Left, SimulationGame.VisibleArea.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
            Point chunkBottomRight = GeometryUtils.GetChunkPosition(SimulationGame.VisibleArea.Right, SimulationGame.VisibleArea.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

            for (int chunkX = chunkTopLeft.X; chunkX <= chunkBottomRight.X; chunkX++)
            {
                for (int chunkY = chunkTopLeft.Y; chunkY <= chunkBottomRight.Y; chunkY++)
                {
                    WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                    if (SimulationGame.IsDebug)
                    {
                        SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle(chunkX * WorldGrid.WorldChunkPixelSize.X, chunkY * WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y), worldGridChunk.IsPersistent ? Color.Blue : Color.Red);
                    }

                    if (worldGridChunk.AmbientObjects != null)
                    {
                        foreach (AmbientObject ambientObject in worldGridChunk.AmbientObjects)
                        {
                            if (SimulationGame.VisibleArea.Contains(ambientObject.Position) && ambientObject.InteriorID == SimulationGame.Player.InteriorID)
                            {
                                if (ambientObject.CustomRenderer != null)
                                {
                                    ambientObject.CustomRenderer.Draw(spriteBatch, gameTime);
                                }
                                else
                                {
                                    AmbientObjectRenderer.Draw(spriteBatch, gameTime, ambientObject);
                                }
                            }
                        }
                    }

                    if (worldGridChunk.ContainedObjects != null)
                    {
                        foreach (var containedObject in worldGridChunk.ContainedObjects)
                        {
                            if (SimulationGame.VisibleArea.Contains(containedObject.Position) && containedObject.InteriorID == SimulationGame.Player.InteriorID)
                            {
                                if (containedObject.CustomRenderer != null)
                                {
                                    containedObject.CustomRenderer.Draw(spriteBatch, gameTime);
                                }
                                else
                                {
                                    if (containedObject is LivingEntity)
                                    {
                                        LivingEntityRenderer.Draw(spriteBatch, gameTime, (LivingEntity)containedObject);
                                    }
                                    else if (containedObject is AmbientHitableObject)
                                    {
                                        AmbientHitableObjectRenderer.Draw(spriteBatch, gameTime, (AmbientHitableObject)containedObject);
                                    }
                                }
                            }
                        }
                    }

                    if (worldGridChunk.ContainedEffects != null)
                    {
                        foreach (var effectItem in worldGridChunk.ContainedEffects)
                        {
                            EffectRenderer.Draw(spriteBatch, gameTime, effectItem.Value);
                        }
                    }

                    if (SimulationGame.IsDebug && worldGridChunk.WorldLinks != null)
                    {
                        foreach (var worldLinkItem in worldGridChunk.WorldLinks)
                        {
                            if (SimulationGame.VisibleArea.Contains(new Point(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y)))
                            {
                                SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y), Color.DarkBlue);
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        private void selectGameObjects(Rect selectionRect)
        {
            // Is Deselection Mode?
            if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftAlt) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightAlt))
            {
                if (SimulationGame.Player.InteriorID == Interior.Outside)
                {
                    // Check collision with interactive && contained objects
                    Point chunkTopLeft     = GeometryUtils.GetChunkPosition(selectionRect.Left, selectionRect.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                    Point chunkBottomRight = GeometryUtils.GetChunkPosition(selectionRect.Right, selectionRect.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                    for (int chunkX = chunkTopLeft.X - 1; chunkX <= chunkBottomRight.X + 1; chunkX++)
                    {
                        for (int chunkY = chunkTopLeft.Y - 1; chunkY <= chunkBottomRight.Y + 1; chunkY++)
                        {
                            WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                            addSelectedObjectsFromWorldPart(selectionRect, worldGridChunk, true);
                        }
                    }
                }
                else
                {
                    addSelectedObjectsFromWorldPart(selectionRect, SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID), true);
                }

                if (SelectedGameObjects.Count > 0)
                {
                    gameObjectSelection?.Invoke(SelectedGameObjects);
                }
            }
            else
            {
                if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftShift) == false && SimulationGame.KeyboardState.IsKeyDown(Keys.RightShift) == false)
                {
                    SelectedBlockPosition = Point.Zero;
                    SelectedBlockType     = null;
                    SelectedWorldLink     = null;
                    SelectedGameObjects.Clear();
                }

                if (SimulationGame.Player.InteriorID == Interior.Outside)
                {
                    // Check collision with interactive && contained objects
                    Point chunkTopLeft     = GeometryUtils.GetChunkPosition(selectionRect.Left, selectionRect.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                    Point chunkBottomRight = GeometryUtils.GetChunkPosition(selectionRect.Right, selectionRect.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                    for (int chunkX = chunkTopLeft.X - 1; chunkX <= chunkBottomRight.X + 1; chunkX++)
                    {
                        for (int chunkY = chunkTopLeft.Y - 1; chunkY <= chunkBottomRight.Y + 1; chunkY++)
                        {
                            WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                            addSelectedObjectsFromWorldPart(selectionRect, worldGridChunk);
                        }
                    }
                }
                else
                {
                    addSelectedObjectsFromWorldPart(selectionRect, SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID));
                }

                if (SelectedGameObjects.Count == 0)
                {
                    WorldPart worldPart = (SimulationGame.Player.InteriorID == Interior.Outside) ? SimulationGame.World.GetFromRealPoint((int)selectionRect.X, (int)selectionRect.Y) : (WorldPart)SimulationGame.World.InteriorManager.Get(SimulationGame.Player.InteriorID);

                    if (worldPart.WorldLinks != null)
                    {
                        foreach (var worldLinkItem in worldPart.WorldLinks)
                        {
                            Rect renderPosition = new Rect(worldLinkItem.Value.FromBlock.X * WorldGrid.BlockSize.X, worldLinkItem.Value.FromBlock.Y * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                            if (renderPosition.Contains(selectionRect.GetPosition()))
                            {
                                SelectedWorldLink = worldLinkItem.Value;
                                worldLinkSelection?.Invoke(SelectedWorldLink);

                                return;
                            }
                        }
                    }

                    // We get the block
                    SelectedBlockPosition = GeometryUtils.GetBlockFromReal((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y);
                    SelectedBlockType     = BlockType.lookup[SimulationGame.World.GetBlockType(SelectedBlockPosition.X, SelectedBlockPosition.Y, SimulationGame.Player.InteriorID)];

                    blockSelection?.Invoke(SelectedBlockType);
                }
                else
                {
                    gameObjectSelection?.Invoke(SelectedGameObjects);
                }
            }
        }
Beispiel #9
0
        protected static void Serialize(WorldGridChunk worldGridChunk, ref JObject jObject)
        {
            WorldPartSerialization.Serialize(worldGridChunk, ref jObject);

            SerializationUtils.AddToObject(jObject, worldGridChunk, worldGridChunkType, serializeableProperties);
        }
Beispiel #10
0
        protected static void Deserialize(ref JObject jObject, WorldGridChunk worldGridChunk)
        {
            WorldPartSerialization.Deserialize(ref jObject, worldGridChunk);

            SerializationUtils.SetFromObject(jObject, worldGridChunk, worldGridChunkType, serializeableProperties);
        }
        public static bool IsRectBlockedAccurate(HitableObject origin, Rect rect)
        {
            ThreadingUtils.assertMainThread();

            if (origin.InteriorID == Interior.Outside)
            {
                // Check if blocks are of type blocking
                Point topLeft     = GeometryUtils.GetChunkPosition(rect.Left, rect.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
                Point bottomRight = GeometryUtils.GetChunkPosition(rect.Right, rect.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                for (int blockX = topLeft.X; blockX <= bottomRight.X; blockX++)
                {
                    for (int blockY = topLeft.Y; blockY <= bottomRight.Y; blockY++)
                    {
                        Point          chunkPos       = GeometryUtils.GetChunkPosition(blockX, blockY, WorldGrid.WorldChunkBlockSize.X, WorldGrid.WorldChunkBlockSize.Y);
                        WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkPos.X, chunkPos.Y);

                        int blockType = worldGridChunk.GetBlockType(blockX, blockY);

                        if (IsBlockBlocking(blockType))
                        {
                            return(true);
                        }
                    }
                }

                // Check collision with interactive && contained objects
                Point chunkTopLeft     = GeometryUtils.GetChunkPosition(rect.Left, rect.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                Point chunkBottomRight = GeometryUtils.GetChunkPosition(rect.Right, rect.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                for (int chunkX = chunkTopLeft.X; chunkX <= chunkBottomRight.X; chunkX++)
                {
                    for (int chunkY = chunkTopLeft.Y; chunkY <= chunkBottomRight.Y; chunkY++)
                    {
                        WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                        if (worldGridChunk.OverlappingObjects != null)
                        {
                            foreach (HitableObject hitableObject in worldGridChunk.OverlappingObjects)
                            {
                                if (hitableObject.IsBlocking() && hitableObject != origin && hitableObject.BlockingBounds.Intersects(rect))
                                {
                                    return(true);
                                }
                            }
                        }

                        if (worldGridChunk.ContainedObjects != null)
                        {
                            foreach (var hitableObject in worldGridChunk.ContainedObjects)
                            {
                                if (hitableObject.IsBlocking() && hitableObject != origin && hitableObject.BlockingBounds.Intersects(rect))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }

                return(false);
            }
            else
            {
                Interior interior = SimulationGame.World.InteriorManager.Get(origin.InteriorID);

                // Check if blocks are of type blocking
                Point topLeft     = GeometryUtils.GetChunkPosition(rect.Left, rect.Top, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);
                Point bottomRight = GeometryUtils.GetChunkPosition(rect.Right, rect.Bottom, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

                for (int blockX = topLeft.X; blockX <= bottomRight.X; blockX++)
                {
                    for (int blockY = topLeft.Y; blockY <= bottomRight.Y; blockY++)
                    {
                        if (blockX < 0 || blockX >= interior.Dimensions.X)
                        {
                            return(true);
                        }
                        if (blockY < 0 || blockY >= interior.Dimensions.Y)
                        {
                            return(true);
                        }

                        int blockType = interior.GetBlockType(blockX, blockY);

                        if (IsBlockBlocking(blockType))
                        {
                            return(true);
                        }
                    }
                }

                foreach (var hitableObject in interior.ContainedObjects)
                {
                    if (hitableObject.IsBlocking() && hitableObject != origin && hitableObject.BlockingBounds.Intersects(rect))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
        public static List <HitableObject> GetHittedObjects(Rect hitboxBounds, string interiorId, HitableObject origin)
        {
            ThreadingUtils.assertMainThread();
            List <HitableObject> hittedObjecs = new List <HitableObject>();

            if (interiorId == Interior.Outside)
            {
                // Check collision with interactive && contained objects
                Point chunkTopLeft     = GeometryUtils.GetChunkPosition(hitboxBounds.Left, hitboxBounds.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                Point chunkBottomRight = GeometryUtils.GetChunkPosition(hitboxBounds.Right, hitboxBounds.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                for (int chunkX = chunkTopLeft.X; chunkX <= chunkBottomRight.X; chunkX++)
                {
                    for (int chunkY = chunkTopLeft.Y; chunkY <= chunkBottomRight.Y; chunkY++)
                    {
                        WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                        if (worldGridChunk.OverlappingObjects != null)
                        {
                            foreach (HitableObject hitableObject in worldGridChunk.OverlappingObjects)
                            {
                                if (hitableObject != origin && hitableObject.IsHitable() && hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                                {
                                    if (hittedObjecs.Contains(hitableObject) == false && (hitableObject is LivingEntity == false || ((LivingEntity)hitableObject).IsDead() == false))
                                    {
                                        hittedObjecs.Add(hitableObject);
                                    }
                                }
                            }
                        }

                        if (worldGridChunk.ContainedObjects != null)
                        {
                            foreach (var hitableObject in worldGridChunk.ContainedObjects)
                            {
                                if (hitableObject != origin && hitableObject.IsHitable() && hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                                {
                                    if (hittedObjecs.Contains(hitableObject) == false && (hitableObject is LivingEntity == false || ((LivingEntity)hitableObject).IsDead() == false))
                                    {
                                        hittedObjecs.Add(hitableObject);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Interior interior = SimulationGame.World.InteriorManager.Get(interiorId);

                foreach (var hitableObject in interior.ContainedObjects)
                {
                    if (hitableObject != origin && hitableObject.IsHitable() && hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                    {
                        if (hittedObjecs.Contains(hitableObject) == false && (hitableObject is LivingEntity == false || ((LivingEntity)hitableObject).IsDead() == false))
                        {
                            hittedObjecs.Add(hitableObject);
                        }
                    }
                }
            }

            return(hittedObjecs);
        }
        public static LivingEntity GetClosestLivingTarget(Rect hitboxBounds, string interiorId, HitableObject origin, int maxAggro)
        {
            ThreadingUtils.assertMainThread();

            HitableObject closestTarget   = null;
            float         closestDistance = float.PositiveInfinity;

            if (interiorId == Interior.Outside)
            {
                // Check collision with interactive && contained objects
                Point chunkTopLeft     = GeometryUtils.GetChunkPosition(hitboxBounds.Left, hitboxBounds.Top, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);
                Point chunkBottomRight = GeometryUtils.GetChunkPosition(hitboxBounds.Right, hitboxBounds.Bottom, WorldGrid.WorldChunkPixelSize.X, WorldGrid.WorldChunkPixelSize.Y);

                for (int chunkX = chunkTopLeft.X; chunkX <= chunkBottomRight.X; chunkX++)
                {
                    for (int chunkY = chunkTopLeft.Y; chunkY <= chunkBottomRight.Y; chunkY++)
                    {
                        WorldGridChunk worldGridChunk = SimulationGame.World.GetFromChunkPoint(chunkX, chunkY);

                        if (worldGridChunk.OverlappingObjects != null)
                        {
                            foreach (HitableObject hitableObject in worldGridChunk.OverlappingObjects)
                            {
                                if (hitableObject is LivingEntity &&
                                    hitableObject != origin &&
                                    hitableObject.IsHitable() &&
                                    ((LivingEntity)origin).GetAggroTowardsEntity((LivingEntity)hitableObject) <= maxAggro &&
                                    hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                                {
                                    var distance = GeometryUtils.GetDiagonalDistance(hitableObject.Position.X, hitableObject.Position.Y, origin.Position.X, origin.Position.Y);

                                    if (distance < closestDistance)
                                    {
                                        closestDistance = distance;
                                        closestTarget   = hitableObject;
                                    }
                                }
                            }
                        }


                        if (worldGridChunk.ContainedObjects != null)
                        {
                            foreach (var hitableObject in worldGridChunk.ContainedObjects)
                            {
                                if (hitableObject is LivingEntity &&
                                    hitableObject != origin &&
                                    hitableObject.IsHitable() &&
                                    ((LivingEntity)origin).GetAggroTowardsEntity((LivingEntity)hitableObject) <= maxAggro &&
                                    hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                                {
                                    var distance = GeometryUtils.GetDiagonalDistance(hitableObject.Position.X, hitableObject.Position.Y, origin.Position.X, origin.Position.Y);

                                    if (distance < closestDistance)
                                    {
                                        closestDistance = distance;
                                        closestTarget   = hitableObject;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Interior interior = SimulationGame.World.InteriorManager.Get(interiorId);

                foreach (var hitableObject in interior.ContainedObjects)
                {
                    if (hitableObject is LivingEntity &&
                        hitableObject != origin &&
                        hitableObject.IsHitable() &&
                        ((LivingEntity)origin).GetAggroTowardsEntity((LivingEntity)hitableObject) <= maxAggro &&
                        hitableObject.HitBoxBounds.Intersects(hitboxBounds))
                    {
                        var distance = GeometryUtils.GetDiagonalDistance(hitableObject.Position.X, hitableObject.Position.Y, origin.Position.X, origin.Position.Y);

                        if (distance < closestDistance)
                        {
                            closestDistance = distance;
                            closestTarget   = hitableObject;
                        }
                    }
                }
            }

            return((LivingEntity)closestTarget);
        }