use crate::{context::ResourceContext, plugin::ActiveBuff};
use async_trait::async_trait;
#[async_trait]
pub trait RoomBuffHook: Send + Sync {
async fn on_buff_applied(&self, _buff: &ActiveBuff, _resources: &mut ResourceContext) {
}
async fn on_buff_removed(&self, _buff: &ActiveBuff, _resources: &mut ResourceContext) {
}
async fn on_buff_expired(&self, _buff: &ActiveBuff, _resources: &mut ResourceContext) {
}
async fn on_buff_tick(&self, _buff: &ActiveBuff, _resources: &mut ResourceContext) {
}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct DefaultRoomBuffHook;
#[async_trait]
impl RoomBuffHook for DefaultRoomBuffHook {
}
#[cfg(test)]
mod tests {
use crate::plugin::{ActiveBuff, BuffConfig};
use super::*;
#[tokio::test]
async fn test_default_hook_does_nothing() {
let hook = DefaultRoomBuffHook;
let buff = ActiveBuff::new(BuffConfig {
id: "test".to_string(),
name: "Test Buff".to_string(),
duration: super::super::types::BuffDuration::Permanent,
effect: super::super::types::BuffEffect::AttackBonus(10),
});
let mut resources = ResourceContext::new();
hook.on_buff_applied(&buff, &mut resources).await;
hook.on_buff_removed(&buff, &mut resources).await;
hook.on_buff_expired(&buff, &mut resources).await;
hook.on_buff_tick(&buff, &mut resources).await;
}
}