refactor(blazing): 重构任务系统并优化相关功能

- 重构了任务系统的数据结构和执行逻辑
- 优化了地图加载和怪物刷新机制
- 改进了宠物系统的基础架构
- 调整了玩家信息和背包的处理方式
- 统一了数据访问层的接口和实现
This commit is contained in:
2025-08-30 21:59:52 +08:00
parent 2ed5c2db27
commit 75e428f62e
23 changed files with 326 additions and 230 deletions

View File

@@ -5,7 +5,13 @@ import (
)
type IModel interface {
TableName() string
GroupName() string
}
type UserModel interface {
GetData() string
SetData(data string)
TableName() string
GroupName() string
}

View File

@@ -1,6 +1,7 @@
package xmlres
import (
"blazing/common/utils"
"os"
"github.com/ECUST-XX/xml"
@@ -23,11 +24,13 @@ func getXml[T any](path string) T {
}
var (
MapConfig Maps //地图配置
ItemsConfig Items //物品配置
TalkConfig TalkCount //任务配置
Monster MonsterRoot //野怪配置
Skill MovesTbl //技能配置
MapConfig Maps //地图配置
ItemsConfig Items //物品配置
TalkConfig TalkCount //任务配置
//Monster MonsterRoot //野怪配置
MonsterMap map[int]TMapConfig
//Skill MovesTbl //技能配置
SkillMap map[int]Move
)
func initfile() {
@@ -36,8 +39,18 @@ func initfile() {
MapConfig = getXml[Maps](path + "210.xml")
ItemsConfig = getXml[Items](path + "43.xml")
TalkConfig = getXml[TalkCount](path + "talk.xml")
Monster = getXml[MonsterRoot](path + "地图配置野怪.xml")
Skill = getXml[MovesTbl](path + "227.xml")
Monster := getXml[MonsterRoot](path + "地图配置野怪.xml")
MonsterMap = utils.ToMap(Monster.Maps, func(m TMapConfig) int {
return m.ID
})
Skill := getXml[MovesTbl](path + "227.xml")
SkillMap = utils.ToMap[Move, int](Skill.Moves, func(m Move) int {
return m.ID
})
}

View File

@@ -4,7 +4,6 @@ import (
"encoding/xml"
"fmt"
"io"
"log"
"net/http"
"time"
)
@@ -87,31 +86,3 @@ func ReadHTTPFile(url string) ([]byte, error) {
return content, nil
}
func getxml() ([]byte, error) {
// 读取整个文件内容,返回字节切片和错误
content, err := ReadHTTPFile("http://127.0.0.1:8080/assets/227.xml")
if err != nil {
// 处理错误(文件不存在、权限问题等)
log.Fatalf("无法读取文件: %v", err)
}
return content, nil
}
func getMoves() MovesMap {
// 解析XML到结构体
var maps MovesTbl
t1, _ := getxml()
xml.Unmarshal(t1, &maps)
var mapss MovesMap
mapss.Moves = make(map[int]Move, 0)
for _, v := range maps.Moves {
mapss.Moves[int(v.ID)] = v
}
return mapss
}
// 全局函数配置
var MovesConfig = getMoves()

View File

@@ -8,6 +8,7 @@ import (
"blazing/common/data/share"
"blazing/common/data/socket"
"blazing/logic/service/maps"
"github.com/gogf/gf/v2/os/glog"
"github.com/panjf2000/gnet/v2"
@@ -49,6 +50,9 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
if v.Player != nil {
glog.Debug(context.Background(), v.Player.Info.UserID, "断开连接")
maps.LeaveMap(v.Player)
v.Player.IsLogin = false
socket.Mainplayer.Delete(v.Player.Info.UserID)
share.ShareManager.DeleteUserOnline(v.Player.Info.UserID) //设置用户登录服务器

22
common/utils/tomap.go Normal file
View File

@@ -0,0 +1,22 @@
package utils
// ToMap converts a slice to a map with the keyFunc determining what the key of a value should be.
// Will override any double values.
func ToMap[T any, K comparable](slice []T, keyFunc func(T) K) map[K]T {
m := make(map[K]T, len(slice))
for _, v := range slice {
m[keyFunc(v)] = v
}
return m
}
// ToSliceMap converts a slice to a map with the keyFunc determining what the key of a value should be.
// Will append to the slice if the key already exists.
func ToSliceMap[T any, K comparable](slice []T, keyFunc func(T) K) map[K][]T {
m := make(map[K][]T, len(slice))
for _, v := range slice {
key := keyFunc(v)
m[key] = append(m[key], v)
}
return m
}