优化体力自然恢复

This commit is contained in:
wh_zcy 2022-12-31 14:56:50 +08:00
parent a9964388cf
commit ea8007afa0
3 changed files with 31 additions and 57 deletions

View File

@ -125,8 +125,6 @@ type (
CheckTujianHero(session IUserSession, heros []string) []bool CheckTujianHero(session IUserSession, heros []string) []bool
// bingo设置玩家等级 // bingo设置玩家等级
BingoSetUserLv(session IUserSession, lv int32) error BingoSetUserLv(session IUserSession, lv int32) error
// 增加体力
AddUserVit(session IUserSession, add int32) (code pb.ErrorCode)
BingoSetUserVipLv(session IUserSession, lv int32) error BingoSetUserVipLv(session IUserSession, lv int32) error
} }
//武器模块 //武器模块

View File

@ -31,17 +31,6 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
) )
rsp := &pb.UserLoginResp{} rsp := &pb.UserLoginResp{}
defer func() {
if user != nil && code == pb.ErrorCode_Success {
rsp.Data = user
rsp.TimeNow = configure.Now().Unix() // 设置服务器时间
err = session.SendMsg(string(this.module.GetType()), UserSubTypeLogin, rsp)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
}
}()
//从mgo查询user //从mgo查询user
user, err = this.module.modelUser.FindByAccount(req.Sid, req.Account) user, err = this.module.modelUser.FindByAccount(req.Sid, req.Account)
@ -152,5 +141,13 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
this.module.ModulePrivilege.CheckDailyPrivilegeMail(session) this.module.ModulePrivilege.CheckDailyPrivilegeMail(session)
rsp.Data = user
rsp.TimeNow = configure.Now().Unix() // 设置服务器时间
err = session.SendMsg(string(this.module.GetType()), UserSubTypeLogin, rsp)
if err != nil {
code = pb.ErrorCode_SystemError
return
}
return return
} }

View File

@ -367,6 +367,14 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
return return
} }
} }
ggd := this.configure.GetGlobalConf()
if ggd == nil {
return
}
if change.Ps+add > ggd.PsUl {
code = pb.ErrorCode_UserVitLimit
return
}
change.Ps += add change.Ps += add
default: default:
err = errors.New(fmt.Sprintf("%s no supported", attr)) err = errors.New(fmt.Sprintf("%s no supported", attr))
@ -723,56 +731,27 @@ func (this *User) recoverUserVit(uid string) {
add = 0 add = 0
} }
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok { update := map[string]interface{}{
if code := this.AddAttributeValue(isession, comm.ResPs, add, false); code == pb.ErrorCode_Success { "lastRecoverVitSec": cur,
update := map[string]interface{}{ }
"lastRecoverVitSec": cur, if add > 0 {
} u.Ps += add
if err := this.modelUser.Change(u.Uid, update); err == nil { update["ps"] = u.Ps
if changed > 0 { }
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged", if err := this.modelUser.Change(u.Uid, update); err == nil {
&pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil { if changed > 0 {
this.Error("玩家体力变化 UserVitChangedPush推送失败", if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
log.Field{Key: "uid", Value: u.Uid}, &pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil {
log.Field{Key: comm.ResPs, Value: changed}, this.Error("玩家体力变化 UserVitChangedPush推送失败",
) log.Field{Key: "uid", Value: u.Uid},
} log.Field{Key: comm.ResPs, Value: changed},
} )
} }
} }
} }
} }
} }
// 增加玩家体力
func (this *User) AddUserVit(session comm.IUserSession, add int32) (code pb.ErrorCode) {
u := this.GetUser(session.GetUserId())
if u == nil {
return
}
ggd := this.configure.GetGlobalConf()
if ggd == nil {
return
}
changed := u.Ps + add
if changed <= ggd.PsUl {
if code = this.AddAttributeValue(session, comm.ResPs, add, false); code == pb.ErrorCode_Success {
if err := session.SendMsg(string(this.GetType()), "vitchanged",
&pb.UserVitChangedPush{Ps: changed}); err != nil {
this.Error("玩家体力变化 UserVitChangedPush推送失败",
log.Field{Key: "uid", Value: u.Uid},
log.Field{Key: comm.ResPs, Value: changed},
)
code = pb.ErrorCode_SystemError
}
}
} else {
code = pb.ErrorCode_UserVitLimit
}
return
}
func (this *User) BingoSetUserVipLv(session comm.IUserSession, lv int32) error { func (this *User) BingoSetUserVipLv(session comm.IUserSession, lv int32) error {
if lv <= 0 { if lv <= 0 {
return comm.NewCustomError(pb.ErrorCode_ReqParameterError) return comm.NewCustomError(pb.ErrorCode_ReqParameterError)