2021-02-07 21:39:21 +00:00
|
|
|
use super::{Command, Execution, ExecutionResult};
|
2020-10-31 12:40:44 +00:00
|
|
|
use crate::cofd::dice::{roll_pool, DicePool, DicePoolWithContext};
|
|
|
|
use crate::context::Context;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
|
|
|
pub struct PoolRollCommand(pub DicePool);
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl Command for PoolRollCommand {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"roll dice pool"
|
|
|
|
}
|
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
|
2020-10-31 12:40:44 +00:00
|
|
|
let pool_with_ctx = DicePoolWithContext(&self.0, ctx);
|
2021-01-30 14:17:34 +00:00
|
|
|
let rolled_pool = roll_pool(&pool_with_ctx).await?;
|
2020-10-31 12:40:44 +00:00
|
|
|
|
2021-01-30 14:17:34 +00:00
|
|
|
let html = format!(
|
|
|
|
"<p><strong>Pool:</strong> {}</p><p><strong>Result</strong>: {}</p>",
|
|
|
|
rolled_pool, rolled_pool.roll
|
|
|
|
);
|
2020-10-31 12:40:44 +00:00
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
Execution::success(html)
|
2020-10-31 12:40:44 +00:00
|
|
|
}
|
|
|
|
}
|