Ejemplo n.º 1
0
    // === ACTIONS =================================================================================

    public void MeleeAttack(BattleUnit other)
    {
        battler.AnimateAttack();

        int dmg = 0;

        if (RandUtils.Chance(Get(StatTag.ACC) / 100.0f))
        {
            battler.GetComponent <CharaEvent>().FaceToward(other.battler.GetComponent <MapEvent>());
            dmg = (int)Get(StatTag.DMG);
            battle.Log(this + " attacked " + other + " for " + dmg + " damage.");
            if (Get(StatTag.ATTACKS) < 1)
            {
                isRecovering = true;
            }
            else if (Get(StatTag.ATTACKS) > 1)
            {
                canActAgain = true;
            }
        }
        else
        {
            battle.Log(this + " missed " + other + ".");
        }

        if (dmg > 0)
        {
            other.TakeDamage(dmg, battler.damageAnimation);
        }
    }
Ejemplo n.º 2
0
        string GetNamePart(RaceId race, int index)
        {
            var path      = $"country_{race}_{index}";
            var nameParts = Content.ResourceManager.GetString(path).Split(";");

            return(RandUtils.GetItem(nameParts));
        }
Ejemplo n.º 3
0
    public List <Encounter> GenerateEncounters(int level)
    {
        //int targetDanger;
        //if (level < firstLevelDangerOverrides.Count) {
        //    targetDanger = firstLevelDangerOverrides[level];
        //} else {
        //    targetDanger = baseDanger + level * dangerPerLevel;
        //}

        List <Encounter> results = new List <Encounter>();
        int added  = 0;
        int target = Random.Range(enemiesLow, enemiesHigh);

        while (results.Count < target)
        {
            RandUtils.Shuffle(encounters);
            Encounter toAdd = null;
            foreach (Encounter encounter in encounters)
            {
                if (level >= encounter.levelMin &&
                    level <= encounter.levelMax &&
                    RandUtils.Chance(encounter.rarity / 100.0f))
                {
                    toAdd  = encounter;
                    added += 1;
                    break;
                }
            }
            if (toAdd != null)
            {
                results.Add(toAdd);
            }
        }
        return(results);
    }
        public void EncodingIsOrderPreserving()
        {
            RandUtils randUtils = new RandUtils();

            List <ulong>  listOfNumbers   = new List <ulong>();
            List <string> listOfEncodings = new List <string>();

            // Generate 100,000 ulongs and insert them in a list
            for (int i = 0; i < NumUlongs; i += 1)
            {
                listOfNumbers.Add(randUtils.GenerateRandomUlong());
            }

            // Sort the list of numbers
            listOfNumbers.Sort();

            // Encode the numbers one by one and insert them in the list in order
            for (int i = 0; i < NumUlongs; i += 1)
            {
                listOfEncodings.Add(new string(Base64OrderPreservingAzureCompatEncoding.Encode(listOfNumbers[i], Base64OrderPreservingAzureCompatEncoding.SortOrders.Ordinal)));
            }

            // Check that the list of encoding numbers is already sorted
            List <string> orderedListOfEncodings = listOfEncodings.OrderBy(x => x, StringComparer.Ordinal).ToList();

            CollectionAssert.AreEqual(listOfEncodings, orderedListOfEncodings);
        }
        public void WhenIFillPrimaryContactForm(string modification)
        {
            ContactForm form;

            if (Ctx.NewAccount)
            {
                form = new ContactForm
                {
                    FirstName    = "F" + RandUtils.RandomName(9),
                    LastName     = "L" + RandUtils.RandomName(9),
                    CompanyName  = "C" + RandUtils.RandomString(9),
                    Email        = "E" + RandUtils.RandomString(6) + "@test.com.block",
                    PhoneNumber  = "1" + RandUtils.RandomNumber(9),
                    AddressLine1 = "1009 Lenox Dr",
                    AddressLine2 = "",
                    City         = "Lawrence Township",
                    State        = "NJ",
                    Zip          = "08648",
                    Country      = "United States"
                };
            }
            else
            {
                var acct = Ctx.OriginalAccount;
                form = new ContactForm(acct.PrimaryContact, acct.PrimaryAddress);
            }

            if (modification.Length > 0)
            {
                form.FirstName    = "F" + RandUtils.RandomName(9);
                form.LastName     = "L" + RandUtils.RandomName(9);
                form.Email        = "E" + RandUtils.RandomString(6) + "@test.com.block";
                form.PhoneNumber  = "1" + RandUtils.RandomNumber(9);
                form.AddressLine1 = "1009 Lenox Dr";
                form.AddressLine2 = "";
                form.City         = "Lawrence Township";
                form.State        = "NJ";
                form.Zip          = "08648";
                form.Country      = "United States";
            }

            Ctx.PrimaryContact = form;

            new Pages.CSA.ContactDetails(Driver).FillPrimaryContact(
                form.FirstName,
                form.LastName,
                form.CompanyName,
                form.Email,
                form.PhoneNumber,
                form.City,
                form.State,
                form.Zip,
                form.AddressLine1,
                form.AddressLine2,
                form.Country
                );

            Console.WriteLine($"company={form.CompanyName} name={form.LastName}, {form.FirstName}");
        }
        public void EncodeDecode()
        {
            RandUtils randUtils = new RandUtils();

            // The Assert is placed in the for-loop so that if we fail, we fail early
            for (int i = 0; i < NumUlongs; i += 1)
            {
                ulong  current         = randUtils.GenerateRandomUlong();
                char[] ordinalEncoding = Base64OrderPreservingAzureCompatEncoding.Encode(current, Base64OrderPreservingAzureCompatEncoding.SortOrders.Ordinal);
                Assert.AreEqual(current, Base64OrderPreservingAzureCompatEncoding.Decode(ordinalEncoding, Base64OrderPreservingAzureCompatEncoding.SortOrders.Ordinal));
                char[] lexiEncoding = Base64OrderPreservingAzureCompatEncoding.Encode(current, Base64OrderPreservingAzureCompatEncoding.SortOrders.Lexicographic);
                Assert.AreEqual(current, Base64OrderPreservingAzureCompatEncoding.Decode(lexiEncoding, Base64OrderPreservingAzureCompatEncoding.SortOrders.Lexicographic));
            }
        }
