- 重构了任务系统的数据结构和执行逻辑 - 优化了地图加载和怪物刷新机制 - 改进了宠物系统的基础架构 - 调整了玩家信息和背包的处理方式 - 统一了数据访问层的接口和实现
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package xmlres
|
||
|
||
import (
|
||
"encoding/xml"
|
||
"fmt"
|
||
"io"
|
||
"net/http"
|
||
"time"
|
||
)
|
||
|
||
// MovesTbl 定义 XML 根元素
|
||
type MovesTbl struct {
|
||
XMLName xml.Name `xml:"MovesTbl"`
|
||
Moves []Move `xml:"Moves>Move"`
|
||
EFF []SideEffect `xml:"SideEffects>SideEffect"`
|
||
}
|
||
type MovesMap struct {
|
||
XMLName xml.Name `xml:"MovesTbl"`
|
||
Moves map[int]Move
|
||
EFF []SideEffect `xml:"SideEffects>SideEffect"`
|
||
}
|
||
|
||
// Move 定义单个技能的结构
|
||
type Move struct {
|
||
ID int `xml:"ID,attr"`
|
||
Name string `xml:"Name,attr"`
|
||
Category int `xml:"Category,attr"`
|
||
Type int `xml:"Type,attr"`
|
||
Power int `xml:"Power,attr"`
|
||
MaxPP int `xml:"MaxPP,attr"`
|
||
Accuracy int `xml:"Accuracy,attr"`
|
||
CritRate int `xml:"CritRate,attr,omitempty"`
|
||
Priority int `xml:"Priority,attr,omitempty"`
|
||
MustHit int `xml:"MustHit,attr,omitempty"`
|
||
SwapElemType int `xml:"SwapElemType,attr,omitempty"`
|
||
CopyElemType int `xml:"CopyElemType,attr,omitempty"`
|
||
CritAtkFirst int `xml:"CritAtkFirst,attr,omitempty"`
|
||
CritAtkSecond int `xml:"CritAtkSecond,attr,omitempty"`
|
||
CritSelfHalfHp int `xml:"CritSelfHalfHp,attr,omitempty"`
|
||
CritFoeHalfHp int `xml:"CritFoeHalfHp,attr,omitempty"`
|
||
DmgBindLv int `xml:"DmgBindLv,attr,omitempty"`
|
||
PwrBindDv int `xml:"PwrBindDv,attr,omitempty"`
|
||
PwrDouble int `xml:"PwrDouble,attr,omitempty"`
|
||
|
||
SideEffect string `xml:"SideEffect,attr,omitempty"`
|
||
SideEffectArg string `xml:"SideEffectArg,attr,omitempty"`
|
||
AtkNum int `xml:"AtkNum,attr,omitempty"`
|
||
Url string `xml:"Url,attr,omitempty"`
|
||
|
||
Info string `xml:"info,attr,omitempty"`
|
||
|
||
CD int `xml:"CD,attr"`
|
||
}
|
||
type SideEffect struct {
|
||
ID int `xml:"ID,attr"`
|
||
Help string `xml:"help,attr"`
|
||
Des string `xml:"des,attr"`
|
||
}
|
||
|
||
// ReadHTTPFile 通过HTTP GET请求获取远程文件内容
|
||
// url: 远程文件的URL地址
|
||
// 返回文件内容字节流和可能的错误
|
||
func ReadHTTPFile(url string) ([]byte, error) {
|
||
// 创建HTTP客户端并设置超时时间(避免无限等待)
|
||
client := &http.Client{
|
||
Timeout: 30 * time.Second, // 30秒超时
|
||
}
|
||
|
||
// 发送GET请求
|
||
resp, err := client.Get(url)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("请求失败: %w", err)
|
||
}
|
||
defer resp.Body.Close() // 确保响应体被关闭
|
||
|
||
// 检查响应状态码
|
||
if resp.StatusCode != http.StatusOK {
|
||
return nil, fmt.Errorf("请求返回非成功状态码: %d", resp.StatusCode)
|
||
}
|
||
|
||
// 读取响应体内容
|
||
content, err := io.ReadAll(resp.Body)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("读取内容失败: %w", err)
|
||
}
|
||
|
||
return content, nil
|
||
}
|