Files
bl/logic/controller/login.go
昔念 35c89215f7 ```
feat(player): 重构玩家金币系统,使用BaseSysUserService管理金币

将玩家金币逻辑从PlayerInfo中移除,改为通过BaseSysUserService进行统一管理。
新增了金币的获取与设置方法,支持以分为单位的精确计算。
调整了登录时用户服务的初始化逻辑,确保User字段正确赋值。

fix(pet): 修复宠物性格道具使用逻辑错误

更新了多个性格相关道具的处理方式,包括新增的性格转换道具范围。
修正了性格随机与指定逻辑,避免越界问题并增强可维护性。

feat(fight): 战斗初始化时恢复宠物状态

在战斗初始化阶段调用宠物治愈方法,确保战斗开始前宠物处于健康状态。

feat(admin): 调整管理员会话获取接口参数类型

修改GetPerson方法传入参数为uint32类型,提高数据一致性与安全性。

refactor(model): 移除PlayerInfo中的GoldBean字段

金币字段不再存储于PlayerInfo结构体中,转而由BaseSysUser模块统一管理。
```
2025-12-06 23:59:00 +08:00

106 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/data/share"
"blazing/common/data/xmlres"
"blazing/cool"
"fmt"
"blazing/common/socket/errorcode"
"blazing/logic/service/user"
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/base/service"
blservice "blazing/modules/blazing/service"
"context"
"time"
"github.com/gogf/gf/v2/os/gtime"
"github.com/panjf2000/gnet/v2"
)
func IsToday(t time.Time) bool {
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
// 处理命令: 1001
func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.LoginMSInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
tt := data.CheakSession()
if !tt {
defer c.Close()
return
}
cool.Loger.Info(context.TODO(), "准备踢人")
err1 := h.RPCClient.Kick(data.Head.UserID) //先踢人
if err1 != nil {
fmt.Println("踢人失败", err)
}
//player.KickPlayer(data.Head.UserID)
cool.Loger.Info(context.TODO(), "踢人请求完成,继续登录流程")
// <-time.After(time.Millisecond * 3000)
share.ShareManager.SetUserOnline(data.Head.UserID, h.Port) //设置用户登录服务器
t := player.GetPlayer(c, data.Head.UserID)
if t == nil {
cool.Loger.Error(context.Background(), "获取玩家失败", data.Head.UserID)
defer c.Close()
return
}
t.Service = blservice.NewUserService(data.Head.UserID)
t.User = service.NewBaseSysUserService()
t.Info = t.Service.Info.Person(data.Head.UserID)
if t.Info == nil {
defer c.Close()
return
}
t.Info.UserID = data.Head.UserID
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() //通知客户端登录成功
result = user.NewOutInfo() //设置登录消息
result.PlayerInfo = *t.Info
defer space.GetSpace(t.Info.MapID).EnterMap(t)
return result, 0
}