GetRandomInt() public static method

public static GetRandomInt ( ) : int
return int
Beispiel #1
0
        public static void AddRandomArmor(LivingObject living, ArmorSlot slot)
        {
            var itemIDs = Items.GetItemInfos(ItemCategory.Armor).Where(ii => ii.ArmorInfo.Slot == slot).ToArray();
            var itemID  = itemIDs[Helpers.GetRandomInt(itemIDs.Length)].ID;

            AddEquipment(living, itemID);
        }
Beispiel #2
0
        public static void AddRandomWeapon(LivingObject living)
        {
            var itemIDs = Items.GetItemInfos(ItemCategory.Weapon).ToArray();
            var itemID  = itemIDs[Helpers.GetRandomInt(itemIDs.Length)].ID;

            AddEquipment(living, itemID);
        }
Beispiel #3
0
        LivingObject CreateDwarf(int i)
        {
            var builder = new LivingObjectBuilder(LivingID.Dwarf)
            {
                Color  = (GameColor)Helpers.GetRandomInt(GameColorRGB.NUMCOLORS - 1) + 1,
                Gender = LivingGender.Male,
            };

            switch (i)
            {
            case 0:
                builder.Name = "Doc";
                builder.SetSkillLevel(SkillID.Mining, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 1:
                builder.Name = "Grumpy";
                builder.SetSkillLevel(SkillID.Carpentry, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 2:
                builder.Name = "Happy";
                builder.SetSkillLevel(SkillID.WoodCutting, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 3:
                builder.Name = "Sleepy";
                builder.SetSkillLevel(SkillID.Masonry, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 4:
                builder.Name = "Bashful";
                builder.SetSkillLevel(SkillID.BlackSmithing, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 5:
                builder.Name = "Sneezy";
                builder.SetSkillLevel(SkillID.GemCutting, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;

            case 6:
                builder.Name = "Dopey";
                builder.SetSkillLevel(SkillID.Smelting, 80);
                builder.SetSkillLevel(SkillID.Fighting, 40);
                break;
            }

            var dwarf = builder.Create(this.World);

            Helpers.AddGem(dwarf);
            Helpers.AddBattleGear(dwarf);

            return(dwarf);
        }
Beispiel #4
0
        public static void AddGem(LivingObject living)
        {
            var world = living.World;

            var materials = Materials.GetMaterials(MaterialCategory.Gem).ToArray();
            var material  = materials[Helpers.GetRandomInt(materials.Length)].ID;

            var itemBuilder = new ItemObjectBuilder(ItemID.Gem, material);
            var item        = itemBuilder.Create(world);

            item.MoveToMustSucceed(living);
        }
Beispiel #5
0
        LivingObject CreateRandomLiving(int z)
        {
            var li = m_livingInfos[Helpers.GetRandomInt(m_livingInfos.Length)];

            var livingBuilder = new LivingObjectBuilder(li.ID);
            var living        = livingBuilder.Create(m_world);

            living.SetAI(new Dwarrowdelf.AI.MonsterAI(living, m_world.PlayerID));

            Helpers.AddBattleGear(living);

            return(living);
        }
Beispiel #6
0
        Player CreatePlayer(EnvironmentObject env)
        {
            const int NUM_DWARVES = 1;

            var player = new DungeonPlayer(2, this);

            var startRect = FindStartLocation(env);

            if (!startRect.HasValue)
            {
                throw new Exception();
            }

            var startLocs = startRect.Value.Range().ToArray();

            // clear trees
            foreach (var p in startLocs)
            {
                var td = env.GetTileData(p);
                if (td.HasTree)
                {
                    td.ID         = TileID.Grass;
                    td.MaterialID = MaterialID.RyeGrass;
                    env.SetTileData(p, td);
                }
            }

            var list = new List <LivingObject>();

            for (int i = 0; i < NUM_DWARVES; ++i)
            {
                var p = startLocs[Helpers.GetRandomInt(startLocs.Length - 1)];

                var l = CreateDwarf(i);
                l.Strength = 100;

                l.MoveToMustSucceed(env, p);

                list.Add(l);
            }

            player.AddControllables(list);

            return(player);
        }
Beispiel #7
0
        static IntVector3?GetRandomRoomLoc(EnvironmentObject env, ref IntGrid2Z grid)
        {
            int x = grid.X + Helpers.GetRandomInt(grid.Columns);
            int y = grid.Y + Helpers.GetRandomInt(grid.Rows);

            foreach (var p in IntVector2.SquareSpiral(new IntVector2(x, y), Math.Max(grid.Columns, grid.Rows)))
            {
                if (env.Size.Plane.Contains(p) == false)
                {
                    continue;
                }

                var p3 = new IntVector3(p, grid.Z);

                if (env.CanEnter(p3) == false)
                {
                    continue;
                }

                return(p3);
            }

            return(null);
        }
Beispiel #8
0
        void CreateMonsters()
        {
            foreach (var kvp in m_rooms)
            {
                int z     = kvp.Key;
                var rooms = kvp.Value;

                for (int i = 0; i < 10; ++i)
                {
                    var room = new IntGrid2Z(rooms[Helpers.GetRandomInt(rooms.Length)], z);

                    var pn = GetRandomRoomLoc(m_env, ref room);
                    if (pn.HasValue == false)
                    {
                        continue;
                    }

                    var p = pn.Value;

                    var living = CreateRandomLiving(z);
                    living.MoveToMustSucceed(m_env, p);
                }
            }
        }
Beispiel #9
0
 static GameColor GetRandomColor()
 {
     return((GameColor)Helpers.GetRandomInt(GameColorRGB.NUMCOLORS - 1) + 1);
 }
Beispiel #10
0
        static MaterialID GetRandomMaterial(MaterialCategory category)
        {
            var materials = Materials.GetMaterials(category).Select(mi => mi.ID).ToArray();

            return(materials[Helpers.GetRandomInt(materials.Length)]);
        }
Beispiel #11
0
        Player CreatePlayer(int playerNum, EnvironmentObject env)
        {
            const int NUM_DWARVES = 7;

            var player = new FortressPlayer(2 + playerNum, this, env);

            IntVector3 pos;

            switch (playerNum)
            {
            case 0:
                pos = env.StartLocation;
                break;

            case 1:
                pos = env.GetSurfaceLocation(env.Width / 4, env.Height / 4);
                break;

            case 2:
                pos = env.GetSurfaceLocation(env.Width / 4 * 3, env.Height / 4 * 3);
                break;

            default:
                throw new Exception();
            }

            var startRect = FindStartLocation(env, pos);

            if (!startRect.HasValue)
            {
                throw new Exception();
            }

            player.EnvObserver.Add(startRect.Value);

            var startLocs = startRect.Value.Range().ToArray();

            // clear trees
            foreach (var p in startLocs)
            {
                var td = env.GetTileData(p);
                if (td.HasTree)
                {
                    td.ID         = TileID.Grass;
                    td.MaterialID = MaterialID.RyeGrass;
                    env.SetTileData(p, td);
                }
            }

            var list = new List <LivingObject>();

            for (int i = 0; i < NUM_DWARVES; ++i)
            {
                var p = startLocs[Helpers.GetRandomInt(startLocs.Length - 1)];

                var l = CreateDwarf(i);

                l.SetAI(new DwarfAI(l, player.EnvObserver, this.World.PlayerID));

                l.MoveToMustSucceed(env, p);

                list.Add(l);
            }

            player.AddControllables(list);

            return(player);
        }