43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
use crate::payload::{Decode, Encode, SeStringChunkKind, SeInteractableKind};
|
|
use std::io::{Read, Seek};
|
|
use crate::Payload;
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
pub struct QuestPayload(pub u32);
|
|
|
|
impl QuestPayload {
|
|
const OFFSET: u32 = 65536;
|
|
}
|
|
|
|
impl From<u32> for QuestPayload {
|
|
fn from(id: u32) -> Self {
|
|
Self(id)
|
|
}
|
|
}
|
|
|
|
impl Decode for QuestPayload {
|
|
fn decode<R: Read + Seek>(reader: R, _chunk_len: usize) -> Result<Self, crate::Error> {
|
|
let id = Self::read_integer(reader)? + Self::OFFSET;
|
|
Ok(Self(id))
|
|
}
|
|
}
|
|
|
|
impl Encode for QuestPayload {
|
|
fn encode(&self) -> Vec<u8> {
|
|
use std::iter::once;
|
|
|
|
let id = Self::make_integer(self.0 - Self::OFFSET);
|
|
let chunk_len = id.len() + 4;
|
|
|
|
once(Payload::START_BYTE)
|
|
.chain(once(SeStringChunkKind::Interactable.as_u8()))
|
|
.chain(once(chunk_len as u8))
|
|
.chain(once(SeInteractableKind::QuestLink.as_u8()))
|
|
.chain(id.into_iter())
|
|
.chain(once(0x01))
|
|
.chain(once(0x01))
|
|
.chain(once(Payload::END_BYTE))
|
|
.collect()
|
|
}
|
|
}
|