/// <summary> /// Returns the bid money to the highest bidder because they have been outbid /// </summary> /// <param name="auction">The auction the bid belongs to</param> public void Outbid(AuctionItem auction) { if (m_Mobile == null || m_Mobile.Account == null) { return; } AuctionCheck check = new AuctionGoldCheck(auction, AuctionResult.Outbid); if (!this.m_Mobile.Backpack.TryDropItem(m_Mobile, check, false)) { m_Mobile.BankBox.DropItem(check); } // Send notice AuctionMessaging.SendOutbidMessage(auction, m_Amount, m_Mobile); }
/// <summary> /// Returns the bid money to the bidder because the auction has been canceled /// </summary> /// <param name="auction">The auction the bid belongs to</param> public void AuctionCanceled(AuctionItem auction) { if (m_Mobile == null) { return; } AuctionCheck check = new AuctionGoldCheck(auction, AuctionResult.SystemStopped); if (m_Mobile.Backpack == null || !m_Mobile.Backpack.TryDropItem(m_Mobile, check, false)) { if (m_Mobile.BankBox != null) { m_Mobile.BankBox.DropItem(check); } else { check.Delete(); } } }
/// <summary> /// Returns the bid money to the bidder because the auction has been canceled /// </summary> /// <param name="auction">The auction the bid belongs to</param> public void AuctionCanceled( AuctionItem auction ) { if ( m_Mobile == null ) return; AuctionCheck check = new AuctionGoldCheck( auction, AuctionResult.SystemStopped ); if ( m_Mobile.Backpack == null || ! m_Mobile.Backpack.TryDropItem( m_Mobile, check, false ) ) { if ( m_Mobile.BankBox != null ) m_Mobile.BankBox.DropItem( check ); else check.Delete(); } }
/// <summary> /// Returns the bid money to the highest bidder because they have been outbid /// </summary> /// <param name="auction">The auction the bid belongs to</param> public void Outbid( AuctionItem auction ) { if ( m_Mobile == null || m_Mobile.Account == null ) return; AuctionCheck check = new AuctionGoldCheck( auction, AuctionResult.Outbid ); if ( ! this.m_Mobile.Backpack.TryDropItem( m_Mobile, check, false ) ) { m_Mobile.BankBox.DropItem( check ); } // Send notice AuctionMessaging.SendOutbidMessage( auction, m_Amount, m_Mobile ); }
/// <summary> /// Attempts to buy now /// </summary> /// <param name="m">The user trying to purchase</param> /// <returns>True if the item has been sold</returns> public bool DoBuyNow( Mobile m ) { if ( !Banker.Withdraw( m, m_BuyNow ) ) { m.SendMessage( AuctionConfig.MessageHue, AuctionSystem.ST[ 211 ] ); return false; } AuctionSystem.Auctions.Remove( this ); if ( HighestBid != null ) { HighestBid.Outbid( this ); } // Simulate bid Bid bid = new Bid( m, BuyNow ); m_Bids.Insert( 0, bid ); AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.BuyNow ); AuctionItemCheck item = new AuctionItemCheck( this, AuctionResult.BuyNow ); GiveItemTo( m, item ); GiveItemTo( m_Owner, gold ); // Over. AuctionLog.WriteEnd( this, AuctionResult.BuyNow, m, null ); return true; }
/// <summary> /// The pending period has timed out and the auction must end unsuccesfully /// </summary> public void PendingTimeOut() { AuctionSystem.Pending.Remove( this ); m_OwnerPendency = AuctionPendency.NotAccepted; m_BuyerPendency = AuctionPendency.NotAccepted; m_OwnerMessage = AuctionMessage.None; m_BuyerMessage = AuctionMessage.None; AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingTimedOut ); AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingTimedOut ); if ( item != null ) GiveItemTo( m_Owner, item ); GiveItemTo( HighestBid.Mobile, gold ); // Over, this auction no longer exists AuctionLog.WriteEnd( this, AuctionResult.PendingTimedOut, null, null ); }
/// <summary> /// Validates the pending status of the auction. This method should be called whenever a pendency /// value is changed. If the auction has been validated, it will finalize items and remove the auction from the system. /// This is the only method that should be used to finalize a pending auction. /// </summary> public void Validate() { if ( ! AuctionSystem.Pending.Contains( this ) ) return; if ( m_OwnerPendency == AuctionPendency.Accepted && m_BuyerPendency == AuctionPendency.Accepted ) { // Both parts confirmed the auction m_Pending = false; AuctionSystem.Pending.Remove( this ); AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingAccepted ); AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingAccepted ); if ( item != null ) { GiveItemTo( HighestBid.Mobile, item ); // Item to buyer } GiveItemTo( m_Owner, gold ); // Gold to owner // Over, this auction no longer exists AuctionLog.WriteEnd( this, AuctionResult.PendingAccepted, null, null ); } else if ( m_OwnerPendency == AuctionPendency.NotAccepted || m_BuyerPendency == AuctionPendency.NotAccepted ) { // At least one part refused m_Pending = false; AuctionSystem.Pending.Remove( this ); AuctionCheck item = new AuctionItemCheck( this, AuctionResult.PendingRefused ); AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.PendingRefused ); if ( item != null ) { GiveItemTo( m_Owner, item ); // Give item back to owner } GiveItemTo( HighestBid.Mobile, gold ); // Give gold to highest bidder // Over, this auction no longer exists AuctionLog.WriteEnd( this, AuctionResult.PendingRefused, null, null ); } }
/// <summary> /// Ends the auction. /// This function is called by the auction system during its natural flow /// </summary> /// <param name="m">The Mobile eventually forcing the ending</param> public void End( Mobile m ) { AuctionSystem.Auctions.Remove( this ); if ( HighestBid == null ) { // No bids, simply return the item AuctionCheck item = new AuctionItemCheck( this, AuctionResult.NoBids ); GiveItemTo( m_Owner, item ); // Over, this auction no longer exists AuctionLog.WriteEnd( this, AuctionResult.NoBids, m, null ); } else { // Verify that all items still exist too, otherwise make it pending if ( IsValid() && ReserveMet ) { // Auction has been succesful AuctionCheck item = new AuctionItemCheck( this, AuctionResult.Succesful ); GiveItemTo( HighestBid.Mobile, item ); AuctionCheck gold = new AuctionGoldCheck( this, AuctionResult.Succesful ); GiveItemTo( m_Owner, gold ); // Over, this auction no longer exists AuctionLog.WriteEnd( this, AuctionResult.Succesful, m, null ); } else { // Reserve hasn't been met or auction isn't valid, this auction is pending m_Pending = true; m_PendingEnd = DateTime.Now + TimeSpan.FromDays( AuctionConfig.DaysForConfirmation ); AuctionSystem.Pending.Add( this ); DoOwnerMessage(); DoBuyerMessage(); Mobile owner = GetOnlineMobile( m_Owner ); Mobile buyer = GetOnlineMobile( HighestBid.Mobile ); SendMessage( owner ); SendMessage( buyer ); AuctionScheduler.UpdateDeadline( m_PendingEnd ); AuctionLog.WritePending( this, ReserveMet ? "Item deleted" : "Reserve not met" ); } } }
/// <summary> /// Forces the end of the auction and removes it from the system /// </summary> /// <param name="m">The staff member deleting the auction</param> /// <param name="itemfate">Specifies what should occur with the item</param> public void StaffDelete( Mobile m, ItemFate itemfate ) { if ( AuctionSystem.Auctions.Contains( this ) ) AuctionSystem.Auctions.Remove( this ); else if ( AuctionSystem.Pending.Contains( this ) ) AuctionSystem.Pending.Remove( this ); if ( HighestBid != null ) { AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.StaffRemoved ); GiveItemTo( HighestBid.Mobile, gold ); } AuctionItemCheck check = new AuctionItemCheck( this, AuctionResult.StaffRemoved ); string comments = null; switch( itemfate ) { case ItemFate.Delete : check.ForceDelete(); comments = "The item has been deleted"; break; case ItemFate.ReturnToOwner: GiveItemTo( m_Owner, check ); comments = "The item has been returned to the owner"; break; case ItemFate.ReturnToStaff: GiveItemTo( m, check ); comments = "The item has been claimed by the staff"; break; } AuctionLog.WriteEnd( this, AuctionResult.StaffRemoved, m, comments ); // OVer. }
/// <summary> /// Forces the end of the auction when the item or creature has been deleted /// </summary> public void EndInvalid() { AuctionSystem.Auctions.Remove( this ); if ( HighestBid != null ) { AuctionGoldCheck gold = new AuctionGoldCheck( this, AuctionResult.ItemDeleted ); GiveItemTo( HighestBid.Mobile, gold ); } // The item has been deleted, no need to return it to the owner. // If it's a statuette, delete it if ( Creature && m_Item != null ) { m_Item.Delete(); } AuctionLog.WriteEnd( this, AuctionResult.ItemDeleted, null, null ); // Over. }