mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Choose random plaza tile
This commit is contained in:
parent
2fbddafd0a
commit
70538dae66
@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
/// The limit on how many characters that a player can have
|
/// The limit on how many characters that a player can have
|
||||||
pub const MAX_CHARACTERS_PER_PLAYER: usize = 8;
|
pub const MAX_CHARACTERS_PER_PLAYER: usize = 8;
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||||
|
#[serde(transparent)]
|
||||||
pub struct CharacterId(pub i64);
|
pub struct CharacterId(pub i64);
|
||||||
|
|
||||||
pub const MAX_NAME_LENGTH: usize = 20;
|
pub const MAX_NAME_LENGTH: usize = 20;
|
||||||
|
@ -577,7 +577,11 @@ fn choose_plaza(ctx: &mut NpcCtx, site: SiteId) -> Option<Vec2<f32>> {
|
|||||||
.and_then(|site| ctx.index.sites.get(site.world_site?).site2())
|
.and_then(|site| ctx.index.sites.get(site.world_site?).site2())
|
||||||
.and_then(|site2| {
|
.and_then(|site2| {
|
||||||
let plaza = &site2.plots[site2.plazas().choose(&mut ctx.rng)?];
|
let plaza = &site2.plots[site2.plazas().choose(&mut ctx.rng)?];
|
||||||
Some(site2.tile_center_wpos(plaza.root_tile()).as_())
|
let tile = plaza
|
||||||
|
.tiles()
|
||||||
|
.choose(&mut ctx.rng)
|
||||||
|
.unwrap_or_else(|| plaza.root_tile());
|
||||||
|
Some(site2.tile_center_wpos(tile).as_())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_get_slots_with_empty_profile() {
|
fn test_get_slots_with_empty_profile() {
|
||||||
let profile = Profile::default();
|
let profile = Profile::default();
|
||||||
let slots = profile.get_hotbar_slots("TestServer", Some(12345));
|
let slots = profile.get_hotbar_slots("TestServer", Some(CharacterId(12345)));
|
||||||
assert_eq!(slots, [(); 10].map(|()| None))
|
assert_eq!(slots, [(); 10].map(|()| None))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +261,6 @@ mod tests {
|
|||||||
fn test_set_slots_with_empty_profile() {
|
fn test_set_slots_with_empty_profile() {
|
||||||
let mut profile = Profile::default();
|
let mut profile = Profile::default();
|
||||||
let slots = [(); 10].map(|()| None);
|
let slots = [(); 10].map(|()| None);
|
||||||
profile.set_hotbar_slots("TestServer", Some(12345), slots);
|
profile.set_hotbar_slots("TestServer", Some(CharacterId(12345)), slots);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@ impl Plot {
|
|||||||
pub fn kind(&self) -> &PlotKind { &self.kind }
|
pub fn kind(&self) -> &PlotKind { &self.kind }
|
||||||
|
|
||||||
pub fn root_tile(&self) -> Vec2<i32> { self.root_tile }
|
pub fn root_tile(&self) -> Vec2<i32> { self.root_tile }
|
||||||
|
|
||||||
|
pub fn tiles(&self) -> impl ExactSizeIterator<Item = Vec2<i32>> + '_ {
|
||||||
|
self.tiles.iter().copied()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum PlotKind {
|
pub enum PlotKind {
|
||||||
|
Loading…
Reference in New Issue
Block a user