diff --git a/proto/idl/enums.proto b/proto/idl/enums.proto index d74c118..91a4528 100644 --- a/proto/idl/enums.proto +++ b/proto/idl/enums.proto @@ -324,32 +324,64 @@ enum UpgradeMasterType { MasterTreasureRefine = 4; } + +// MailType 邮件类型 +enum MailType { + MailTypeNone = 0; + + // 普通邮件 + MailNormal = 1; + + // 特殊邮件 + MailSpecial = 2; + + // 后台邮件 + MailBackground = 3; + + // 全服邮件 + MailAllRegion = 4; +} + +enum MailStatus { + + //未读 + Unread = 0; + + //已读 + HasRead = 1; + + //已领取 + Received = 2; + + //已删除 + Deleted = 3; +} + enum AttrType { AttrTypeNone = 0; //无属性 Attack = 1; //攻击 Hp = 2; //生命 - AttrPhysicalDefense = 3; //物防 - AttrMagicDefense = 4; //法防 - AttrAttackRatio = 5; //攻击加成 - AttrHpRatio = 6; //生命加成 - AttrPhysicalDefenseRatio = 7; //物防加成 - AttrMagicDefenseRatio = 8; //法防加成 - AttrDamageRatio = 9; //伤害加成 - AttrDamageRelief = 10; //伤害减免 - AttrCriticalRatio = 11; //暴击几率 - AttrCriticalResistance = 12; //抗暴几率 - AttrCriticalDamage = 13; //暴击伤害 - AttrCriticalDamageRelief = 14; //暴伤减免 - AttrHitRate = 15; //命中几率 - AttrDodgeRate = 16; //闪避几率 - AttrTreatRatio = 17; //治疗加成 - AttrByTreatedRatio = 18; //被治疗率 - AttrFinalDamageRatio = 19; //最终增伤 - AttrFinalDamageRelief = 20; //最终减伤 - AttrBlockRate = 21; //格挡 - AttrBlockResistance = 22; //抗格挡 - AttrSpeed = 23; //速度 - Nums = 24; //属性总数量 + PhysicalDefense = 3; //物防 + MagicDefense = 4; //法防 + AttackRatio = 5; //攻击加成 + HpRatio = 6; //生命加成 + PhysicalDefenseRatio = 7; //物防加成 + MagicDefenseRatio = 8; //法防加成 + DamageRatio = 9; //伤害加成 + DamageRelief = 10; //伤害减免 + CriticalRate = 11; //暴击几率 + CriticalResistance = 12; //抗暴几率 + CriticalDamage = 13; //暴击伤害 + CriticalDamageRelief = 14; //暴伤减免 + HitRate = 15; //命中几率 + DodgeRate = 16; //闪避几率 + TreatRatio = 17; //治疗加成 + ByTreatedRate = 18; //被治疗率 + FinalDamageRatio = 19; //最终增伤 + FinalDamageRelief = 20; //最终减伤 + BlockRate = 21; //格挡 + BlockResistance = 22; //抗格挡 + AttrNums = 23; //属性总数量 } diff --git a/proto/idl/mod_mail.proto b/proto/idl/mod_mail.proto new file mode 100644 index 0000000..454d94a --- /dev/null +++ b/proto/idl/mod_mail.proto @@ -0,0 +1,90 @@ +syntax = "proto3"; +package Pb; +option go_package = "pb/"; + +import "enums.proto"; +import "mod_item.proto"; + +// ModId.ModuleMail = 8000; +// 邮件模块消息定义 +// 如果定义的消息内没有字段或者消息被注释掉了,说明该请求不需要参数,发送消息时仅发送包头即可,包体可为空, 返回的消息亦是如此。 + +message Mail { + uint64 Uid = 1; //唯一ID + MailType Type = 2; //邮件类型,见MailType + string title = 3; //标题 + string content = 4; //内容 + int64 CreateTime = 5; //创建时间 + int64 Expiration = 6; //过期时间,0不过期 + MailStatus Status = 7; //邮件状态,见MailStatus + repeated string Args = 8; //邮件参数,用于替换内容中的占符 + repeated Item ItemList = 9; //物品列表, 没有物品为空 +} + +message MailChange { + uint64 Uid = 1; //唯一ID + MailStatus Status = 7; //邮件状态,见MailStatus +} + +// MsgId.ModMailList = 8001; +// MsgId.ModMailSend = 8002; +// 邮件列表返回 +message MailListAck { + repeated Mail MailList = 1; +} + +// MsgId.ModMailSend = 8002; +// 邮件发送请求 +message MailSendReq { + uint64 UserId = 1; //用户ID + uint32 AreaId = 2; //区ID(服务器ID) + uint64 RoleId = 3; //角色ID + Mail Mail = 4; //邮件 +} + +// MsgId.ModMailSend = 8002; +// 邮件发送返回 +message MailSendAck { + Mail Mail = 1; +} + +// MsgId.ModMailChange = 8003; +// 邮件为变更列表返回 +message MailChangeListAck { + repeated MailChange ChangeList = 1; +} + +// MsgId.ModMailRead = 8004; +// 邮件读取请求 +message MailReadReq { + uint64 Uid = 1; //唯一ID +} + +// MsgId.ModMailReceive = 8005; +// 邮件物品领取请求 +message MailReceiveReq { + uint64 Uid = 1; //唯一ID +} + +// MsgId.ModMailReceiveAll = 8006; +// 邮件物品领取所有 +message MailReceiveAllReq { +} + +// MsgId.ModMailReceive = 8005; +// MsgId.ModMailReceiveAll = 8006; +// 邮件物品领取返回 +message MailReceiveAck { + repeated Item ItemList = 1; +} + +// MsgId.ModMailDelete = 8007; +// 邮件删除请求 +message MailDeleteReq { + uint64 Uid = 1; //唯一ID +} + +// MsgId.ModMailDeleteAll = 8008; +// 邮件删除所有请求 +message MailDeleteAllReq { +} \ No newline at end of file diff --git a/servers/game/handler/player_mail.go b/servers/game/handler/player_mail.go index 25d7a50..056728d 100644 --- a/servers/game/handler/player_mail.go +++ b/servers/game/handler/player_mail.go @@ -1,194 +1,251 @@ package handler -//func (this *PlayerHandler) MailRead(player *logic.Player, msg *net.Message) { -// var req = new(proto.MsgMailReadReq) -// var err = msg.Read(req) -// if err != nil { -// this.logger.Error("Read message failed, ", err) -// _ = player.TipNotice(proto.ErrMessageError) -// return -// } -// -// if req.Id == 0 { -// this.logger.Error("Parameter error, req.Id == 0") -// _ = player.TipNotice(proto.ErrParameterError) -// return -// } -// -// var mail = player.Mail[req.Id] -// if mail == nil { -// this.logger.Error("Parameter error, Player 'Mail' was not found, id: ", req.Id) -// _ = player.TipNotice(proto.ErrMailNotFound) -// return -// } -// -// if proto.MailStatus(mail.Status) >= proto.MailStatusHasRead { -// return -// } -// -// mail.Status = uint32(proto.MailStatusHasRead) -// -// player.SaveModel(mail) -// -// _ = player.Send(proto.ModIdMail, proto.MsgIdMailRead, &proto.MsgMailReadAck{MailChange: &proto.MailChange{Id: mail.Id, Status: mail.Status}}) -// -// this.eventManager.PlayerMailLog(player, logic.LogTypeMailRead, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) -//} -// -//func (this *PlayerHandler) MailReceive(player *logic.Player, msg *net.Message) { -// var req = new(proto.MsgMailReceiveReq) -// var err = msg.Read(req) -// if err != nil { -// this.logger.Error("Read message failed, ", err) -// _ = player.TipNotice(proto.ErrMessageError) -// return -// } -// -// if req.Id == 0 { -// this.logger.Error("Parameter error, req.Id == 0") -// _ = player.TipNotice(proto.ErrParameterError) -// return -// } -// -// var mail = player.Mail[req.Id] -// if mail == nil { -// this.logger.Error("Parameter error, Player 'Mail' was not found, id: ", req.Id) -// _ = player.TipNotice(proto.ErrMailNotFound) -// return -// } -// -// if proto.MailStatus(mail.Status) >= proto.MailStatusReceived { -// return -// } -// -// if len(mail.ItemId) == 0 || len(mail.ItemNum) == 0 { -// return -// } -// -// var rewardList []*proto.ItemPair -// for i := range mail.ItemId { -// _ = player.AddItem(mail.ItemId[i], mail.ItemNum[i], logic.LogTypeItemObtainByMail) -// rewardList = append(rewardList, &proto.ItemPair{ItemId: mail.ItemId[i], ItemNum: mail.ItemNum[i]}) -// } -// -// mail.Status = uint32(proto.MailStatusReceived) -// -// player.SaveModel(mail) -// -// _ = player.Send(proto.ModIdMail, proto.MsgIdMailReceive, &proto.MsgMailReceiveAck{ -// MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}, -// MailChange: &proto.MailChange{Id: mail.Id, Status: mail.Status}, -// }) -// -// this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) -//} -// -//func (this *PlayerHandler) MailReceiveAll(player *logic.Player, _ *net.Message) { -// var rewardList []*proto.ItemPair -// var changeList []*proto.MailChange -// var itemPair = map[uint32]uint32{} -// for id, mail := range player.Mail { -// if proto.MailStatus(mail.Status) >= proto.MailStatusReceived { -// continue -// } -// -// if len(mail.ItemId) == 0 || len(mail.ItemNum) == 0 { -// return -// } -// -// for i := range mail.ItemId { -// itemPair[mail.ItemId[i]] += mail.ItemNum[i] -// } -// -// mail.Status = uint32(proto.MailStatusReceived) -// player.SaveModel(mail) -// -// changeList = append(changeList, &proto.MailChange{Id: id, Status: mail.Status}) -// -// this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) -// } -// -// for itemId, itemNum := range itemPair { -// _ = player.AddItem(itemId, itemNum, logic.LogTypeItemObtainByMail) -// rewardList = append(rewardList, &proto.ItemPair{ItemId: itemId, ItemNum: itemNum}) -// } -// -// if len(changeList) > 0 { -// _ = player.Send(proto.ModIdMail, proto.MsgIdMailReceiveAll, &proto.MsgMailReceiveAllAck{ -// MsgRewardListAck: &proto.MsgRewardListAck{RewardList: rewardList}, -// ChangeList: changeList, -// }) -// } -//} -// -//func (this *PlayerHandler) MailDelete(player *logic.Player, msg *net.Message) { -// var req = new(proto.MsgMailDeleteReq) -// var err = msg.Read(req) -// if err != nil { -// this.logger.Error("Read message failed, ", err) -// _ = player.TipNotice(proto.ErrMessageError) -// return -// } -// -// if req.Id == 0 { -// this.logger.Error("Parameter error, req.Id == 0") -// _ = player.TipNotice(proto.ErrParameterError) -// return -// } -// -// var mail = player.Mail[req.Id] -// if mail == nil { -// this.logger.Error("Parameter error, Player 'Mail' was not found, id: ", req.Id) -// _ = player.TipNotice(proto.ErrMailNotFound) -// return -// } -// -// if proto.MailType(mail.Type) == proto.MailTypeRegion { -// if proto.MailStatus(mail.Status) >= proto.MailStatusDeleted { -// return -// } -// mail.Status = uint32(proto.MailStatusDeleted) -// player.SaveModel(mail) -// } else { -// delete(player.Mail, req.Id) -// player.WipeModel(mail) -// } -// -// _ = player.Send(proto.ModIdMail, proto.MsgIdMailDelete, &proto.MsgMailDeleteAck{MailChange: &proto.MailChange{Id: mail.Id, Status: mail.Status}}) -// -// this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) -//} -// -//func (this *PlayerHandler) MailDeleteAll(player *logic.Player, _ *net.Message) { -// var changeList []*proto.MailChange -// for id, mail := range player.Mail { -// if proto.MailStatus(mail.Status) < proto.MailStatusHasRead { -// continue -// } -// -// if len(mail.ItemId) > 0 { -// if proto.MailStatus(mail.Status) < proto.MailStatusReceived { -// continue -// } -// } -// -// if proto.MailType(mail.Type) == proto.MailTypeRegion { -// if proto.MailStatus(mail.Status) >= proto.MailStatusDeleted { -// continue -// } -// mail.Status = uint32(proto.MailStatusDeleted) -// player.SaveModel(mail) -// } else { -// delete(player.Mail, id) -// player.WipeModel(mail) -// } -// -// changeList = append(changeList, &proto.MailChange{Id: id, Status: uint32(proto.MailStatusDeleted)}) -// -// this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) -// } -// -// if len(changeList) > 0 { -// _ = player.Send(proto.ModIdMail, proto.MsgIdMailDeleteAll, &proto.MsgMailDeleteAllAck{ChangeList: changeList}) -// } -//} +import ( + "ecs/proto" + "ecs/proto/pb" + "ecs/servers/game/logic" + "github.com/oylshe1314/framework/net" +) + +func (this *PlayerHandler) MailSend(player *logic.Player, msg *net.Message) { + var req = new(pb.MailSendReq) + var err = msg.Read(req) + if err != nil { + this.logger.Error("Read message failed, ", err) + _ = player.TipNotice(proto.TipMessageError) + return + } + + if req.UserId == 0 { + this.logger.Error("Parameter error, req.UserId == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + if req.AreaId == 0 { + this.logger.Error("Parameter error, req.AreaId == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + if req.RoleId == 0 { + this.logger.Error("Parameter error, req.RoleId == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + if req.Mail == nil { + this.logger.Error("Parameter error, req.Mail == nil") + _ = player.TipNotice(proto.TipParameterError) + return + } + + _ = player.TipNotice(proto.TipServerError) +} + +func (this *PlayerHandler) MailRead(player *logic.Player, msg *net.Message) { + var req = new(pb.MailReadReq) + var err = msg.Read(req) + if err != nil { + this.logger.Error("Read message failed, ", err) + _ = player.TipNotice(proto.TipMessageError) + return + } + + if req.Uid == 0 { + this.logger.Error("Parameter error, req.Uid == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + var mail = player.Mail[req.Uid] + if mail == nil { + this.logger.Error("Parameter error, player 'Mail' was not found, req.Uid: ", req.Uid) + _ = player.TipNotice(proto.TipMailNotFound) + return + } + + if pb.MailStatus(mail.Status) >= pb.MailStatus_HasRead { + return + } + + mail.Status = uint32(pb.MailStatus_HasRead) + + player.SaveModel(mail) + + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailRead, &pb.MailChangeListAck{ + ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}}, + }) + + // this.eventManager.PlayerMailLog(player, logic.LogTypeMailRead, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) +} + +func (this *PlayerHandler) MailReceive(player *logic.Player, msg *net.Message) { + var req = new(pb.MailReceiveReq) + var err = msg.Read(req) + if err != nil { + this.logger.Error("Read message failed, ", err) + _ = player.TipNotice(proto.TipMessageError) + return + } + + if req.Uid == 0 { + this.logger.Error("Parameter error, req.Uid == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + var mail = player.Mail[req.Uid] + if mail == nil { + this.logger.Error("Parameter error, player 'Mail' was not found, req.Uid: ", req.Uid) + _ = player.TipNotice(proto.TipMailNotFound) + return + } + + if len(mail.Items) == 0 { + this.logger.Error("Parameter error, len(mail.Items) == 0, req.Uid: ", req.Uid) + _ = player.TipNotice(proto.TipMailNoItems) + return + } + + if pb.MailStatus(mail.Status) >= pb.MailStatus_Received { + return + } + + var itemList []*pb.Item + for i := range mail.Items { + _ = player.AddItem(mail.Items[i][0], mail.Items[i][1], logic.LogTypeItemObtainByMail) + itemList = append(itemList, &pb.Item{ItemId: mail.Items[i][0], ItemNum: mail.Items[i][1]}) + } + + mail.Status = uint32(pb.MailStatus_Received) + + player.SaveModel(mail) + + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailReceive, &pb.MailReceiveAck{ + ItemList: itemList, + }) + + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{ + ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}}, + }) + + // this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) +} + +func (this *PlayerHandler) MailReceiveAll(player *logic.Player, _ *net.Message) { + var changeList []*pb.MailChange + var mailItems = map[uint32]uint32{} + for uid, mail := range player.Mail { + if pb.MailStatus(mail.Status) >= pb.MailStatus_Received { + continue + } + + if len(mail.Items) == 0 { + continue + } + + for i := range mail.Items { + mailItems[mail.Items[i][0]] += mail.Items[i][1] + } + + mail.Status = uint32(pb.MailStatus_Received) + player.SaveModel(mail) + + changeList = append(changeList, &pb.MailChange{Uid: uid, Status: pb.MailStatus(mail.Status)}) + + //this.eventManager.PlayerMailLog(player, logic.LogTypeMailReward, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) + } + + var itemList []*pb.Item + for itemId, itemNum := range mailItems { + _ = player.AddItem(itemId, itemNum, logic.LogTypeItemObtainByMail) + itemList = append(itemList, &pb.Item{ItemId: itemId, ItemNum: itemNum}) + } + + if len(itemList) > 0 { + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailReceiveAll, &pb.MailReceiveAck{ + ItemList: itemList, + }) + } + + if len(changeList) > 0 { + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{ + ChangeList: changeList, + }) + } +} + +func (this *PlayerHandler) MailDelete(player *logic.Player, msg *net.Message) { + var req = new(pb.MailDeleteReq) + var err = msg.Read(req) + if err != nil { + this.logger.Error("Read message failed, ", err) + _ = player.TipNotice(proto.TipMessageError) + return + } + + if req.Uid == 0 { + this.logger.Error("Parameter error, req.Uid == 0") + _ = player.TipNotice(proto.TipParameterError) + return + } + + var mail = player.Mail[req.Uid] + if mail == nil { + //this.logger.Error("Parameter error, Player 'Mail' was not found, req.Uid: ", req.Uid) + //_ = player.TipNotice(proto.TipMailNotFound) + return + } + + if pb.MailType(mail.Type) == pb.MailType_MailAllRegion { + if pb.MailStatus(mail.Status) >= pb.MailStatus_Deleted { + return + } + mail.Status = uint32(pb.MailStatus_Deleted) + player.SaveModel(mail) + } else { + delete(player.Mail, req.Uid) + player.WipeModel(mail) + } + + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{ + ChangeList: []*pb.MailChange{{Uid: mail.Uid, Status: pb.MailStatus(mail.Status)}}, + }) + + // this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) +} + +func (this *PlayerHandler) MailDeleteAll(player *logic.Player, _ *net.Message) { + var changeList []*pb.MailChange + for id, mail := range player.Mail { + if pb.MailStatus(mail.Status) < pb.MailStatus_HasRead { + continue + } + + if len(mail.Items) > 0 { + if pb.MailStatus(mail.Status) < pb.MailStatus_Received { + continue + } + } + + if pb.MailType(mail.Type) == pb.MailType_MailAllRegion { + if pb.MailStatus(mail.Status) >= pb.MailStatus_Deleted { + continue + } + mail.Status = uint32(pb.MailStatus_Deleted) + player.SaveModel(mail) + } else { + delete(player.Mail, id) + player.WipeModel(mail) + } + + changeList = append(changeList, &pb.MailChange{Uid: id, Status: pb.MailStatus_Deleted}) + + //this.eventManager.PlayerMailLog(player, logic.LogTypeMailDelete, mail.Id, mail.Type, 0, mail.Title, mail.Content, mail.ItemId, mail.ItemNum, 0, mail.CreateTime) + } + + if len(changeList) > 0 { + _ = player.Send(pb.ModId_ModuleMail, pb.MsgId_ModMailChange, &pb.MailChangeListAck{ChangeList: changeList}) + } +} diff --git a/servers/game/logic/player_mail.go b/servers/game/logic/player_mail.go index c328c8d..ea39fbc 100644 --- a/servers/game/logic/player_mail.go +++ b/servers/game/logic/player_mail.go @@ -1,84 +1,71 @@ package logic -//type PlayerMail struct { -// Id uint64 `bson:"id" key:"1"` -// Type uint32 `bson:"type"` -// Title string `bson:"title"` -// Content string `bson:"content"` -// Args []string `bson:"args"` -// Status uint32 `bson:"status"` -// ItemId []uint32 `bson:"item_id"` -// ItemNum []uint32 `bson:"item_num"` -// CreateTime int64 `bson:"create_time"` -// Expiration int64 `bson:"expiration"` -//} -// -//func (this *PlayerMail) BuildMsgMail() *proto.Mail { -// var itemList []*proto.ItemPair -// for i, itemId := range this.ItemId { -// itemList = append(itemList, &proto.ItemPair{ItemId: itemId, ItemNum: this.ItemNum[i]}) -// } -// return &proto.Mail{ -// Id: this.Id, -// Type: this.Type, -// Title: this.Title, -// Content: this.Content, -// Args: this.Args, -// Status: this.Status, -// ItemList: itemList, -// CreateTime: this.CreateTime, -// Expiration: this.Expiration, -// } -//} -// -//func (this *Player) AddMail(tipe proto.MailType, title, content string, args []string, itemId, itemNum []uint32, createTime int64, expiration ...int64) { -// counter, err := this.manager.mongoClient.Counter("mail_id", 1) -// if err != nil { -// this.manager.logger.Error("Get counter failed, ", err) -// return -// } -// -// this.addMail(util.EncryptUid(counter), tipe, title, content, args, itemId, itemNum, createTime, expiration...) -//} -// -//func (this *Player) addMail(mailId uint64, tipe proto.MailType, title, content string, args []string, itemId, itemNum []uint32, createTime int64, expiration ...int64) { -// var mail = &PlayerMail{ -// Id: mailId, -// Type: uint32(tipe), -// Title: title, -// Content: content, -// Args: args, -// Status: uint32(proto.MailStatusUnread), -// ItemId: itemId, -// ItemNum: itemNum, -// CreateTime: createTime, -// } -// -// if len(expiration) > 0 { -// mail.Expiration = expiration[0] -// } else { -// mail.Expiration = mail.CreateTime + util.DayTotalSeconds*30 -// } -// -// this.Mail[mail.Id] = mail -// this.SaveModel(mail) -// -// _ = this.Send(proto.ModIdMail, proto.MsgIdMailSend, &proto.MsgMailSendAck{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() *proto.MsgMailListAck { -// var mailList []*proto.Mail -// for _, mail := range this.Mail { -// if proto.MailStatus(mail.Status) >= proto.MailStatusDeleted { -// continue -// } -// var itemList []*proto.ItemPair -// for i := range mail.ItemId { -// itemList = append(itemList, &proto.ItemPair{ItemId: mail.ItemId[i], ItemNum: mail.ItemNum[i]}) -// } -// mailList = append(mailList, mail.BuildMsgMail()) -// } -// return &proto.MsgMailListAck{List: mailList} -//} +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} +}