From 6e9e2458e32e324253bad5b0942073002365b38b Mon Sep 17 00:00:00 2001 From: flswld Date: Mon, 27 Nov 2023 22:02:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gdconf/scene_point.go | 4 +- gs/game/game.go | 7 + gs/game/game_command_gm.go | 10 +- gs/game/game_route_manager.go | 6 + gs/game/game_tick_manager.go | 6 + gs/game/player_login.go | 11 +- gs/game/player_mail.go | 199 +++++++++++++++++++++++++++ gs/game/player_scene.go | 14 +- gs/model/mail.go | 17 +++ gs/model/player.go | 7 +- protocol/cmd/cmd_id_proto_obj_map.go | 13 ++ 11 files changed, 271 insertions(+), 23 deletions(-) create mode 100644 gs/game/player_mail.go create mode 100644 gs/model/mail.go diff --git a/gdconf/scene_point.go b/gdconf/scene_point.go index e261d615..ae99fb39 100644 --- a/gdconf/scene_point.go +++ b/gdconf/scene_point.go @@ -49,7 +49,7 @@ type ScenePoint struct { type PointData struct { Id int32 `json:"-"` PointType int `json:"-"` - PointTypeStr string `json:"$type"` // 传送点类型 + PointTypeStr string `json:"pointType"` // 传送点类型 TranPos *Position `json:"tranPos"` // 传送后位置 TranRot *Position `json:"tranRot"` // 传送后朝向 DungeonIds []int32 `json:"dungeonIds"` // 地牢id列表 @@ -115,7 +115,7 @@ func (g *GameDataConfig) loadScenePoint() { case PointTypeStrOther: pointData.PointType = PointTypeOther default: - logger.Error("unknown scene point type: %v", pointData.PointTypeStr) + logger.Info("unknown scene point type: %v", pointData.PointTypeStr) pointData.PointType = PointTypeOther } scenePoint.PointMap[int32(pointId)] = pointData diff --git a/gs/game/game.go b/gs/game/game.go index 52653869..628fd8ac 100644 --- a/gs/game/game.go +++ b/gs/game/game.go @@ -53,6 +53,7 @@ type Game struct { isStop bool // 停服标志 dispatchCancel bool // 取消调度标志 endlessLoopCounter map[int]uint64 // 死循环保护计数器 + transactionSeq uint32 // 事务序列号 ai *model.Player // 本服的Ai玩家对象 } @@ -68,6 +69,7 @@ func NewGameCore(discoveryClient *rpc.DiscoveryClient, db *dao.Dao, messageQueue r.isStop = false r.dispatchCancel = false r.endlessLoopCounter = make(map[int]uint64) + r.transactionSeq = 0 GAME = r LOCAL_EVENT_MANAGER = NewLocalEventManager() ROUTE_MANAGER = NewRouteManager() @@ -300,6 +302,11 @@ func (g *Game) EndlessLoopCheck(checkType int) { } } +func (g *Game) NewTransaction(uid uint32) string { + g.transactionSeq++ + return strconv.Itoa(int(uid)) + "-" + strconv.Itoa(int(time.Now().Unix())) + "-" + strconv.Itoa(int(g.transactionSeq)) +} + var EXIT_SAVE_FIN_CHAN chan bool func (g *Game) ServerStopNotify() { diff --git a/gs/game/game_command_gm.go b/gs/game/game_command_gm.go index 6c1dbf06..58ca93cb 100644 --- a/gs/game/game_command_gm.go +++ b/gs/game/game_command_gm.go @@ -501,7 +501,6 @@ func (g *GMCmd) GMClearQuest(userId uint32) { return } player.DbQuest = nil - GAME.AcceptQuest(player, false) GAME.LogoutPlayer(userId) } @@ -853,3 +852,12 @@ func (g *GMCmd) GetPlayerPos(userId uint32) (*model.Vector, *model.Vector) { } return GAME.GetPlayerPos(player), player.GetPos() } + +func (g *GMCmd) SendMail(userId uint32, title string, content string) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + GAME.AddPlayerMail(userId, title, content) +} diff --git a/gs/game/game_route_manager.go b/gs/game/game_route_manager.go index e12ca14e..3c4b3f00 100644 --- a/gs/game/game_route_manager.go +++ b/gs/game/game_route_manager.go @@ -137,6 +137,12 @@ func (r *RouteManager) initRoute() { cmd.UnlockAvatarTalentReq: GAME.UnlockAvatarTalentReq, cmd.ReliquaryUpgradeReq: GAME.ReliquaryUpgradeReq, cmd.ReliquaryPromoteReq: GAME.ReliquaryPromoteReq, + cmd.GetAllMailReq: GAME.GetAllMailReq, + cmd.GetAllMailNotify: GAME.GetAllMailNotify, + cmd.DelMailReq: GAME.DelMailReq, + cmd.GetMailItemReq: GAME.GetMailItemReq, + cmd.ReadMailNotify: GAME.ReadMailNotify, + cmd.ChangeMailStarNotify: GAME.ChangeMailStarNotify, } } diff --git a/gs/game/game_tick_manager.go b/gs/game/game_tick_manager.go index 2c3bb514..0d6360f0 100644 --- a/gs/game/game_tick_manager.go +++ b/gs/game/game_tick_manager.go @@ -66,6 +66,12 @@ func (t *TickManager) CreateUserGlobalTick(userId uint32) { // DestroyUserGlobalTick 销毁玩家tick对象 func (t *TickManager) DestroyUserGlobalTick(userId uint32) { + userTick, exist := t.userTickMap[userId] + if !exist { + logger.Error("user not exist, uid: %v", userId) + return + } + userTick.globalTick.Stop() delete(t.userTickMap, userId) } diff --git a/gs/game/player_login.go b/gs/game/player_login.go index ccccf553..af84840a 100644 --- a/gs/game/player_login.go +++ b/gs/game/player_login.go @@ -104,12 +104,11 @@ func (g *Game) OnLogin(userId uint32, clientSeq uint32, gateAppId string, player player.MpPos = new(model.Vector) player.MpRot = new(model.Vector) - dbQuest := player.GetDbQuest() - for _, quest := range dbQuest.GetQuestMap() { - if quest.State == constant.QUEST_STATE_UNFINISHED { - quest.State = constant.QUEST_STATE_UNSTARTED - g.StartQuest(player, quest.QuestId, false) - } + if player.DbQuest == nil { + player.SceneId = 3 + player.Pos = &model.Vector{X: 2747, Y: 194, Z: -1719} + player.Rot = &model.Vector{X: 0, Y: 307, Z: 0} + g.AcceptQuest(player, false) } g.TriggerOpenState(userId) diff --git a/gs/game/player_mail.go b/gs/game/player_mail.go new file mode 100644 index 00000000..ef932c1d --- /dev/null +++ b/gs/game/player_mail.go @@ -0,0 +1,199 @@ +package game + +import ( + "time" + + "hk4e/gs/model" + "hk4e/pkg/logger" + "hk4e/pkg/object" + "hk4e/protocol/cmd" + "hk4e/protocol/proto" + + pb "google.golang.org/protobuf/proto" +) + +/************************************************** 接口请求 **************************************************/ + +func (g *Game) GetAllMailReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.GetAllMailReq) + + rsp := &proto.GetAllMailRsp{ + MailList: g.PacketMailList(player.PlayerId), + IsCollected: req.IsCollected, + IsTruncated: false, + } + g.SendMsg(cmd.GetAllMailRsp, player.PlayerId, player.ClientSeq, rsp) +} + +func (g *Game) GetAllMailNotify(player *model.Player, payloadMsg pb.Message) { + ntf := payloadMsg.(*proto.GetAllMailNotify) + + pbMailList := make([]*proto.MailData, 0) + if player.ClientVersion >= 400 { + pbMailList = g.PacketMailList(player.PlayerId) + } + + g.SendMsg(cmd.GetAllMailResultNotify, player.PlayerId, player.ClientSeq, &proto.GetAllMailResultNotify{ + Transaction: g.NewTransaction(player.PlayerId), + MailList: pbMailList, + PageIndex: 1, + TotalPageCount: 1, + IsCollected: ntf.IsCollected, + }) +} + +func (g *Game) DelMailReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.DelMailReq) + + g.DelPlayerMail(player.PlayerId, req.MailIdList) + + rsp := &proto.DelMailRsp{ + MailIdList: req.MailIdList, + } + g.SendMsg(cmd.DelMailRsp, player.PlayerId, player.ClientSeq, rsp) +} + +func (g *Game) GetMailItemReq(player *model.Player, payloadMsg pb.Message) { + req := payloadMsg.(*proto.GetMailItemReq) + + rsp := &proto.GetMailItemRsp{ + MailIdList: req.MailIdList, + ItemList: nil, + } + g.SendMsg(cmd.GetMailItemRsp, player.PlayerId, player.ClientSeq, rsp) +} + +func (g *Game) ReadMailNotify(player *model.Player, payloadMsg pb.Message) { + ntf := payloadMsg.(*proto.ReadMailNotify) + g.ReadPlayerMail(player.PlayerId, ntf.MailIdList) +} + +func (g *Game) ChangeMailStarNotify(player *model.Player, payloadMsg pb.Message) { + ntf := payloadMsg.(*proto.ChangeMailStarNotify) + g.StarPlayerMail(player.PlayerId, ntf.MailIdList, ntf.IsStar) +} + +/************************************************** 游戏功能 **************************************************/ + +var MailIdSeq uint32 = 0 + +func (g *Game) AddPlayerMail(userId uint32, title string, content string) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + MailIdSeq++ + mail := &model.Mail{ + MailId: MailIdSeq, + Title: title, + Content: content, + Sender: "flswld", + SendTime: uint32(time.Now().Unix()), + ExpireTime: uint32(time.Now().Add(time.Hour * 24).Unix()), + IsRead: false, + IsStar: false, + } + player.MailMap[mail.MailId] = mail + ntf := &proto.MailChangeNotify{ + MailList: []*proto.MailData{g.PacketMail(mail)}, + DelMailIdList: nil, + } + g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf) +} + +func (g *Game) DelPlayerMail(userId uint32, mailIdList []uint32) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + for _, mailId := range mailIdList { + delete(player.MailMap, mailId) + } + ntf := &proto.MailChangeNotify{ + MailList: nil, + DelMailIdList: mailIdList, + } + g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf) +} + +func (g *Game) ReadPlayerMail(userId uint32, mailIdList []uint32) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + for _, mailId := range mailIdList { + mail, exist := player.MailMap[mailId] + if !exist { + return + } + mail.IsRead = true + } +} + +func (g *Game) StarPlayerMail(userId uint32, mailIdList []uint32, isStar bool) { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return + } + pbMailList := make([]*proto.MailData, 0) + for _, mailId := range mailIdList { + mail, exist := player.MailMap[mailId] + if !exist { + return + } + mail.IsStar = isStar + pbMail := g.PacketMail(mail) + if pbMail == nil { + return + } + pbMailList = append(pbMailList, pbMail) + } + ntf := &proto.MailChangeNotify{ + MailList: pbMailList, + DelMailIdList: nil, + } + g.SendMsg(cmd.MailChangeNotify, player.PlayerId, player.ClientSeq, ntf) +} + +/************************************************** 打包封装 **************************************************/ + +func (g *Game) PacketMail(mail *model.Mail) *proto.MailData { + return &proto.MailData{ + MailId: mail.MailId, + MailTextContent: &proto.MailTextContent{ + Title: mail.Title, + Content: mail.Content, + Sender: mail.Sender, + }, + ItemList: nil, + SendTime: mail.SendTime, + ExpireTime: mail.ExpireTime, + Importance: uint32(object.ConvBoolToInt64(mail.IsStar)), + IsRead: mail.IsRead, + IsAttachmentGot: false, + ConfigId: 0, + ArgumentList: nil, + CollectState: proto.MailCollectState_MAIL_NOT_COLLECTIBLE, + } +} + +func (g *Game) PacketMailList(userId uint32) []*proto.MailData { + player := USER_MANAGER.GetOnlineUser(userId) + if player == nil { + logger.Error("player is nil, uid: %v", userId) + return nil + } + pbMailList := make([]*proto.MailData, 0) + for _, mail := range player.MailMap { + pbMail := g.PacketMail(mail) + if pbMail == nil { + return nil + } + pbMailList = append(pbMailList, pbMail) + } + return pbMailList +} diff --git a/gs/game/player_scene.go b/gs/game/player_scene.go index 55e3c0d5..2388ac6f 100644 --- a/gs/game/player_scene.go +++ b/gs/game/player_scene.go @@ -1427,8 +1427,6 @@ func (g *Game) SetPlayerWeather(player *model.Player, weatherAreaId uint32, clim /************************************************** 打包封装 **************************************************/ -var SceneTransactionSeq uint32 = 0 - func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.PlayerEnterSceneNotify { world := WORLD_MANAGER.GetWorldById(player.WorldId) if world == nil { @@ -1454,11 +1452,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyLogin(player *model.Player) *proto.Pl WorldType: 1, SceneTagIdList: make([]uint32, 0), } - SceneTransactionSeq++ - playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.GetSceneId())) + "-" + - strconv.Itoa(int(player.PlayerId)) + "-" + - strconv.Itoa(int(time.Now().Unix())) + "-" + - strconv.Itoa(int(SceneTransactionSeq)) + playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.GetSceneId())) + "-" + g.NewTransaction(player.PlayerId) // TODO 暂时先解锁全部场景标签 看着喜庆 for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() { if uint32(sceneTagDataConfig.SceneId) == player.GetSceneId() { @@ -1520,11 +1514,7 @@ func (g *Game) PacketPlayerEnterSceneNotifyCore( DungeonId: dungeonId, SceneTagIdList: make([]uint32, 0), } - SceneTransactionSeq++ - playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(sceneId)) + "-" + - strconv.Itoa(int(player.PlayerId)) + "-" + - strconv.Itoa(int(time.Now().Unix())) + "-" + - strconv.Itoa(int(SceneTransactionSeq)) + playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(sceneId)) + "-" + g.NewTransaction(player.PlayerId) // TODO 暂时先解锁全部场景标签 看着喜庆 for _, sceneTagDataConfig := range gdconf.GetSceneTagDataMap() { if uint32(sceneTagDataConfig.SceneId) == sceneId { diff --git a/gs/model/mail.go b/gs/model/mail.go new file mode 100644 index 00000000..0e4f05b7 --- /dev/null +++ b/gs/model/mail.go @@ -0,0 +1,17 @@ +package model + +import ( + "go.mongodb.org/mongo-driver/bson/primitive" +) + +type Mail struct { + ID primitive.ObjectID `bson:"_id,omitempty"` + MailId uint32 `bson:"mail_id"` + Title string `bson:"title"` + Content string `bson:"content"` + Sender string `bson:"sender"` + SendTime uint32 `bson:"send_time"` + ExpireTime uint32 `bson:"expire_time"` + IsRead bool `bson:"is_read"` + IsStar bool `bson:"is_star"` +} diff --git a/gs/model/player.go b/gs/model/player.go index f7357397..9721903b 100644 --- a/gs/model/player.go +++ b/gs/model/player.go @@ -89,8 +89,9 @@ type Player struct { MpPos *Vector `bson:"-" msgpack:"-"` // 多人世界坐标 MpRot *Vector `bson:"-" msgpack:"-"` // 多人世界朝向 // 特殊数据 - ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 数据量偏大 只从db读写 不保存到redis - RemoteWorldPlayerNum uint32 `bson:"-"` // 远程展示世界内人数 在线同步到redis 不保存到db + ChatMsgMap map[uint32][]*ChatMsg `bson:"-" msgpack:"-"` // 聊天信息 只从db读写 不保存到redis + RemoteWorldPlayerNum uint32 `bson:"-"` // 远程展示世界内人数 不保存到db 在线同步到redis + MailMap map[uint32]*Mail `bson:"-" msgpack:"-"` // 邮件信息 只从db读写 不保存到redis } // 存档场景 @@ -179,6 +180,8 @@ func (p *Player) InitOnlineData() { dbWeapon.InitDbWeapon(p) dbItem := p.GetDbItem() dbItem.InitDbItem(p) + + p.MailMap = make(map[uint32]*Mail) } type Vector struct { diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index a2a61fe9..26f331f0 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -446,6 +446,19 @@ func (c *CmdProtoMap) registerMessage() { c.regMsg(ServerLogNotify, func() any { return new(proto.ServerLogNotify) }) c.regMsg(MarkEntityInMinMapNotify, func() any { return new(proto.MarkEntityInMinMapNotify) }) c.regMsg(UnmarkEntityInMinMapNotify, func() any { return new(proto.UnmarkEntityInMinMapNotify) }) + + // 邮件 + c.regMsg(GetAllMailReq, func() any { return new(proto.GetAllMailReq) }) // 获取邮件列表请求 + c.regMsg(GetAllMailRsp, func() any { return new(proto.GetAllMailRsp) }) // 获取邮件列表响应 + c.regMsg(GetAllMailNotify, func() any { return new(proto.GetAllMailNotify) }) // 获取邮件列表通知 + c.regMsg(GetAllMailResultNotify, func() any { return new(proto.GetAllMailResultNotify) }) // 获取邮件列表结果通知 + c.regMsg(MailChangeNotify, func() any { return new(proto.MailChangeNotify) }) // 新邮件通知 + c.regMsg(DelMailReq, func() any { return new(proto.DelMailReq) }) // 删除邮件请求 + c.regMsg(DelMailRsp, func() any { return new(proto.DelMailRsp) }) // 删除邮件响应 + c.regMsg(GetMailItemReq, func() any { return new(proto.GetMailItemReq) }) // 邮件领奖请求 + c.regMsg(GetMailItemRsp, func() any { return new(proto.GetMailItemRsp) }) // 邮件领奖响应 + c.regMsg(ReadMailNotify, func() any { return new(proto.ReadMailNotify) }) // 邮件阅读通知 + c.regMsg(ChangeMailStarNotify, func() any { return new(proto.ChangeMailStarNotify) }) // 邮件收藏通知 } func (c *CmdProtoMap) regMsg(cmdId uint16, protoObjNewFunc func() any) {