Merge branch 'juliancoffee/dungeon_chests' into 'master'

Rebalance chest density in dungeons

See merge request veloren/veloren!2803
This commit is contained in:
Samuel Keiffer 2021-09-02 22:58:33 +00:00
commit 7295204227
8 changed files with 34 additions and 21 deletions

View File

@ -1,8 +1,8 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 5, 10)),
(1.0, ItemQuantity("common.items.utility.coins", 2, 4)),
// Food
(1.0, LootTable("common.loot_tables.food.wild_ingredients")),
// Nothing
(2.0, None),
]
]

View File

@ -1,10 +1,10 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 10, 25)),
(1.0, ItemQuantity("common.items.utility.coins", 4, 10)),
// Food
(1.0, LootTable("common.loot_tables.food.wild_ingredients")),
// Nothing
(2.0, None),
// Placeholder Drop Location
(1.0, Item("common.items.crafting_ing.sticky_thread")),
]
]

View File

@ -1,8 +1,8 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 25, 50)),
(1.0, ItemQuantity("common.items.utility.coins", 10, 20)),
// Food
(1.0, LootTable("common.loot_tables.food.wild_ingredients")),
// Nothing
(2.0, None),
]
]

View File

@ -1,8 +1,8 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 50, 100)),
(1.0, ItemQuantity("common.items.utility.coins", 20, 40)),
// Food
(1.0, LootTable("common.loot_tables.food.prepared")),
// Nothing
(2.0, None),
]
]

View File

@ -1,8 +1,8 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 100, 250)),
(1.0, ItemQuantity("common.items.utility.coins", 40, 100)),
// Food
(1.0, LootTable("common.loot_tables.food.prepared")),
// Nothing
(2.0, None),
]
]

View File

@ -1,6 +1,6 @@
[
// Currency
(1.0, ItemQuantity("common.items.utility.coins", 200, 500)),
(1.0, ItemQuantity("common.items.utility.coins", 100, 200)),
// Food
(1.0, LootTable("common.loot_tables.food.prepared")),
// Cheese

View File

@ -1,6 +1,6 @@
[
// Currency
(50.0, ItemQuantity("common.items.utility.coins", 100, 300)),
(50.0, ItemQuantity("common.items.utility.coins", 50, 100)),
// Nothing
(50.0, None),
// Special

View File

@ -63,6 +63,8 @@ lazy_static! {
.clone();
}
fn floor_amount(difficulty: u32) -> u32 { 3 + difficulty / 2 }
impl Dungeon {
pub fn generate(wpos: Vec2<i32>, land: &Land, rng: &mut impl Rng) -> Self {
let mut ctx = GenCtx { land, rng };
@ -75,7 +77,7 @@ impl Dungeon {
err
)
});
let floors = 3 + difficulty / 2;
let floors = floor_amount(difficulty);
Self {
name: {
@ -383,7 +385,7 @@ impl Floor {
difficulty: u32,
) -> (Self, Vec2<i32>) {
const MAX_WIDTH: u32 = 4;
let floors = 3 + difficulty / 2;
let floors = floor_amount(difficulty);
let final_level = level == floors as i32 - 1;
let width = (2 + difficulty / 2).min(MAX_WIDTH);
let height = (15 + difficulty * 3).min(30);
@ -516,11 +518,20 @@ impl Floor {
None => return,
};
let loot_density = |difficulty, level| {
let max_floor = floor_amount(difficulty);
// We count floors from 0, don't divide by zero
let current_floor = level + 1;
let ratio = f64::from(current_floor) / f64::from(max_floor);
// filter starting floors
let ratio = 0.0_f64.max(ratio - 0.55);
0.00175 * ratio as f32
};
match ctx.rng.gen_range(0..5) {
// Miniboss room
0 => self.create_room(Room {
seed: ctx.rng.gen(),
loot_density: 0.000025 + level as f32 * 0.00015,
loot_density: loot_density(self.difficulty, level),
kind: RoomKind::Miniboss,
area,
height: ctx.rng.gen_range(15..20),
@ -530,7 +541,7 @@ impl Floor {
// Fight room with enemies in it
_ => self.create_room(Room {
seed: ctx.rng.gen(),
loot_density: 0.000025 + level as f32 * 0.00015,
loot_density: loot_density(self.difficulty, level),
kind: RoomKind::Fight,
area,
height: ctx.rng.gen_range(10..15),
@ -1219,8 +1230,9 @@ impl Floor {
let seed = room.seed;
let loot_density = room.loot_density;
let difficulty = room.difficulty;
// Place chests with a random distribution based on the room's loot density in
// valid sprite locations, filled based on the room's difficulty
// Place chests with a random distribution based on the
// room's loot density in valid sprite locations,
// filled based on the room's difficulty
let chest_sprite = prim(Primitive::Sampling(
sprite_layer,
Box::new(move |pos| RandomField::new(seed).chance(pos, loot_density * 0.5)),
@ -1236,9 +1248,10 @@ impl Floor {
}));
chests = Some((chest_sprite, chest_sprite_fill));
// If a room has pillars, the current tile aligns with the pillar spacing, and
// we're not too close to a wall (i.e. the adjacent tiles are rooms and not
// hallways/solid), place a pillar
// If a room has pillars, the current tile aligns with
// the pillar spacing, and we're not too close to a wall
// (i.e. the adjacent tiles are rooms and not hallways/solid),
// place a pillar
if room
.pillars
.map(|pillar_space| {