|
|
@ -25,6 +25,9 @@ use location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; |
|
|
|
use drops::DropTable;
|
|
|
|
use items;
|
|
|
|
use room;
|
|
|
|
use maps::room::{RoomMode, Episode, Difficulty};
|
|
|
|
//use quests::{load_standard_quests, load_government_quests};
|
|
|
|
use quests::{QuestList, QuestLoadError};
|
|
|
|
use maps::Holiday;
|
|
|
|
use maps::area::MapAreaError;
|
|
|
|
use maps::maps::{Maps, MapsError, generate_free_roam_maps};
|
|
|
@ -293,14 +296,14 @@ impl SendServerPacket for SendShipPacket { |
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ItemShops {
|
|
|
|
pub weapon_shop: HashMap<(maps::room::Difficulty, SectionID), Arc<Mutex<WeaponShop<rand_chacha::ChaCha20Rng>>>>,
|
|
|
|
pub weapon_shop: HashMap<(Difficulty, SectionID), Arc<Mutex<WeaponShop<rand_chacha::ChaCha20Rng>>>>,
|
|
|
|
pub tool_shop: Arc<Mutex<ToolShop<rand_chacha::ChaCha20Rng>>>,
|
|
|
|
pub armor_shop: Arc<Mutex<ArmorShop<rand_chacha::ChaCha20Rng>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ItemShops {
|
|
|
|
fn default() -> ItemShops {
|
|
|
|
let difficulty = [maps::room::Difficulty::Normal, maps::room::Difficulty::Hard, maps::room::Difficulty::VeryHard, maps::room::Difficulty::Ultimate];
|
|
|
|
let difficulty = [Difficulty::Normal, Difficulty::Hard, Difficulty::VeryHard, Difficulty::Ultimate];
|
|
|
|
let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum,
|
|
|
|
SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill];
|
|
|
|
|
|
|
@ -327,8 +330,10 @@ pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> { |
|
|
|
port: Option<u16>,
|
|
|
|
auth_token: Option<AuthToken>,
|
|
|
|
event: Option<Holiday>,
|
|
|
|
map_builder: Option<Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>,
|
|
|
|
drop_table_builder: Option<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
|
|
|
|
map_builder: Option<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
|
|
|
|
drop_table_builder: Option<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
|
|
|
|
standard_quest_builder: Option<Box<dyn Fn(RoomMode) -> Result<quests::QuestList, QuestLoadError> + Send + Sync>>,
|
|
|
|
government_quest_builder: Option<Box<dyn Fn(RoomMode) -> Result<quests::QuestList, QuestLoadError> + Send + Sync>>,
|
|
|
|
num_blocks: usize,
|
|
|
|
}
|
|
|
|
|
|
|
@ -343,6 +348,8 @@ impl<EG: EntityGateway + Clone + 'static> Default for ShipServerStateBuilder<EG> |
|
|
|
event: None,
|
|
|
|
map_builder: None,
|
|
|
|
drop_table_builder: None,
|
|
|
|
standard_quest_builder: None,
|
|
|
|
government_quest_builder: None,
|
|
|
|
num_blocks: 2,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -386,17 +393,29 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { |
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
pub fn map_builder(mut self, map_builder: Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
pub fn map_builder(mut self, map_builder: Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
self.map_builder = Some(map_builder);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
pub fn drop_table_builder(mut self, drop_table_builder: Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
pub fn drop_table_builder(mut self, drop_table_builder: Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
self.drop_table_builder = Some(drop_table_builder);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
pub fn standard_quest_builder(mut self, standard_quest_builder: Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
self.standard_quest_builder = Some(standard_quest_builder);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
pub fn government_quest_builder(mut self, government_quest_builder: Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>) -> ShipServerStateBuilder<EG> {
|
|
|
|
self.government_quest_builder = Some(government_quest_builder);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[must_use]
|
|
|
|
pub fn blocks(mut self, num_blocks: usize) -> ShipServerStateBuilder<EG> {
|
|
|
|
self.num_blocks = num_blocks;
|
|
|
@ -417,6 +436,8 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { |
|
|
|
event: self.event.unwrap_or(Holiday::None),
|
|
|
|
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))),
|
|
|
|
standard_quest_builder: Arc::new(self.standard_quest_builder.unwrap_or(Box::new(|_| Ok(QuestList::new())))),
|
|
|
|
government_quest_builder: Arc::new(self.government_quest_builder.unwrap_or(Box::new(|_| Ok(QuestList::new())))),
|
|
|
|
|
|
|
|
auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())),
|
|
|
|
ship_list: Arc::new(RwLock::new(Vec::new())),
|
|
|
@ -464,8 +485,10 @@ 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 Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>,
|
|
|
|
drop_table_builder: Arc<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
|
|
|
|
map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
|
|
|
|
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
|
|
|
|
standard_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
|
|
|
|
government_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> {
|
|
|
@ -707,7 +730,8 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { |
|
|
|
RecvShipPacket::CreateRoom(create_room) => {
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|
handler::room::create_room(id, create_room, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state,
|
|
|
|
&block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(), self.event).await?
|
|
|
|
&block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(),
|
|
|
|
self.standard_quest_builder.clone(), self.government_quest_builder.clone(), self.event).await?
|
|
|
|
},
|
|
|
|
RecvShipPacket::RoomNameRequest(_req) => {
|
|
|
|
let block = self.blocks.get_from_client(id, &self.clients).await?;
|
|
|
|