|
|
@ -2,7 +2,6 @@ use std::io::{Cursor, Read, Seek, SeekFrom}; |
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use crate::common::serverstate::ClientId;
|
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms};
|
|
|
|
use crate::ship::quests::QuestList;
|
|
|
|
use crate::ship::location::{ClientLocation, ClientLocationError};
|
|
|
|
use crate::ship::packet::builder::quest;
|
|
|
|
use libpso::util::array_to_utf8;
|
|
|
@ -37,24 +36,38 @@ fn parse_filename(filename_bytes: &[u8; 16]) -> Result<(u16, u16, QuestFileType) |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn send_quest_category_list(id: ClientId, quests: &QuestList) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
let qcl = quest::quest_category_list(quests);
|
|
|
|
pub fn send_quest_category_list(id: ClientId, 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);
|
|
|
|
Ok(Box::new(vec![(id, SendShipPacket::QuestCategoryList(qcl))].into_iter()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn select_quest_category(id: ClientId, menuselect: &MenuSelect, quests: &QuestList) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
let (_, category_quests) = quests.iter()
|
|
|
|
pub fn select_quest_category(id: ClientId, menuselect: &MenuSelect, 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 (_, category_quests) = room.quests.iter()
|
|
|
|
.nth(menuselect.item as usize)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(menuselect.item))?;
|
|
|
|
|
|
|
|
let ql = quest::quest_list(menuselect.item, category_quests);
|
|
|
|
|
|
|
|
for q in ql.quests.clone() {
|
|
|
|
println!("name: {:?} quest_id: {}", q.name, q.quest_id);
|
|
|
|
}
|
|
|
|
Ok(Box::new(vec![(id, SendShipPacket::QuestOptionList(ql))].into_iter()))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn quest_detail(id: ClientId, questdetailrequest: &QuestDetailRequest, quests: &QuestList) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
let (_, category_quests) = quests.iter()
|
|
|
|
pub fn quest_detail(id: ClientId, questdetailrequest: &QuestDetailRequest, 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 (_, category_quests) = room.quests.iter()
|
|
|
|
.nth(questdetailrequest.category as usize)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(questdetailrequest.category as u32))?;
|
|
|
|
|
|
|
@ -68,9 +81,13 @@ pub fn quest_detail(id: ClientId, questdetailrequest: &QuestDetailRequest, quest |
|
|
|
Ok(Box::new(vec![(id, SendShipPacket::QuestDetail(qd))].into_iter()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn player_chose_quest(id: ClientId, questmenuselect: &QuestMenuSelect, quests: &QuestList, clients: &mut Clients, client_location: &ClientLocation, rooms: &mut Rooms)
|
|
|
|
pub fn player_chose_quest(id: ClientId, questmenuselect: &QuestMenuSelect, clients: &mut Clients, client_location: &ClientLocation, rooms: &mut Rooms)
|
|
|
|
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
let (_, category_quests) = quests.iter()
|
|
|
|
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 (_, category_quests) = room.quests.iter()
|
|
|
|
.nth(questmenuselect.category as usize)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(questmenuselect.category as u32))?;
|
|
|
|
|
|
|
@ -79,10 +96,6 @@ pub fn player_chose_quest(id: ClientId, questmenuselect: &QuestMenuSelect, quest |
|
|
|
q.id == questmenuselect.quest as u16
|
|
|
|
}).ok_or(ShipError::InvalidQuest(questmenuselect.quest as u32))?;
|
|
|
|
|
|
|
|
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))?;
|
|
|
|
room.maps.set_quest_data(quest.enemies.clone(), quest.objects.clone(), &room.rare_monster_table);
|
|
|
|
room.map_areas = quest.map_areas.clone();
|
|
|
|
|
|
|
@ -100,9 +113,14 @@ pub fn player_chose_quest(id: ClientId, questmenuselect: &QuestMenuSelect, quest |
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn quest_file_request(id: ClientId, quest_file_request: &QuestFileRequest, quests: &QuestList) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
pub fn quest_file_request(id: ClientId, quest_file_request: &QuestFileRequest, 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 (category_id, quest_id, datatype) = parse_filename(&quest_file_request.filename)?;
|
|
|
|
let (_, category_quests) = quests.iter()
|
|
|
|
let (_, category_quests) = room.quests.iter()
|
|
|
|
.nth(category_id as usize)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(category_id as u32))?;
|
|
|
|
|
|
|
@ -124,9 +142,14 @@ pub fn quest_file_request(id: ClientId, quest_file_request: &QuestFileRequest, q |
|
|
|
Ok(Box::new(vec![(id, SendShipPacket::QuestChunk(qc))].into_iter()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn quest_chunk_ack(id: ClientId, quest_chunk_ack: &QuestChunkAck, quests: &QuestList) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|
|
|
pub fn quest_chunk_ack(id: ClientId, quest_chunk_ack: &QuestChunkAck, 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 (category_id, quest_id, datatype) = parse_filename(&quest_chunk_ack.filename)?;
|
|
|
|
let (_, category_quests) = quests.iter()
|
|
|
|
let (_, category_quests) = room.quests.iter()
|
|
|
|
.nth(category_id as usize)
|
|
|
|
.ok_or(ShipError::InvalidQuestCategory(category_id as u32))?;
|
|
|
|
|
|
|
|