Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2022-07-28 15:01:13 +08:00
commit f85674bcd0
17 changed files with 95 additions and 75 deletions

View File

@ -28,7 +28,7 @@ func (this *apiComp) ChanageChannel(session comm.IUserSession, req *pb.ChatChana
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
this.module.modelChat.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{
"chatchannel": req.ChannelId, "chatchannel": req.ChannelId,
}) })
} }

View File

@ -23,7 +23,7 @@ func (this *apiComp) CrossChannel(session comm.IUserSession, req *pb.ChatCrossCh
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
this.module.modelChat.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{
"chatchannel": channel, "chatchannel": channel,
}) })
session.SendMsg(string(this.module.GetType()), "crosschannel", &pb.ChatCrossChannelResp{ChannelId: channel}) session.SendMsg(string(this.module.GetType()), "crosschannel", &pb.ChatCrossChannelResp{ChannelId: channel})

View File

@ -21,7 +21,7 @@ func (this *apiComp) SpanGetList(session comm.IUserSession, req *pb.ChatSpanGetL
list []*pb.DBChat list []*pb.DBChat
group int32 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) this.module.Errorf("err:%v", err)
return return
} }

View File

@ -26,7 +26,7 @@ func (this *apiComp) SpanSend(session comm.IUserSession, req *pb.ChatSpanSendReq
group int32 group int32
max_chat 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 code = pb.ErrorCode_DBError
return return
} }

View File

@ -220,7 +220,7 @@ func (this *modelChatComp) RemoveCrossChannelMember(session comm.IUserSession) (
var ( var (
result *pb.DBUserExpand 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) this.module.Errorf("err:%v", err)
return return
} }

View File

@ -517,43 +517,17 @@ func (this *MCompModel) DelListlds(uid string, ids ...string) (err error) {
} }
// 清除玩家英雄缓存信息 // 清除玩家英雄缓存信息
func (this *MCompModel) ClearnHeroCache(uid string, ids ...string) (err error) { // func (this *MCompModel) ClearnHeroCache(uid string, ids ...string) (err error) {
listkey := this.ukey(uid) // listkey := this.ukey(uid)
for _, v := range ids { // for _, v := range ids {
key := this.ukeylist(uid, v) // key := this.ukeylist(uid, v)
if err = this.Redis.Delete(key); err != nil { // if err = this.Redis.Delete(key); err != nil {
return // return
} // }
} // }
err = this.Redis.HDel(listkey, ids...) // err = this.Redis.HDel(listkey, ids...)
return // 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) Batchgetlists(key string) (result []map[string]string, err error) { 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) err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value)
return return
} }
// 删除玩家缓存信息
func (this *MCompModel) CleanUserRecord(uid string) (err error) {
err = this.Redis.Delete(this.ukey(uid))
if err != nil {
return err
}
return
}

View File

@ -112,7 +112,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
hero = this.initHero(uid, heroCfgId) hero = this.initHero(uid, heroCfgId)
if hero != nil { 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) sz := make(map[string]bool, 0)
for k := range result.GetTujian() { for k := range result.GetTujian() {
sz[k] = true sz[k] = true
@ -122,7 +122,8 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
initUpdate := map[string]interface{}{ initUpdate := map[string]interface{}{
"tujian": sz, "tujian": sz,
} }
this.ChanageUserExpand(uid, initUpdate)
this.moduleHero.ModuleUser.ChanageUserExpand(uid, initUpdate)
} }
} }
hero.SameCount = count hero.SameCount = count
@ -401,26 +402,10 @@ func (this *ModelHero) PropertyCompute(hero *pb.DBHero) {
if lvGrow == nil { if lvGrow == nil {
return 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] curHp := hero.Property[comm.Hp]
exprHp := fmt.Sprintf("%v + %v * %v/1000 + %v * %v/1000", 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) hp, _ := mengine.ParseAndExec(exprHp)
curAtk := hero.Property[comm.Atk] curAtk := hero.Property[comm.Atk]

View File

@ -26,7 +26,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq
return return
} }
if session.GetUserId() != "" { 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 code = pb.ErrorCode_DBError
return return
} }
@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq
userexpand = &pb.DBUserExpand{} 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(), "lastreadnotiftime": time.Now().Unix(),
}) })
session.SendMsg(string(this.module.GetType()), "getlist", &pb.NotifyGetListResp{LastReadTime: userexpand.Lastreadnotiftime, SysNotify: notify}) session.SendMsg(string(this.module.GetType()), "getlist", &pb.NotifyGetListResp{LastReadTime: userexpand.Lastreadnotiftime, SysNotify: notify})

