예제 #1
0
        protected virtual void CreateDynamicTiles(List <Dungeons.TileContainers.DungeonNode> mazeNodes)
        {
            if (mazeNodes.Any(i => !i.Created))
            {
                Logger.LogError("!i.Created ");
                return;
            }
            {
                var roomGen = CreateRoomContentGeneratorForExtraEnemies();
                foreach (var en in extraEnemies)
                {
                    var maze = mazeNodes.GetRandomElem();
                    roomGen.AddExtraEnemy(maze, en);
                }
            }

            if (LevelIndex < MaxLevelIndex)
            {
                var indexWithStairsDown = mazeNodes.Count - 1;
                if (RandHelper.GetRandomDouble() > .5f)
                {
                    indexWithStairsDown = mazeNodes.Count - 2;
                }

                if (indexWithStairsDown < 0)
                {
                    indexWithStairsDown = 0;
                }

                var maze = mazeNodes[indexWithStairsDown];

                GenerateStairsDown(maze);
                //node.SetTile(stairs, new System.Drawing.Point(3, 1));
            }
        }
예제 #2
0
        public T RollDice(T unset, T[] skip, double factor = 0)
        {
            var rand = RandHelper.GetRandomDouble();

            if (factor != 0)
            {
                rand -= factor;
            }
            var matches = GetMatchesAboveThreashold(rand);

            if (matches.Any())
            {
                return(RandHelper.GetRandomElem <T>(matches, skip));
            }
            return(unset);
        }
예제 #3
0
        private EntranceSide CalcSide(EntranceSide current, EntranceSide next, float chanceForLevelTurn)//, int currentNodeIndex)
        {
            if (info != null && info.ForcedNextRoomSide != null)
            {
                return(info.ForcedNextRoomSide.Value);
            }

            EntranceSide side = GetRandSide();

            if (current == next)
            {
                if (RandHelper.GetRandomDouble() >= chanceForLevelTurn)
                {
                    side = side == EntranceSide.Bottom ? EntranceSide.Right : EntranceSide.Bottom;
                }
            }

            return(side);
        }
예제 #4
0
파일: Gem.cs 프로젝트: tomaszkot/Roguelike
        public void SetRandomKindAndLevelSize(int gameLevel, bool setKind)
        {
            GameLevel = gameLevel;

            if (setKind)
            {
                GemKind = RandHelper.GetRandomEnumValue <GemKind>();
            }
            EnchanterSize = EnchanterSize.Small;
            var smaller = RandHelper.GetRandomDouble() < 0.5f;

            if (gameLevel >= 10)
            {
                EnchanterSize = EnchanterSize.Big;
            }
            else if (gameLevel >= 8)
            {
                EnchanterSize = smaller ? EnchanterSize.Medium : EnchanterSize.Big;
            }
            else if (gameLevel >= 6)
            {
                EnchanterSize = smaller ? EnchanterSize.Small : EnchanterSize.Medium;
            }
            else if (gameLevel >= 4)
            {
                smaller = false;
            }

            if (!smaller && gameLevel < 10)
            {
                Damaged = true;
            }

            if (RandHelper.GetRandomDouble() < 0.3f)
            {
                Damaged = true;
            }

            SetProps();
        }
예제 #5
0
        protected virtual Tuple <string, EquipmentMaterial> GetLootAtLevel(int level)
        {
            Tuple <string, EquipmentMaterial> res = new Tuple <string, EquipmentMaterial>("", EquipmentMaterial.Unset);
            EquipmentMaterial mat = EquipmentMaterial.Unset;
            bool upgMaterial      = false;

            if (level > MaterialProps.SteelDropLootSrcLevel)
            {
                mat = EquipmentMaterial.Iron;
                if (RandHelper.GetRandomDouble() > 0.33f)//make it more unpredictable
                {
                    mat         = EquipmentMaterial.Steel;
                    upgMaterial = true;
                }
            }
            else if (level > MaterialProps.IronDropLootSrcLevel)
            {
                if (RandHelper.GetRandomDouble() > 0.33f)
                {
                    mat         = EquipmentMaterial.Iron;
                    upgMaterial = true;
                }
            }

            if (upgMaterial)
            {
                level--;
            }

            var plains = prototypes.Values.Where(i => i.Class == EquipmentClass.Plain).ToList();

            res = GetRandomFromList(level, ref mat, plains);
            //if (eq !=null mat != EquipmentMaterial.Bronze)
            //{
            //  EnsureMaterialFromLootSource(eq);
            //}
            return(res);
        }
