impls claims on looted items
This commit is contained in:
@@ -3,13 +3,11 @@ use diesel::dsl::{Eq, Filter, Select};
|
||||
use crate::schema::{looted, items};
|
||||
use crate::DbConnection;
|
||||
|
||||
type ItemColumns = ( looted::id, looted::name, looted::base_price, );
|
||||
type ItemColumns =
|
||||
( looted::id, looted::name, looted::base_price, );
|
||||
const ITEM_COLUMNS: ItemColumns =
|
||||
( looted::id, looted::name, looted::base_price, );
|
||||
type OwnedBy = Select<OwnedLoot, ItemColumns>;
|
||||
const ITEM_COLUMNS: ItemColumns = ( looted::id, looted::name, looted::base_price, );
|
||||
|
||||
/// New type to handle the inventory (items table)
|
||||
/// This will be used to reduce confusion with looted items.
|
||||
struct InventoryItem(Item);
|
||||
|
||||
/// Represents a unique item in inventory
|
||||
///
|
||||
@@ -43,6 +41,14 @@ struct Loot {
|
||||
owner: i32,
|
||||
}
|
||||
|
||||
impl Loot {
|
||||
/// A filter on Loot that is owned by given player
|
||||
fn owned_by(id: i32) -> OwnedLoot {
|
||||
looted::table
|
||||
.filter(looted::owner_id.eq(id))
|
||||
}
|
||||
}
|
||||
|
||||
/// An item being looted or bought.
|
||||
///
|
||||
/// The owner is set to 0 in case of looting,
|
||||
@@ -54,43 +60,3 @@ struct NewLoot<'a> {
|
||||
base_price: i32,
|
||||
owner_id: i32,
|
||||
}
|
||||
|
||||
impl<'a> NewLoot<'a> {
|
||||
fn insert(&self, conn: &DbConnection) -> QueryResult<i32> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Loot {
|
||||
/// A filter on Loot that is owned by given player
|
||||
fn owned_by(id: i32) -> OwnedLoot {
|
||||
looted::table
|
||||
.filter(looted::owner_id.eq(id))
|
||||
}
|
||||
/// Loot an item, adding it to the group chest
|
||||
fn loot(name: &str, base_price: i32) -> Result<i32, ()> {
|
||||
let loot = NewLoot{ name, base_price, owner_id: 0 };
|
||||
// Insert into table
|
||||
// Retrieve id of created loot
|
||||
let loot_id = 0;
|
||||
Ok(loot_id)
|
||||
}
|
||||
/// Delete the item, returning the gained wealth
|
||||
fn sell(_modifier: i8) -> Result<i32, ()> {
|
||||
// Calculate sell value : base_value / 2 * modifier
|
||||
// Delete recording of loot
|
||||
Err(())
|
||||
}
|
||||
fn buy(buyer_id: i32, item_desc: (&str, i32)) -> Result<i32, ()> {
|
||||
let loot = NewLoot{
|
||||
name: item_desc.0,
|
||||
base_price: item_desc.1,
|
||||
owner_id: buyer_id
|
||||
};
|
||||
// Insert into table
|
||||
// Retrieve id of created loot;
|
||||
|
||||
// Withdraw value from player wealth.
|
||||
Ok(item_desc.1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user