View File

@ -62,7 +62,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
initUpdate := map[string]interface{}{ initUpdate := map[string]interface{}{
"modifynameCount": 1, //修改名称1次 "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 code = pb.ErrorCode_DBError
return return
} }

View File

@ -23,7 +23,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c
return return
} }
expand, err := this.module.modelUser.GetUserExpand(session.GetUserId()) expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
@ -82,7 +82,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c
update = utils.StructToMap(curFigure) 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 { if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil {

View File

@ -17,7 +17,7 @@ func (this *apiComp) GetTujian(session comm.IUserSession, req *pb.UserGetTujianR
} }
rsp := &pb.UserGetTujianResp{} 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) this.module.Errorf("err:%v", err)
return return
} else { } else {

View File

@ -28,7 +28,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
return return
} }
expand, err := this.module.modelUser.GetUserExpand(session.GetUserId()) expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
@ -52,7 +52,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
mc := map[string]interface{}{ mc := map[string]interface{}{
"modifynameCount": expand.ModifynameCount - 1, "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 code = pb.ErrorCode_DBError
return return
} }

View File

@ -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)
}

View File

@ -7,7 +7,7 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
// 记录一些扩展数据 // 记录一些扩展数据 图鉴 改名次数等
type ModelRecord struct { type ModelRecord struct {
modules.MCompModel modules.MCompModel
} }

View File

@ -63,7 +63,7 @@ func (this *ModelSetting) UpdateSetting(uid string, data map[string]interface{})
//校验时间和初始次数 //校验时间和初始次数
func (this *ModelSetting) checkInitCount(uid string) bool { func (this *ModelSetting) checkInitCount(uid string) bool {
ue, err := this.moduleUser.modelSetting.GetUserExpand(uid) ue, err := this.moduleUser.modelExpand.GetUserExpand(uid)
if err != nil { if err != nil {
return false return false
} }
@ -80,7 +80,7 @@ func (this *ModelSetting) checkInitCount(uid string) bool {
} }
ue.InitdataCount++ ue.InitdataCount++
} else { } else {
} }
} }

View File

@ -152,7 +152,7 @@ func (this *ModelUser) InitFigure(uid string) {
update := map[string]interface{}{ update := map[string]interface{}{
"preinstall": figureMap, "preinstall": figureMap,
} }
this.ChanageUserExpand(uid, update) this.moduleUser.modelExpand.ChanageUserExpand(uid, update)
} }
// change exp // change exp

View File

@ -21,6 +21,7 @@ type User struct {
modelUser *ModelUser modelUser *ModelUser
modelSession *ModelSession modelSession *ModelSession
modelSetting *ModelSetting modelSetting *ModelSetting
modelExpand *ModelExpand
configure *modules.MCompConfigure configure *modules.MCompConfigure
} }
@ -46,6 +47,7 @@ func (this *User) OnInstallComp() {
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser) this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession)
this.modelSetting = this.RegisterComp(new(ModelSetting)).(*ModelSetting) 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) { func (this *User) CleanSession(session comm.IUserSession) {
this.modelSession.Del(session.GetUserId(), modules.SetDBMgoLog(false)) this.modelSession.Del(session.GetUserId(), modules.SetDBMgoLog(false))
this.modelUser.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) { 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 { func (this *User) ChanageUserExpand(uid string, value map[string]interface{}) error {
return this.modelUser.ChanageUserExpand(uid, value) return this.modelExpand.ChanageUserExpand(uid, value)
} }