| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using Server.MirDatabase;
- namespace Server.MirEnvir
- {
- public class MailInfo
- {
- protected static Envir Envir
- {
- get { return Envir.Main; }
- }
- public ulong MailID;
- public string Sender;
- public int RecipientIndex;
- public CharacterInfo RecipientInfo;
- public string Message = string.Empty;
- public uint Gold = 0;
- public List<UserItem> Items = new List<UserItem>();
- public DateTime DateSent, DateOpened;
- public bool Sent
- {
- get { return DateSent > DateTime.MinValue; }
- }
- public bool Opened
- {
- get { return DateOpened > DateTime.MinValue; }
- }
- public bool Locked;
- public bool Collected;
- public bool Parcel //parcel if item contains gold or items.
- {
- get { return Gold > 0 || Items.Count > 0; }
- }
- public bool CanReply;
- public MailInfo(int recipientIndex, bool canReply = false)
- {
- MailID = ++Envir.NextMailID;
- RecipientIndex = recipientIndex;
- CanReply = canReply;
- }
- public MailInfo(BinaryReader reader, int version, int customversion)
- {
- MailID = reader.ReadUInt64();
- Sender = reader.ReadString();
- RecipientIndex = reader.ReadInt32();
- Message = reader.ReadString();
- Gold = reader.ReadUInt32();
- int count = reader.ReadInt32();
- for (int i = 0; i < count; i++)
- {
- UserItem item = new UserItem(reader, version, customversion);
- if (Envir.BindItem(item))
- Items.Add(item);
- }
- DateSent = DateTime.FromBinary(reader.ReadInt64());
- DateOpened = DateTime.FromBinary(reader.ReadInt64());
- Locked = reader.ReadBoolean();
- Collected = reader.ReadBoolean();
- CanReply = reader.ReadBoolean();
- }
- public void Save(BinaryWriter writer)
- {
- writer.Write(MailID);
- writer.Write(Sender);
- writer.Write(RecipientIndex);
- writer.Write(Message);
- writer.Write(Gold);
- writer.Write(Items.Count);
- for (int i = 0; i < Items.Count; i++)
- Items[i].Save(writer);
- writer.Write(DateSent.ToBinary());
- writer.Write(DateOpened.ToBinary());
- writer.Write(Locked);
- writer.Write(Collected);
- writer.Write(CanReply);
- }
- public void Send()
- {
- if (Sent) return;
- Collected = true;
- if (Parcel)
- {
- if(Items.Count > 0 && Gold > 0)
- {
- if(!Settings.MailAutoSendGold || !Settings.MailAutoSendItems)
- {
- Collected = false;
- }
- }
- if(Items.Count > 0)
- {
- if (!Settings.MailAutoSendItems)
- {
- Collected = false;
- }
- }
- else
- {
- if (!Settings.MailAutoSendGold)
- {
- Collected = false;
- }
- }
- }
- if (RecipientInfo == null)
- {
- RecipientInfo = Envir.GetCharacterInfo(RecipientIndex);
- }
- RecipientInfo.Mail.Add(this); //add to players inbox
- if (RecipientInfo.Player != null)
- {
- RecipientInfo.Player.NewMail = true; //notify player of new mail --check in player process
- }
- DateSent = Envir.Now;
- }
- public ClientMail CreateClientMail()
- {
- return new ClientMail
- {
- MailID = MailID,
- SenderName = Sender,
- Message = Message,
- Locked = Locked,
- CanReply = CanReply,
- Gold = Gold,
- Items = Items,
- Opened = Opened,
- Collected = Collected,
- DateSent = DateSent
- };
- }
- }
- // player bool NewMail (process in envir loop) - send all mail on login
- // Send mail from player (auto from player)
- // Send mail from Envir (mir administrator)
- }
|