works on resolve_claims
This commit is contained in:
@@ -10,11 +10,7 @@ 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>;
|
||||
|
||||
/// Represents a unique item in inventory
|
||||
///
|
||||
/// It is also used as a public representation of Loot, since owner
|
||||
/// information is implicit.
|
||||
/// Or maybe this is a little too confusing ??
|
||||
/// Represents a basic item
|
||||
#[derive(Debug, Queryable, Serialize, Deserialize, Clone)]
|
||||
pub struct Item {
|
||||
pub id: i32,
|
||||
@@ -47,7 +43,10 @@ impl<'q> Inventory<'q> {
|
||||
type WithOwner = Eq<looted::owner_id, i32>;
|
||||
type OwnedLoot = Filter<looted::table, WithOwner>;
|
||||
|
||||
/// Represents an item that has been looted
|
||||
|
||||
|
||||
/// Represents an item that has been looted,
|
||||
/// hence has an owner.
|
||||
#[derive(Identifiable, Debug, Queryable, Serialize)]
|
||||
#[table_name = "looted"]
|
||||
pub(super) struct Loot {
|
||||
@@ -63,13 +62,24 @@ impl Loot {
|
||||
looted::table.filter(looted::owner_id.eq(id))
|
||||
}
|
||||
|
||||
fn owns(player: i32, item: i32) -> Exists<Find<OwnedLoot, i32>> {
|
||||
exists(Loot::owned_by(player).find(item))
|
||||
}
|
||||
|
||||
pub(super) fn exists(id: i32) -> Exists<Find<looted::table, i32>> {
|
||||
exists(looted::table.find(id))
|
||||
}
|
||||
|
||||
pub(crate) fn set_owner(&self, owner: i32) -> () {
|
||||
diesel::update(looted::table.find(self.id))
|
||||
.set(looted::dsl::owner_id.eq(owner))
|
||||
}
|
||||
|
||||
/// TODO: should belong inside Item impl
|
||||
pub(crate) fn value(&self) -> i32 {
|
||||
self.base_price
|
||||
}
|
||||
|
||||
/// TODO: should belong inside Item impl
|
||||
pub(crate) fn sell_value(&self) -> i32 {
|
||||
self.base_price / 2
|
||||
}
|
||||
}
|
||||
|
||||
/// Manager for a player's loot
|
||||
|
||||
Reference in New Issue
Block a user