81 lines
2.6 KiB
Go
81 lines
2.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"ecs/proto/pb"
|
|
)
|
|
|
|
type PlayerMail struct {
|
|
Uid uint64 `bson:"uid" key:"1"`
|
|
Type uint32 `bson:"type"`
|
|
SentUserId uint64 `bson:"sent_user_id"`
|
|
SentServerId uint32 `bson:"sent_server_id"`
|
|
SentRoleId uint64 `bson:"sent_role_id"`
|
|
Title string `bson:"title"`
|
|
Content string `bson:"content"`
|
|
Status uint32 `bson:"status"`
|
|
CreateTime int64 `bson:"create_time"`
|
|
Expiration int64 `bson:"expiration"`
|
|
Args []string `bson:"args"`
|
|
Items [][2]uint32 `bson:"items"`
|
|
}
|
|
|
|
func (this *PlayerMail) BuildMsgMail() *pb.Mail {
|
|
var itemList []*pb.Item
|
|
for i := range this.Items {
|
|
itemList = append(itemList, &pb.Item{ItemId: this.Items[i][0], ItemNum: this.Items[i][1]})
|
|
}
|
|
return &pb.Mail{
|
|
Uid: this.Uid,
|
|
Type: pb.MailType(this.Type),
|
|
SentUserId: this.SentUserId,
|
|
SentServerId: this.SentServerId,
|
|
SentRoleId: this.SentRoleId,
|
|
Title: this.Title,
|
|
Content: this.Content,
|
|
CreateTime: this.CreateTime,
|
|
Expiration: this.Expiration,
|
|
Status: pb.MailStatus(this.Status),
|
|
Args: this.Args,
|
|
ItemList: itemList,
|
|
}
|
|
}
|
|
|
|
func (this *Player) AddMail(uid uint64, tipe pb.MailType, sentUserId uint64, sentServerId uint32, sentRoleId uint64, title, content string, createTime, expiration int64, args []string, items [][2]uint32) {
|
|
var mail = &PlayerMail{
|
|
Uid: uid,
|
|
Type: uint32(tipe),
|
|
SentUserId: sentUserId,
|
|
SentServerId: sentServerId,
|
|
SentRoleId: sentRoleId,
|
|
Title: title,
|
|
Content: content,
|
|
Status: uint32(pb.MailStatus_Unread),
|
|
CreateTime: createTime,
|
|
Expiration: expiration,
|
|
Args: args,
|
|
Items: items,
|
|
}
|
|
|
|
this.Mail[mail.Uid] = mail
|
|
this.SaveModel(mail)
|
|
|
|
_ = this.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailSend, &pb.MailSendAck{Mail: mail.BuildMsgMail()})
|
|
|
|
this.manager.eventManager.PlayerMailLog(this, LogTypeMailReceived, mail.Uid, mail.Type, mail.SentUserId, mail.SentServerId, mail.SentRoleId, mail.Title, mail.Content, mail.CreateTime, mail.Expiration, mail.Args, mail.Items)
|
|
}
|
|
|
|
func (this *Player) BuildMsgMailListAck() *pb.MailListAck {
|
|
var mailList []*pb.Mail
|
|
for _, mail := range this.Mail {
|
|
if pb.MailStatus(mail.Status) >= pb.MailStatus_Deleted {
|
|
continue
|
|
}
|
|
var itemList []*pb.Item
|
|
for i := range mail.Items {
|
|
itemList = append(itemList, &pb.Item{ItemId: mail.Items[i][0], ItemNum: mail.Items[i][1]})
|
|
}
|
|
mailList = append(mailList, mail.BuildMsgMail())
|
|
}
|
|
return &pb.MailListAck{MailList: mailList}
|
|
}
|