Browse Source

add quest_group for displaying regular or govt quests

pull/86/head
andy 3 years ago
parent
commit
e7297b21c0
  1. 9
      data/quests/bb/ep1/multi/quests.toml
  2. 15
      src/ship/packet/handler/quest.rs
  3. 32
      src/ship/room.rs
  4. 4
      src/ship/ship.rs

9
data/quests/bb/ep1/multi/quests.toml

@ -133,12 +133,3 @@ dat = "q137-evt-bb.dat"
bin = "q138-evt-bb.bin" bin = "q138-evt-bb.bin"
dat = "q138-evt-bb.dat" dat = "q138-evt-bb.dat"
[Shop]
list_order = 5
description = "Time to do some shopping!"
[[Shop.quests]]
bin = "q219-shp-bb.bin"
dat = "q219-shp-bb.dat"

15
src/ship/packet/handler/quest.rs

@ -36,12 +36,13 @@ fn parse_filename(filename_bytes: &[u8; 16]) -> Result<(u16, u16, QuestFileType)
} }
pub fn send_quest_category_list(id: ClientId, client_location: &ClientLocation, rooms: &mut Rooms) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
pub fn send_quest_category_list(id: ClientId, rql: &RequestQuestList, client_location: &ClientLocation, rooms: &mut Rooms) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?; let room_id = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() })?;
let room = rooms.get_mut(room_id.0) let room = rooms.get_mut(room_id.0)
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut() .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let qcl = quest::quest_category_list(&room.quests);
let qcl = quest::quest_category_list(&room.quests[rql.flag as usize]);
room.set_quest_group(rql.flag as usize);
Ok(Box::new(vec![(id, SendShipPacket::QuestCategoryList(qcl))].into_iter())) Ok(Box::new(vec![(id, SendShipPacket::QuestCategoryList(qcl))].into_iter()))
} }
@ -50,7 +51,7 @@ pub fn select_quest_category(id: ClientId, menuselect: &MenuSelect, client_locat
let room = rooms.get_mut(room_id.0) let room = rooms.get_mut(room_id.0)
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut() .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let (_, category_quests) = room.quests.iter()
let (_, category_quests) = room.quests[room.quest_group].iter() // TODO: error handling for invalid quest group
.nth(menuselect.item as usize) .nth(menuselect.item as usize)
.ok_or(ShipError::InvalidQuestCategory(menuselect.item))?; .ok_or(ShipError::InvalidQuestCategory(menuselect.item))?;
@ -67,7 +68,7 @@ pub fn quest_detail(id: ClientId, questdetailrequest: &QuestDetailRequest, clien
let room = rooms.get_mut(room_id.0) let room = rooms.get_mut(room_id.0)
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut() .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let (_, category_quests) = room.quests.iter()
let (_, category_quests) = room.quests[room.quest_group].iter()
.nth(questdetailrequest.category as usize) .nth(questdetailrequest.category as usize)
.ok_or(ShipError::InvalidQuestCategory(questdetailrequest.category as u32))?; .ok_or(ShipError::InvalidQuestCategory(questdetailrequest.category as u32))?;
@ -87,7 +88,7 @@ pub fn player_chose_quest(id: ClientId, questmenuselect: &QuestMenuSelect, clien
let room = rooms.get_mut(room_id.0) let room = rooms.get_mut(room_id.0)
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut() .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let (_, category_quests) = room.quests.iter()
let (_, category_quests) = room.quests[room.quest_group].iter()
.nth(questmenuselect.category as usize) .nth(questmenuselect.category as usize)
.ok_or(ShipError::InvalidQuestCategory(questmenuselect.category as u32))?; .ok_or(ShipError::InvalidQuestCategory(questmenuselect.category as u32))?;
@ -120,7 +121,7 @@ pub fn quest_file_request(id: ClientId, quest_file_request: &QuestFileRequest, c
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let (category_id, quest_id, datatype) = parse_filename(&quest_file_request.filename)?; let (category_id, quest_id, datatype) = parse_filename(&quest_file_request.filename)?;
let (_, category_quests) = room.quests.iter()
let (_, category_quests) = room.quests[room.quest_group].iter()
.nth(category_id as usize) .nth(category_id as usize)
.ok_or(ShipError::InvalidQuestCategory(category_id as u32))?; .ok_or(ShipError::InvalidQuestCategory(category_id as u32))?;
@ -149,7 +150,7 @@ pub fn quest_chunk_ack(id: ClientId, quest_chunk_ack: &QuestChunkAck, client_loc
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?; .ok_or(ShipError::InvalidRoom(room_id.0 as u32))?;
let (category_id, quest_id, datatype) = parse_filename(&quest_chunk_ack.filename)?; let (category_id, quest_id, datatype) = parse_filename(&quest_chunk_ack.filename)?;
let (_, category_quests) = room.quests.iter()
let (_, category_quests) = room.quests[room.quest_group].iter()
.nth(category_id as usize) .nth(category_id as usize)
.ok_or(ShipError::InvalidQuestCategory(category_id as u32))?; .ok_or(ShipError::InvalidQuestCategory(category_id as u32))?;

32
src/ship/room.rs

@ -179,7 +179,8 @@ pub struct RoomState {
pub monster_stats: Box<HashMap<MonsterType, MonsterStats>>, pub monster_stats: Box<HashMap<MonsterType, MonsterStats>>,
pub map_areas: MapAreaLookup, pub map_areas: MapAreaLookup,
pub rare_monster_table: Box<RareMonsterAppearTable>, pub rare_monster_table: Box<RareMonsterAppearTable>,
pub quests: quests::QuestList,
pub quest_group: usize,
pub quests: Vec<quests::QuestList>,
// items on ground // items on ground
// enemy info // enemy info
} }
@ -215,6 +216,10 @@ impl RoomState {
difficulty + 0x22 difficulty + 0x22
} }
pub fn set_quest_group(&mut self, group: usize) {
self.quest_group = group;
}
pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom, section_id: SectionID) -> Result<RoomState, RoomCreationError> { pub fn from_create_room(create_room: &libpso::packet::ship::CreateRoom, section_id: SectionID) -> Result<RoomState, RoomCreationError> {
if [create_room.battle, create_room.challenge, create_room.single_player].iter().sum::<u8>() > 1 { if [create_room.battle, create_room.challenge, create_room.single_player].iter().sum::<u8>() > 1 {
return Err(RoomCreationError::InvalidMode) return Err(RoomCreationError::InvalidMode)
@ -245,15 +250,36 @@ impl RoomState {
}; };
let rare_monster_table = RareMonsterAppearTable::new(room_mode.episode()); let rare_monster_table = RareMonsterAppearTable::new(room_mode.episode());
// push the usual set of quests for the selected mode
let mut qpath = PathBuf::from("data/quests/bb"); let mut qpath = PathBuf::from("data/quests/bb");
qpath.push(room_mode.episode().to_string()); qpath.push(room_mode.episode().to_string());
qpath.push(room_mode.to_string()); qpath.push(room_mode.to_string());
qpath.push("quests.toml"); qpath.push("quests.toml");
let room_quests = match quests::load_quests(&mut qpath) {
let mut room_quests = Vec::new();
let quest_list = match quests::load_quests(&mut qpath) {
Ok(qlist) => qlist, Ok(qlist) => qlist,
Err(_) => return Err(RoomCreationError::CouldNotLoadQuests), Err(_) => return Err(RoomCreationError::CouldNotLoadQuests),
}; };
room_quests.push(quest_list);
// if multiplayer also push the government quests
if let RoomMode::Multi {..} = room_mode {
qpath = PathBuf::from("data/quests/bb/");
qpath.push(room_mode.episode().to_string());
qpath.push("government/quests.toml");
let quest_list = match quests::load_quests(&mut qpath) {
Ok(qlist) => qlist,
Err(_) => return Err(RoomCreationError::CouldNotLoadQuests),
};
room_quests.push(quest_list);
}
Ok(RoomState { Ok(RoomState {
monster_stats: Box::new(load_monster_stats_table(&room_mode).map_err(|_| RoomCreationError::CouldNotLoadMonsterStats(room_mode))?), monster_stats: Box::new(load_monster_stats_table(&room_mode).map_err(|_| RoomCreationError::CouldNotLoadMonsterStats(room_mode))?),
mode: room_mode, mode: room_mode,
@ -266,6 +292,8 @@ impl RoomState {
drop_table: Box::new(DropTable::new(room_mode.episode(), room_mode.difficulty(), section_id)), drop_table: Box::new(DropTable::new(room_mode.episode(), room_mode.difficulty(), section_id)),
bursting: false, bursting: false,
map_areas: MapAreaLookup::new(&room_mode.episode()), map_areas: MapAreaLookup::new(&room_mode.episode()),
// quests: quest_list,
quest_group: 0,
quests: room_quests, quests: room_quests,
}) })
} }

4
src/ship/ship.rs

@ -712,9 +712,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;
Box::new(handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_manager, &self.level_table, &mut block.rooms, &mut self.entity_gateway).await?.into_iter()) Box::new(handler::lobby::change_lobby(id, pkt.lobby, &mut block.client_location, &self.clients, &mut self.item_manager, &self.level_table, &mut block.rooms, &mut self.entity_gateway).await?.into_iter())
}, },
RecvShipPacket::RequestQuestList(_) => {
RecvShipPacket::RequestQuestList(rql) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;
handler::quest::send_quest_category_list(id, &block.client_location, &mut block.rooms)?
handler::quest::send_quest_category_list(id, rql, &block.client_location, &mut block.rooms)?
}, },
RecvShipPacket::QuestFileRequest(quest_file_request) => { RecvShipPacket::QuestFileRequest(quest_file_request) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;

Loading…
Cancel
Save