diff --git a/modules/user/module.go b/modules/user/module.go index e1bd7cbca..57802bef0 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -580,7 +580,8 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn } change.Ps += add userEx.ConsumPs += -add - this.ModuleUiGame.HDPSTodayConsum(session.GetUserId(), userEx.ConsumPs) + this.recoverUserPs(user) + go this.ModuleUiGame.HDPSTodayConsum(session.GetUserId(), userEx.ConsumPs) } else { if change.Ps+add > ggd.PsUl { change.Ps = ggd.PsUl @@ -709,6 +710,7 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn comm.Integral: change.Integral, comm.Profit: change.Profit, comm.Deposit: change.Deposit, + "lastRecoverPsSec": user.LastRecoverPsSec, } //user ex @@ -964,138 +966,107 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error { return nil } +// // 玩家体力恢复 +// func (this *User) RecoverUserPsStart(session comm.IUserSession) (recoverTime int64) { +// var ( +// yu int32 +// add int32 +// changed int32 +// ) +// // 推送红点信息 +// re := this.ModuleTools.GetGlobalConf().PsRecovery +// if re <= 0 { +// return +// } +// u, err := this.GetUser(session.GetUserId()) +// if err != nil { +// return +// } +// if u.LastRecoverPsSec == 0 { +// u.LastRecoverPsSec = configure.Now().Unix() +// } +// diff := configure.Now().Unix() - u.LastRecoverPsSec +// yu = int32(diff / int64(re)) +// if yu > 0 { +// pconf := this.configure.GetPlayerlvConf(u.Lv) +// if pconf == nil { +// return +// } +// if u.Ps < pconf.PsCeiling { +// total := u.Ps + yu +// if total > pconf.PsCeiling { +// add = pconf.PsCeiling - u.Ps +// changed = pconf.PsCeiling +// } else { +// add = yu +// changed = total +// u.LastRecoverPsSec += int64(yu * re) +// } +// } else { +// add = 0 +// } +// //u.LastRecoverPsSec = time.Now().Unix() +// update := map[string]interface{}{} +// if add > 0 { +// u.Ps += add +// update["ps"] = u.Ps +// update["lastRecoverPsSec"] = u.LastRecoverPsSec +// } +// if err := this.modelUser.Change(u.Uid, update); err == nil { +// if changed > 0 { +// this.reddot.PushReddot(session, &pb.ReddotItem{ +// Rid: int32(comm.Reddot30100), +// Nextchanagetime: u.LastRecoverPsSec + int64(re), +// }) +// session.Push() +// } +// } +// } +// recoverTime = u.LastRecoverPsSec + int64(re) +// return recoverTime +// } + // 玩家体力恢复 -func (this *User) RecoverUserPsStart(session comm.IUserSession) (recoverTime int64) { +func (this *User) recoverUserPs(user *pb.DBUser) (total int32, nexttime int64) { var ( - yu int32 - add int32 - changed int32 + yu int32 + add int32 ) - // 推送红点信息 - re := this.ModuleTools.GetGlobalConf().PsRecovery - if re <= 0 { - return - } - u, err := this.GetUser(session.GetUserId()) - if err != nil { - return - } - diff := time.Now().Unix() - u.LastRecoverPsSec - yu = int32(diff / int64(re)) - if yu > 0 { - pconf := this.configure.GetPlayerlvConf(u.Lv) - if pconf == nil { - return - } - if u.Ps < pconf.PsCeiling { - total := u.Ps + yu - if total > pconf.PsCeiling { - add = pconf.PsCeiling - u.Ps - changed = pconf.PsCeiling - } else { - add = yu - changed = total - if u.LastRecoverPsSec != 0 { - u.LastRecoverPsSec += int64(yu * re) - if u.LastRecoverPsSec > time.Now().Unix() { - u.LastRecoverPsSec = time.Now().Unix() - } - } - } - } else { - add = 0 - } - //u.LastRecoverPsSec = time.Now().Unix() - update := map[string]interface{}{} - if add > 0 { - u.Ps += add - update["ps"] = u.Ps - update["lastRecoverPsSec"] = u.LastRecoverPsSec - } - if err := this.modelUser.Change(u.Uid, update); err == nil { - if changed > 0 { - this.reddot.PushReddot(session, &pb.ReddotItem{ - Rid: int32(comm.Reddot30100), - Nextchanagetime: u.LastRecoverPsSec + int64(re), - }) - session.Push() - } - } - } - recoverTime = u.LastRecoverPsSec + int64(re) - return recoverTime -} -// 玩家体力恢复 -func (this *User) recoverUserPs(uid string) { - if this.IsCross() { - return - } - - u, err := this.GetUser(uid) - if err != nil { - return - } ggd := this.ModuleTools.GetGlobalConf() if ggd == nil { return } - - var ( - yu int32 - add int32 - changed int32 - ) + pconf := this.configure.GetPlayerlvConf(user.Lv) + if pconf == nil { + return + } + if user.Ps >= pconf.PsCeiling { + return + } + total = pconf.PsCeiling cur := time.Now().Unix() - if u.LastRecoverPsSec == 0 { - update := map[string]interface{}{ - "lastRecoverPsSec": cur, - } - this.modelUser.Change(u.Uid, update) + if user.LastRecoverPsSec == 0 { + user.LastRecoverPsSec = cur return } else { - diff := cur - u.LastRecoverPsSec + diff := cur - user.LastRecoverPsSec yu = int32(diff / int64(ggd.PsRecovery)) } if yu > 0 { - pconf := this.configure.GetPlayerlvConf(u.Lv) - if pconf == nil { - return - } - if u.Ps < pconf.PsCeiling { - total := u.Ps + yu - if total > pconf.PsCeiling { - add = pconf.PsCeiling - u.Ps - changed = pconf.PsCeiling - } else { - add = yu - changed = total - } + total := user.Ps + yu + if total > pconf.PsCeiling { + add = pconf.PsCeiling - user.Ps } else { - add = 0 - } + add = yu - update := map[string]interface{}{ - "lastRecoverPsSec": 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()), "pschanged", - &pb.UserPsChangedPush{Ps: changed}, u.Uid); err != nil { - this.Error("玩家体力变化 UserPsChangedPush推送失败", - log.Field{Key: "uid", Value: u.Uid}, - log.Field{Key: comm.ResPs, Value: changed}, - log.Field{Key: "err", Value: err.Error()}, - ) - } - } } + user.LastRecoverPsSec = cur + user.Ps += add + nexttime = user.LastRecoverPsSec + int64(ggd.PsRecovery) } + return } func (this *User) BingoSetUserVipLv(session comm.IUserSession, lv int32) (errdata *pb.ErrorData) { @@ -1256,6 +1227,7 @@ func (this *User) RemainingPS(uid string) (ps int32) { // 查询每日红点信息 func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) { var ( + user *pb.DBUser info *pb.DBSign progress int32 err error @@ -1279,10 +1251,17 @@ func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red } break case comm.Reddot30100: // 体力恢复 - t := this.RecoverUserPsStart(session) + user, err = this.GetUser(session.GetUserId()) + if err != nil { + this.Errorln(err) + return + } + total, t := this.recoverUserPs(user) reddot[comm.Reddot30100] = &pb.ReddotItem{ Rid: int32(comm.Reddot30100), Nextchanagetime: t, + Progress: user.Ps, + Total: total, } break }