2021-02-07 21:39:21 +00:00
|
|
|
use super::{Command, Execution, ExecutionResult};
|
2020-10-31 13:19:38 +00:00
|
|
|
use crate::context::Context;
|
2020-11-04 20:09:39 +00:00
|
|
|
use crate::cthulhu::dice::{regular_roll, AdvancementRoll, DiceRoll, DiceRollWithContext};
|
2020-10-31 13:19:38 +00:00
|
|
|
use async_trait::async_trait;
|
|
|
|
|
|
|
|
pub struct CthRoll(pub DiceRoll);
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl Command for CthRoll {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"roll percentile pool"
|
|
|
|
}
|
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
async fn execute(&self, ctx: &Context<'_>) -> ExecutionResult {
|
2020-11-04 20:09:39 +00:00
|
|
|
let roll_with_ctx = DiceRollWithContext(&self.0, ctx);
|
2021-01-30 14:17:34 +00:00
|
|
|
let executed_roll = regular_roll(&roll_with_ctx).await?;
|
|
|
|
|
|
|
|
let html = format!(
|
|
|
|
"<p><strong>Roll:</strong> {}</p><p><strong>Result</strong>: {}</p>",
|
|
|
|
executed_roll, executed_roll.roll
|
|
|
|
);
|
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
Execution::success(html)
|
2020-10-31 13:19:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CthAdvanceRoll(pub AdvancementRoll);
|
2020-10-31 14:03:18 +00:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl Command for CthAdvanceRoll {
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
"roll percentile pool"
|
|
|
|
}
|
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
async fn execute(&self, _ctx: &Context<'_>) -> ExecutionResult {
|
2020-10-31 14:03:18 +00:00
|
|
|
//TODO this will be converted to a result when supporting variables.
|
|
|
|
let roll = self.0.roll();
|
|
|
|
let html = format!(
|
|
|
|
"<p><strong>Roll:</strong> {}</p><p><strong>Result</strong>: {}</p>",
|
|
|
|
self.0, roll
|
|
|
|
);
|
|
|
|
|
2021-02-07 21:39:21 +00:00
|
|
|
Execution::success(html)
|
2020-10-31 14:03:18 +00:00
|
|
|
}
|
|
|
|
}
|