MailInfo.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using Server.MirDatabase;
  2. namespace Server.MirEnvir
  3. {
  4. public class MailInfo
  5. {
  6. protected static Envir Envir
  7. {
  8. get { return Envir.Main; }
  9. }
  10. public ulong MailID;
  11. public string Sender;
  12. public int RecipientIndex;
  13. public CharacterInfo RecipientInfo;
  14. public string Message = string.Empty;
  15. public uint Gold = 0;
  16. public List<UserItem> Items = new List<UserItem>();
  17. public DateTime DateSent, DateOpened;
  18. public bool Sent
  19. {
  20. get { return DateSent > DateTime.MinValue; }
  21. }
  22. public bool Opened
  23. {
  24. get { return DateOpened > DateTime.MinValue; }
  25. }
  26. public bool Locked;
  27. public bool Collected;
  28. public bool Parcel //parcel if item contains gold or items.
  29. {
  30. get { return Gold > 0 || Items.Count > 0; }
  31. }
  32. public bool CanReply;
  33. public MailInfo(int recipientIndex, bool canReply = false)
  34. {
  35. MailID = ++Envir.NextMailID;
  36. RecipientIndex = recipientIndex;
  37. CanReply = canReply;
  38. }
  39. public MailInfo(BinaryReader reader, int version, int customversion)
  40. {
  41. MailID = reader.ReadUInt64();
  42. Sender = reader.ReadString();
  43. RecipientIndex = reader.ReadInt32();
  44. Message = reader.ReadString();
  45. Gold = reader.ReadUInt32();
  46. int count = reader.ReadInt32();
  47. for (int i = 0; i < count; i++)
  48. {
  49. UserItem item = new UserItem(reader, version, customversion);
  50. if (Envir.BindItem(item))
  51. Items.Add(item);
  52. }
  53. DateSent = DateTime.FromBinary(reader.ReadInt64());
  54. DateOpened = DateTime.FromBinary(reader.ReadInt64());
  55. Locked = reader.ReadBoolean();
  56. Collected = reader.ReadBoolean();
  57. CanReply = reader.ReadBoolean();
  58. }
  59. public void Save(BinaryWriter writer)
  60. {
  61. writer.Write(MailID);
  62. writer.Write(Sender);
  63. writer.Write(RecipientIndex);
  64. writer.Write(Message);
  65. writer.Write(Gold);
  66. writer.Write(Items.Count);
  67. for (int i = 0; i < Items.Count; i++)
  68. Items[i].Save(writer);
  69. writer.Write(DateSent.ToBinary());
  70. writer.Write(DateOpened.ToBinary());
  71. writer.Write(Locked);
  72. writer.Write(Collected);
  73. writer.Write(CanReply);
  74. }
  75. public void Send()
  76. {
  77. if (Sent) return;
  78. Collected = true;
  79. if (Parcel)
  80. {
  81. if(Items.Count > 0 && Gold > 0)
  82. {
  83. if(!Settings.MailAutoSendGold || !Settings.MailAutoSendItems)
  84. {
  85. Collected = false;
  86. }
  87. }
  88. if(Items.Count > 0)
  89. {
  90. if (!Settings.MailAutoSendItems)
  91. {
  92. Collected = false;
  93. }
  94. }
  95. else
  96. {
  97. if (!Settings.MailAutoSendGold)
  98. {
  99. Collected = false;
  100. }
  101. }
  102. }
  103. if (RecipientInfo == null)
  104. {
  105. RecipientInfo = Envir.GetCharacterInfo(RecipientIndex);
  106. }
  107. RecipientInfo.Mail.Add(this); //add to players inbox
  108. if (RecipientInfo.Player != null)
  109. {
  110. RecipientInfo.Player.NewMail = true; //notify player of new mail --check in player process
  111. }
  112. DateSent = Envir.Now;
  113. }
  114. public ClientMail CreateClientMail()
  115. {
  116. return new ClientMail
  117. {
  118. MailID = MailID,
  119. SenderName = Sender,
  120. Message = Message,
  121. Locked = Locked,
  122. CanReply = CanReply,
  123. Gold = Gold,
  124. Items = Items,
  125. Opened = Opened,
  126. Collected = Collected,
  127. DateSent = DateSent
  128. };
  129. }
  130. }
  131. // player bool NewMail (process in envir loop) - send all mail on login
  132. // Send mail from player (auto from player)
  133. // Send mail from Envir (mir administrator)
  134. }