make character short function take the id of the character instead of adding it later
This commit is contained in:
parent
731f22a2c2
commit
3da8c9d5c0
3 changed files with 68 additions and 67 deletions
|
@ -1,4 +1,8 @@
|
|||
use crate::game::{character_sheet::*, chat_message::ChatMessage, entry::{ActionDefinition, ActionResult, DiceRoll, GameEntry}};
|
||||
use crate::game::{
|
||||
character_sheet::*,
|
||||
chat_message::ChatMessage,
|
||||
entry::{ActionDefinition, ActionResult, DiceRoll, GameEntry},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tavern_macros::CharacterSheet;
|
||||
|
||||
|
@ -58,11 +62,7 @@ pub struct Pathfinder2rCharacterSheet {
|
|||
impl Pathfinder2rCharacterSheet {
|
||||
fn set_items(&mut self, entry: EntryType) {
|
||||
if let EntryType::Array(a) = entry {
|
||||
let ws: Vec<Entry> = a
|
||||
.iter()
|
||||
.map(|e| Entry::load(&e.as_text()))
|
||||
.flatten()
|
||||
.collect();
|
||||
let ws: Vec<Entry> = a.iter().map(|e| Entry::load(&e.as_text())).flatten().collect();
|
||||
self.weapon = [None, None];
|
||||
for w in ws {
|
||||
if let Entry::Weapon(w) = w {
|
||||
|
@ -74,8 +74,7 @@ impl Pathfinder2rCharacterSheet {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let s = entry.as_text();
|
||||
if let Some(Entry::Weapon(w)) = Entry::load(&s) {
|
||||
self.weapon[0] = Some(w);
|
||||
|
@ -97,46 +96,61 @@ impl Character<Entry> for Pathfinder2rCharacterSheet {
|
|||
fn use_action(&mut self, entry: &Entry, action: &ActionResult) -> ChatMessage {
|
||||
match entry {
|
||||
Entry::Weapon(_) => ChatMessage::new("Attack".to_string())
|
||||
.with_action(
|
||||
ActionDefinition::new("Attack".to_string())
|
||||
.with_roll(DiceRoll::new("Piercing".to_string(), 12, 1))
|
||||
)
|
||||
.with_action(
|
||||
ActionDefinition::new("Double".to_string())
|
||||
.with_roll(DiceRoll::new("Piercing".to_string(), 12, 2))
|
||||
),
|
||||
Entry::Consumable(_consumable) => if action.name == "consume" {
|
||||
ChatMessage::new("Heal".to_string())
|
||||
.with_action(
|
||||
.with_action(ActionDefinition::new("Attack".to_string()).with_roll(DiceRoll::new(
|
||||
"Piercing".to_string(),
|
||||
12,
|
||||
1,
|
||||
)))
|
||||
.with_action(ActionDefinition::new("Double".to_string()).with_roll(DiceRoll::new(
|
||||
"Piercing".to_string(),
|
||||
12,
|
||||
2,
|
||||
))),
|
||||
Entry::Consumable(_consumable) => {
|
||||
if action.name == "consume" {
|
||||
ChatMessage::new("Heal".to_string()).with_action(
|
||||
ActionDefinition::new("Heal".to_string())
|
||||
.with_roll(DiceRoll::new("Heal".to_string(), 6, 0).constant(6))
|
||||
.with_roll(DiceRoll::new("Heal".to_string(), 6, 0).constant(6)),
|
||||
)
|
||||
} else { todo!() },
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Entry::Spell(_spell) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn actions(&self, entry: &Entry) -> Vec<ActionDefinition> {
|
||||
let v;
|
||||
match entry {
|
||||
Entry::Weapon(_) =>
|
||||
// should technically check if the item is in the user's packpack or something
|
||||
// but for now just return a constant list
|
||||
v = vec![ ("wield", 0), ("attack", 1), ("drop", 0), ("stow", 0) ],
|
||||
Entry::Weapon(_) =>
|
||||
// should technically check if the item is in the user's packpack or something
|
||||
// but for now just return a constant list
|
||||
{
|
||||
v = vec![("wield", 0), ("attack", 1), ("drop", 0), ("stow", 0)]
|
||||
}
|
||||
Entry::Consumable(_) => v = vec![("consume", 0), ("stow", 0), ("drop", 0)],
|
||||
Entry::Spell(_) => v = vec![("cast", 1)],
|
||||
};
|
||||
v.iter()
|
||||
.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()
|
||||
}
|
||||
|
||||
fn short(&self) -> CharacterShort {
|
||||
|
||||
fn short(&self, id: usize) -> CharacterShort {
|
||||
CharacterShort {
|
||||
id: 0,
|
||||
id,
|
||||
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()),
|
||||
health: Some(
|
||||
["Dying", "Hurt", "Harmed", "Unharmed"][((self.health * 4) / self.max_health) as usize].to_string(),
|
||||
),
|
||||
level: Some(1),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue