资源整合,所有变更资源主动推送给客户端

This commit is contained in:
meixiongfeng 2022-07-14 15:53:08 +08:00
parent dd1ba19d30
commit 0a37601f1a
29 changed files with 236 additions and 109 deletions

View File

@ -26,9 +26,9 @@ type (
//查询用户背包多个物品数量 //查询用户背包多个物品数量
QueryItemsAmount(source *ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32) QueryItemsAmount(source *ModuleCallSource, uId string, itemid ...int32) (result map[int32]uint32)
///添加单个物品到背包 (可以加物品和减物品) ///添加单个物品到背包 (可以加物品和减物品)
AddItem(source *ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) AddItem(source *ModuleCallSource, uId string, itemid, addnum int32, bPush bool) (code pb.ErrorCode)
///添加多个物品到背包 (可以加物品和减物品) ///添加多个物品到背包 (可以加物品和减物品)
AddItems(source *ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) AddItems(source *ModuleCallSource, uId string, items map[int32]int32, bPush bool) (code pb.ErrorCode)
} }
//英雄 //英雄
@ -36,7 +36,7 @@ type (
//查询用户卡片数量 //查询用户卡片数量
QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32)
//创建新英雄 //创建新英雄
CreateHero(uid string, heroCfgId ...int32) error CreateHero(uid string, bPush bool, heroCfgId ...int32) error
// 获取英雄 // 获取英雄
// heroId 英雄ID // heroId 英雄ID
@ -55,8 +55,8 @@ type (
GetUserSession(uid string) *pb.CacheUser GetUserSession(uid string) *pb.CacheUser
//查询用户属性值 例如 金币 经验 //查询用户属性值 例如 金币 经验
QueryAttributeValue(uid string, attr string) (value int32) QueryAttributeValue(uid string, attr string) (value int32)
//添加/减少属性值 //添加/减少属性值 第四个参数控制是否推送给前端
AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) AddAttributeValue(uid string, attr string, add int32, bPush bool) (code pb.ErrorCode)
} }
//武器模块 //武器模块
IEquipment interface { IEquipment interface {
@ -65,7 +65,7 @@ type (
//查询服务资源数量 参数武器配置id //查询服务资源数量 参数武器配置id
QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32) QueryEquipmentAmount(source *ModuleCallSource, uid string, equipmentId int32) (amount uint32)
//添加新武器 //添加新武器
AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) AddNewEquipments(source *ModuleCallSource, uid string, cIds map[int32]uint32, bPush bool) (code pb.ErrorCode)
} }
IStory interface { IStory interface {
// 修改章节信息 // 修改章节信息

View File

@ -71,7 +71,7 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgrade
} }
} }
if issucc { if issucc {
if code = this.module.CheckConsumeRes(session.GetUserId(), intensify.Need); code != pb.ErrorCode_Success { if code = this.module.CheckConsumeRes(session.GetUserId(), intensify.Need, true); code != pb.ErrorCode_Success {
return return
} }
modifyequipments = make([]*pb.DB_Equipment, 0) modifyequipments = make([]*pb.DB_Equipment, 0)

View File

@ -80,7 +80,7 @@ func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid s
} }
//添加武器 //添加武器
func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32) (code pb.ErrorCode) { func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid string, cIds map[int32]uint32, bPush bool) (code pb.ErrorCode) {
var ( var (
err error err error
change []*pb.DB_Equipment change []*pb.DB_Equipment
@ -90,7 +90,7 @@ func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid strin
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return
} }
if len(change) > 0 { if len(change) > 0 && bPush {
this.equipmentsChangePush(uid, change) this.equipmentsChangePush(uid, change)
} }
return return

View File

@ -102,7 +102,7 @@ func Test_Module_AddNewEquipments(t *testing.T) {
Module: "Test", Module: "Test",
FuncName: "Test_Module", FuncName: "Test_Module",
Describe: "摸底测试", Describe: "摸底测试",
}, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}) }, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}, true)
log.Debugf("Test_Module Code:%d", code) log.Debugf("Test_Module Code:%d", code)
} }

View File

@ -54,7 +54,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
return return
} }
// 消耗校验 // 消耗校验
code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed) code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed, true)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }

View File

