impls add player admin action
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user