Browse Source

mapbuilder trait -> just a function

pull/127/head
jake 2 years ago
parent
commit
33b80d7235
  1. 19
      src/ship/map/maps.rs
  2. 6
      src/ship/packet/handler/room.rs
  3. 6
      src/ship/room.rs
  4. 10
      src/ship/ship.rs

19
src/ship/map/maps.rs

@ -358,23 +358,7 @@ impl Maps {
}
}
pub trait MapBuilder: Send + Sync {
fn generate_maps(&self, room_mode: RoomMode, event: ShipEvent) -> Maps;
}
#[derive(Clone)]
pub struct FreeRoamMapBuilder {
}
impl FreeRoamMapBuilder {
pub fn new() -> FreeRoamMapBuilder {
FreeRoamMapBuilder {
}
}
}
impl MapBuilder for FreeRoamMapBuilder {
fn generate_maps(&self, room_mode: RoomMode, event: ShipEvent) -> Maps {
pub fn generate_free_roam_maps(room_mode: RoomMode, event: ShipEvent) -> Maps {
let rare_monster_table = RareMonsterAppearTable::new(room_mode.episode());
let map_variants = map_variants(room_mode.episode(), room_mode.player_mode());
Maps {
@ -391,4 +375,3 @@ impl MapBuilder for FreeRoamMapBuilder {
map_variants,
}
}
}

6
src/ship/packet/handler/room.rs

@ -10,8 +10,8 @@ use crate::common::leveltable::LEVEL_TABLE;
use crate::entity::character::SectionID;
use crate::ship::drops::DropTable;
use crate::ship::ship::{SendShipPacket, Clients, ShipEvent};
use crate::ship::room::{Rooms, Episode, Difficulty, RoomState};
use crate::ship::map::MapBuilder;
use crate::ship::room::{Rooms, Episode, Difficulty, RoomState, RoomMode};
use crate::ship::map::Maps;
use crate::ship::location::{ClientLocation, RoomId, RoomLobby, GetAreaError};
use crate::ship::packet::builder;
use crate::ship::items::state::ItemState;
@ -22,7 +22,7 @@ pub async fn create_room(id: ClientId,
clients: &Clients,
item_state: &mut ItemState,
rooms: &Rooms,
map_builder: Arc<Box<dyn MapBuilder>>,
map_builder: Arc<Box<dyn Fn(RoomMode, ShipEvent) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
event: ShipEvent)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {

6
src/ship/room.rs

@ -8,7 +8,7 @@ use futures::stream::{FuturesOrdered, Stream};
use thiserror::Error;
use rand::Rng;
use crate::ship::map::{Maps, MapBuilder};
use crate::ship::map::Maps;
use crate::ship::drops::DropTable;
use crate::entity::character::SectionID;
use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats};
@ -358,7 +358,7 @@ impl RoomState {
}
pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom,
map_builder: Arc<Box<dyn MapBuilder>>,
map_builder: Arc<Box<dyn Fn(RoomMode, ShipEvent) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
section_id: SectionID,
event: ShipEvent)
@ -425,7 +425,7 @@ impl RoomState {
random_seed: rand::thread_rng().gen(),
name: String::from_utf16_lossy(&create_room.name).trim_matches(char::from(0)).into(),
password: create_room.password,
maps: map_builder.generate_maps(room_mode, event),
maps: map_builder(room_mode, event),
section_id,
drop_table: Box::new(drop_table_builder(room_mode.episode(), room_mode.difficulty(), section_id)),
bursting: false,

10
src/ship/ship.rs

@ -33,7 +33,7 @@ use crate::ship::location::{ClientLocation, RoomLobby, ClientLocationError, Room
use crate::ship::drops::DropTable;
use crate::ship::items;
use crate::ship::room;
use crate::ship::map::{MapBuilder, FreeRoamMapBuilder, MapsError, MapAreaError};
use crate::ship::map::{Maps, MapsError, MapAreaError, generate_free_roam_maps};
use crate::ship::packet::handler;
use crate::ship::shops::{WeaponShop, ToolShop, ArmorShop};
use crate::ship::trade::TradeState;
@ -380,7 +380,7 @@ pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> {
port: Option<u16>,
auth_token: Option<AuthToken>,
event: Option<ShipEvent>,
map_builder: Option<Box<dyn MapBuilder>>,
map_builder: Option<Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>>,
drop_table_builder: Option<Box<dyn Fn(room::Episode, room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
num_blocks: usize,
}
@ -439,7 +439,7 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
}
#[must_use]
pub fn map_builder(mut self, map_builder: Box<dyn MapBuilder>) -> ShipServerStateBuilder<EG> {
pub fn map_builder(mut self, map_builder: Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
self.map_builder = Some(map_builder);
self
}
@ -468,7 +468,7 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
shops: ItemShops::default(),
blocks: Blocks(blocks),
event: self.event.unwrap_or(ShipEvent::None),
map_builder: Arc::new(self.map_builder.unwrap_or(Box::new(FreeRoamMapBuilder::new()))),
map_builder: Arc::new(self.map_builder.unwrap_or(Box::new(generate_free_roam_maps))),
drop_table_builder: Arc::new(self.drop_table_builder.unwrap_or(Box::new(DropTable::new))),
auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())),
@ -518,7 +518,7 @@ pub struct ShipServerState<EG: EntityGateway + Clone + 'static> {
ship_list: Arc<RwLock<Vec<Ship>>>,
shipgate_sender: Option<channel::Sender<ShipMessage>>,
trades: TradeState,
map_builder: Arc<Box<dyn MapBuilder>>,
map_builder: Arc<Box<dyn Fn(room::RoomMode, ShipEvent) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(room::Episode, room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
}

Loading…
Cancel
Save