Ejemplo n.º 7
0
 private Item GeneratePickup(int level)
 {
     if (level < 2)
     {
         return(null);
     }
     if (RandUtils.Chance(0.7f))
     {
         return(scissors);
     }
     else
     {
         return(eraser);
     }
 }
Ejemplo n.º 8
0
        ConsoleColor GetNewCountryColor(ICollection <ConsoleColor> exceptions)
        {
            var values = new List <ConsoleColor>((ConsoleColor[])Enum.GetValues(typeof(ConsoleColor)));

            values.Remove(ConsoleColor.Black);
            values.Remove(ConsoleColor.White);
            values.Remove(ConsoleColor.Green);
            foreach (var exc in exceptions)
            {
                if (values.Count > 0)
                {
                    values.Remove(exc);
                }
            }
            return(RandUtils.GetItem(values));
        }
Ejemplo n.º 9
0
    public Skill(Scroll scroll)
    {
        this.scroll = scroll;
        data        = scroll.data;
        mods        = new List <SkillModifier>();
        foreach (SkillModifier.Type type in scroll.mods)
        {
            mods.Add(new SkillModifier(type));
        }

        // generation
        if (data.prohibitedToBeCD)
        {
            costMP = data.baseCost;
        }
        else if (data.prohibitedToBeMP)
        {
            costCD = data.baseCost;
        }
        else if (RandUtils.Chance(0.7f))
        {
            costMP = data.baseCost;
        }
        else
        {
            costCD = Mathf.CeilToInt(data.baseCost / 8.0f);
        }

        pageCost     = data.basePages;
        longformName = "";
        foreach (SkillModifier mod in mods)
        {
            longformName = mod.MutateName(longformName);
            pageCost     = mod.MutatePages(pageCost);
            if (costMP > 0)
            {
                costMP = mod.MutateCost(costMP);
            }
            else
            {
                costCD = mod.MutateCost(costCD);
            }
        }
        longformName = skillName + " [ " + pageCost + "pg " + (costMP > 0 ? costMP + "mp" : costCD + "cd") + " ] " + longformName;
    }
