use super::config::LootConfig;
use super::hook::{DefaultLootHook, LootHook};
use super::service::LootService;
use super::system::LootSystem;
use crate::Plugin;
use std::sync::Arc;
#[derive(Plugin)]
#[plugin(name = "issun:loot")]
pub struct LootPlugin {
#[plugin(skip)]
hook: Arc<dyn LootHook>,
#[resource]
config: LootConfig,
#[service]
service: LootService,
#[system]
system: LootSystem,
}
impl LootPlugin {
pub fn new() -> Self {
let hook = Arc::new(DefaultLootHook);
Self {
hook: hook.clone(),
config: LootConfig::default(),
service: LootService::new(),
system: LootSystem::new(hook),
}
}
pub fn with_hook<H: LootHook + 'static>(mut self, hook: H) -> Self {
let hook = Arc::new(hook);
self.hook = hook.clone();
self.system = LootSystem::new(hook);
self
}
pub fn with_config(mut self, config: LootConfig) -> Self {
self.config = config;
self
}
}
impl Default for LootPlugin {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::plugin::Plugin;
#[test]
fn test_plugin_creation() {
let plugin = LootPlugin::new();
assert_eq!(plugin.name(), "issun:loot");
}
#[test]
fn test_plugin_with_custom_hook() {
struct CustomHook;
#[async_trait::async_trait]
impl LootHook for CustomHook {}
let plugin = LootPlugin::new().with_hook(CustomHook);
assert_eq!(plugin.name(), "issun:loot");
}
#[test]
fn test_plugin_with_custom_config() {
let config = LootConfig {
global_drop_multiplier: 1.5,
};
let plugin = LootPlugin::new().with_config(config);
assert_eq!(plugin.name(), "issun:loot");
}
}