|
|
@ -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 = 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))?;
|
|
|
|
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()))
|
|
|
|
}
|
|
|
|
|
|
|
@ -50,7 +51,7 @@ pub fn select_quest_category(id: ClientId, menuselect: &MenuSelect, client_locat |
|
|
|
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))?;
|
|
|
|
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)
|
|
|
|
.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)
|
|
|
|
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
|
|
|
|
.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)
|
|
|
|
.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)
|
|
|
|
.ok_or(ShipError::InvalidRoom(room_id.0 as u32))?.as_mut()
|
|
|
|
.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)
|
|
|
|
.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))?;
|
|
|
|
|
|
|
|
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)
|
|
|
|
.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))?;
|
|
|
|
|
|
|
|
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)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(category_id as u32))?;
|
|
|
|
|
|
|
|