Ejemplo n.º 10
0
        Race GetRace(bool player)
        {
            if (player && (_raceSettings.PlayerRace != null))
            {
                return(_raceSettings.PlayerRace);
            }
            var allRaces    = _raceSettings.AllRaces;
            var raceChances = new List <double>();

            foreach (var race in allRaces)
            {
                var count = Countries.Count(c => c.Kind.Id == race);
                raceChances.Add(1 / (2 * count + 1));
            }
            var id = RandUtils.GetItemWithChances(allRaces, raceChances);

            return(_raceSettings.Get(id));
        }
Ejemplo n.º 11
0
    private Scroll GenerateScroll(int level)
    {
        int modCount = 0;

        if (level >= 8)
        {
            modCount = RandUtils.Chance(0.6f) ? 1 : 0;
        }
        else if (level >= 4)
        {
            modCount = RandUtils.Chance(0.35f) ? 1 : 0;
        }
        else
        {
            modCount = RandUtils.Chance(0.1f) ? 1 : 0;
        }

        List <SkillModifier.Type> toApply = new List <SkillModifier.Type>();
        List <SkillModifier.Type> mods    = new List <SkillModifier.Type>(
            (SkillModifier.Type[])System.Enum.GetValues(typeof(SkillModifier.Type)));

        while (toApply.Count < modCount)
        {
            SkillModifier.Type mod = mods[Random.Range(0, mods.Count)];
            if (!toApply.Contains(mod))
            {
                toApply.Add(mod);
            }
        }

        Scroll scroll = Instantiate(this.scroll);

        scroll.mods = toApply;
        while (scroll.data == null)
        {
            SkillData skill = skills[Random.Range(0, skills.Count)];
            if (RandUtils.Chance((skill.rarity - level) / 100.0f))
            {
                scroll.data = skill;
            }
        }

        return(scroll);
    }
Ejemplo n.º 12
0
    public void FillWithVault(TacticsTerrainMesh mesh)
    {
        if (RandUtils.Chance(0.4f))
        {
            return;
        }
        if (vaults == null)
        {
            vaults = Resources.Load <VaultList>(VaultsPath);
        }
        bool flipX = RandUtils.Flip();
        bool flipY = RandUtils.Flip();
        TacticsTerrainMesh vault = vaults.vaults[Random.Range(0, vaults.vaults.Count)];

        for (int trueY = 0; trueY < cell.sizeY; trueY += 1)
        {
            for (int trueX = 0; trueX < cell.sizeX; trueX += 1)
            {
                int x = flipX ? trueX : (cell.sizeX - 1 - trueX);
                int y = flipY ? trueY : (cell.sizeY - 1 - trueY);
                mesh.SetHeight(cell.startX + x, cell.startY + y,
                               mesh.HeightAt(cell.startX + x, cell.startY + y) + vault.HeightAt(x, y) - 1.0f);
                Tile topTile = vault.TileAt(x, y);
                if (topTile != mesh.defaultTopTile)
                {
                    mesh.SetTile(cell.startX + x, cell.startY + y, topTile);
                }
                for (float h = 0.0f; h < vault.HeightAt(x, y); h += 0.5f)
                {
                    foreach (OrthoDir dir in System.Enum.GetValues(typeof(OrthoDir)))
                    {
                        Tile t = vault.TileAt(x, y, h, dir);
                        if (t != mesh.defaultFaceTile)
                        {
                            mesh.SetTile(cell.startX + x, cell.startY + y, mesh.HeightAt(x, y) - 1 + h, dir, t);
                        }
                    }
                }
            }
        }
    }
        public void WhenISelectAnAccountWithProration(string proration)
        {
            var imis = Context <IMIS>(IMIS);

            Name cm    = null;
            int  count = 0;

            while (count < 10)
            {
                IEnumerable <Name> names;
                if (proration == "with")
                {
                    names = imis.FindAccountWithProration(15);
                }
                else
                {
                    names = imis.FindAccountWithoutProration(15);
                }
                var coId = LockUtils.PickUnusedAccount("coid", names.Select(o => o.ID));
                if (coId != null)
                {
                    cm = names.Where(o => o.ID == coId).First();
                    break;
                }
                count += 1;
                Task.Delay(RandUtils.RandInt(1000, 2000)).Wait();
            }

            cm.ShouldNotBeNull();
            cm.ID.ShouldNotBeEmpty();

            Console.WriteLine($"CO_ID={cm.ID}");

            var account = new Account(imis, cm.ID);

            Ctx.OriginalAccount = account;
        }
