dice rolling (with a dialog and basic chat output)
This commit is contained in:
parent
45106498b4
commit
8b9b5db299
7 changed files with 244 additions and 63 deletions
35
src/lib.rs
35
src/lib.rs
|
@ -1,5 +1,5 @@
|
|||
use api::game_actions::SpawnToken;
|
||||
use game::{chat_message::ChatMessage, Game, GameImpl};
|
||||
use game::{chat_message::ChatMessage, entry::{ActionDefinition, DiceRoll}, Game, GameImpl};
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
|
||||
pub mod api;
|
||||
|
@ -18,7 +18,22 @@ impl GameServer {
|
|||
Self {
|
||||
_game: Game::new(),
|
||||
tokens: vec![("assets/pf2r/tokens/louise.jpg".to_string(), 2, 2)],
|
||||
chat: Vec::new(),
|
||||
chat: vec![
|
||||
(
|
||||
"Server".to_string(),
|
||||
ChatMessage::new("a weapon description".to_string())
|
||||
.id(1)
|
||||
.character(Some("Sword or something".to_string()))
|
||||
.with_action(
|
||||
ActionDefinition::new("weapon/attack".to_string())
|
||||
.display_name(Some("Attack +7".to_string()))
|
||||
.with_roll(DiceRoll::new("Pierce".to_string(), 12, 1).constant(1))
|
||||
.with_roll(DiceRoll::new("Fire".to_string(), 4, 2))
|
||||
)
|
||||
.with_action(ActionDefinition::new("Attack +3".to_string()))
|
||||
.with_action(ActionDefinition::new("Attack -1".to_string()))
|
||||
)
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +91,7 @@ impl GameServer {
|
|||
amount = self.chat.len();
|
||||
}
|
||||
let start = if amount >= self.chat.len() {
|
||||
self.chat.len()
|
||||
0
|
||||
} else {
|
||||
self.chat.len() - amount
|
||||
};
|
||||
|
@ -106,6 +121,20 @@ impl GameServer {
|
|||
_ = broadcast.send((None, api::Response::MoveToken { token_id, x, y }));
|
||||
}
|
||||
},
|
||||
api::Request::ActionResult(result) => {
|
||||
let msg = ChatMessage::new(
|
||||
result.results.iter()
|
||||
// .map(|d| &d.result_text)
|
||||
.fold(String::new(), |a,b| a + &format!("{}: {} = {}\n", &b.name, &b.result_text, b.result))
|
||||
)
|
||||
.character(Some(result.name))
|
||||
.source(id.clone())
|
||||
.targets(Some(result.targets))
|
||||
.id(self.chat.len() + 1);
|
||||
self.chat.push((id, msg.clone()));
|
||||
_ = broadcast.send((None, api::Response::Message(msg)));
|
||||
|
||||
}
|
||||
api::Request::Quit => _ = broadcast.send((None, api::Response::Quit { id })),
|
||||
api::Request::Kick(id) => _ = broadcast.send((Some(id), api::Response::Shutdown)),
|
||||
api::Request::Shutdown => break,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue