impls add player admin action

This commit is contained in:
2019-07-03 14:11:26 +02:00
parent 5a792edb20
commit c95c13bf18
6 changed files with 72 additions and 15 deletions

View File

@@ -49,6 +49,7 @@ impl Loot {
}
}
type ItemDesc<'a> = (&'a str, i32);
/// An item being looted or bought.
///
/// The owner is set to 0 in case of looting,
@@ -60,3 +61,21 @@ struct NewLoot<'a> {
base_price: i32,
owner_id: i32,
}
impl<'a> NewLoot<'a> {
fn to_group(desc: ItemDesc<'a>) -> Self {
Self {
name: desc.0,
base_price: desc.1,
owner_id: 0,
}
}
fn to_player(player: i32, desc: ItemDesc<'a>) -> Self {
Self {
name: desc.0,
base_price: desc.1,
owner_id: player,
}
}
}

View File

@@ -3,6 +3,5 @@ mod player;
mod claim;
pub use item::Item;
pub use player::Player;
pub use player::WealthUpdate;
pub use player::{Player, NewPlayer, WealthUpdate};
pub use claim::{NewClaim, Claim};

View File

@@ -72,6 +72,19 @@ pub struct NewPlayer<'a> {
pp: i32,
}
impl<'a> NewPlayer<'a> {
pub fn create(name: &'a str, wealth: f32) -> Self {
let wealth = WealthUpdate::from_gp(wealth);
Self {
name,
cp: wealth.cp,
sp: wealth.sp,
gp: wealth.gp,
pp: wealth.pp,
}
}
}
#[cfg(test)]
mod tests {
use super::*;