예제 #6
0
        public void GenerateRandomInterior(EventHandler <DungeonNode> CustomInteriorDecorator)
        {
            if (!Inited())
            {
                return;
            }

            if (!generationInfo.GenerateRandomInterior && !generationInfo.ForceChildIslandInterior)
            {
                return;
            }

            Interior?interior = null;
            var      rand     = RandHelper.GetRandomDouble();

            if (!dungeonNode.Secret && generationInfo.ChildIslandAllowed && (generationInfo.ForceChildIslandInterior || rand < .33))
            {
                var island = GenerateChildIslands();
                if (island == null)
                {
                    interior = GenerateRandomSimpleInterior(true);
                }
                else if (CustomInteriorDecorator != null)
                {
                    CustomInteriorDecorator(this, island.FirstOrDefault());//currently only one is send
                }
            }
            else if (generationInfo.GenerateRandomInterior)
            {
                interior = GenerateRandomSimpleInterior();
            }

            if (generationInfo.GenerateRandomInterior)
            {
                GenerateRandomStonesBlocks();
            }
        }
예제 #7
0
 private static EntranceSide GetRandSide()
 {
     return(RandHelper.GetRandomDouble() >= .5f ? EntranceSide.Bottom : EntranceSide.Right);
 }
예제 #8
0
        public PassiveSpell ApplyPassiveSpell(LivingEntity caster, SpellSource spellSource, Point?destPoint = null)
        {
            var    spell         = spellSource.CreateSpell(caster);
            string preventReason = "";

            if (!gm.Context.CanUseScroll(caster, spellSource, spell, ref preventReason))
            {
                gm.ReportFailure(preventReason);
                return(null);
            }

            if (spell is PassiveSpell ps)
            {
                if (ps.Kind == SpellKind.Teleport)
                {
                    if (destPoint != null)
                    {
                        var currentTile   = gm.CurrentNode.GetTile(destPoint.Value);
                        var teleportSpell = ps as TeleportSpell;
                        if (teleportSpell.Range < gm.Hero.DistanceFrom(currentTile))
                        {
                            gm.ReportFailure("Range of spell is too small (max:" + teleportSpell.Range + ")");
                            return(null);
                        }

                        if (currentTile.IsEmpty || currentTile is Loot)
                        {
                            gm.CurrentNode.SetTile(gm.Hero, destPoint.Value);
                        }
                        else
                        {
                            gm.ReportFailure("Can not cast on the pointed tile");
                            return(null);
                        }
                    }
                }
                else if (ps.Kind == SpellKind.Dziewanna)
                {
                    int maxApples = 1;
                    if (RandHelper.GetRandomDouble() > 0.5)
                    {
                        maxApples += 1;
                    }
                    for (int appleIndex = 0; appleIndex < maxApples; appleIndex++)
                    {
                        var  enemies = gm.CurrentNode.GetNeighborTiles <Enemy>(gm.Hero);
                        bool added   = false;
                        foreach (var en in enemies)
                        {
                            var emptyOnes = gm.CurrentNode.GetEmptyNeighborhoodTiles(en, false);
                            if (emptyOnes.Any())
                            {
                                AddApple(emptyOnes.First());
                                added = true;
                                break;
                            }
                        }
                        if (!added)
                        {
                            var emp = gm.CurrentNode.GetClosestEmpty(gm.Hero);
                            AddApple(emp);
                        }
                    }
                }
                else
                {
                    caster.ApplyPassiveSpell(ps);
                }

                gm.UtylizeSpellSource(caster, spellSource, spell);
                gm.AppendAction <LivingEntityAction>((LivingEntityAction ac) =>
                                                     { ac.Kind = LivingEntityActionKind.Teleported; ac.Info = gm.Hero.Name + " used " + spellSource.Kind.ToDescription() + " scroll"; ac.InvolvedEntity = caster; });

                if (caster is Hero)
                {
                    HandleHeroActionDone();
                }

                return(ps);
            }
            else
            {
                gm.Logger.LogError("!PassiveSpell " + spellSource);
                gm.ReportFailure("");
            }

            return(null);
        }