From 4aa24af2fd4461cec841a91b7d7b9fcb8ecf271f Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 16 Oct 2023 16:05:14 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BD=93=E5=8A=9B?= =?UTF-8?q?=E7=BA=A2=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/reddot/api_getall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/reddot/api_getall.go b/modules/reddot/api_getall.go index 04770a263..5fb9b3cca 100644 --- a/modules/reddot/api_getall.go +++ b/modules/reddot/api_getall.go @@ -61,7 +61,7 @@ func (this *apiComp) GetAll(session comm.IUserSession, req *pb.ReddotGetAllReq) reddot[int32(k)] = v } //用户 - for k, v := range this.module.ModuleUser.Reddot(session, comm.Reddot27101) { + for k, v := range this.module.ModuleUser.Reddot(session, comm.Reddot27101, comm.Reddot30100) { reddot[int32(k)] = v } From fe22b55d46bde26375e7615295fb6ef15740e926 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 16 Oct 2023 16:46:44 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BD=93=E5=8A=9B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/module.go | 209 ++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 115 deletions(-) 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 } From 32e2027622a5ac1831d4b8adb6021bc576ddcafd Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 16 Oct 2023 17:01:05 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=93=E5=8A=9B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/module.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/user/module.go b/modules/user/module.go index 57802bef0..64e4a96e4 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -578,9 +578,10 @@ func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atn } return } - change.Ps += add + user.Ps += add userEx.ConsumPs += -add this.recoverUserPs(user) + change.Ps = user.Ps go this.ModuleUiGame.HDPSTodayConsum(session.GetUserId(), userEx.ConsumPs) } else { if change.Ps+add > ggd.PsUl { @@ -1259,6 +1260,7 @@ func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red total, t := this.recoverUserPs(user) reddot[comm.Reddot30100] = &pb.ReddotItem{ Rid: int32(comm.Reddot30100), + Activated: true, Nextchanagetime: t, Progress: user.Ps, Total: total, From 76a39dc5941e7f1d9b09955f7e4b7317dc7a17d0 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 16 Oct 2023 17:10:33 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BD=93=E5=8A=9B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/user/module.go b/modules/user/module.go index 64e4a96e4..114507488 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -1065,8 +1065,8 @@ func (this *User) recoverUserPs(user *pb.DBUser) (total int32, nexttime int64) { } user.LastRecoverPsSec = cur user.Ps += add - nexttime = user.LastRecoverPsSec + int64(ggd.PsRecovery) } + nexttime = user.LastRecoverPsSec + int64(ggd.PsRecovery) return } From b9fbdf2a51e4adb909422646270b47ee825c2f59 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Mon, 16 Oct 2023 17:31:08 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BD=93=E5=8A=9B?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/user/module.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/user/module.go b/modules/user/module.go index 114507488..f69aa7120 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -1028,7 +1028,7 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error { // } // 玩家体力恢复 -func (this *User) recoverUserPs(user *pb.DBUser) (total int32, nexttime int64) { +func (this *User) recoverUserPs(user *pb.DBUser) (change bool, total int32, nexttime int64) { var ( yu int32 add int32 @@ -1049,6 +1049,7 @@ func (this *User) recoverUserPs(user *pb.DBUser) (total int32, nexttime int64) { cur := time.Now().Unix() if user.LastRecoverPsSec == 0 { user.LastRecoverPsSec = cur + change = true return } else { diff := cur - user.LastRecoverPsSec @@ -1065,6 +1066,7 @@ func (this *User) recoverUserPs(user *pb.DBUser) (total int32, nexttime int64) { } user.LastRecoverPsSec = cur user.Ps += add + change = true } nexttime = user.LastRecoverPsSec + int64(ggd.PsRecovery) return @@ -1257,7 +1259,7 @@ func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red this.Errorln(err) return } - total, t := this.recoverUserPs(user) + change, total, t := this.recoverUserPs(user) reddot[comm.Reddot30100] = &pb.ReddotItem{ Rid: int32(comm.Reddot30100), Activated: true, @@ -1265,6 +1267,12 @@ func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red Progress: user.Ps, Total: total, } + if change { + this.modelUser.Change(session.GetUserId(), map[string]interface{}{ + "ps": user.Ps, + "lastRecoverPsSec": user.LastRecoverPsSec, + }) + } break }