Пример #1
0
        private void SpawnShop(IMap map, ISystemContainer systemContainer, int power, List <IEntity> itemList, IRandom random, IShopGenerator shopGenerator)
        {
            int retries = 25;

            MapCoordinate emptyLocation = null;
            IEntity       shop          = null;

            emptyLocation = map.GetEmptyPosition(systemContainer.PositionSystem, random);

            if (emptyLocation == null)
            {
                return;
            }

            for (int i = 0; i < retries; i++)
            {
                var itemLevel = random.Between(0, power + 2);
                shop = shopGenerator.GenerateShop(systemContainer, random.Between(4, 10), itemLevel, itemList, random);

                if (shop != null)
                {
                    break;
                }
            }

            if (shop == null)
            {
                return;
            }

            systemContainer.PositionSystem.SetPosition(shop, emptyLocation);
        }
        private MapCoordinate PickRandomCoordinate(IMap map, IRandom random, int i)
        {
            var size        = map.GetSize();
            var key         = map.MapKey;
            var temperature = (double)i / 20;
            var randWidth   = (int)(size.Width * temperature);
            var randHeight  = (int)(size.Height * temperature);

            return(new MapCoordinate(key, random.Between(-randWidth, randWidth), random.Between(-randHeight, randHeight)));
        }
        private void SpawnMonster(IMap map, ISystemContainer systemContainer, int power, MonsterList monsterList, IRandom random)
        {
            int retries = 25;

            MapCoordinate emptyLocation = null;
            IEntity       monster       = null;

            for (int i = 0; i < retries; i++)
            {
                emptyLocation = map.GetQuickEmptyPosition(systemContainer.PositionSystem, random);

                if (emptyLocation != null)
                {
                    break;
                }
            }

            for (int i = 0; i < retries; i++)
            {
                var randomPower = power + random.Between(-5, 3);
                monster = PickMonsterToSpawn(monsterList, randomPower, random);

                if (monster != null)
                {
                    break;
                }
            }

            if (emptyLocation == null || monster == null)
            {
                return;
            }

            systemContainer.PrototypeSystem.CreateAt(monster, emptyLocation);
        }
        private void RandomiseWealthAmount(IEntity item, int itemLevel, IRandom random)
        {
            var wealth = item.Get <Wealth>();

            var minAmount = 1 + itemLevel * wealth.Amount;
            var maxAmount = 20 + itemLevel * wealth.Amount * 2;

            wealth.Amount = random.Between(minAmount, maxAmount);
        }
Пример #5
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var data        = eventData as DamageEventData;
            int randomiseBy = Math.Max(data.Damage / RANDOMISATION_DENOMINATOR, 1);

            for (int i = 0; i < RANDOM_ROLLS; i++)
            {
                data.Damage += _random.Between(-randomiseBy, +randomiseBy);
            }

            return(true);
        }
        public IMap Generate(string mapName, IRandom random, IProgress <string> progress)
        {
            Random = random;

            wallCell  = PrototypeSystem.Get(WallCell);
            floorCell = PrototypeSystem.Get(FloorCell);

            var map = new Map(mapName, wallCell);

            Room previousRoom = null;

            for (int i = 0; i < numRooms; i++)
            {
                int leftX = Random.Between(0, size);
                int topY  = Random.Between(0, size);

                var room = new Room
                {
                    LeftX   = leftX,
                    RightX  = leftX + roomSize - 1,
                    TopY    = topY,
                    BottomY = topY + roomSize - 1
                };

                map.SetCellsInRange(
                    room.LeftX, room.RightX,
                    room.TopY, room.BottomY,
                    floorCell);

                if (previousRoom != null)
                {
                    DigTunnel(map, room, previousRoom);
                }

                previousRoom = room;
            }

            return(map);
        }
        private IMap CreateBlankRoom(IRandom random)
        {
            var map = new Map("Blank Room", _wallCell);

            var xSize = random.Between(3, 12);
            var ySize = random.Between(3, 12);

            for (int x = 0; x <= xSize; x++)
            {
                for (int y = 0; y <= ySize; y++)
                {
                    map.SetCell(new MapCoordinate(map.MapKey, x, y), _floorCell);
                    if (IsOnWall(xSize, ySize, x, y) && random.PercentageChance(0.1))
                    {
                        map.MapGenCommands.Add(new MapGenCommand {
                            MapGenCommandType = MapGenCommandType.Entity, Parameters = "Props:VaultConnection", Vector = new Vector(x, y)
                        });
                    }
                }
            }

            return(map);
        }
Пример #8
0
        private void SpawnItem(IMap map, ISystemContainer systemContainer, int power, List <IEntity> itemList, IRandom random, IItemGenerator itemGenerator)
        {
            int retries = 25;

            MapCoordinate emptyLocation = null;
            IEntity       item          = null;

            for (int i = 0; i < retries; i++)
            {
                emptyLocation = map.GetQuickEmptyPosition(systemContainer.PositionSystem, random);

                if (emptyLocation != null)
                {
                    break;
                }
            }

            if (emptyLocation == null)
            {
                return;
            }

            for (int i = 0; i < retries; i++)
            {
                var itemLevel = random.Between(0, power + 2);
                item = itemGenerator.GenerateItem(itemList, itemLevel, random);

                if (item != null)
                {
                    break;
                }
            }

            if (item == null)
            {
                return;
            }

            systemContainer.PositionSystem.SetPosition(item, emptyLocation);
        }
 public Vector GetPointInRoom(IRandom random)
 {
     return(new Vector(
                random.Between(LeftX, RightX),
                random.Between(TopY, BottomY)));
 }
        public void Enchant(IEntity item, ItemClass itemClass, int itemLevel, IRandom random, RarityPicker rarityPicker)
        {
            var rarity = rarityPicker.Rarity;

            if (rarity == "Normal")
            {
                return;
            }

            if (rarity == "Magic")
            {
                SetEnchantedLineInDescription(item);

                if (random.PickOneFrom(1, 2) == 1)
                {
                    var enchantPower = (int)(itemLevel * 1.5);

                    var enchantment1 = GetEnchantmentFor(item, itemClass, enchantPower, random);

                    ApplyEnchantmentTo(item, enchantment1);

                    if (random.PickOneFrom(1, 2) == 1)
                    {
                        _itemNamer.NameMagicItem(item, enchantment1, null);
                    }
                    else
                    {
                        _itemNamer.NameMagicItem(item, null, enchantment1);
                    }
                }
                else
                {
                    var enchantPower = itemLevel;

                    var enchantment1 = GetEnchantmentFor(item, itemClass, enchantPower, random);

                    ApplyEnchantmentTo(item, enchantment1);

                    var enchantment2 = GetEnchantmentFor(item, itemClass, enchantPower, random);

                    ApplyEnchantmentTo(item, enchantment2);

                    _itemNamer.NameMagicItem(item, enchantment1, enchantment2);
                }

                return;
            }

            if (rarity == "Rare")
            {
                var numberOfEnchantments = random.Between(4, 6);
                var enchantPower         = itemLevel;

                for (int i = 0; i < numberOfEnchantments; i++)
                {
                    var enchantment = GetEnchantmentFor(item, itemClass, enchantPower, random);

                    ApplyEnchantmentTo(item, enchantment);
                }

                _itemNamer.NameRareItem(item, itemClass, random);

                return;
            }

            throw new ApplicationException("Unknown rarity in Enchant: " + rarity);
        }