示例#1
0
        /// <summary>
        /// Places items in the dungeon
        /// </summary>
        /// <param name="worldRef">The world in which to place the items</param>
        /// <param name="prosperity">The prosperity of the world, the lower the better</param>
        /// <returns>The items placed</returns>
        public static List <ItemInstance> PlaceItems(WorldInstance worldRef, int prosperity = 50)
        {
            List <ItemInstance> placedItems = new List <ItemInstance>();

            int dungeonArea  = worldRef.Tiles.GetLength(0) * worldRef.Tiles.GetLength(1);
            int itemsToPlace = dungeonArea / prosperity;

            List <Vector2Int> unavailablePoints = new List <Vector2Int>();

            foreach (JoyObject wall in worldRef.Walls.Values)
            {
                unavailablePoints.Add(wall.WorldPosition);
            }

            for (int i = 0; i < itemsToPlace; i++)
            {
                Vector2Int point = new Vector2Int(RNG.Roll(1, worldRef.Tiles.GetLength(0) - 1), RNG.Roll(1, worldRef.Tiles.GetLength(1) - 1));

                while (unavailablePoints.Contains(point))
                {
                    point = new Vector2Int(RNG.Roll(1, worldRef.Tiles.GetLength(0) - 1), RNG.Roll(1, worldRef.Tiles.GetLength(1) - 1));
                }

                ItemInstance item = ItemProvider.RandomItem(false);
                item.Move(point);
                placedItems.Add(item);
            }

            return(placedItems);
        }
示例#2
0
 public void PlaceItemInWorld(ItemInstance item)
 {
     m_Backpack.Remove(item);
     item.Move(WorldPosition);
     MyWorld.AddObject(item);
 }
示例#3
0
        protected void CalculateLightLevels()
        {
            m_Light = new int[m_Light.GetLength(0), m_Light.GetLength(1)];

            //Do objects first
            List <JoyObject> objects = m_Objects.ToList();

            for (int i = 0; i < objects.Count; i++)
            {
                if (objects[i] is ItemInstance == false)
                {
                    continue;
                }

                ItemInstance item = (ItemInstance)objects[i];

                int xMin, xMax;
                int yMin, yMax;

                xMin = Math.Max(0, item.WorldPosition.x - (item.ItemType.LightLevel));
                xMax = Math.Min(m_Light.GetLength(0) - 1, item.WorldPosition.x + (item.ItemType.LightLevel));

                yMin = Math.Max(0, item.WorldPosition.y - (item.ItemType.LightLevel));
                yMax = Math.Min(m_Light.GetLength(1) - 1, item.WorldPosition.y + (item.ItemType.LightLevel));

                if (item.ItemType.LightLevel > 0)
                {
                    for (int x = xMin; x < xMax; x++)
                    {
                        for (int y = yMin; y < yMax; y++)
                        {
                            m_Light = LightTiles(new Vector2Int(x, y), item, m_Light);
                        }
                    }
                }
            }

            //Then the objects used by entities
            List <Entity> entities = m_Entities.ToList();

            for (int i = 0; i < entities.Count; i++)
            {
                Entity entity = entities[i];
                for (int j = 0; j < entity.Backpack.Count; j++)
                {
                    ItemInstance item = entity.Backpack[j];
                    item.Move(entity.WorldPosition);

                    int xMin, xMax;
                    int yMin, yMax;

                    xMin = Math.Max(0, entity.WorldPosition.x - (item.ItemType.LightLevel));
                    xMax = Math.Min(m_Light.GetLength(0) - 1, entity.WorldPosition.x + (item.ItemType.LightLevel));

                    yMin = Math.Max(0, entity.WorldPosition.y - (item.ItemType.LightLevel));
                    yMax = Math.Min(m_Light.GetLength(1) - 1, entity.WorldPosition.y + (item.ItemType.LightLevel));

                    if (item.ItemType.LightLevel > 0)
                    {
                        for (int x = xMin; x < xMax; x++)
                        {
                            for (int y = yMin; y < yMax; y++)
                            {
                                m_Light = LightTiles(new Vector2Int(x, y), item, m_Light);
                            }
                        }
                    }
                }
            }
        }