Auctions
Read more about the Auctions system in Hiro here .
Initializing the auctions system #
The auctions system relies on the Nakama System
and an ILogger, both must be passed in as dependencies via the constructor.
| |
Subscribing to changes in the auctions system #
You can listen for changes in the auctions system so that you can respond appropriately, such as updating the UI, by implementing the IObserver pattern, or use the SystemObserver<T> type which handles it for you.
| |
Refreshing the auctions system #
To ensure the auctions system has the latest information from Nakama you can refresh it.
| |
Creating a New Auction #
To create a new auction, use the CreateAsync function.
| |
Restricting an auction to specific players #
CreateAsync also accepts an optional allowedUserIds parameter. When you pass a non-empty list of player IDs, the auction is only visible to and biddable by those players, letting you build restricted auctions such as guild sales, friends-only listings, or one-to-one trades on top of the auction system.
| |
The resulting Auction object exposes the whitelist back to you as Auction.AllowedUserIds, and an Auction.ImmediateBuyout flag that tells you whether a bid meeting the buyout price will immediately complete the auction. This flag is copied from the AuctionTemplateCondition.ImmediateBuyout setting on the auction template used to create it.
Placing a Bid on an Auction #
You can place a bid on an auction using the BidAsync function.
| |
Bidding with items #
BidAsync also accepts an optional bidInstanceIds parameter, a list of inventory item instance IDs the bidder escrows as part of the bid. currencies is now optional too, so you can bid with items alone, currency alone, or a combination of both. This is what powers item-for-item trades between players on directed auctions.
| |
The same currencies and bidInstanceIds parameters are available on the socket variant of BidAsync(ISocket socket, ...).
Canceling an Auction #
If an auction needs to be canceled before it ends, the CancelAsync method can be used.
| |
Claiming a Winning Bid #
Once an auction has ended, the winning bidder can claim their item using ClaimBidAsync.
| |
Claiming a created auction #
Once an auction has ended, the seller can claim its outcome using ClaimCreatedAsync.
| |
If the winning bidder escrowed items instead of, or alongside, currency, those items are returned to the seller through AuctionClaimCreated.ReceivedItems when the auction completes successfully. AuctionClaimCreated.ReturnedItems still holds the seller’s own listed items if the auction failed instead.
Listing Available Auctions #
You can list the currently available auctions using the ListAsync function.
| |
Listing auctions directed at you #
ListAsync also accepts an optional allowedOnly parameter. When true, the results only include directed auctions where you’re on the allowedUserIds whitelist. When false or omitted, the results only include public auctions instead, so the two sets never overlap: call ListAsync twice, once with allowedOnly: true and once without it, if you need both directed and public auctions.
| |
This maps to the AuctionListRequest.AllowedOnly field sent to the server.
