add AccessLevel stuff to charactersheet trait
This commit is contained in:
parent
0eaffc9a8f
commit
473161674f
5 changed files with 77 additions and 32 deletions
|
@ -17,15 +17,25 @@ pub trait Character<E: GameEntry> : CharacterSheet {
|
|||
|
||||
pub trait CharacterSheet : Default {
|
||||
/// Character sheet inputs (stuff that are not calculated from different items), such as Name, Age, Strength
|
||||
fn inputs(&self) -> Vec<(String, EntryType)>;
|
||||
/// All fields in the character sheet
|
||||
fn inputs(&self, access: AccessLevel) -> Vec<(String, EntryType)>;
|
||||
/// All fields in the character sheet, maybe change it to only a vec of strings?
|
||||
fn fields(&self) -> Vec<(String, EntryType)>;
|
||||
/// Character sheet to display, ordered. `None`s can be used to convey a seperator (of any sort)
|
||||
fn display(&self) -> Vec<Option<(String, EntryType)>>;
|
||||
fn display(&self, access: AccessLevel) -> Vec<Option<(String, EntryType)>>;
|
||||
/// Gets a character sheet entry value
|
||||
fn get(&self, entry: &str) -> Option<EntryType>;
|
||||
fn get(&self, entry: &str, access: AccessLevel) -> Option<EntryType>;
|
||||
/// Sets a cahrater sheet entry value
|
||||
fn set(&mut self, entry: &str, value: EntryType);
|
||||
fn set(&mut self, entry: &str, value: EntryType, access: AccessLevel);
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AccessLevel {
|
||||
Admin = 0, Owner = 1, PartyMember = 2, World = 3,
|
||||
}
|
||||
impl AccessLevel {
|
||||
pub fn has_access(self, other: Self) -> bool {
|
||||
(self as u8) <= (other as u8)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -9,8 +9,10 @@ pub mod chat_message;
|
|||
pub mod entry;
|
||||
|
||||
pub trait GameImpl<C: Character<A> + Serialize, A: entry::GameEntry + Serialize> {
|
||||
/// Creates a new game
|
||||
fn new() -> Self;
|
||||
fn create_character(&mut self);
|
||||
/// Creates a new character, returning the character id
|
||||
fn create_character(&mut self) -> usize;
|
||||
}
|
||||
|
||||
pub struct Game<C: Character<A> + Serialize, A: entry::GameEntry + Serialize> {
|
||||
|
@ -27,7 +29,8 @@ impl<C: Character<A> + Serialize, A: entry::GameEntry + Serialize> GameImpl<C, A
|
|||
}
|
||||
}
|
||||
|
||||
fn create_character(&mut self) {
|
||||
fn create_character(&mut self) -> usize {
|
||||
self.characters.push(C::default());
|
||||
self.characters.len() - 1
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ impl GameServer {
|
|||
.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 +3".to_string()).with_roll(DiceRoll::new("Base".to_string(), 20, 1)))
|
||||
.with_action(ActionDefinition::new("Attack -1".to_string()))
|
||||
)
|
||||
],
|
||||
|
@ -48,6 +48,7 @@ impl GameServer {
|
|||
println!("Got message from {}: {:?}", &id, &req);
|
||||
|
||||
match req {
|
||||
// ignore errors and re-login requests
|
||||
api::Request::Error => {}
|
||||
api::Request::Login(_) => {}
|
||||
api::Request::Message(mut msg) => {
|
||||
|
|
|
@ -9,6 +9,7 @@ use entry::{Entry, Weapon};
|
|||
pub struct Pathfinder2rCharacterSheet {
|
||||
// Genral stuff
|
||||
#[Input("Name")]
|
||||
#[Access(World)]
|
||||
name: String,
|
||||
#[Input("Weapons")]
|
||||
#[InputExpr(set_items, get_items)]
|
||||
|
@ -30,6 +31,7 @@ pub struct Pathfinder2rCharacterSheet {
|
|||
// Skills
|
||||
#[Seperator]
|
||||
#[Field("Acrobatics")]
|
||||
#[Access(PartyMember)]
|
||||
#[FieldExpr(self.dex + self.acrobatics_prof * 2)]
|
||||
_acro: i32,
|
||||
#[Input("Acrobatics Prof")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue