pub struct AuctionHouse {
pub listings: HashMap<u64, Listing>,
pub bids: HashMap<u64, Vec<Bid>>,
pub pending_mail: Vec<MailMessage>,
pub listing_fee_rate: f32,
pub cut_rate: f32,
/* private fields */
}Expand description
Player-driven auction house.
Fields§
§listings: HashMap<u64, Listing>§bids: HashMap<u64, Vec<Bid>>§pending_mail: Vec<MailMessage>Pending mail messages to be delivered to players.
listing_fee_rate: f32Fraction of sale price taken as listing fee.
cut_rate: f32Fraction of sale price taken as auction house cut.
Implementations§
Source§impl AuctionHouse
impl AuctionHouse
pub fn new() -> Self
Sourcepub fn post_listing(
&mut self,
seller_id: impl Into<String>,
item_id: impl Into<String>,
quantity: u32,
quality: u8,
buyout_price: Option<Currency>,
min_bid: Currency,
duration_secs: f32,
current_time: f32,
seller_currency: &mut Currency,
) -> Result<u64, String>
pub fn post_listing( &mut self, seller_id: impl Into<String>, item_id: impl Into<String>, quantity: u32, quality: u8, buyout_price: Option<Currency>, min_bid: Currency, duration_secs: f32, current_time: f32, seller_currency: &mut Currency, ) -> Result<u64, String>
Post a new listing.
Returns Ok(listing_id) or Err with a reason.
seller_currency is charged the listing fee upfront.
Sourcepub fn highest_bid(&self, listing_id: u64) -> Option<&Bid>
pub fn highest_bid(&self, listing_id: u64) -> Option<&Bid>
Get the current highest bid for a listing.
Sourcepub fn place_bid(
&mut self,
listing_id: u64,
bidder_id: impl Into<String>,
amount: Currency,
current_time: f32,
bidder_currency: &mut Currency,
) -> Result<(), String>
pub fn place_bid( &mut self, listing_id: u64, bidder_id: impl Into<String>, amount: Currency, current_time: f32, bidder_currency: &mut Currency, ) -> Result<(), String>
Place a bid on a listing.
Validates bid > current highest (and >= min_bid).
Refunds the previous highest bidder.
bidder_currency is debited the bid amount.
Sourcepub fn place_bid_str(
&mut self,
listing_id: u64,
bidder_id: &str,
amount: Currency,
current_time: f32,
bidder_currency: &mut Currency,
) -> Result<(), String>
pub fn place_bid_str( &mut self, listing_id: u64, bidder_id: &str, amount: Currency, current_time: f32, bidder_currency: &mut Currency, ) -> Result<(), String>
Place a bid with explicit bidder_id string (preferred API).
Sourcepub fn buyout(
&mut self,
listing_id: u64,
buyer_id: &str,
current_time: f32,
buyer_currency: &mut Currency,
) -> Result<(String, u32, u8), String>
pub fn buyout( &mut self, listing_id: u64, buyer_id: &str, current_time: f32, buyer_currency: &mut Currency, ) -> Result<(String, u32, u8), String>
Instant buyout of a listing.
buyer_currency is debited the buyout price.
Seller receives payout minus AH cut via mail.
Sourcepub fn tick(&mut self, current_time: f32)
pub fn tick(&mut self, current_time: f32)
Advance time: expire listings, award to highest bidder, handle mail.
Sourcepub fn search(
&self,
current_time: f32,
item_id: Option<&str>,
max_price: Option<u64>,
quality_min: Option<u8>,
) -> Vec<&Listing>
pub fn search( &self, current_time: f32, item_id: Option<&str>, max_price: Option<u64>, quality_min: Option<u8>, ) -> Vec<&Listing>
Search for active listings matching criteria.
item_id: optional filter by itemmax_price: optional maximum buyout price in copperquality_min: optional minimum quality
Sourcepub fn listings_for_item(
&self,
current_time: f32,
item_id: &str,
) -> Vec<&Listing>
pub fn listings_for_item( &self, current_time: f32, item_id: &str, ) -> Vec<&Listing>
All active listings for a specific item, sorted by buyout price ascending.
Sourcepub fn drain_mail(&mut self) -> Vec<MailMessage>
pub fn drain_mail(&mut self) -> Vec<MailMessage>
Drain pending mail messages (call this to deliver them to the mail system).
Sourcepub fn active_listing_count(&self, current_time: f32) -> usize
pub fn active_listing_count(&self, current_time: f32) -> usize
Number of active listings.
Trait Implementations§
Source§impl Clone for AuctionHouse
impl Clone for AuctionHouse
Source§fn clone(&self) -> AuctionHouse
fn clone(&self) -> AuctionHouse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuctionHouse
impl Debug for AuctionHouse
Auto Trait Implementations§
impl Freeze for AuctionHouse
impl RefUnwindSafe for AuctionHouse
impl Send for AuctionHouse
impl Sync for AuctionHouse
impl Unpin for AuctionHouse
impl UnsafeUnpin for AuctionHouse
impl UnwindSafe for AuctionHouse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.