@ -27,7 +27,7 @@ func (this *apiComp) Chouka(session comm.IUserSession, req *pb.HeroChoukaReq) (c
}() }()
heroCfgIds := req.HeroIds heroCfgIds := req.HeroIds
if err := this.module.modelHero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil { if err := this.module.modelHero.createMultiHero(session.GetUserId(), false, heroCfgIds...); err != nil {
code = pb.ErrorCode_HeroCreate code = pb.ErrorCode_HeroCreate
return return
} }

View File

@ -93,7 +93,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
return return
} }
// 消耗校验 // 消耗校验
code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need) code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need, true)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }
@ -117,7 +117,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
return return
} }
for i := 0; i < int(v.N); i++ { // 有多少张加多少次 for i := 0; i < int(v.N); i++ { // 有多少张加多少次
this.module.modelHero.createOneHero(session.GetUserId(), int32(value)) this.module.modelHero.createOneHero(session.GetUserId(), int32(value), true)
} }
} }
} }

View File

@ -56,7 +56,7 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson
return return
} }
// 消耗校验 // 消耗校验
code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var) code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var, true)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }

View File

@ -113,7 +113,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
} }
// 消耗道具 // 消耗道具
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold) // 减少金币 code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), "gold", -target.Gold, true) // 减少金币
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
this.module.Errorf("cost gold failed ,count = %d", target.Gold) this.module.Errorf("cost gold failed ,count = %d", target.Gold)
code = pb.ErrorCode_GoldNoEnough code = pb.ErrorCode_GoldNoEnough

View File

@ -129,7 +129,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
} }
// 消耗道具 // 消耗道具
for _, v := range costRes { for _, v := range costRes {
code = this.module.CheckConsumeRes(session.GetUserId(), v) code = this.module.CheckConsumeRes(session.GetUserId(), v, true)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }

View File

@ -70,7 +70,7 @@ func TestMain(m *testing.M) {
//创建一个英雄s //创建一个英雄s
func TestCreateOneHero(t *testing.T) { func TestCreateOneHero(t *testing.T) {
err := module.modelHero.createOneHero("u1", 25001) err := module.modelHero.createOneHero("u1", 25001, true)
fmt.Println(err) fmt.Println(err)
} }

View File

@ -85,7 +85,7 @@ func (this *ModelHero) initHeroSkill(hero *pb.DBHero) []*pb.SkillData {
} }
//创建一个指定的英雄 //创建一个指定的英雄
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) { func (this *ModelHero) createOneHero(uid string, heroCfgId int32, bPush bool) (err error) {
hero := this.initHero(uid, heroCfgId) hero := this.initHero(uid, heroCfgId)
if hero != nil { if hero != nil {
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
@ -93,16 +93,24 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
return return
} }
} }
// 创建英雄成功 向客户端推送数据
if bPush {
if session, ok := this.moduleHero.GetUserSession(uid); ok {
session.SendMsg(string(this.moduleHero.GetType()), "addhero", &pb.AddNewHeroPush{Hero: hero})
err = session.Push()
}
}
return nil return nil
} }
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID //创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error { func (this *ModelHero) createMultiHero(uid string, bPush bool, heroCfgIds ...int32) error {
heroes := this.moduleHero.modelHero.getHeroList(uid) heroes := this.moduleHero.modelHero.getHeroList(uid)
if len(heroes) == 0 { if len(heroes) == 0 {
for _, v := range heroCfgIds { for _, v := range heroCfgIds {
if err := this.createOneHero(uid, v); err != nil { if err := this.createOneHero(uid, v, bPush); err != nil {
return err return err
} }
} }
@ -126,7 +134,7 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
return err return err
} }
} else { } else {
if err := this.createOneHero(uid, v); err != nil { if err := this.createOneHero(uid, v, bPush); err != nil {
return err return err
} }
} }

View File

@ -39,8 +39,8 @@ func (this *Hero) OnInstallComp() {
} }
//创建新英雄 //创建新英雄
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error { func (this *Hero) CreateHero(uid string, bPush bool, heroCfgId ...int32) error {
return this.modelHero.createMultiHero(uid, heroCfgId...) return this.modelHero.createMultiHero(uid, bPush, heroCfgId...)
} }
//获取英雄 //获取英雄

View File

