refactor(fight): 重构战斗系统

- 优化了技能解析和存储逻辑
- 重构了战斗流程和回合结算机制
- 调整了数据结构以提高性能
- 移除了未使用的代码和注释
This commit is contained in:
2025-09-04 23:57:22 +08:00
parent 51407864b7
commit 7d48e9ab64
17 changed files with 224 additions and 377 deletions

View File

@@ -49,10 +49,18 @@ func initfile() {
})
Skill := getXml[MovesTbl](path + "227.xml")
SkillMap = utils.ToMap[Move, int](Skill.Moves, func(m Move) int {
return m.ID
// SkillMap = utils.ToMap[Move, int](Skill.Moves, func(m Move) int {
// return m.ID
// })
SkillMap = make(map[int]Move, len(Skill.Moves))
for _, v := range Skill.Moves {
v.SideEffectS = parseSideEffectArgs(v.SideEffect)
v.SideEffectArgS = parseSideEffectArgs(v.SideEffectArg)
SkillMap[v.ID] = v
}
})
pet := getXml[Monsters](path + "226.xml")
PetMAP = utils.ToMap[PetInfo, int](pet.Monsters, func(m PetInfo) int {
return m.ID

View File

@@ -20,11 +20,11 @@ type PetInfo struct {
Type int `xml:"Type,attr"` //类型
GrowthType int `xml:"GrowthType,attr"` //成长类型
HP int `xml:"HP,attr"` //血量种族值
Atk int `xml:"Atk,attr"`
Def int `xml:"Def,attr"`
SpAtk int `xml:"SpAtk,attr"`
SpDef int `xml:"SpDef,attr"`
Spd int `xml:"Spd,attr"`
Atk uint32 `xml:"Atk,attr"` //攻击种族值
Def uint32 `xml:"Def,attr"`
SpAtk uint32 `xml:"SpAtk,attr"`
SpDef uint32 `xml:"SpDef,attr"`
Spd uint32 `xml:"Spd,attr"`
YieldingExp int `xml:"YieldingExp,attr"`
CatchRate string `xml:"CatchRate,attr"`
YieldingEV string `xml:"YieldingEV,attr"`

View File

@@ -5,9 +5,28 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"strings"
"time"
)
func parseSideEffectArgs(argsStr string) []int {
if argsStr == "" {
return []int{}
}
parts := strings.Fields(argsStr)
args := make([]int, 0, len(parts))
for _, part := range parts {
if num, err := strconv.Atoi(part); err == nil {
args = append(args, num)
}
}
return args
}
// MovesTbl 定义 XML 根元素
type MovesTbl struct {
XMLName xml.Name `xml:"MovesTbl"`
@@ -43,15 +62,18 @@ type Move struct {
PwrBindDv int `xml:"PwrBindDv,attr,omitempty"` //威力power取决于自身的潜力个体值
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"`
SideEffect string `xml:"SideEffect,attr,omitempty"`
SideEffectArg string `xml:"SideEffectArg,attr,omitempty"`
SideEffectS []int
SideEffectArgS []int
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"`

View File

@@ -50,6 +50,7 @@ var s = `
func Test_main(t *testing.T) {
initfile()
fmt.Println(SkillMap[10073])
}