some more progress on character stuff but its really hard

This commit is contained in:
Rusty Striker 2024-10-16 16:40:10 +03:00
parent 5cdfe71528
commit e8291e15d9
Signed by: RustyStriker
GPG key ID: 9DBDBC7C48FC3C31
5 changed files with 22 additions and 3 deletions

View file

@ -45,7 +45,7 @@ pub enum Response {
GetChatHistory(Vec<ChatMessage>), GetChatHistory(Vec<ChatMessage>),
MoveToken { token_id: usize, x: f32, y: f32 }, MoveToken { token_id: usize, x: f32, y: f32 },
SpawnToken(SpawnToken), SpawnToken(SpawnToken),
CharacterCreated(usize),
Quit { id: String }, Quit { id: String },
Shutdown, Shutdown,

View file

@ -15,6 +15,8 @@ pub trait Character<E: GameEntry> : CharacterSheet {
/// - `roll damage` will be done on the attacking character, which show the `damage` and `double` actions /// - `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) /// - `damage` will be used on the target character (which could apply reductions as well)
fn use_action(&mut self, entry: &E, action: &ActionResult) -> ChatMessage; 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 { pub trait CharacterSheet : Default {

View file

@ -30,10 +30,12 @@ pub struct Game<C: Character<A> + Serialize, A: entry::GameEntry + Serialize> {
} }
impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>> GameImpl<'a, C, A> for Game<C, A> { impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>> GameImpl<'a, C, A> for Game<C, A> {
fn new() -> Self { 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 { Self {
_a: PhantomData, _a: PhantomData,
characters: Vec::new(), characters: Vec::new(),
tokens: HashMap::new(), tokens,
} }
} }
fn create_character(&mut self) -> usize { fn create_character(&mut self) -> usize {

View file

@ -162,7 +162,7 @@ impl GameServer {
if self.users.get(&id).map(|a| *a).unwrap_or(false) { if self.users.get(&id).map(|a| *a).unwrap_or(false) {
let new_id = self.game.create_character(); let new_id = self.game.create_character();
// return the new id with the character i think // return the new id with the character i think
_ = broadcast.send((Some(id), api::Response::CharacterCreated(new_id)));
} }
}, },
api::Request::Quit => { api::Request::Quit => {

View file

@ -14,6 +14,12 @@ pub struct Pathfinder2rCharacterSheet {
#[Input("Weapons")] #[Input("Weapons")]
#[InputExpr(set_items, get_items)] #[InputExpr(set_items, get_items)]
weapon: [Option<Weapon>; 2], weapon: [Option<Weapon>; 2],
#[Input("Health")]
#[Access(PartyMember)]
health: i32,
#[Input("Max Health")]
#[Access(PartyMember)]
max_health: i32,
// Attributes // Attributes
#[Seperator] #[Seperator]
#[Input("Strength")] #[Input("Strength")]
@ -124,4 +130,13 @@ impl Character<Entry> for Pathfinder2rCharacterSheet {
.map(|s| ActionDefinition { name: s.0.to_string(), targets: s.1, display_name: None, source: None, rolls: None }) .map(|s| ActionDefinition { name: s.0.to_string(), targets: s.1, display_name: None, source: None, rolls: None })
.collect() .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),
}
}
} }