@ -62,7 +62,7 @@ func (this *Items) QueryItemsAmount(source *comm.ModuleCallSource, uId string, i
} }
///添加单个物品到背包 (可以加物品和减物品) ///添加单个物品到背包 (可以加物品和减物品)
func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32) (code pb.ErrorCode) { func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, addnum int32, bPush bool) (code pb.ErrorCode) {
var ( var (
err error err error
change []*pb.DB_UserItemData change []*pb.DB_UserItemData
@ -79,12 +79,15 @@ func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, ad
} }
return return
} }
this.itemsChangePush(uId, change) //推送道具背包变化 if bPush {
this.itemsChangePush(uId, change) //推送道具背包变化
}
return return
} }
///添加多个物品到背包 (可以加物品和减物品) ///添加多个物品到背包 (可以加物品和减物品)
func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32) (code pb.ErrorCode) { func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map[int32]int32, bPush bool) (code pb.ErrorCode) {
var ( var (
err error err error
change []*pb.DB_UserItemData change []*pb.DB_UserItemData
@ -102,7 +105,7 @@ func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map
} }
return return
} }
if len(change) > 0 { if len(change) > 0 && bPush {
this.itemsChangePush(uId, change) //推送道具背包变化 this.itemsChangePush(uId, change) //推送道具背包变化
} }
return return

View File

@ -94,6 +94,6 @@ func Test_Modules_AddItems(t *testing.T) {
Module: "Test", Module: "Test",
FuncName: "Test_Modules_AddItems", FuncName: "Test_Modules_AddItems",
Describe: "测试模块接口", Describe: "测试模块接口",
}, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}) }, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}, true)
log.Debugf("Test_Modules_AddItems code:%v", code) log.Debugf("Test_Modules_AddItems code:%v", code)
} }

View File

@ -46,7 +46,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma
} }
res = append(res, d) res = append(res, d)
} }
code = this.module.api.module.CheckConsumeRes(session.GetUserId(), res) // 领取附件 code = this.module.api.module.CheckConsumeRes(session.GetUserId(), res, true) // 领取附件
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
// 修改状态 // 修改状态
this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID) this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID)

View File

@ -36,17 +36,18 @@ func (this *Mail) OnInstallComp() {
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
} }
// mail := &pb.DBMailData{
// ObjId: primitive.NewObjectID().Hex(),
// Uid: uId,
// Title: "系统邮件",
// Contex: "恭喜获得专属礼包一份",
// CreateTime: uint64(time.Now().Unix()),
// DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件
// Check: false,
// Reward: false,
// }
func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool { func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool {
// mail := &pb.DBMailData{
// ObjId: primitive.NewObjectID().Hex(),
// Uid: uId,
// Title: "系统邮件",
// Contex: "恭喜获得专属礼包一份",
// CreateTime: uint64(time.Now().Unix()),
// DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件
// Check: false,
// Reward: false,
// }
if mail == nil { if mail == nil {
return false return false
} }
@ -55,12 +56,16 @@ func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool {
this.ModuleBase.Errorf("create mail failed") this.ModuleBase.Errorf("create mail failed")
} }
// 通知玩家 // 通知玩家
var _cache = &pb.CacheUser{} this.AddNewMailPush(uId, mail)
err = this.modelMail.MCompModel.Get(uId, _cache)
if err == nil {
return false
}
this.SendMsgToUser(string(this.GetType()), "newmail", mail, _cache)
return true return true
} }
// 获得新邮件 推送给玩家
func (this *Mail) AddNewMailPush(uid string, mail *pb.DBMailData) (err error) {
if session, ok := this.GetUserSession(uid); ok {
session.SendMsg(string(this.GetType()), "newmail", &pb.MailGetNewMailPush{Mail: mail})
err = session.Push()
}
return
}

View File

