AuctionInfo.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Server.MirEnvir;
  2. namespace Server.MirDatabase
  3. {
  4. public class AuctionInfo
  5. {
  6. protected static Envir Envir
  7. {
  8. get { return Envir.Main; }
  9. }
  10. public ulong AuctionID;
  11. public UserItem Item;
  12. public DateTime ConsignmentDate;
  13. public uint Price, CurrentBid;
  14. public int SellerIndex, CurrentBuyerIndex;
  15. public CharacterInfo SellerInfo, CurrentBuyerInfo;
  16. public bool Expired, Sold;
  17. public MarketItemType ItemType;
  18. public AuctionInfo()
  19. {
  20. }
  21. public AuctionInfo(CharacterInfo info, UserItem item, uint price, MarketItemType itemType)
  22. {
  23. AuctionID = ++Envir.NextAuctionID;
  24. SellerIndex = info.Index;
  25. SellerInfo = info;
  26. ConsignmentDate = Envir.Now;
  27. Item = item;
  28. Price = price;
  29. ItemType = itemType;
  30. if (itemType == MarketItemType.Auction)
  31. {
  32. CurrentBid = Price;
  33. }
  34. }
  35. public AuctionInfo(BinaryReader reader, int version, int customversion)
  36. {
  37. AuctionID = reader.ReadUInt64();
  38. Item = new UserItem(reader, version, customversion);
  39. ConsignmentDate = DateTime.FromBinary(reader.ReadInt64());
  40. Price = reader.ReadUInt32();
  41. SellerIndex = reader.ReadInt32();
  42. Expired = reader.ReadBoolean();
  43. Sold = reader.ReadBoolean();
  44. if (version > 79)
  45. {
  46. ItemType = (MarketItemType)reader.ReadByte();
  47. CurrentBid = reader.ReadUInt32();
  48. if (CurrentBid < Price)
  49. CurrentBid = Price;
  50. CurrentBuyerIndex = reader.ReadInt32();
  51. }
  52. }
  53. public void Save(BinaryWriter writer)
  54. {
  55. writer.Write(AuctionID);
  56. Item.Save(writer);
  57. writer.Write(ConsignmentDate.ToBinary());
  58. writer.Write(Price);
  59. writer.Write(SellerIndex);
  60. writer.Write(Expired);
  61. writer.Write(Sold);
  62. writer.Write((byte)ItemType);
  63. writer.Write(CurrentBid);
  64. writer.Write(CurrentBuyerIndex);
  65. }
  66. private string GetSellerLabel(bool userMatch)
  67. {
  68. switch (ItemType)
  69. {
  70. case MarketItemType.GameShop:
  71. return "";
  72. case MarketItemType.Consign:
  73. return userMatch ? (Sold ? "Sold" : (Expired ? "Expired" : "For Sale")) : SellerInfo.Name;
  74. case MarketItemType.Auction:
  75. return userMatch ? (Sold ? "Sold" : (Expired ? "Expired" : CurrentBid > Price ? "Bid Met" : "No Bid")) : SellerInfo.Name;
  76. }
  77. return "";
  78. }
  79. public ClientAuction CreateClientAuction(bool userMatch)
  80. {
  81. return new ClientAuction
  82. {
  83. AuctionID = AuctionID,
  84. Item = Item,
  85. Seller = GetSellerLabel(userMatch),
  86. Price = ItemType == MarketItemType.Auction ? CurrentBid : Price,
  87. ConsignmentDate = ConsignmentDate,
  88. ItemType = ItemType
  89. };
  90. }
  91. }
  92. }