72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"ecs/proto/pb"
|
|
)
|
|
|
|
type PlayerMail struct {
|
|
Uid uint64 `bson:"uid" key:"1"`
|
|
Type uint32 `bson:"type"`
|
|
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),
|
|
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, title, content string, createTime, expiration int64, args []string, items [][2]uint32) {
|
|
var mail = &PlayerMail{
|
|
Uid: uid,
|
|
Type: uint32(tipe),
|
|
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, LogTypeMailGet, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime)
|
|
}
|
|
|
|
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}
|
|
}
|