@ -137,7 +137,7 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
} }
//校验消耗资源 //校验消耗资源
func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) { func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
var ( var (
err error err error
resID int resID int
@ -191,10 +191,10 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
for _, v := range res { for _, v := range res {
if v.A == comm.AttrType { //用户属性资源 if v.A == comm.AttrType { //用户属性资源
this.ModuleUser.AddAttributeValue(uid, v.T, -1*v.N) this.ModuleUser.AddAttributeValue(uid, v.T, -1*v.N, bPush)
} else if v.A == comm.ItemType { //道具资源 } else if v.A == comm.ItemType { //道具资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N) this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N, bPush)
} }
// else if v.A == comm.HeroType { //卡片资源 // else if v.A == comm.HeroType { //卡片资源
// resID, _ = strconv.Atoi(v.T) // resID, _ = strconv.Atoi(v.T)
@ -210,7 +210,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
} }
//发放资源 //发放资源
func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.ErrorCode) { func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn, bPush bool) (code pb.ErrorCode) {
var ( var (
resID int resID int
) )
@ -221,20 +221,20 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.Er
} }
for _, v := range res { for _, v := range res {
if v.A == comm.AttrType { //用户属性资源 if v.A == comm.AttrType { //用户属性资源
code = this.ModuleUser.AddAttributeValue(uid, v.T, v.N) code = this.ModuleUser.AddAttributeValue(uid, v.T, v.N, bPush)
} else if v.A == comm.ItemType { //道具资源 } else if v.A == comm.ItemType { //道具资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
code = this.ModuleItems.AddItem(source, uid, int32(resID), v.N) code = this.ModuleItems.AddItem(source, uid, int32(resID), v.N, bPush)
} else if v.A == comm.HeroType { //卡片资源 } else if v.A == comm.HeroType { //卡片资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
err := this.ModuleHero.CreateHero(uid, int32(resID), v.N) err := this.ModuleHero.CreateHero(uid, bPush, int32(resID))
if err != nil { if err != nil {
code = pb.ErrorCode_HeroMaxCount code = pb.ErrorCode_HeroMaxCount
} }
} else if v.A == comm.EquipmentType { } else if v.A == comm.EquipmentType {
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
code = this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}) code = this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}, bPush)
} }
} }
return return

View File

@ -45,10 +45,10 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.ShopBuyReq) (code pb
} }
} }
if code = this.module.CheckConsumeRes(session.GetUserId(), conf.Need); code != pb.ErrorCode_Success { if code = this.module.CheckConsumeRes(session.GetUserId(), conf.Need, true); code != pb.ErrorCode_Success {
return return
} }
if code = this.module.DispenseRes(session.GetUserId(), conf.Iteminfo); code != pb.ErrorCode_Success { if code = this.module.DispenseRes(session.GetUserId(), conf.Iteminfo, true); code != pb.ErrorCode_Success {
return return
} }
shopitem.BuyNum++ shopitem.BuyNum++

View File

@ -94,7 +94,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
} }
if req.IsManualRefresh && shopconf.Rtype == 1 { //可以手动刷新 if req.IsManualRefresh && shopconf.Rtype == 1 { //可以手动刷新
if code = this.module.CheckConsumeRes(session.GetUserId(), shopconf.Rneed); code != pb.ErrorCode_Success { if code = this.module.CheckConsumeRes(session.GetUserId(), shopconf.Rneed, true); code != pb.ErrorCode_Success {
return return
} }
var _items []*cfg.Game_shopitemData var _items []*cfg.Game_shopitemData

View File

@ -50,6 +50,6 @@ func (this *apiComp) ActiveReceive(session comm.IUserSession, req *pb.TaskActive
} }
//派发奖励 //派发奖励
code = this.moduleTask.DispenseRes(session.GetUserId(), conf.Reword) code = this.moduleTask.DispenseRes(session.GetUserId(), conf.Reword, true)
return return
} }

View File

@ -38,7 +38,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
return return
} }
//奖励 //奖励
if code = this.moduleTask.CheckConsumeRes(session.GetUserId(), conf.Reword); code != pb.ErrorCode_Success { if code = this.moduleTask.CheckConsumeRes(session.GetUserId(), conf.Reword, true); code != pb.ErrorCode_Success {
return return
} }

View File

