use super::*;
pub trait Behavior {
fn name(&self) -> &str {
"behavior"
}
fn interests(&self) -> Interests {
Interests::NONE
}
fn raw_packets(&self, version: GameVersion) -> std::borrow::Cow<'static, [i32]> {
let _ = version;
std::borrow::Cow::Borrowed(&[])
}
fn start(&mut self, ctx: &mut TickContext<'_>) {
let _ = ctx;
}
fn tick(&mut self, ctx: &mut TickContext<'_>);
fn running(&self) -> bool {
true
}
fn after_tick(&mut self, view: &TickView<'_>) {
let _ = view;
}
fn stop(&mut self, reason: &str) {
let _ = reason;
}
fn configuration_dialog(
&mut self,
dialog: &crate::dialog::Dialog,
) -> Option<crate::dialog::DialogAnswer> {
let _ = dialog;
None
}
}
impl<B: Behavior + ?Sized> Behavior for Box<B> {
fn name(&self) -> &str {
(**self).name()
}
fn interests(&self) -> Interests {
(**self).interests()
}
fn raw_packets(&self, version: GameVersion) -> std::borrow::Cow<'static, [i32]> {
(**self).raw_packets(version)
}
fn start(&mut self, ctx: &mut TickContext<'_>) {
(**self).start(ctx);
}
fn tick(&mut self, ctx: &mut TickContext<'_>) {
(**self).tick(ctx);
}
fn running(&self) -> bool {
(**self).running()
}
fn after_tick(&mut self, view: &TickView<'_>) {
(**self).after_tick(view);
}
fn stop(&mut self, reason: &str) {
(**self).stop(reason);
}
fn configuration_dialog(
&mut self,
dialog: &crate::dialog::Dialog,
) -> Option<crate::dialog::DialogAnswer> {
(**self).configuration_dialog(dialog)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ClickRefused {
Turning,
Inventory(ghast_inventory::ClickError),
Dead,
}
impl std::fmt::Display for ClickRefused {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ClickRefused::Turning => f.write_str("the player is turning"),
ClickRefused::Inventory(e) => write!(f, "{e}"),
ClickRefused::Dead => f.write_str("the player is dead"),
}
}
}
impl std::error::Error for ClickRefused {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ClickTicket {
pub window_id: i32,
pub action: i16,
}
impl ClickTicket {
#[must_use]
pub fn matches(&self, r: &ghast_inventory::ClickResult) -> bool {
r.window_id == self.window_id && r.action == self.action
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Idle;
impl Behavior for Idle {
fn name(&self) -> &str {
"idle"
}
fn tick(&mut self, _ctx: &mut TickContext<'_>) {}
}