feat(login): 重构登录逻辑并迁移每日重置功能到 Personself 方法
将原本在 Controller.Login 中处理的每日重置逻辑(如电池、任务等)迁移到 service.Info.Personself 方法中,并移除对 gtime.Now().Time 的旧引用。同时更新了 相关的时间判断函数 IsToday,使其支持 *gtime.Time 类型。 此外,清理无用导入包,优化日志打印方式,并修复部分结构体字段定义与使用问题。
This commit is contained in:
@@ -50,6 +50,7 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
|
|||||||
|
|
||||||
copier.CopyWithOption(onpet, oldpet.Data, copier.Option{DeepCopy: true})
|
copier.CopyWithOption(onpet, oldpet.Data, copier.Option{DeepCopy: true})
|
||||||
onpet.CatchTime = oldpetc
|
onpet.CatchTime = oldpetc
|
||||||
|
onpet.EffectInfo = oldpet.Data.EffectInfo
|
||||||
} else {
|
} else {
|
||||||
hd := item.PetItemRegistry.GetHandler(data.ItemID)
|
hd := item.PetItemRegistry.GetHandler(data.ItemID)
|
||||||
if hd == nil {
|
if hd == nil {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/common/data/share"
|
"blazing/common/data/share"
|
||||||
"blazing/common/data/xmlres"
|
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
@@ -17,7 +16,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
|
||||||
"github.com/panjf2000/gnet/v2"
|
"github.com/panjf2000/gnet/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
|
|||||||
}
|
}
|
||||||
t.Service = blservice.NewUserService(data.Head.UserID)
|
t.Service = blservice.NewUserService(data.Head.UserID)
|
||||||
t.User = service.NewBaseSysUserService()
|
t.User = service.NewBaseSysUserService()
|
||||||
t.Info = t.Service.Info.Person(data.Head.UserID)
|
t.Info = t.Service.Info.Personself()
|
||||||
if t.Info == nil {
|
if t.Info == nil {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
return
|
return
|
||||||
@@ -67,32 +65,6 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
|
|||||||
t.Info.UserID = data.Head.UserID
|
t.Info.UserID = data.Head.UserID
|
||||||
t.Logintime = uint32(time.Now().Unix()) //保存时间戳
|
t.Logintime = uint32(time.Now().Unix()) //保存时间戳
|
||||||
|
|
||||||
cool.Loger.Info(context.Background(), "用户上次重置日期", t.Info.LastResetTime.String())
|
|
||||||
if !IsToday(t.Info.LastResetTime) { //判断是否是今天
|
|
||||||
t.Info.LastResetTime = gtime.Now().Time
|
|
||||||
//每天login时候检查重置时间,然后把电池,任务,挖矿重置
|
|
||||||
//挖矿需要单独存,因为防止多开挖矿
|
|
||||||
t.Info.TimeToday = 0 //重置电池
|
|
||||||
|
|
||||||
for i := 400; i < 500; i++ { //每日任务区段
|
|
||||||
|
|
||||||
tttL, ok := xmlres.TaskMap[i]
|
|
||||||
if ok {
|
|
||||||
if tttL.Type == 1 { //日常任务
|
|
||||||
t.Info.TaskList[i-1] = 0 //重置每日任务
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
for i := 0; i < 50; i++ { //每日任务区段
|
|
||||||
t.Info.DailyResArr[i] = 0 //重置每日任务
|
|
||||||
|
|
||||||
}
|
|
||||||
//defer t.Service.Talk_Reset()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
t.CompleteLogin() //通知客户端登录成功
|
t.CompleteLogin() //通知客户端登录成功
|
||||||
|
|
||||||
result = user.NewOutInfo() //设置登录消息
|
result = user.NewOutInfo() //设置登录消息
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func (e *Effect8) DamageFloor(t *info.DamageZone) bool {
|
|||||||
if t.Type == info.DamageType.Red {
|
if t.Type == info.DamageType.Red {
|
||||||
t.Damage = alpacadecimal.NewFromInt(utils.Min(t.Damage.IntPart(),
|
t.Damage = alpacadecimal.NewFromInt(utils.Min(t.Damage.IntPart(),
|
||||||
int64(e.Ctx().Opp.CurrentPet.Info.Hp)-1))
|
int64(e.Ctx().Opp.CurrentPet.Info.Hp)-1))
|
||||||
|
e.max = t.Damage
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ func (f *FightC) handleTimeout(ourID, oppID uint32, actions map[uint32]action.Ba
|
|||||||
if _, exists := actions[pid]; exists {
|
if _, exists := actions[pid]; exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cool.Loger.Debug(context.Background(), "玩家%d 超时\n", pid)
|
cool.Loger.Debug(context.Background(), "玩家超时", pid)
|
||||||
|
|
||||||
f.Reason = info.BattleOverReason.PlayerOVerTime
|
f.Reason = info.BattleOverReason.PlayerOVerTime
|
||||||
f.closefight = true
|
f.closefight = true
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ func init() {
|
|||||||
PetItemRegistry.RegisterExact(300024, func(itemid uint32, onpet *model.PetInfo) bool {
|
PetItemRegistry.RegisterExact(300024, func(itemid uint32, onpet *model.PetInfo) bool {
|
||||||
|
|
||||||
onpet.Downgrade(1)
|
onpet.Downgrade(1)
|
||||||
|
onpet.NextLvExp = 0
|
||||||
onpet.Update_EXP()
|
onpet.Update_EXP()
|
||||||
onpet.Ev = [6]uint32{}
|
onpet.Ev = [6]uint32{}
|
||||||
onpet.Dv = uint32(grand.Intn(32))
|
onpet.Dv = uint32(grand.Intn(32))
|
||||||
|
|||||||
@@ -211,7 +211,8 @@ func (h *ClientData) OnEvent(v []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cool.Loger.Debug(context.TODO(), "接收数据", header.UserID, header.CMD)
|
fmt.Println("接收数据", header.UserID, header.CMD)
|
||||||
|
// cool.Loger.Debug(context.TODO(), "接收数据", header.UserID, header.CMD)
|
||||||
h.Recv(header)
|
h.Recv(header)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package model
|
|||||||
import (
|
import (
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const TableNamePlayerInfo = "player_info"
|
const TableNamePlayerInfo = "player_info"
|
||||||
@@ -13,6 +13,7 @@ const TableNamePlayerInfo = "player_info"
|
|||||||
type Player struct {
|
type Player struct {
|
||||||
*cool.Model
|
*cool.Model
|
||||||
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||||
|
LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
||||||
Data string `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
Data string `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||||
}
|
}
|
||||||
type PlayerEX struct {
|
type PlayerEX struct {
|
||||||
@@ -68,7 +69,7 @@ func NewPlayerInfo() PlayerInfo {
|
|||||||
|
|
||||||
type PlayerInfo struct {
|
type PlayerInfo struct {
|
||||||
ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池
|
ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池
|
||||||
LastResetTime time.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
//LastResetTime time.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
||||||
OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数
|
OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数
|
||||||
// OutInfo 字段
|
// OutInfo 字段
|
||||||
UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到
|
UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/common/data/xmlres"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/os/glog"
|
"github.com/gogf/gf/v2/os/glog"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||||
@@ -60,6 +62,46 @@ func (s *InfoService) Person(userid uint32) *model.PlayerInfo {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret := tt.Data
|
||||||
|
return &ret
|
||||||
|
|
||||||
|
}
|
||||||
|
func (s *InfoService) Personself() *model.PlayerInfo {
|
||||||
|
m := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||||
|
var tt model.PlayerEX
|
||||||
|
err := m.Scan(&tt)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !IsToday(tt.LastResetTime) { //判断是否是今天
|
||||||
|
|
||||||
|
//每天login时候检查重置时间,然后把电池,任务,挖矿重置
|
||||||
|
//挖矿需要单独存,因为防止多开挖矿
|
||||||
|
tt.LastResetTime = gtime.Now()
|
||||||
|
|
||||||
|
for i := 400; i < 500; i++ { //每日任务区段
|
||||||
|
|
||||||
|
tttL, ok := xmlres.TaskMap[i]
|
||||||
|
if ok {
|
||||||
|
if tttL.Type == 1 { //日常任务
|
||||||
|
tt.Data.TaskList[i-1] = 0 //重置每日任务
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
for i := 0; i < 50; i++ { //每日任务区段
|
||||||
|
tt.Data.DailyResArr[i] = 0 //重置每日任务
|
||||||
|
|
||||||
|
}
|
||||||
|
//defer t.Service.Talk_Reset()
|
||||||
|
_, err := m.Save(tt)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
ret := tt.Data
|
ret := tt.Data
|
||||||
return &ret
|
return &ret
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
"blazing/modules/blazing/model"
|
"blazing/modules/blazing/model"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
|
// func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
|
||||||
@@ -53,7 +55,12 @@ func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsToday 判断给定时间是否是今天
|
// IsToday 判断给定时间是否是今天
|
||||||
func IsToday(t time.Time) bool {
|
func IsToday(t1 *gtime.Time) bool {
|
||||||
|
if t1 == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
t := t1.Time
|
||||||
|
|
||||||
// 获取当前时间
|
// 获取当前时间
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user