@ -69,7 +69,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
//初始化英雄卡 //初始化英雄卡
if val := this.module.configure.GetGlobalConf("init_hero"); val != "" { if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
defaultHero := utils.TrInt32(val) defaultHero := utils.TrInt32(val)
err = this.hero.CreateHero(session.GetUserId(), defaultHero...) err = this.hero.CreateHero(session.GetUserId(), true, defaultHero...)
if err != nil { if err != nil {
code = pb.ErrorCode_HeroInitCreat code = pb.ErrorCode_HeroInitCreat
return return

View File

@ -41,7 +41,7 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c
N: req.Res.N, N: req.Res.N,
} }
res = append(res, atn) res = append(res, atn)
code = this.module.DispenseRes(session.GetUserId(), res) code = this.module.DispenseRes(session.GetUserId(), res, true)
rsp.Res = req.Res rsp.Res = req.Res
return return
} }

View File

@ -74,7 +74,7 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
} }
//用户资源 //用户资源
func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) { func (this *User) AddAttributeValue(uid string, attr string, add int32, bPush bool) (code pb.ErrorCode) {
if add == 0 { if add == 0 {
log.Errorf("attr no changed,uid: %s attr: %s add: %d", uid, attr, add) log.Errorf("attr no changed,uid: %s attr: %s add: %d", uid, attr, add)
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
@ -86,6 +86,13 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
return return
} }
_change := &pb.UserResChangePush{
Gold: user.Gold,
Exp: user.Exp,
Lv: user.Lv,
Vip: user.Vip,
Diamond: user.Diamond,
}
update := make(map[string]interface{}) update := make(map[string]interface{})
switch attr { switch attr {
case comm.ResGold: case comm.ResGold:
@ -95,6 +102,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
return return
} }
} }
_change.Gold += add
update[comm.ResGold] = user.Gold + add update[comm.ResGold] = user.Gold + add
case comm.ResExp: case comm.ResExp:
if add < 0 { if add < 0 {
@ -103,6 +111,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
return return
} }
} }
_change.Exp += add
update[comm.ResExp] = user.Exp + add update[comm.ResExp] = user.Exp + add
case comm.ResDiamond: case comm.ResDiamond:
if add < 0 { if add < 0 {
@ -111,6 +120,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
return return
} }
} }
_change.Diamond += add
update[comm.ResDiamond] = user.Diamond + add update[comm.ResDiamond] = user.Diamond + add
} }
@ -127,6 +137,18 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
if err != nil { if err != nil {
this.SendMsgToUser(string(this.GetType()), "addres", data, _cache) this.SendMsgToUser(string(this.GetType()), "addres", data, _cache)
} }
if bPush {
this.UserChangePush(uid, _change) // 推送玩家数据变化
}
return return
} }
//推送玩家账号信息变化消息
func (this *User) UserChangePush(uid string, resChange *pb.UserResChangePush) (err error) {
if session, ok := this.ModuleBase.GetUserSession(uid); ok {
session.SendMsg(string(this.GetType()), "userchange", resChange)
err = session.Push()
}
return
}

View File

