Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
f85674bcd0
@ -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,
|
||||
})
|
||||
}
|
||||
|
@ -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})
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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})
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
49
modules/user/model_expand.go
Normal file
49
modules/user/model_expand.go
Normal 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)
|
||||
|
||||
}
|
@ -7,7 +7,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
// 记录一些扩展数据
|
||||
// 记录一些扩展数据 图鉴 改名次数等
|
||||
type ModelRecord struct {
|
||||
modules.MCompModel
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user