Ejemplo n.º 14
0
    public void GenerateMesh(MapGenerator lastMap = null)
    {
        TacticsTerrainMesh mesh = GetComponent <TacticsTerrainMesh>();

        // copy oldbie values if needed
        if (lastMap != null)
        {
            sizeInRoomsMin    = lastMap.sizeInRoomsMin;
            sizeInRoomsMax    = lastMap.sizeInRoomsMax;
            stairLength       = lastMap.stairLength;
            startEventPrefab  = lastMap.startEventPrefab;
            endEventPrefab    = lastMap.endEventPrefab;
            impassEventPrefab = lastMap.impassEventPrefab;
            defaultImpassTile = lastMap.defaultImpassTile;
            chestEventPrefab  = lastMap.chestEventPrefab;
            targetPrefab      = lastMap.targetPrefab;
            finalLevel        = lastMap.finalLevel;
            finalLevelPrefab  = lastMap.finalLevelPrefab;
            table             = lastMap.table;
            level             = lastMap.level + 1;
        }

        if (level == finalLevel)
        {
            Map other = Instantiate(finalLevelPrefab);
            Global.Instance().Maps.activeMap = other;
            return;
        }

        // wipe what's already there

        mesh.ClearTiles();
        foreach (MapEvent toRemove in GetComponent <Map>().GetEvents <MapEvent>())
        {
            if (toRemove.GetComponent <PCEvent>() == null)
            {
                if (toRemove.GetComponent <BattleEvent>() && Application.isPlaying)
                {
                    GetComponent <BattleController>().RemoveUnit(toRemove.GetComponent <BattleEvent>().unit);
                }
                GetComponent <Map>().RemoveEvent(toRemove, true);
            }
        }

        // work out some constants
        if (Flip())
        {
            sizeInRooms = new Vector2Int(sizeInRoomsMin.x, sizeInRoomsMax.y);
        }
        else
        {
            sizeInRooms = new Vector2Int(sizeInRoomsMax.x, sizeInRoomsMin.y);
        }
        int seed = (int)DateTime.Now.Ticks;

        Random.InitState(seed);
        Debug.Log("using seed " + seed);
        rooms       = new RoomInfo[sizeInRooms.x, sizeInRooms.y];
        sizeInCells = sizeInRooms * 2 - new Vector2Int(1, 1);
        cells       = new CellInfo[sizeInCells.x, sizeInCells.y];

        // are we going to add the starting stairwell on the left or right?
        if (lastMap != null)
        {
            if (lastMap.endStairsNW)
            {
                entryRoomCoords = new Vector2Int(Random.Range(0, 2), 0);
                startStairsSW   = false;
            }
            else
            {
                entryRoomCoords = new Vector2Int(0, Random.Range(0, 2));
                startStairsSW   = true;
            }
            exitRoomCoords = new Vector2Int(sizeInRooms.x - 1, sizeInRooms.y - 1);
            if (Flip())
            {
                exitRoomCoords.x -= Random.Range(0, 2);
            }
            else
            {
                exitRoomCoords.y -= Random.Range(0, 2);
            }
        }
        else
        {
            if (entryRoomCoords == Vector2Int.zero)
            {
                startStairsSW = Flip();
            }
            else if (entryRoomCoords.y > 0)
            {
                startStairsSW = true;
            }
            else
            {
                startStairsSW = false;
            }
        }
        if (exitRoomCoords == new Vector2Int(sizeInRooms.x - 1, sizeInRooms.y - 1))
        {
            endStairsNW = Flip();
        }
        else if (exitRoomCoords.x < sizeInRooms.x - 1)
        {
            endStairsNW = true;
        }
        else
        {
            endStairsNW = false;
        }

        // set the size and start of each room and hallway
        cells   = new CellInfo[sizeInCells.x, sizeInCells.y];
        widths  = new int[sizeInCells.x];
        heights = new int[sizeInCells.y];
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            if (y % 2 == 1)
            {
                heights[y] = RandomHallSize();
            }
            else
            {
                heights[y] = RandomRoomSize();
            }
        }
        for (int x = 0; x < sizeInCells.x; x += 1)
        {
            if (x % 2 == 1)
            {
                widths[x] = RandomHallSize();
            }
            else
            {
                widths[x] = RandomRoomSize();
            }
        }
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            for (int x = 0; x < sizeInCells.x; x += 1)
            {
                cells[x, y] = new CellInfo(x, y, widths[x], heights[y]);
                if (x % 2 == 1 || y % 2 == 1)
                {
                    if (x % 2 == 1 && y % 2 == 1)
                    {
                        cells[x, y].type = CellInfo.CellType.Pillar;
                    }
                    else
                    {
                        cells[x, y].type = CellInfo.CellType.Hall;
                    }
                }
                else
                {
                    cells[x, y].type = CellInfo.CellType.Room;
                }
                if (x == 0)
                {
                    cells[x, y].startX = startStairsSW ? stairLength : 0;
                }
                else
                {
                    cells[x, y].startX = cells[x - 1, y].startX + widths[x - 1];
                }
                if (y == 0)
                {
                    cells[x, y].startY = startStairsSW ? 0 : stairLength;
                }
                else
                {
                    cells[x, y].startY = cells[x, y - 1].startY + heights[y - 1];
                }
            }
        }

        // set the elevation of each room
        for (int diag = 0; diag < sizeInRooms.x + sizeInRooms.y; diag += 1)
        {
            int x = diag;
            int y = 0;
            while (x >= 0)
            {
                if (x < sizeInRooms.x && y < sizeInRooms.y)
                {
                    float z;
                    if (x == 0 && y == 0)
                    {
                        z = stairLength / 2.0f + 0.5f;
                    }
                    else
                    {
                        float oldZ;
                        if (y == 0)
                        {
                            oldZ = rooms[x - 1, y].z;
                        }
                        else if (x == 0)
                        {
                            oldZ = rooms[x, y - 1].z;
                        }
                        else
                        {
                            oldZ = Math.Max(rooms[x, y - 1].z, rooms[x - 1, y].z);
                        }
                        z = RandomNewZ(oldZ);
                    }
                    rooms[x, y] = new RoomInfo(cells[x * 2, y * 2], z);
                }
                x -= 1;
                y += 1;
            }
        }

        // determine the initial passability map
        cells[0, 0].connected = true;
        UpdatePassability();

        // knock down walls until all rooms are accessible
        List <RoomInfo> roomsToGo = new List <RoomInfo>();

        for (int x = 0; x < sizeInRooms.x; x += 1)
        {
            for (int y = 0; y < sizeInRooms.y; y += 1)
            {
                roomsToGo.Add(rooms[x, y]);
            }
        }
        while (roomsToGo.Count > 0)
        {
            int      index = Random.Range(0, roomsToGo.Count);
            RoomInfo room  = roomsToGo[index];
            if (room.cell.connected)
            {
                roomsToGo.RemoveAt(index);
                continue;
            }
            List <RoomInfo> adjacents = room.cell.AdjacentRooms(this);
            RandUtils.Shuffle(adjacents);
            RoomInfo adj = null;
            foreach (RoomInfo adj2 in adjacents)
            {
                if (!adj2.cell.connected)
                {
                    continue;
                }
                CellInfo connector = cells[(room.cell.x + adj2.cell.x) / 2, (room.cell.y + adj2.cell.y) / 2];
                if (Mathf.Abs(adj2.z - room.z) / (widths[connector.x] * heights[connector.y]) > 2)
                {
                    continue;
                }
                adj = adj2;
                break;
            }
            if (adj == null)
            {
                continue;
            }
            roomsToGo.RemoveAt(index);
            cells[(room.cell.x + adj.cell.x) / 2, (room.cell.y + adj.cell.y) / 2].connected = true;
            room.cell.connected = adj.cell.connected;

            if (adj.cell.connected)
            {
                UpdatePassability();
            }
        }

        // convert halls into stairways as needed
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            for (int x = 0; x < sizeInCells.x; x += 1)
            {
                CellInfo cell = cells[x, y];
                if (cell.type == CellInfo.CellType.Hall && cell.connected)
                {
                    List <RoomInfo> rooms  = cell.AdjacentRooms(this);
                    float           deltaZ = Math.Abs(rooms[0].z - rooms[1].z);
                    if (deltaZ > 1)
                    {
                        if (deltaZ > cell.sizeX / 2 && deltaZ > cell.sizeY / 2)
                        {
                            cell.type = CellInfo.CellType.Switchback;
                        }
                        else
                        {
                            cell.type = CellInfo.CellType.Stairway;
                        }
                    }
                }
            }
        }

        // set pillar heights to sane values
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            for (int x = 0; x < sizeInCells.x; x += 1)
            {
                CellInfo cell = cells[x, y];
                if (cell.type == CellInfo.CellType.Pillar)
                {
                    CellInfo n = cells[x, y + 1];
                    CellInfo e = cells[x + 1, y];
                    CellInfo s = cells[x, y - 1];
                    CellInfo w = cells[x - 1, y];
                    if (n.type == CellInfo.CellType.Stairway && e.type == CellInfo.CellType.Stairway)
                    {
                        cell.pillarZ        = rooms[(x + 1) / 2, (y + 1) / 2].z;
                        e.stairAnchoredHigh = true;
                        n.stairAnchoredHigh = true;
                    }
                    else if (s.type == CellInfo.CellType.Switchback && s.sizeX > 1)
                    {
                        cell.pillarZ = (s.AdjacentRooms(this)[0].z + s.AdjacentRooms(this)[1].z) / 2.0f;
                    }
                    else if (w.type == CellInfo.CellType.Switchback && s.sizeY > 1)
                    {
                        cell.pillarZ = (w.AdjacentRooms(this)[0].z + w.AdjacentRooms(this)[1].z) / 2.0f;
                    }
                    else
                    {
                        cell.pillarZ = rooms[(x - 1) / 2, (y - 1) / 2].z;
                    }
                }
            }
        }

        // decorator fringe
        RoomInfo cornerRoom = rooms[sizeInRooms.x - 1, sizeInRooms.y - 1];
        int      wallX      = cornerRoom.cell.startX + cornerRoom.cell.sizeX + 1;
        int      wallY      = cornerRoom.cell.startY + cornerRoom.cell.sizeY + 1;

        mesh.Resize(new Vector2Int(
                        wallX + (endStairsNW ? 0 : stairLength),
                        wallY + (endStairsNW ? stairLength : 0)),
                    0.0f);
        for (int x = startStairsSW ? stairLength : 0; x < wallX; x += 1)
        {
            mesh.SetHeight(x, wallY - 1, cornerRoom.z + MaxHeightDelta + 1);
            mesh.SetTile(x, wallY - 1, defaultImpassTile);
        }
        for (int y = startStairsSW ? 0 : stairLength; y < wallY; y += 1)
        {
            mesh.SetHeight(wallX - 1, y, cornerRoom.z + MaxHeightDelta + 1);
            mesh.SetTile(wallX - 1, y, defaultImpassTile);
        }

        // render terrain
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            for (int x = 0; x < sizeInCells.x; x += 1)
            {
                CellInfo cell = cells[x, y];
                if (cell.type != CellInfo.CellType.Pillar)
                {
                    cell.RenderTerrain(this, mesh);
                }
            }
        }
        for (int y = 0; y < sizeInCells.y; y += 1)
        {
            for (int x = 0; x < sizeInCells.x; x += 1)
            {
                CellInfo cell = cells[x, y];
                if (cell.type == CellInfo.CellType.Pillar)
                {
                    cell.RenderTerrain(this, mesh);
                }
            }
        }

        // render rooms
        for (int x = 0; x < sizeInRooms.x; x += 1)
        {
            for (int y = 0; y < sizeInRooms.y; y += 1)
            {
                rooms[x, y].FillWithVault(mesh);
            }
        }

        // add the starter stairs
        RoomInfo startRoom = rooms[entryRoomCoords.x, entryRoomCoords.y];
        int      stairX, stairZ;

        if (startStairsSW)
        {
            stairX = startRoom.cell.startX - 1;
            stairZ = startRoom.cell.startY + (startRoom.cell.sizeY / 2);
        }
        else
        {
            stairX = startRoom.cell.startX + (startRoom.cell.sizeX / 2);
            stairZ = startRoom.cell.startY - 1;
        }
        float stairY = startRoom.z - 0.5f;

        for (int i = 0; i < stairLength; i += 1)
        {
            mesh.SetHeight(stairX, stairZ, stairY);
            MapEvent3D ev;
            if (i == 0)
            {
                ev = Instantiate(startEventPrefab);
            }
            else
            {
                ev = Instantiate(impassEventPrefab);
            }
            GetComponent <Map>().AddEvent(ev);
            ev.SetLocation(new Vector2Int(stairX, stairZ));
            stairY -= 0.5f;
            stairX += startStairsSW ? -1 : 0;
            stairZ += startStairsSW ? 0 : -1;
        }

        // add the end stairs
        RoomInfo endRoom = rooms[exitRoomCoords.x, exitRoomCoords.y];

        if (endStairsNW)
        {
            stairX = endRoom.cell.startX + (endRoom.cell.sizeX / 2);
            stairZ = endRoom.cell.startY + endRoom.cell.sizeY;
        }
        else
        {
            stairX = endRoom.cell.startX + endRoom.cell.sizeX;
            stairZ = endRoom.cell.startY + (endRoom.cell.sizeY / 2);
        }
        stairY = endRoom.z + 0.5f;
        for (int i = 0; i < stairLength; i += 1)
        {
            MapEvent3D ev;
            if (i == 0)
            {
                ev = Instantiate(endEventPrefab);
            }
            else
            {
                ev = Instantiate(impassEventPrefab);
            }
            GetComponent <Map>().AddEvent(ev);
            ev.SetLocation(new Vector2Int(stairX, stairZ));
            mesh.SetHeight(stairX, stairZ, stairY);
            stairY += 0.5f;
            stairX += endStairsNW ? 0 : 1;
            stairZ += endStairsNW ? 1 : 0;
        }

        // add the zoom target
        MapEvent3D zoom = Instantiate(targetPrefab);

        GetComponent <Map>().AddEvent(zoom);
        zoom.SetLocation(new Vector2Int(mesh.size.x / 2, mesh.size.y / 2));

        // generate the encounters
        List <RoomInfo> validRooms = new List <RoomInfo>();

        for (int x = 0; x < sizeInRooms.x; x += 1)
        {
            for (int y = 0; y < sizeInRooms.y; y += 1)
            {
                if (x != entryRoomCoords.x || y != entryRoomCoords.y)
                {
                    validRooms.Add(rooms[x, y]);
                }
            }
        }
        List <Encounter> encounters = table.GenerateEncounters(level);

        foreach (Encounter encounter in encounters)
        {
            RoomInfo   room = validRooms[Random.Range(0, validRooms.Count)];
            Vector2Int loc  = new Vector2Int(
                Random.Range(room.cell.startX, room.cell.startX + room.cell.sizeX),
                Random.Range(room.cell.startY, room.cell.startY + room.cell.sizeY));
            encounter.PlaceAt(GetComponent <Map>(), loc);
        }

        // generate the chests
        List <Item> items = table.GenerateItems(level);

        foreach (Item item in items)
        {
            ChestEvent chest = Instantiate(chestEventPrefab);
            GetComponent <Map>().AddEvent(chest.GetComponent <MapEvent>());
            Vector2Int loc;
            do
            {
                RoomInfo room = validRooms[Random.Range(0, validRooms.Count)];
                loc = new Vector2Int(
                    Random.Range(room.cell.startX + 1, room.cell.startX + room.cell.sizeX - 1),
                    Random.Range(room.cell.startY + 1, room.cell.startY + room.cell.sizeY - 1));
            } while (!chest.GetComponent <MapEvent>().CanPassAt(loc));
            chest.PopulateAndPlace(item, loc);
        }

        mesh.Rebuild(true);
    }