@ -1323,6 +1323,54 @@ func (x *HeroLockResp) GetHero() *DBHero {
return nil return nil
} }
// 增加新英雄推送
type AddNewHeroPush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Hero *DBHero `protobuf:"bytes,1,opt,name=hero,proto3" json:"hero"` // 英雄对象
}
func (x *AddNewHeroPush) Reset() {
*x = AddNewHeroPush{}
if protoimpl.UnsafeEnabled {
mi := &file_hero_hero_msg_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AddNewHeroPush) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddNewHeroPush) ProtoMessage() {}
func (x *AddNewHeroPush) ProtoReflect() protoreflect.Message {
mi := &file_hero_hero_msg_proto_msgTypes[25]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AddNewHeroPush.ProtoReflect.Descriptor instead.
func (*AddNewHeroPush) Descriptor() ([]byte, []int) {
return file_hero_hero_msg_proto_rawDescGZIP(), []int{25}
}
func (x *AddNewHeroPush) GetHero() *DBHero {
if x != nil {
return x.Hero
}
return nil
}
var File_hero_hero_msg_proto protoreflect.FileDescriptor var File_hero_hero_msg_proto protoreflect.FileDescriptor
var file_hero_hero_msg_proto_rawDesc = []byte{ var file_hero_hero_msg_proto_rawDesc = []byte{
@ -1444,8 +1492,11 @@ var file_hero_hero_msg_proto_rawDesc = []byte{
0x65, 0x72, 0x6f, 0x69, 0x64, 0x22, 0x2b, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x6f, 0x63, 0x65, 0x72, 0x6f, 0x69, 0x64, 0x22, 0x2b, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x6f, 0x63,
0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65,
0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x72, 0x6f, 0x22, 0x2d, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x4e, 0x65, 0x77, 0x48, 0x65, 0x72, 0x6f,
0x6f, 0x33, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, 0x72,
0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (
@ -1460,7 +1511,7 @@ func file_hero_hero_msg_proto_rawDescGZIP() []byte {
return file_hero_hero_msg_proto_rawDescData return file_hero_hero_msg_proto_rawDescData
} }
var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 27) var file_hero_hero_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 28)
var file_hero_hero_msg_proto_goTypes = []interface{}{ var file_hero_hero_msg_proto_goTypes = []interface{}{
(*HeroInfoReq)(nil), // 0: HeroInfoReq (*HeroInfoReq)(nil), // 0: HeroInfoReq
(*HeroInfoResp)(nil), // 1: HeroInfoResp (*HeroInfoResp)(nil), // 1: HeroInfoResp
@ -1487,32 +1538,34 @@ var file_hero_hero_msg_proto_goTypes = []interface{}{
(*HeroProperty)(nil), // 22: HeroProperty (*HeroProperty)(nil), // 22: HeroProperty
(*HeroLockReq)(nil), // 23: HeroLockReq (*HeroLockReq)(nil), // 23: HeroLockReq
(*HeroLockResp)(nil), // 24: HeroLockResp (*HeroLockResp)(nil), // 24: HeroLockResp
nil, // 25: HeroProperty.PropertyEntry (*AddNewHeroPush)(nil), // 25: AddNewHeroPush
nil, // 26: HeroProperty.AddPropertyEntry nil, // 26: HeroProperty.PropertyEntry
(*DBHero)(nil), // 27: DBHero nil, // 27: HeroProperty.AddPropertyEntry
(*DBHero)(nil), // 28: DBHero
} }
var file_hero_hero_msg_proto_depIdxs = []int32{ var file_hero_hero_msg_proto_depIdxs = []int32{
27, // 0: HeroInfoResp.base:type_name -> DBHero 28, // 0: HeroInfoResp.base:type_name -> DBHero
27, // 1: HeroListResp.list:type_name -> DBHero 28, // 1: HeroListResp.list:type_name -> DBHero
27, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero 28, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero
7, // 3: HeroStrengthenUpStarReq.hero:type_name -> CostCardData 7, // 3: HeroStrengthenUpStarReq.hero:type_name -> CostCardData
7, // 4: HeroStrengthenUpStarReq.heroRace:type_name -> CostCardData 7, // 4: HeroStrengthenUpStarReq.heroRace:type_name -> CostCardData
27, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero 28, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero
27, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero 28, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero
27, // 7: HeroResonanceResp.hero:type_name -> DBHero 28, // 7: HeroResonanceResp.hero:type_name -> DBHero
27, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero 28, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero
27, // 9: HeroResonanceResetResp.hero:type_name -> DBHero 28, // 9: HeroResonanceResetResp.hero:type_name -> DBHero
27, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero 28, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero
27, // 11: HeroAwakenResp.hero:type_name -> DBHero 28, // 11: HeroAwakenResp.hero:type_name -> DBHero
27, // 12: HeroChoukaResp.heroes:type_name -> DBHero 28, // 12: HeroChoukaResp.heroes:type_name -> DBHero
25, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry 26, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry
26, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry 27, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry
27, // 15: HeroLockResp.hero:type_name -> DBHero 28, // 15: HeroLockResp.hero:type_name -> DBHero
16, // [16:16] is the sub-list for method output_type 28, // 16: AddNewHeroPush.hero:type_name -> DBHero
16, // [16:16] is the sub-list for method input_type 17, // [17:17] is the sub-list for method output_type
16, // [16:16] is the sub-list for extension type_name 17, // [17:17] is the sub-list for method input_type
16, // [16:16] is the sub-list for extension extendee 17, // [17:17] is the sub-list for extension type_name
0, // [0:16] is the sub-list for field type_name 17, // [17:17] is the sub-list for extension extendee
0, // [0:17] is the sub-list for field type_name
} }
func init() { file_hero_hero_msg_proto_init() } func init() { file_hero_hero_msg_proto_init() }
@ -1822,6 +1875,18 @@ func file_hero_hero_msg_proto_init() {
return nil return nil
} }
} }
file_hero_hero_msg_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AddNewHeroPush); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -1829,7 +1894,7 @@ func file_hero_hero_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_hero_hero_msg_proto_rawDesc, RawDescriptor: file_hero_hero_msg_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 27, NumMessages: 28,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

