体力恢复调整

This commit is contained in:
meixiongfeng 2023-09-12 15:14:21 +08:00
parent f711ac613c
commit 6e89c06973
6 changed files with 113 additions and 51 deletions

View File

@ -643,6 +643,8 @@ const (
//种族塔
Reddot29101 ReddotType = 29101 // 今日剩余可挑战关卡x
Reddot30100 ReddotType = 30100 // 体力恢复
)
type TaskType int32

View File

@ -11,7 +11,7 @@ func (this *apiComp) GetCheck(session comm.IUserSession, req *pb.ReddotGetReq) (
return
}
// /获取系统公告
// 红点数据
func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (errdata *pb.ErrorData) {
var (
reddot map[int32]*pb.ReddotItem = make(map[int32]*pb.ReddotItem)
@ -92,6 +92,10 @@ func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (errda
for k, v := range this.module.gourmet.Reddot(session, _rid) {
reddot[int32(k)] = v
}
case comm.Reddot30100:
for k, v := range this.module.ModuleUser.Reddot(session, _rid) {
reddot[int32(k)] = v
}
}
}
session.SendMsg(string(this.module.GetType()), "get", &pb.ReddotGetAllResp{Reddot: reddot})

View File

@ -128,6 +128,16 @@ func (this *Turntable) EventUserLogin(session comm.IUserSession) {
turntable *pb.DBTurntable
err error
)
endTime := this.ModuleTools.GetGlobalConf().SignAccount
if user := this.ModuleUser.GetUser(session.GetUserId()); user != nil {
if configure.Now().Unix() > user.Ctime+int64(endTime*24*3600) {
bEnd = true
}
}
if !bEnd {
return
}
if turntable, err = this.modelt.getUserTurntable(session.GetUserId()); err != nil {
return
@ -135,33 +145,27 @@ func (this *Turntable) EventUserLogin(session comm.IUserSession) {
if turntable.Reward {
return
}
endTime := 28 // 等配置
if user := this.ModuleUser.GetUser(session.GetUserId()); user != nil {
if configure.Now().Unix() > user.Ctime+int64(endTime*24*3600) {
bEnd = true
}
}
if bEnd { // 活动结束 活动道具转换
t := this.ModuleTools.GetGlobalConf().VenturegiftsDraw
var reward []*pb.UserAssets
if item, err := this.configure.GetItemConfigureData(t); err != nil {
amount := this.ModuleItems.QueryItemAmount(session.GetUserId(), t)
if amount > 0 {
this.ModuleItems.AddItem(session, t, -int32(amount), true)
for _, v := range item.Sale {
reward = append(reward, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N * int32(amount),
})
}
// 发邮件
this.mail.SendMailByCid(session, comm.Venturegifts, reward)
// 活动结束 活动道具转换
t := this.ModuleTools.GetGlobalConf().VenturegiftsDraw
var reward []*pb.UserAssets
if item, err := this.configure.GetItemConfigureData(t); err != nil {
amount := this.ModuleItems.QueryItemAmount(session.GetUserId(), t)
if amount > 0 {
this.ModuleItems.AddItem(session, t, -int32(amount), true)
for _, v := range item.Sale {
reward = append(reward, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N * int32(amount),
})
}
// 发邮件
this.mail.SendMailByCid(session, comm.Venturegifts, reward)
}
turntable.Reward = true
this.modelt.Change(session.GetUserId(), map[string]interface{}{
"reward": turntable.Reward,
})
}
turntable.Reward = true
this.modelt.Change(session.GetUserId(), map[string]interface{}{
"reward": turntable.Reward,
})
}

View File

@ -163,7 +163,7 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (err
}
this.module.ModuleHero.CheckPeachReward(session, user.Ctime)
// this.module.RecoverUserPsStart(user.Uid)
go this.module.RecoverUserPsStart(session.Clone())
// 日常登录任务
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype7, 1))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype230, 1, int32(configure.Now().Weekday())))

View File

@ -64,6 +64,7 @@ type User struct {
modelSign *ModelSign // 签到
timerLock sync.Mutex
timerMap map[string]*time.Ticker
reddot comm.IReddot
}
func (this *User) GetType() core.M_Modules {
@ -97,7 +98,10 @@ func (this *User) Start() (err error) {
return
}
this.chat = module.(comm.IChat)
if module, err = this.service.GetModule(comm.ModuleReddot); err != nil {
return
}
this.reddot = module.(comm.IReddot)
return
}
@ -946,31 +950,61 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error {
}
// 玩家体力恢复
func (this *User) RecoverUserPsStart(uid string) {
go func(uid string) {
timeSec := time.NewTicker(time.Second * 30)
this.timerLock.Lock()
this.timerMap[uid] = timeSec
this.timerLock.Unlock()
for {
select {
case <-timeSec.C:
this.recoverUserPs(uid)
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 := this.GetUser(session.GetUserId())
if u == 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
}
} 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()
}
}
}(uid)
}
// 停止计时
func (this *User) stopTicker(uid string) {
if t, ok := this.timerMap[uid]; ok {
if t != nil {
t.Stop()
this.timerLock.Lock()
delete(this.timerMap, uid)
this.timerLock.Unlock()
}
}
recoverTime = u.LastRecoverPsSec + int64(re)
return recoverTime
}
// 玩家体力恢复
@ -1220,7 +1254,15 @@ func (this *User) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red
Total: 1,
}
break
case comm.Reddot30100: // 体力恢复
t := this.RecoverUserPsStart(session)
reddot[comm.Reddot30100] = &pb.ReddotItem{
Rid: int32(comm.Reddot30100),
Nextchanagetime: t,
}
break
}
}
return
}

View File

@ -22,7 +22,17 @@ func (this *apiComp) SignGetList(session comm.IUserSession, req *pb.VentureSignG
if errdata = this.SignGetListCheck(session, req); errdata != nil {
return
}
endTime := this.module.ModuleTools.GetGlobalConf().SignAccount
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
if configure.Now().Unix() > user.Ctime+int64(endTime*24*3600) {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ActivityOver,
Title: pb.ErrorCode_ActivityOver.ToString(),
Message: err.Error(),
}
return
}
}
if sign, err = this.module.ModelSign.getUserSign(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,