From e8291e15d9a792b6d3fa071e01d5af8e53b3e1c2 Mon Sep 17 00:00:00 2001 From: Rusty Striker Date: Wed, 16 Oct 2024 16:40:10 +0300 Subject: [PATCH] some more progress on character stuff but its really hard --- src/api/mod.rs | 2 +- src/game/character_sheet.rs | 2 ++ src/game/mod.rs | 4 +++- src/lib.rs | 2 +- src/pathfinder2r_impl/mod.rs | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index fc87804..d0fc053 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -45,7 +45,7 @@ pub enum Response { GetChatHistory(Vec), MoveToken { token_id: usize, x: f32, y: f32 }, SpawnToken(SpawnToken), - + CharacterCreated(usize), Quit { id: String }, Shutdown, diff --git a/src/game/character_sheet.rs b/src/game/character_sheet.rs index 79f6bc6..a3da416 100644 --- a/src/game/character_sheet.rs +++ b/src/game/character_sheet.rs @@ -15,6 +15,8 @@ pub trait Character : CharacterSheet { /// - `roll damage` will be done on the attacking character, which show the `damage` and `double` actions /// - `damage` will be used on the target character (which could apply reductions as well) fn use_action(&mut self, entry: &E, action: &ActionResult) -> ChatMessage; + /// character short display, containing basic info like name(title) level and health + fn short(&self) -> CharacterShort; } pub trait CharacterSheet : Default { diff --git a/src/game/mod.rs b/src/game/mod.rs index 73916f7..03e09b4 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -30,10 +30,12 @@ pub struct Game + Serialize, A: entry::GameEntry + Serialize> { } impl<'a, C: Character + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>> GameImpl<'a, C, A> for Game { fn new() -> Self { + let mut tokens = HashMap::new(); + tokens.insert(0, TokenInfo { character: "bart".to_string(), map_id: 0, img_source: "assets/pf2r/tokens/louise.jpg".to_string(), x: 2.0, y: 2.0 }); Self { _a: PhantomData, characters: Vec::new(), - tokens: HashMap::new(), + tokens, } } fn create_character(&mut self) -> usize { diff --git a/src/lib.rs b/src/lib.rs index 4ff6a0d..1e4a787 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,7 +162,7 @@ impl GameServer { if self.users.get(&id).map(|a| *a).unwrap_or(false) { let new_id = self.game.create_character(); // return the new id with the character i think - + _ = broadcast.send((Some(id), api::Response::CharacterCreated(new_id))); } }, api::Request::Quit => { diff --git a/src/pathfinder2r_impl/mod.rs b/src/pathfinder2r_impl/mod.rs index ef60276..a05ebf4 100644 --- a/src/pathfinder2r_impl/mod.rs +++ b/src/pathfinder2r_impl/mod.rs @@ -14,6 +14,12 @@ pub struct Pathfinder2rCharacterSheet { #[Input("Weapons")] #[InputExpr(set_items, get_items)] weapon: [Option; 2], + #[Input("Health")] + #[Access(PartyMember)] + health: i32, + #[Input("Max Health")] + #[Access(PartyMember)] + max_health: i32, // Attributes #[Seperator] #[Input("Strength")] @@ -124,4 +130,13 @@ impl Character for Pathfinder2rCharacterSheet { .map(|s| ActionDefinition { name: s.0.to_string(), targets: s.1, display_name: None, source: None, rolls: None }) .collect() } + + fn short(&self) -> CharacterShort { + CharacterShort { + title: self.name.clone(), + sub_title: Some("A Character!".to_string()), + health: Some([ "Dying", "Hurt", "Harmed", "Unharmed" ][((self.health * 4) / self.max_health) as usize].to_string()), + level: Some(1), + } + } }