```
refactor(logic): 重构服务器启动逻辑与任务状态管理 - 移除了 `gcmd` 包在 controller 中的直接使用,改为通过参数传递端口和服务器类型 - 统一使用 `GetTask` 和 `SetTask` 方法替代直接访问 `TaskList` 数组,提升代码可维护性 - 修改了战斗逻辑中部分调试打印语句,并优化战斗循环结束日志输出 - 调整了新手玩家初始化流程,默认完成新手任务4 - 更新了数据库模型字段及结构定义,如增加 `max_ts` 字段、扩展 `TaskList` 长度等 - 改进了宠物添加逻辑,采用 SQL 方式确保捕捉时间唯一递增 - 清理了无用或注释掉的旧代码块
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/lunixbochs/struc"
|
||||
)
|
||||
@@ -38,9 +37,8 @@ func ParseCmd[T any](a T, data []byte) T {
|
||||
//fmt.Println(data)
|
||||
}
|
||||
|
||||
func init() { //默认初始化扫描
|
||||
// 解析命令行参数
|
||||
cool.Config.PortBL = gcmd.GetOpt("port", "1").Uint16()
|
||||
func Init(isgame bool) { //默认初始化扫描
|
||||
|
||||
// 获取对象的反射值和类型
|
||||
value := reflect.ValueOf(Maincontroller)
|
||||
|
||||
@@ -60,12 +58,12 @@ func init() { //默认初始化扫描
|
||||
continue
|
||||
}
|
||||
|
||||
if cool.Config.PortBL == 0 && func_cmd > 1000 { //判断login服务器
|
||||
if !isgame && func_cmd > 1000 { //判断login服务器
|
||||
continue
|
||||
|
||||
}
|
||||
|
||||
if cool.Config.PortBL != 0 && func_cmd < 1000 { //判断login服务器
|
||||
if isgame && func_cmd < 1000 { //判断login服务器
|
||||
continue
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,8 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
if taskid != 0 {
|
||||
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID {
|
||||
if c.Info.TaskList[taskid-1] != 3 {
|
||||
if c.GetTask(taskid) == player.Unaccepted {
|
||||
c.SetTask(taskid, player.Completed) //设置完成任务
|
||||
c.Info.TaskList[taskid-1] = 3
|
||||
|
||||
moinfo.PetList[0].Downgrade(1)
|
||||
|
||||
@@ -19,8 +19,9 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *player.Playe
|
||||
// //isdaliy = true
|
||||
// }
|
||||
|
||||
if c.Info.TaskList[data.TaskId-1] == 0 {
|
||||
c.Info.TaskList[data.TaskId-1] = 1
|
||||
if c.GetTask(int(data.TaskId)) == player.Unaccepted {
|
||||
c.SetTask(int(data.TaskId), player.Accepted)
|
||||
|
||||
}
|
||||
c.Service.Task.Exec(uint32(data.TaskId), func(t *model.TaskEX) bool {
|
||||
t.Data = []uint32{}
|
||||
@@ -54,13 +55,13 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Playe
|
||||
* 完成任务
|
||||
*/
|
||||
func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if c.Info.TaskList[data.TaskId-1] != 1 { //如果任务没有接受或者已经完成Complete_Task
|
||||
|
||||
if c.GetTask(int(data.TaskId)) != player.Accepted { //如果任务没有接受或者已经完成Complete_Task
|
||||
return result, 0
|
||||
|
||||
}
|
||||
c.Info.TaskList[data.TaskId-1] = 3
|
||||
|
||||
c.SetTask(int(data.TaskId), player.Completed)
|
||||
|
||||
result = &task.CompleteTaskOutboundInfo{
|
||||
TaskId: data.TaskId,
|
||||
ItemList: make([]model.ItemInfo, 0),
|
||||
@@ -111,10 +112,9 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *player.Pla
|
||||
*/
|
||||
func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *player.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) {
|
||||
|
||||
if c.Info.TaskList[data.TaskId-1] == 1 {
|
||||
c.Info.TaskList[data.TaskId-1] = 0
|
||||
if c.GetTask(int(data.TaskId)) == player.Accepted {
|
||||
c.SetTask(int(data.TaskId), player.Unaccepted)
|
||||
return &task.DeleteTaskOutboundInfo{TaskId: data.TaskId}, 0
|
||||
|
||||
}
|
||||
|
||||
return &task.DeleteTaskOutboundInfo{}, 0
|
||||
|
||||
Reference in New Issue
Block a user