diff --git a/go.mod b/go.mod index 5e08804..2144f14 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ go 1.24 require ( github.com/json-iterator/go v1.1.12 - github.com/oylshe1314/framework v1.0.19 + github.com/oylshe1314/framework v1.0.21 github.com/xuri/excelize/v2 v2.9.1 go.mongodb.org/mongo-driver v1.17.4 golang.org/x/crypto v0.39.0 google.golang.org/protobuf v1.36.6 ) -replace github.com/oylshe1314/framework v1.0.19 => D:\sk\projects\golang\framework-1.0.19 +replace github.com/oylshe1314/framework v1.0.21 => D:\sk\projects\golang\framework-1.0.21 require ( filippo.io/edwards25519 v1.1.0 // indirect diff --git a/proto/errors.go b/proto/errors.go index 233e0f1..0c96db2 100644 --- a/proto/errors.go +++ b/proto/errors.go @@ -279,8 +279,8 @@ const ( // TipMailNotFound 找不到邮件 TipMailNotFound StringTipError = "MailNotFound" - // TipMailNoReward 邮件无奖励 - TipMailNoReward StringTipError = "MailNoReward" + // TipMailNoItems 邮件无奖励 + TipMailNoItems StringTipError = "MailNoItems" // ----------------------- 任务模块 ----------------------- diff --git a/proto/idl/msg_id.proto b/proto/idl/msg_id.proto index da9587c..246a3a2 100644 --- a/proto/idl/msg_id.proto +++ b/proto/idl/msg_id.proto @@ -178,7 +178,7 @@ enum MsgId { //-------------------------------------------------------------------------- 英雄模块 -------------------------------------------------------------------------- ModHeroList = 5001; - // 英雄升级 + // 英雄变更 ModHeroChange = 5002; // 英雄升级 @@ -208,7 +208,7 @@ enum MsgId { // 英雄名将册激活 ModHeroBookActivate = 5011; - // ModItem begin ----------------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------- 物品模块 -------------------------------------------------------------------------- // 物品列表 ModItemList = 6001; @@ -245,10 +245,35 @@ enum MsgId { // 装备升级 ModItemTreasureRefine = 6024; - //ModCounter begin ----------------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------- 计数模块 -------------------------------------------------------------------------- // 计数器列表 ModCounterList = 7001; // 计数器变更 ModCounterChange = 7002; + + //-------------------------------------------------------------------------- 邮件模块 -------------------------------------------------------------------------- + // 邮件列表 + ModMailList = 8001; + + // 邮件发送 + ModMailSend = 8002; + + // 邮件状态改变 + ModMailChange = 8003; + + // 邮件已读 + ModMailRead = 8004; + + // 邮件物品领取 + ModMailReceive = 8005; + + // 邮件物品领取 + ModMailReceiveAll = 8006; + + // 邮件删除 + ModMailDelete = 8007; + + // 邮件删除 + ModMailDeleteAll = 8008; } \ No newline at end of file diff --git a/servers/game/logic/manager_player.go b/servers/game/logic/manager_player.go index 3458f7f..97df55e 100644 --- a/servers/game/logic/manager_player.go +++ b/servers/game/logic/manager_player.go @@ -2,6 +2,7 @@ package logic import ( "ecs/proto" + "ecs/proto/pb" "ecs/servers/game/data" "github.com/oylshe1314/framework/client/db" "github.com/oylshe1314/framework/errors" @@ -246,8 +247,8 @@ func (this *PlayerManager) NewPlayer() *Player { Equip: map[uint64]*PlayerEquip{}, //GiftPack: map[uint32]*PlayerGiftPack{}, Lineup: map[uint64]*PlayerLineup{}, - //Mail: map[uint64]*PlayerMail{}, - Money: map[uint32]*PlayerMoney{}, + Mail: map[uint64]*PlayerMail{}, + Money: map[uint32]*PlayerMoney{}, //MonthlyCard: map[uint32]*PlayerMonthlyCard{}, //Planet: map[uint32]*PlayerPlanet{}, //RawStone: map[uint32]*PlayerRawStone{}, @@ -523,8 +524,8 @@ func (this *PlayerManager) Unban(player *Player) { this.storeChanges(player) } -func (this *PlayerManager) Handler(modId, msgId uint16, handler MessageHandler) { - this.messageHandlers[util.Compose2uint16(modId, msgId)] = handler +func (this *PlayerManager) Handler(modId pb.ModId, msgId pb.MsgId, handler MessageHandler) { + this.messageHandlers[util.Compose2uint16(uint16(modId), uint16(msgId))] = handler } func (this *PlayerManager) Handle(player *Player, msg *net.Message) { diff --git a/servers/game/logic/player.go b/servers/game/logic/player.go index 6ea8704..568c863 100644 --- a/servers/game/logic/player.go +++ b/servers/game/logic/player.go @@ -74,8 +74,8 @@ type Player struct { Equip map[uint64]*PlayerEquip `bson:"equip"` //GiftPack map[uint32]*PlayerGiftPack `bson:"gift_pack"` Lineup map[uint64]*PlayerLineup `bson:"lineup"` - //Mail map[uint64]*PlayerMail `bson:"mail"` - Money map[uint32]*PlayerMoney `bson:"money"` + Mail map[uint64]*PlayerMail `bson:"mail"` + Money map[uint32]*PlayerMoney `bson:"money"` //MonthlyCard map[uint32]*PlayerMonthlyCard `bson:"monthly_card"` //Planet map[uint32]*PlayerPlanet `bson:"planet"` //RawStone map[uint32]*PlayerRawStone `bson:"raw_stone"` @@ -119,11 +119,11 @@ func (this *Player) Uid() uint64 { return this.RoleId } -func (this *Player) Send(modId, msgId uint16, msg interface{}) (err error) { +func (this *Player) Send(modId pb.ModId, msgId pb.MsgId, msg interface{}) (err error) { if this.conn == nil { return nil } - return this.conn.Send(modId, msgId, msg) + return this.conn.Send(uint16(modId), uint16(msgId), msg) } func (this *Player) TipNotice(err proto.TipError) error { @@ -142,12 +142,12 @@ func (this *Player) unlock() { func (this *Player) sync() { //Role module - _ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleProperty), this.BuildMsgRolePropertyAck()) - _ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleMoneyList), this.BuildMsgMoneyListAck()) - _ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleLineupList), this.BuildMsgLineupListAck()) + _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleProperty, this.BuildMsgRolePropertyAck()) + _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleMoneyList, this.BuildMsgMoneyListAck()) + _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleLineupList, this.BuildMsgLineupListAck()) //Level module - _ = this.Send(uint16(pb.ModId_ModuleLevel), uint16(pb.MsgId_ModLevelCopyStatusList), this.BuildMsgCopyStatusListAck()) + _ = this.Send(pb.ModId_ModuleLevel, pb.MsgId_ModLevelCopyStatusList, this.BuildMsgCopyStatusListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdCopySpeedStatusList, this.BuildMsgCopySpeedStatusListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetList, this.BuildMsgPlanetListAck()) //_ = this.Send(proto.ModIdLevel, proto.MsgIdPlanetRawStoneStatus, this.BuildMsgPlanetRawStoneStatusListAck()) @@ -157,8 +157,8 @@ func (this *Player) sync() { //_ = this.Send(proto.ModIdBattle, proto.MsgIdIdleBattleStatus, this.BuildMsgIdleBattleStatusAck()) //Hero module - _ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroList), this.BuildMsgHeroListAck()) - _ = this.Send(uint16(pb.ModId_ModuleHero), uint16(pb.MsgId_ModHeroBookList), this.BuildMsgHeroBookListAck()) + _ = this.Send(pb.ModId_ModuleHero, pb.MsgId_ModHeroList, this.BuildMsgHeroListAck()) + _ = this.Send(pb.ModId_ModuleHero, pb.MsgId_ModHeroBookList, this.BuildMsgHeroBookListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigComponentList, this.BuildMsgRigComponentListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigEquipList, this.BuildMsgRigEquipListAck()) //_ = this.Send(proto.ModIdRig, proto.MsgIdRigRemainsList, this.BuildMsgRigRemainsListAck()) @@ -171,12 +171,12 @@ func (this *Player) sync() { //_ = this.Send(proto.ModIdRig, proto.MsgIdRigWarshipList, this.BuildMsgWarshipListAck()) //Item module - _ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemList), this.BuildMsgItemListAck()) - _ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemEquipList), this.BuildMsgEquipListAck()) - _ = this.Send(uint16(pb.ModId_ModuleItem), uint16(pb.MsgId_ModItemTreasureList), this.BuildMsgTreasureListAck()) + _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemList, this.BuildMsgItemListAck()) + _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemEquipList, this.BuildMsgEquipListAck()) + _ = this.Send(pb.ModId_ModuleItem, pb.MsgId_ModItemTreasureList, this.BuildMsgTreasureListAck()) //Counter module - _ = this.Send(uint16(pb.ModId_ModuleCounter), uint16(pb.MsgId_ModCounterList), this.BuildMsgCounterListAck()) + _ = this.Send(pb.ModId_ModuleCounter, pb.MsgId_ModCounterList, this.BuildMsgCounterListAck()) ////Mail module //_ = this.Send(proto.ModIdMail, proto.MsgIdMailList, this.BuildMsgMailListAck()) @@ -297,7 +297,7 @@ func (this *Player) exit() { } func (this *Player) kick(message string) { - _ = this.Send(uint16(pb.ModId_ModuleLogin), uint16(pb.MsgId_ModLoginKickOut), &pb.KickOutAck{Message: message}) + _ = this.Send(pb.ModId_ModuleLogin, pb.MsgId_ModLoginKickOut, &pb.KickOutAck{Message: message}) this.exit() } @@ -377,7 +377,7 @@ func (this *Player) SaveArray(field string, index int, value interface{}) { this.SaveField(fmt.Sprint(field, ".", index), value) } -func (this *Player) SaveModel(model interface{}, fields ...string) { +func (this *Player) SaveModel(model interface{}) { key, err := this.modelKey(model) if err != nil { this.manager.logger.Error("Failed to get the key of the model that will be saved, ", err) @@ -387,12 +387,21 @@ func (this *Player) SaveModel(model interface{}, fields ...string) { this.SaveField(key, model) } -func (this *Player) WipeField(field string, value interface{}) { - this.wipe[field] = value +func (this *Player) SaveModelField(model interface{}, field string, value interface{}) { + key, err := this.modelKey(model) + if err != nil { + this.manager.logger.Error("Failed to get the key of the model that will be saved, ", err) + return + } + this.SaveField(fmt.Sprint(key, ".", field), value) } -func (this *Player) WipeArray(field string, index int, value interface{}) { - this.WipeField(fmt.Sprint(field, ".", index), value) +func (this *Player) WipeField(field string) { + this.wipe[field] = 1 +} + +func (this *Player) WipeArray(field string, index int) { + this.WipeField(fmt.Sprint(field, ".", index)) } func (this *Player) WipeModel(model interface{}) { @@ -402,5 +411,5 @@ func (this *Player) WipeModel(model interface{}) { return } - this.WipeField(key, model) + this.WipeField(key) } diff --git a/servers/game/logic/player_check_correct.go b/servers/game/logic/player_check_correct.go index f30fdf1..dc0c3ee 100644 --- a/servers/game/logic/player_check_correct.go +++ b/servers/game/logic/player_check_correct.go @@ -76,10 +76,10 @@ func (this *Player) checkCorrectModules(cur *GameTime) { this.Lineup = make(map[uint64]*PlayerLineup) this.SaveField("money", this.Lineup) } - //if this.Mail == nil { - // this.Mail = make(map[uint64]*PlayerMail) - // this.SaveField("mail", this.Mail) - //} + if this.Mail == nil { + this.Mail = make(map[uint64]*PlayerMail) + this.SaveField("mail", this.Mail) + } if this.Money == nil { this.Money = make(map[uint32]*PlayerMoney) this.SaveField("money", this.Money) @@ -222,20 +222,27 @@ func (this *Player) initLineup(cur *GameTime) { this.SaveModel(lineup) } -// func (this *Player) initMails(cur *GameTime) { -// var cfgTable = this.manager.tables.ServerCfg.Get("init_mails") -// if cfgTable == nil { -// return -// } -// -// itemIds, itemNums, err := util.SplitItemNums(cfgTable.Value1, cfgTable.Value2, 1) -// if err != nil { -// return -// } -// -// this.AddMail(proto.MailTypeNormal, proto.MailTitleSystem, proto.MailContentSystem, nil, itemIds, itemNums, cur.Timestamp) -// } -// +func (this *Player) initMails(cur *GameTime) { + var mails = this.manager.tables.ServerConfig.GetInitMails() + for i := range mails { + var titleId, contentId, itemIds, itemNums = this.manager.tables.ServerConfig.GetInitMail(i) + var items = make([][2]uint32, len(itemIds)) + for ii := range itemIds { + items[ii][0] = uint32(itemIds[ii]) + items[ii][1] = uint32(itemNums[ii]) + } + this.AddMail(util.RandomUid(), + pb.MailType_MailNormal, + util.IntegerToString(titleId), + util.IntegerToString(contentId), + util.Unix(), + 0, + nil, + items, + ) + } +} + // func (this *Player) initTasks(cur *GameTime) { // var cfgTable = this.manager.tables.ServerCfg.Get("init_tasks") // if cfgTable == nil { @@ -267,7 +274,7 @@ func (this *Player) checkCorrectFirstLogin(cur *GameTime) { this.initHeroes(cur) this.initItems(cur) this.initLineup(cur) - //this.initMails(cur) + this.initMails(cur) //this.initTasks(cur) this.initPower(cur) } diff --git a/servers/game/logic/player_check_refresh.go b/servers/game/logic/player_check_refresh.go index 8b3e9bf..5940637 100644 --- a/servers/game/logic/player_check_refresh.go +++ b/servers/game/logic/player_check_refresh.go @@ -32,7 +32,7 @@ func (this *Player) checkRecoveryPower(login bool, pre, cur *GameTime) { this.ChangeProperty(util.NewPair(pb.RolePropertyType_PowerNextTime, cur.Timestamp+int64(RolePowerCycle))) } - _ = this.Send(uint16(pb.ModId_ModuleRole), uint16(pb.MsgId_ModRoleMoneyChange), &pb.MoneyListAck{MoneyList: []*pb.Money{money.BuildMsgMoney()}}) + _ = this.Send(pb.ModId_ModuleRole, pb.MsgId_ModRoleMoneyChange, &pb.MoneyListAck{MoneyList: []*pb.Money{money.BuildMsgMoney()}}) } func (this *Player) checkAcrossTime(login bool, pre, cur *GameTime, handles ...func(login bool, pre, cur *GameTime) bool) bool {