View File

@ -125,3 +125,8 @@ message HeroLockReq{
message HeroLockResp{ message HeroLockResp{
DBHero hero = 1; // DBHero hero = 1; //
} }
//
message AddNewHeroPush{
DBHero hero = 1; //
}

View File

@ -41,7 +41,9 @@ message UserAddResResp {
// //
message UserResChangePush{ message UserResChangePush{
int32 changeType = 1; // 0 1 int32 gold = 1; //@go_tags(`bson:"gold"`)
int32 value = 2; int32 exp = 2; //@go_tags(`bson:"exp"`)
string resName = 3; // int32 lv = 3; //@go_tags(`bson:"lv"`)
int32 vip = 4; //@go_tags(`bson:"vip"`) vip
int32 diamond = 5; //@go_tags(`bson:"diamond"`)
} }

View File

@ -467,9 +467,11 @@ type UserResChangePush struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
ChangeType int32 `protobuf:"varint,1,opt,name=changeType,proto3" json:"changeType"` // 变化类型 0 增加 1 减少 Gold int32 `protobuf:"varint,1,opt,name=gold,proto3" json:"gold" bson:"gold"` //金币
Value int32 `protobuf:"varint,2,opt,name=value,proto3" json:"value"` Exp int32 `protobuf:"varint,2,opt,name=exp,proto3" json:"exp" bson:"exp"` //经验
ResName string `protobuf:"bytes,3,opt,name=resName,proto3" json:"resName"` // 资源名称 Lv int32 `protobuf:"varint,3,opt,name=lv,proto3" json:"lv" bson:"lv"` //等级
Vip int32 `protobuf:"varint,4,opt,name=vip,proto3" json:"vip" bson:"vip"` // vip
Diamond int32 `protobuf:"varint,5,opt,name=diamond,proto3" json:"diamond" bson:"diamond"` // 钻石
} }
func (x *UserResChangePush) Reset() { func (x *UserResChangePush) Reset() {
@ -504,25 +506,39 @@ func (*UserResChangePush) Descriptor() ([]byte, []int) {
return file_user_user_msg_proto_rawDescGZIP(), []int{9} return file_user_user_msg_proto_rawDescGZIP(), []int{9}
} }
func (x *UserResChangePush) GetChangeType() int32 { func (x *UserResChangePush) GetGold() int32 {
if x != nil { if x != nil {
return x.ChangeType return x.Gold
} }
return 0 return 0
} }
func (x *UserResChangePush) GetValue() int32 { func (x *UserResChangePush) GetExp() int32 {
if x != nil { if x != nil {
return x.Value return x.Exp
} }
return 0 return 0
} }
func (x *UserResChangePush) GetResName() string { func (x *UserResChangePush) GetLv() int32 {
if x != nil { if x != nil {
return x.ResName return x.Lv
} }
return "" return 0
}
func (x *UserResChangePush) GetVip() int32 {
if x != nil {
return x.Vip
}
return 0
}
func (x *UserResChangePush) GetDiamond() int32 {
if x != nil {
return x.Diamond
}
return 0
} }
var File_user_user_msg_proto protoreflect.FileDescriptor var File_user_user_msg_proto protoreflect.FileDescriptor
@ -560,15 +576,16 @@ var file_user_user_msg_proto_rawDesc = []byte{
0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x2f, 0x0a, 0x0e, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x2f, 0x0a, 0x0e,
0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d,
0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73,
0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x63, 0x0a, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x75, 0x0a,
0x11, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x11, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75,
0x73, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x54, 0x79, 0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20,
0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x78, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x03,
0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x4e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x69, 0x70, 0x18,
0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x4e, 0x61, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x69,
0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x61, 0x6d, 0x6f, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x69, 0x61,
0x6f, 0x33, 0x6d, 0x6f, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (