优化体力自然恢复
This commit is contained in:
parent
a9964388cf
commit
ea8007afa0
@ -125,8 +125,6 @@ type (
|
||||
CheckTujianHero(session IUserSession, heros []string) []bool
|
||||
// bingo设置玩家等级
|
||||
BingoSetUserLv(session IUserSession, lv int32) error
|
||||
// 增加体力
|
||||
AddUserVit(session IUserSession, add int32) (code pb.ErrorCode)
|
||||
BingoSetUserVipLv(session IUserSession, lv int32) error
|
||||
}
|
||||
//武器模块
|
||||
|
@ -31,17 +31,6 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod
|
||||
)
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -367,6 +367,14 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
return
|
||||
}
|
||||
}
|
||||
ggd := this.configure.GetGlobalConf()
|
||||
if ggd == nil {
|
||||
return
|
||||
}
|
||||
if change.Ps+add > ggd.PsUl {
|
||||
code = pb.ErrorCode_UserVitLimit
|
||||
return
|
||||
}
|
||||
change.Ps += add
|
||||
default:
|
||||
err = errors.New(fmt.Sprintf("%s no supported", attr))
|
||||
@ -723,56 +731,27 @@ func (this *User) recoverUserVit(uid string) {
|
||||
add = 0
|
||||
}
|
||||
|
||||
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok {
|
||||
if code := this.AddAttributeValue(isession, comm.ResPs, add, false); code == pb.ErrorCode_Success {
|
||||
update := map[string]interface{}{
|
||||
"lastRecoverVitSec": cur,
|
||||
}
|
||||
if err := this.modelUser.Change(u.Uid, update); err == nil {
|
||||
if changed > 0 {
|
||||
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
|
||||
&pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil {
|
||||
this.Error("玩家体力变化 UserVitChangedPush推送失败",
|
||||
log.Field{Key: "uid", Value: u.Uid},
|
||||
log.Field{Key: comm.ResPs, Value: changed},
|
||||
)
|
||||
}
|
||||
}
|
||||
update := map[string]interface{}{
|
||||
"lastRecoverVitSec": cur,
|
||||
}
|
||||
if add > 0 {
|
||||
u.Ps += add
|
||||
update["ps"] = u.Ps
|
||||
}
|
||||
if err := this.modelUser.Change(u.Uid, update); err == nil {
|
||||
if changed > 0 {
|
||||
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
|
||||
&pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil {
|
||||
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 {
|
||||
if lv <= 0 {
|
||||
return comm.NewCustomError(pb.ErrorCode_ReqParameterError)
|
||||
|
Loading…
Reference in New Issue
Block a user