diff --git a/modules/chat/api_chanagechannel.go b/modules/chat/api_chanagechannel.go index caf874f78..fcedbec7c 100644 --- a/modules/chat/api_chanagechannel.go +++ b/modules/chat/api_chanagechannel.go @@ -28,7 +28,7 @@ func (this *apiComp) ChanageChannel(session comm.IUserSession, req *pb.ChatChana code = pb.ErrorCode_DBError return } - this.module.modelChat.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ "chatchannel": req.ChannelId, }) } diff --git a/modules/chat/api_crosschannel.go b/modules/chat/api_crosschannel.go index dd8992a40..a32ce3a47 100644 --- a/modules/chat/api_crosschannel.go +++ b/modules/chat/api_crosschannel.go @@ -23,7 +23,7 @@ func (this *apiComp) CrossChannel(session comm.IUserSession, req *pb.ChatCrossCh code = pb.ErrorCode_DBError return } - this.module.modelChat.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ "chatchannel": channel, }) session.SendMsg(string(this.module.GetType()), "crosschannel", &pb.ChatCrossChannelResp{ChannelId: channel}) diff --git a/modules/chat/api_spangetlist.go b/modules/chat/api_spangetlist.go index 670f33217..b01a9850a 100644 --- a/modules/chat/api_spangetlist.go +++ b/modules/chat/api_spangetlist.go @@ -21,7 +21,7 @@ func (this *apiComp) SpanGetList(session comm.IUserSession, req *pb.ChatSpanGetL list []*pb.DBChat group int32 ) - if result, err = this.module.modelChat.GetUserExpand(session.GetUserId()); err != nil { + if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { this.module.Errorf("err:%v", err) return } diff --git a/modules/chat/api_spansend.go b/modules/chat/api_spansend.go index 8b0f262b0..658140716 100644 --- a/modules/chat/api_spansend.go +++ b/modules/chat/api_spansend.go @@ -26,7 +26,7 @@ func (this *apiComp) SpanSend(session comm.IUserSession, req *pb.ChatSpanSendReq group int32 max_chat int32 ) - if userexpand, err = this.module.modelChat.GetUserExpand(session.GetUserId()); err != nil { + if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/chat/modelChat.go b/modules/chat/modelChat.go index fa4669230..1f04e44c4 100644 --- a/modules/chat/modelChat.go +++ b/modules/chat/modelChat.go @@ -220,7 +220,7 @@ func (this *modelChatComp) RemoveCrossChannelMember(session comm.IUserSession) ( var ( result *pb.DBUserExpand ) - if result, err = this.GetUserExpand(session.GetUserId()); err != nil { + if result, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { this.module.Errorf("err:%v", err) return } diff --git a/modules/comp_model.go b/modules/comp_model.go index edaa3836a..31d3a9aad 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -517,43 +517,17 @@ func (this *MCompModel) DelListlds(uid string, ids ...string) (err error) { } // 清除玩家英雄缓存信息 -func (this *MCompModel) ClearnHeroCache(uid string, ids ...string) (err error) { - listkey := this.ukey(uid) - for _, v := range ids { - key := this.ukeylist(uid, v) - if err = this.Redis.Delete(key); err != nil { - return - } - } - err = this.Redis.HDel(listkey, ids...) - return -} - -//获取用户通过扩展表 -func (this *MCompModel) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) { - result = &pb.DBUserExpand{} - key := fmt.Sprintf("userexpand:%s", uid) - if err = this.Redis.HGetAll(key, result); err != nil { - return - } - if err == redis.RedisNil { - if err = this.DB.FindOne(core.SqlTable("userexpand"), bson.M{"uid": uid}).Decode(result); err != nil { - return - } - err = this.Redis.HMSet(key, result) - } - return -} - -//修改用户扩展数据 -func (this *MCompModel) ChanageUserExpand(uid string, value map[string]interface{}) (err error) { - key := fmt.Sprintf("userexpand:%s", uid) - if err = this.Redis.HMSet(key, value); err != nil && err != redis.RedisNil { - return - } - err = this.UpdateModelLogs("userexpand", uid, bson.M{"uid": uid}, value) - return -} +// func (this *MCompModel) ClearnHeroCache(uid string, ids ...string) (err error) { +// listkey := this.ukey(uid) +// for _, v := range ids { +// key := this.ukeylist(uid, v) +// if err = this.Redis.Delete(key); err != nil { +// return +// } +// } +// err = this.Redis.HDel(listkey, ids...) +// return +// } //批量读取列表数据 func (this *MCompModel) Batchgetlists(key string) (result []map[string]string, err error) { @@ -722,3 +696,12 @@ func (this *MCompModel) ChangeUserRecord(uid string, value map[string]interface{ err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value) return } + +// 删除玩家缓存信息 +func (this *MCompModel) CleanUserRecord(uid string) (err error) { + err = this.Redis.Delete(this.ukey(uid)) + if err != nil { + return err + } + return +} diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 1ea8d811e..87d663809 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -112,7 +112,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int hero = this.initHero(uid, heroCfgId) if hero != nil { // 添加图鉴 - if result, err1 := this.GetUserExpand(uid); err1 == nil { + if result, err1 := this.moduleHero.ModuleUser.GetUserExpand(uid); err1 == nil { sz := make(map[string]bool, 0) for k := range result.GetTujian() { sz[k] = true @@ -122,7 +122,8 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int initUpdate := map[string]interface{}{ "tujian": sz, } - this.ChanageUserExpand(uid, initUpdate) + + this.moduleHero.ModuleUser.ChanageUserExpand(uid, initUpdate) } } hero.SameCount = count @@ -401,26 +402,10 @@ func (this *ModelHero) PropertyCompute(hero *pb.DBHero) { if lvGrow == nil { return } - resonConfig, err := this.moduleHero.configure.GetHeroResonanceConfig(hero.HeroID) - if err != nil { - return - } - - // 计算玩家共鸣属性 - property := make(map[string]int32, 0) - for keyType, value := range hero.Energy { - if keyType == 1 { - property[comm.Hp] += int32(math.Floor((1.0 + float64(resonConfig.Hppro*value)/1000) * float64(hero.Property[comm.Hp]))) - } else if keyType == 2 { - property[comm.Atk] += int32(math.Floor((1.0 + float64(resonConfig.Atkpro*value)/1000) * float64(hero.Property[comm.Atk]))) - } else if keyType == 3 { - property[comm.Def] += int32(math.Floor((1.0 + float64(resonConfig.Defpro*value)/1000) * float64(hero.Property[comm.Def]))) - } - } curHp := hero.Property[comm.Hp] exprHp := fmt.Sprintf("%v + %v * %v/1000 + %v * %v/1000", - (curHp + lvGrow.Hp), heroLvCfg.Hp, lvGrow.Hpgrow, heroStarCfg.Hp, stargrowCfg) + (curHp + lvGrow.Hp), heroLvCfg.Hp, lvGrow.Hpgrow, heroStarCfg.Hp, stargrowCfg.StarupHp) hp, _ := mengine.ParseAndExec(exprHp) curAtk := hero.Property[comm.Atk] diff --git a/modules/notify/api_getlist.go b/modules/notify/api_getlist.go index 13e5dcf96..2de69e2c2 100644 --- a/modules/notify/api_getlist.go +++ b/modules/notify/api_getlist.go @@ -26,7 +26,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq return } if session.GetUserId() != "" { - if userexpand, err = this.module.modelNotify.GetUserExpand(session.GetUserId()); err != nil { + if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError return } @@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq userexpand = &pb.DBUserExpand{} } //修改最后公告读取时间 - this.module.modelNotify.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ "lastreadnotiftime": time.Now().Unix(), }) session.SendMsg(string(this.module.GetType()), "getlist", &pb.NotifyGetListResp{LastReadTime: userexpand.Lastreadnotiftime, SysNotify: notify}) diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 006000127..8eeea05ab 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -62,7 +62,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c initUpdate := map[string]interface{}{ "modifynameCount": 1, //修改名称1次 } - if err := this.module.modelUser.ChanageUserExpand(session.GetUserId(), initUpdate); err != nil { + if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), initUpdate); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/user/api_figure.go b/modules/user/api_figure.go index 6eb72fc5a..4f21c8b56 100644 --- a/modules/user/api_figure.go +++ b/modules/user/api_figure.go @@ -23,7 +23,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c return } - expand, err := this.module.modelUser.GetUserExpand(session.GetUserId()) + expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return @@ -82,7 +82,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c update = utils.StructToMap(curFigure) - this.module.modelUser.ChanageUserExpand(session.GetUserId(), update) + this.module.modelExpand.ChanageUserExpand(session.GetUserId(), update) } if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil { diff --git a/modules/user/api_gettujian.go b/modules/user/api_gettujian.go index 9e48d3bc6..58cc1ce7f 100644 --- a/modules/user/api_gettujian.go +++ b/modules/user/api_gettujian.go @@ -17,7 +17,7 @@ func (this *apiComp) GetTujian(session comm.IUserSession, req *pb.UserGetTujianR } rsp := &pb.UserGetTujianResp{} - if result, err := this.module.modelUser.GetUserExpand(session.GetUserId()); err != nil { + if result, err := this.module.modelExpand.GetUserExpand(session.GetUserId()); err != nil { this.module.Errorf("err:%v", err) return } else { diff --git a/modules/user/api_modifyname.go b/modules/user/api_modifyname.go index e7332fe5b..79b7bf133 100644 --- a/modules/user/api_modifyname.go +++ b/modules/user/api_modifyname.go @@ -28,7 +28,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam return } - expand, err := this.module.modelUser.GetUserExpand(session.GetUserId()) + expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return @@ -52,7 +52,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam mc := map[string]interface{}{ "modifynameCount": expand.ModifynameCount - 1, } - if err := this.module.modelUser.ChanageUserExpand(session.GetUserId(), mc); err != nil { + if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), mc); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go new file mode 100644 index 000000000..f6b9d586a --- /dev/null +++ b/modules/user/model_expand.go @@ -0,0 +1,49 @@ +package user + +import ( + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules" + "go_dreamfactory/pb" +) + +// 记录一些扩展数据 +type ModelExpand struct { + modules.MCompModel + moduleUser *User +} + +func (this *ModelExpand) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompModel.Init(service, module, comp, options) + this.TableName = "userexpand" + this.moduleUser = module.(*User) + return +} + +//获取用户 +func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) { + cuser = &pb.CacheUser{} + if err := this.Get(uid, cuser); err != nil { + log.Errorf("GetUserSession err:%v", err) + return + } + return +} + +//获取用户通过扩展表 +func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) { + result = &pb.DBUserExpand{} + if err = this.moduleUser.modelExpand.Get(uid, result); err != nil { + return + } + return result, err +} + +//修改用户扩展数据 +func (this *ModelExpand) ChanageUserExpand(uid string, value map[string]interface{}) (err error) { + if len(value) == 0 { + return nil + } + return this.moduleUser.modelExpand.Change(uid, value) + +} diff --git a/modules/user/model_record.go b/modules/user/model_record.go index 19e136141..55cca24cb 100644 --- a/modules/user/model_record.go +++ b/modules/user/model_record.go @@ -7,7 +7,7 @@ import ( "go_dreamfactory/pb" ) -// 记录一些扩展数据 +// 记录一些扩展数据 图鉴 改名次数等 type ModelRecord struct { modules.MCompModel } diff --git a/modules/user/model_setting.go b/modules/user/model_setting.go index 4dcb7a05a..051129027 100644 --- a/modules/user/model_setting.go +++ b/modules/user/model_setting.go @@ -63,7 +63,7 @@ func (this *ModelSetting) UpdateSetting(uid string, data map[string]interface{}) //校验时间和初始次数 func (this *ModelSetting) checkInitCount(uid string) bool { - ue, err := this.moduleUser.modelSetting.GetUserExpand(uid) + ue, err := this.moduleUser.modelExpand.GetUserExpand(uid) if err != nil { return false } @@ -80,7 +80,7 @@ func (this *ModelSetting) checkInitCount(uid string) bool { } ue.InitdataCount++ } else { - + } } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 31dacf38f..ae23c592a 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -152,7 +152,7 @@ func (this *ModelUser) InitFigure(uid string) { update := map[string]interface{}{ "preinstall": figureMap, } - this.ChanageUserExpand(uid, update) + this.moduleUser.modelExpand.ChanageUserExpand(uid, update) } // change exp diff --git a/modules/user/module.go b/modules/user/module.go index 6cc7559a3..78031ce79 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -21,6 +21,7 @@ type User struct { modelUser *ModelUser modelSession *ModelSession modelSetting *ModelSetting + modelExpand *ModelExpand configure *modules.MCompConfigure } @@ -46,6 +47,7 @@ func (this *User) OnInstallComp() { this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSetting = this.RegisterComp(new(ModelSetting)).(*ModelSetting) + this.modelExpand = this.RegisterComp(new(ModelExpand)).(*ModelExpand) } //获取用户数据 @@ -70,6 +72,7 @@ func (this *User) GetUserSession(uid string) *pb.CacheUser { func (this *User) CleanSession(session comm.IUserSession) { this.modelSession.Del(session.GetUserId(), modules.SetDBMgoLog(false)) this.modelUser.Del(session.GetUserId(), modules.SetDBMgoLog(false)) + //this.modelExpand.Del(session.GetUserId(), modules.SetDBMgoLog(false)) // 暂时不清 } //查询用户属性值 例如 金币 经验 @@ -170,9 +173,9 @@ func (this *User) EventUserChanged(session comm.IUserSession) { } func (this *User) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) { - return this.modelUser.GetUserExpand(uid) + return this.modelExpand.GetUserExpand(uid) } func (this *User) ChanageUserExpand(uid string, value map[string]interface{}) error { - return this.modelUser.ChanageUserExpand(uid, value) + return this.modelExpand.ChanageUserExpand(uid, value) }