资源整合,所有变更资源主动推送给客户端
This commit is contained in:
parent
dd1ba19d30
commit
0a37601f1a
@ -26,9 +26,9 @@ type (
|
||||
//查询用户背包多个物品数量
|
||||
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)
|
||||
//创建新英雄
|
||||
CreateHero(uid string, heroCfgId ...int32) error
|
||||
CreateHero(uid string, bPush bool, heroCfgId ...int32) error
|
||||
|
||||
// 获取英雄
|
||||
// heroId 英雄ID
|
||||
@ -55,8 +55,8 @@ type (
|
||||
GetUserSession(uid string) *pb.CacheUser
|
||||
//查询用户属性值 例如 金币 经验
|
||||
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 {
|
||||
@ -65,7 +65,7 @@ type (
|
||||
//查询服务资源数量 参数武器配置id
|
||||
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 {
|
||||
// 修改章节信息
|
||||
|
@ -71,7 +71,7 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.EquipmentUpgrade
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
modifyequipments = make([]*pb.DB_Equipment, 0)
|
||||
|
@ -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 (
|
||||
err error
|
||||
change []*pb.DB_Equipment
|
||||
@ -90,7 +90,7 @@ func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, uid strin
|
||||
code = pb.ErrorCode_SystemError
|
||||
return
|
||||
}
|
||||
if len(change) > 0 {
|
||||
if len(change) > 0 && bPush {
|
||||
this.equipmentsChangePush(uid, change)
|
||||
}
|
||||
return
|
||||
|
@ -102,7 +102,7 @@ func Test_Module_AddNewEquipments(t *testing.T) {
|
||||
Module: "Test",
|
||||
FuncName: "Test_Module",
|
||||
Describe: "摸底测试",
|
||||
}, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1})
|
||||
}, "0_62b16dda909b2f8faeff788d", map[int32]uint32{10001: 1}, true)
|
||||
log.Debugf("Test_Module Code:%d", code)
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
|
||||
return
|
||||
}
|
||||
// 消耗校验
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed)
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), awakenData.Phaseneed, true)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func (this *apiComp) Chouka(session comm.IUserSession, req *pb.HeroChoukaReq) (c
|
||||
}()
|
||||
|
||||
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
|
||||
return
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
||||
return
|
||||
}
|
||||
// 消耗校验
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need)
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), resonConfig.Need, true)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
@ -117,7 +117,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson
|
||||
return
|
||||
}
|
||||
// 消耗校验
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var)
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), _costConfig.Var, true)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
@ -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 {
|
||||
this.module.Errorf("cost gold failed ,count = %d", target.Gold)
|
||||
code = pb.ErrorCode_GoldNoEnough
|
||||
|
@ -129,7 +129,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
||||
}
|
||||
// 消耗道具
|
||||
for _, v := range costRes {
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), v)
|
||||
code = this.module.CheckConsumeRes(session.GetUserId(), v, true)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
//创建一个英雄s
|
||||
func TestCreateOneHero(t *testing.T) {
|
||||
err := module.modelHero.createOneHero("u1", 25001)
|
||||
err := module.modelHero.createOneHero("u1", 25001, true)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
if hero != 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
|
||||
}
|
||||
}
|
||||
// 创建英雄成功 向客户端推送数据
|
||||
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
|
||||
}
|
||||
|
||||
//创建多个指定的英雄 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)
|
||||
|
||||
if len(heroes) == 0 {
|
||||
for _, v := range heroCfgIds {
|
||||
if err := this.createOneHero(uid, v); err != nil {
|
||||
if err := this.createOneHero(uid, v, bPush); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -126,7 +134,7 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := this.createOneHero(uid, v); err != nil {
|
||||
if err := this.createOneHero(uid, v, bPush); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ func (this *Hero) OnInstallComp() {
|
||||
}
|
||||
|
||||
//创建新英雄
|
||||
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
|
||||
return this.modelHero.createMultiHero(uid, heroCfgId...)
|
||||
func (this *Hero) CreateHero(uid string, bPush bool, heroCfgId ...int32) error {
|
||||
return this.modelHero.createMultiHero(uid, bPush, heroCfgId...)
|
||||
}
|
||||
|
||||
//获取英雄
|
||||
|
@ -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 (
|
||||
err error
|
||||
change []*pb.DB_UserItemData
|
||||
@ -79,12 +79,15 @@ func (this *Items) AddItem(source *comm.ModuleCallSource, uId string, itemid, ad
|
||||
}
|
||||
return
|
||||
}
|
||||
if bPush {
|
||||
this.itemsChangePush(uId, change) //推送道具背包变化
|
||||
}
|
||||
|
||||
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 (
|
||||
err error
|
||||
change []*pb.DB_UserItemData
|
||||
@ -102,7 +105,7 @@ func (this *Items) AddItems(source *comm.ModuleCallSource, uId string, items map
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(change) > 0 {
|
||||
if len(change) > 0 && bPush {
|
||||
this.itemsChangePush(uId, change) //推送道具背包变化
|
||||
}
|
||||
return
|
||||
|
@ -94,6 +94,6 @@ func Test_Modules_AddItems(t *testing.T) {
|
||||
Module: "Test",
|
||||
FuncName: "Test_Modules_AddItems",
|
||||
Describe: "测试模块接口",
|
||||
}, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000})
|
||||
}, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}, true)
|
||||
log.Debugf("Test_Modules_AddItems code:%v", code)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.Ma
|
||||
}
|
||||
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 {
|
||||
// 修改状态
|
||||
this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID)
|
||||
|
@ -36,17 +36,18 @@ func (this *Mail) OnInstallComp() {
|
||||
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 {
|
||||
// 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 {
|
||||
return false
|
||||
}
|
||||
@ -55,12 +56,16 @@ func (this *Mail) CreateNewMail(uId string, mail *pb.DBMailData) bool {
|
||||
this.ModuleBase.Errorf("create mail failed")
|
||||
}
|
||||
// 通知玩家
|
||||
var _cache = &pb.CacheUser{}
|
||||
err = this.modelMail.MCompModel.Get(uId, _cache)
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
this.AddNewMailPush(uId, mail)
|
||||
|
||||
this.SendMsgToUser(string(this.GetType()), "newmail", mail, _cache)
|
||||
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
|
||||
}
|
||||
|
@ -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 (
|
||||
err error
|
||||
resID int
|
||||
@ -191,10 +191,10 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
|
||||
|
||||
for _, v := range res {
|
||||
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 { //道具资源
|
||||
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 { //卡片资源
|
||||
// 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 (
|
||||
resID int
|
||||
)
|
||||
@ -221,20 +221,20 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.Er
|
||||
}
|
||||
for _, v := range res {
|
||||
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 { //道具资源
|
||||
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 { //卡片资源
|
||||
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 {
|
||||
code = pb.ErrorCode_HeroMaxCount
|
||||
}
|
||||
} else if v.A == comm.EquipmentType {
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
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
|
||||
}
|
||||
shopitem.BuyNum++
|
||||
|
@ -94,7 +94,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
var _items []*cfg.Game_shopitemData
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq)
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
|
||||
//初始化英雄卡
|
||||
if val := this.module.configure.GetGlobalConf("init_hero"); val != "" {
|
||||
defaultHero := utils.TrInt32(val)
|
||||
err = this.hero.CreateHero(session.GetUserId(), defaultHero...)
|
||||
err = this.hero.CreateHero(session.GetUserId(), true, defaultHero...)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_HeroInitCreat
|
||||
return
|
||||
|
@ -41,7 +41,7 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c
|
||||
N: req.Res.N,
|
||||
}
|
||||
res = append(res, atn)
|
||||
code = this.module.DispenseRes(session.GetUserId(), res)
|
||||
code = this.module.DispenseRes(session.GetUserId(), res, true)
|
||||
rsp.Res = req.Res
|
||||
return
|
||||
}
|
||||
|
@ -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 {
|
||||
log.Errorf("attr no changed,uid: %s attr: %s add: %d", uid, attr, add)
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
@ -86,6 +86,13 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
|
||||
return
|
||||
}
|
||||
|
||||
_change := &pb.UserResChangePush{
|
||||
Gold: user.Gold,
|
||||
Exp: user.Exp,
|
||||
Lv: user.Lv,
|
||||
Vip: user.Vip,
|
||||
Diamond: user.Diamond,
|
||||
}
|
||||
update := make(map[string]interface{})
|
||||
switch attr {
|
||||
case comm.ResGold:
|
||||
@ -95,6 +102,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.Gold += add
|
||||
update[comm.ResGold] = user.Gold + add
|
||||
case comm.ResExp:
|
||||
if add < 0 {
|
||||
@ -103,6 +111,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.Exp += add
|
||||
update[comm.ResExp] = user.Exp + add
|
||||
case comm.ResDiamond:
|
||||
if add < 0 {
|
||||
@ -111,6 +120,7 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb
|
||||
return
|
||||
}
|
||||
}
|
||||
_change.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 {
|
||||
this.SendMsgToUser(string(this.GetType()), "addres", data, _cache)
|
||||
}
|
||||
if bPush {
|
||||
this.UserChangePush(uid, _change) // 推送玩家数据变化
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -1323,6 +1323,54 @@ func (x *HeroLockResp) GetHero() *DBHero {
|
||||
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_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,
|
||||
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,
|
||||
0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
0x72, 0x6f, 0x22, 0x2d, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x4e, 0x65, 0x77, 0x48, 0x65, 0x72, 0x6f,
|
||||
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 (
|
||||
@ -1460,7 +1511,7 @@ func file_hero_hero_msg_proto_rawDescGZIP() []byte {
|
||||
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{}{
|
||||
(*HeroInfoReq)(nil), // 0: HeroInfoReq
|
||||
(*HeroInfoResp)(nil), // 1: HeroInfoResp
|
||||
@ -1487,32 +1538,34 @@ var file_hero_hero_msg_proto_goTypes = []interface{}{
|
||||
(*HeroProperty)(nil), // 22: HeroProperty
|
||||
(*HeroLockReq)(nil), // 23: HeroLockReq
|
||||
(*HeroLockResp)(nil), // 24: HeroLockResp
|
||||
nil, // 25: HeroProperty.PropertyEntry
|
||||
nil, // 26: HeroProperty.AddPropertyEntry
|
||||
(*DBHero)(nil), // 27: DBHero
|
||||
(*AddNewHeroPush)(nil), // 25: AddNewHeroPush
|
||||
nil, // 26: HeroProperty.PropertyEntry
|
||||
nil, // 27: HeroProperty.AddPropertyEntry
|
||||
(*DBHero)(nil), // 28: DBHero
|
||||
}
|
||||
var file_hero_hero_msg_proto_depIdxs = []int32{
|
||||
27, // 0: HeroInfoResp.base:type_name -> DBHero
|
||||
27, // 1: HeroListResp.list:type_name -> DBHero
|
||||
27, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero
|
||||
28, // 0: HeroInfoResp.base:type_name -> DBHero
|
||||
28, // 1: HeroListResp.list:type_name -> DBHero
|
||||
28, // 2: HeroStrengthenUplvResp.hero:type_name -> DBHero
|
||||
7, // 3: HeroStrengthenUpStarReq.hero:type_name -> CostCardData
|
||||
7, // 4: HeroStrengthenUpStarReq.heroRace:type_name -> CostCardData
|
||||
27, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero
|
||||
27, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero
|
||||
27, // 7: HeroResonanceResp.hero:type_name -> DBHero
|
||||
27, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero
|
||||
27, // 9: HeroResonanceResetResp.hero:type_name -> DBHero
|
||||
27, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero
|
||||
27, // 11: HeroAwakenResp.hero:type_name -> DBHero
|
||||
27, // 12: HeroChoukaResp.heroes:type_name -> DBHero
|
||||
25, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry
|
||||
26, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry
|
||||
27, // 15: HeroLockResp.hero:type_name -> DBHero
|
||||
16, // [16:16] is the sub-list for method output_type
|
||||
16, // [16:16] is the sub-list for method input_type
|
||||
16, // [16:16] is the sub-list for extension type_name
|
||||
16, // [16:16] is the sub-list for extension extendee
|
||||
0, // [0:16] is the sub-list for field type_name
|
||||
28, // 5: HeroStrengthenUpStarResp.hero:type_name -> DBHero
|
||||
28, // 6: HeroStrengthenUpSkillResp.hero:type_name -> DBHero
|
||||
28, // 7: HeroResonanceResp.hero:type_name -> DBHero
|
||||
28, // 8: HeroResonanceResp.upStarCard:type_name -> DBHero
|
||||
28, // 9: HeroResonanceResetResp.hero:type_name -> DBHero
|
||||
28, // 10: HeroResonanceUseEnergyResp.hero:type_name -> DBHero
|
||||
28, // 11: HeroAwakenResp.hero:type_name -> DBHero
|
||||
28, // 12: HeroChoukaResp.heroes:type_name -> DBHero
|
||||
26, // 13: HeroProperty.property:type_name -> HeroProperty.PropertyEntry
|
||||
27, // 14: HeroProperty.addProperty:type_name -> HeroProperty.AddPropertyEntry
|
||||
28, // 15: HeroLockResp.hero:type_name -> DBHero
|
||||
28, // 16: AddNewHeroPush.hero:type_name -> DBHero
|
||||
17, // [17:17] is the sub-list for method output_type
|
||||
17, // [17:17] is the sub-list for method input_type
|
||||
17, // [17:17] is the sub-list for extension 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() }
|
||||
@ -1822,6 +1875,18 @@ func file_hero_hero_msg_proto_init() {
|
||||
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{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
@ -1829,7 +1894,7 @@ func file_hero_hero_msg_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_hero_hero_msg_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 27,
|
||||
NumMessages: 28,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -125,3 +125,8 @@ message HeroLockReq{
|
||||
message HeroLockResp{
|
||||
DBHero hero = 1; // 英雄对象
|
||||
}
|
||||
|
||||
// 增加新英雄推送
|
||||
message AddNewHeroPush{
|
||||
DBHero hero = 1; // 英雄对象
|
||||
}
|
@ -41,7 +41,9 @@ message UserAddResResp {
|
||||
|
||||
// 玩家资源变更推送
|
||||
message UserResChangePush{
|
||||
int32 changeType = 1; // 变化类型 0 增加 1 减少
|
||||
int32 value = 2;
|
||||
string resName = 3; // 资源名称
|
||||
int32 gold = 1; //@go_tags(`bson:"gold"`) 金币
|
||||
int32 exp = 2; //@go_tags(`bson:"exp"`) 经验
|
||||
int32 lv = 3; //@go_tags(`bson:"lv"`) 等级
|
||||
int32 vip = 4; //@go_tags(`bson:"vip"`) vip
|
||||
int32 diamond = 5; //@go_tags(`bson:"diamond"`) 钻石
|
||||
}
|
||||
|
@ -467,9 +467,11 @@ type UserResChangePush struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ChangeType int32 `protobuf:"varint,1,opt,name=changeType,proto3" json:"changeType"` // 变化类型 0 增加 1 减少
|
||||
Value int32 `protobuf:"varint,2,opt,name=value,proto3" json:"value"`
|
||||
ResName string `protobuf:"bytes,3,opt,name=resName,proto3" json:"resName"` // 资源名称
|
||||
Gold int32 `protobuf:"varint,1,opt,name=gold,proto3" json:"gold" bson:"gold"` //金币
|
||||
Exp int32 `protobuf:"varint,2,opt,name=exp,proto3" json:"exp" bson:"exp"` //经验
|
||||
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() {
|
||||
@ -504,25 +506,39 @@ func (*UserResChangePush) Descriptor() ([]byte, []int) {
|
||||
return file_user_user_msg_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *UserResChangePush) GetChangeType() int32 {
|
||||
func (x *UserResChangePush) GetGold() int32 {
|
||||
if x != nil {
|
||||
return x.ChangeType
|
||||
return x.Gold
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UserResChangePush) GetValue() int32 {
|
||||
func (x *UserResChangePush) GetExp() int32 {
|
||||
if x != nil {
|
||||
return x.Value
|
||||
return x.Exp
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UserResChangePush) GetResName() string {
|
||||
func (x *UserResChangePush) GetLv() int32 {
|
||||
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
|
||||
@ -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,
|
||||
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,
|
||||
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,
|
||||
0x73, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x54, 0x79,
|
||||
0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x4e, 0x61,
|
||||
0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
|
||||
0x52, 0x04, 0x67, 0x6f, 0x6c, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x78, 0x70, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x78, 0x70, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x69, 0x70, 0x18,
|
||||
0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x69,
|
||||
0x61, 0x6d, 0x6f, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, 0x69, 0x61,
|
||||
0x6d, 0x6f, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user