Skip to content

Commit

Permalink
Sell Now auction button
Browse files Browse the repository at this point in the history
  • Loading branch information
Suprcode committed May 15, 2021
1 parent 798e9fa commit 365c8d8
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 2 deletions.
36 changes: 35 additions & 1 deletion Client/MirScenes/Dialogs/TrustMerchantDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class TrustMerchantDialog : MirImageControl
public static long SearchTime, MarketTime;

public MirTextBox SearchTextBox, PriceTextBox;
public MirButton FindButton, RefreshButton, MailButton, BuyButton, CloseButton, NextButton, BackButton;
public MirButton FindButton, RefreshButton, MailButton, BuyButton, SellNowButton, CloseButton, NextButton, BackButton;
public MirImageControl TitleLabel;
public MirLabel ItemLabel, PriceLabel, SellerLabel, PageLabel;
public MirLabel DateLabel, ExpireLabel;
Expand Down Expand Up @@ -428,6 +428,25 @@ public TrustMerchantDialog()
}
}
};

SellNowButton = new MirButton
{
Index = 700,
HoverIndex = 701,
PressedIndex = 702,
Library = Libraries.Title,
Location = new Point(324, 448),
Sound = SoundList.ButtonA,
Parent = this,
};
SellNowButton.Click += (o, e) =>
{
if (Selected == null || CMain.Time < MarketTime) return;
MarketTime = CMain.Time + 3000;
Network.Enqueue(new C.MarketSellNow { AuctionID = Selected.Listing.AuctionID });
};

#endregion

#region Search
Expand Down Expand Up @@ -898,6 +917,17 @@ public void UpdateInterface()
MailButton.Enabled = false;
MailButton.GrayScale = true;
}

if (Selected != null && Selected.Listing.Seller == "Bid Met")
{
SellNowButton.Enabled = true;
SellNowButton.GrayScale = false;
}
else
{
SellNowButton.Enabled = false;
SellNowButton.GrayScale = true;
}
}

private void SearchTextBox_KeyPress(object sender, KeyPressEventArgs e)
Expand Down Expand Up @@ -996,6 +1026,7 @@ public void TMerchantDialog(MarketPanelType type)
BuyButton.Index = 703;
BuyButton.HoverIndex = 704;
BuyButton.PressedIndex = 705;
SellNowButton.Visible = false;
UpButton.Visible = true;
DownButton.Visible = true;
PositionBar.Visible = true;
Expand Down Expand Up @@ -1038,6 +1069,7 @@ public void TMerchantDialog(MarketPanelType type)
BuyButton.Index = 706;
BuyButton.HoverIndex = 707;
BuyButton.PressedIndex = 708;
SellNowButton.Visible = false;
UpButton.Visible = false;
DownButton.Visible = false;
PositionBar.Visible = false;
Expand Down Expand Up @@ -1086,6 +1118,7 @@ public void TMerchantDialog(MarketPanelType type)
BuyButton.Index = 706;
BuyButton.HoverIndex = 707;
BuyButton.PressedIndex = 708;
SellNowButton.Visible = true;
UpButton.Visible = false;
DownButton.Visible = false;
PositionBar.Visible = false;
Expand Down Expand Up @@ -1133,6 +1166,7 @@ public void TMerchantDialog(MarketPanelType type)
BuyButton.Index = 703;
BuyButton.HoverIndex = 704;
BuyButton.PressedIndex = 705;
SellNowButton.Visible = false;
UpButton.Visible = true;
DownButton.Visible = true;
PositionBar.Visible = true;
Expand Down
8 changes: 7 additions & 1 deletion Client/MirScenes/GameScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4710,7 +4710,13 @@ private void MarketFail(S.MarketFail p)
MirMessageBox.Show("You are too far away from the Trust Merchant.");
break;
case 8:
MirMessageBox.Show("You cannot hold enough gold to get your sale");
MirMessageBox.Show("You cannot hold enough gold to get your sale.");
break;
case 9:
MirMessageBox.Show("This item has not met the minimum bid yet.");
break;
case 10:
MirMessageBox.Show("Auction has already ended for this item.");
break;
}

Expand Down
10 changes: 10 additions & 0 deletions Server/MirNetwork/MirConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ private void ProcessPacket(Packet p)
case (short)ClientPacketIds.MarketGetBack:
MarketGetBack((C.MarketGetBack)p);
return;
case (short)ClientPacketIds.MarketSellNow:
MarketSellNow((C.MarketSellNow)p);
return;
case (short)ClientPacketIds.RequestUserName:
RequestUserName((C.RequestUserName)p);
return;
Expand Down Expand Up @@ -1266,6 +1269,13 @@ private void MarketBuy(C.MarketBuy p)

Player.MarketBuy(p.AuctionID, p.BidPrice);
}
private void MarketSellNow(C.MarketSellNow p)
{
if (Stage != GameStage.Game) return;

Player.MarketSellNow(p.AuctionID);
}

private void MarketGetBack(C.MarketGetBack p)
{
if (Stage != GameStage.Game) return;
Expand Down
77 changes: 77 additions & 0 deletions Server/MirObjects/PlayerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15033,6 +15033,83 @@ public void MarketBuy(ulong auctionID, uint bidPrice = 0)
Enqueue(new S.MarketFail { Reason = 7 });
}

public void MarketSellNow(ulong auctionID)
{
if (Dead)
{
Enqueue(new S.MarketFail { Reason = 0 });
return;
}

if (NPCPage == null || !String.Equals(NPCPage.Key, NPCScript.MarketKey, StringComparison.CurrentCultureIgnoreCase))
{
Enqueue(new S.MarketFail { Reason = 1 });
return;
}

for (int n = 0; n < CurrentMap.NPCs.Count; n++)
{
NPCObject ob = CurrentMap.NPCs[n];
if (ob.ObjectID != NPCObjectID) continue;
if (!Functions.InRange(ob.CurrentLocation, CurrentLocation, Globals.DataRange)) return;

foreach (AuctionInfo auction in Account.Auctions)
{
if (auction.AuctionID != auctionID) continue;

if (auction.ItemType != MarketItemType.Auction)
{
return;
}

if (auction.CurrentBid <= auction.Price || auction.CurrentBuyerInfo == null)
{
Enqueue(new S.MarketFail { Reason = 9 });
return;
}

if (auction.Sold && auction.Expired)
{
MessageQueue.Enqueue(string.Format("Auction both sold and Expired {0}", Account.AccountID));
return;
}

if (auction.Expired || auction.Sold || Envir.Now >= auction.ConsignmentDate.AddDays(Globals.ConsignmentLength))
{
Enqueue(new S.MarketFail { Reason = 10 });
return;
}

uint cost = auction.CurrentBid;

uint gold = (uint)Math.Max(0, cost - cost * Globals.Commission);

if (!CanGainGold(auction.CurrentBid))
{
Enqueue(new S.MarketFail { Reason = 8 });
return;
}

auction.Sold = true;

string message = string.Format("You won {0} for {1:#,##0} Gold.", auction.Item.FriendlyName, auction.CurrentBid);

Envir.MailCharacter(auction.CurrentBuyerInfo, item: auction.Item, customMessage: message);
Envir.MessageAccount(auction.CurrentBuyerInfo.AccountInfo, string.Format("You bought {0} for {1:#,##0} Gold", auction.Item.FriendlyName, auction.CurrentBid), ChatType.Hint);

Account.Auctions.Remove(auction);
Envir.Auctions.Remove(auction);
GainGold(gold);
Enqueue(new S.MarketSuccess { Message = string.Format("You sold {0} for {1:#,##0} Gold. \nEarnings: {2:#,##0} Gold.\nCommision: {3:#,##0} Gold.‎", auction.Item.FriendlyName, cost, gold, cost - gold) });
MarketSearch(MatchName, MatchType);
return;
}

}

Enqueue(new S.MarketFail { Reason = 7 });
}

public void MarketGetBack(ulong auctionID)
{
if (Dead)
Expand Down
15 changes: 15 additions & 0 deletions Shared/ClientPackets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,21 @@ protected override void WritePacket(BinaryWriter writer)
writer.Write(BidPrice);
}
}
public sealed class MarketSellNow : Packet
{
public override short Index { get { return (short)ClientPacketIds.MarketSellNow; } }

public ulong AuctionID;

protected override void ReadPacket(BinaryReader reader)
{
AuctionID = reader.ReadUInt64();
}
protected override void WritePacket(BinaryWriter writer)
{
writer.Write(AuctionID);
}
}
public sealed class MarketGetBack : Packet
{
public override short Index { get { return (short)ClientPacketIds.MarketGetBack; } }
Expand Down
1 change: 1 addition & 0 deletions Shared/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ public enum ClientPacketIds : short
MarketPage,
MarketBuy,
MarketGetBack,
MarketSellNow,
RequestUserName,
RequestChatItem,
EditGuildMember,
Expand Down
2 changes: 2 additions & 0 deletions Shared/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ private static Packet GetClientPacket(short index)
return new C.MarketBuy();
case (short)ClientPacketIds.MarketGetBack:
return new C.MarketGetBack();
case (short)ClientPacketIds.MarketSellNow:
return new C.MarketSellNow();
case (short)ClientPacketIds.RequestUserName:
return new C.RequestUserName();
case (short)ClientPacketIds.RequestChatItem:
Expand Down

0 comments on commit 365c8d8

Please sign in to comment.