```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(xmlres): 使用rawFlexibleString替换字符串类型以支持灵活解析

- 将EffectArg结构体中的SideEffectArg字段类型从string改为rawFlexibleString
- 将Move结构体中的Name字段类型从string改为rawFlexibleString,并更新反序列化逻辑
- 统一配置文件解析方式,移除磁盘回退机制并简化readConfigContent函数
- 移除不再使用的导入包和变量

fix(fight): 修复战斗系统中的空技能和无效数据问题

- 在
This commit is contained in:
昔念
2026-04-13 11:28:30 +08:00
parent eca7dd86e1
commit 3739c2a6f9
8 changed files with 253 additions and 252 deletions

View File

@@ -5,7 +5,7 @@ type EffectArg struct {
SideEffect []struct {
ID int `json:"ID"`
SideEffectArgcount int `json:"SideEffectArgcount"`
SideEffectArg string `json:"SideEffectArg,omitempty"`
SideEffectArg rawFlexibleString `json:"SideEffectArg,omitempty"`
} `json:"SideEffect"`
} `json:"SideEffects"`
}

View File

@@ -6,9 +6,6 @@ import (
_ "blazing/common/data/xmlres/packed"
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/ECUST-XX/xml"
"github.com/gogf/gf/v2/os/gres"
@@ -16,27 +13,9 @@ import (
)
var path string
var diskConfigPath string
func readConfigContent(path string) []byte {
content := gres.GetContent(path)
if len(content) > 0 {
return content
}
if diskConfigPath == "" {
return content
}
diskPath := filepath.Join(diskConfigPath, strings.TrimPrefix(path, "config/"))
data, err := os.ReadFile(diskPath)
if err != nil {
fmt.Printf("[xmlres] readConfigContent fallback failed: path=%s disk=%s err=%v\n", path, diskPath, err)
return content
}
fmt.Printf("[xmlres] readConfigContent fallback hit: path=%s disk=%s len=%d\n", path, diskPath, len(data))
return data
return gres.GetContent(path)
}
func getXml[T any](path string) T {
@@ -93,9 +72,6 @@ var (
func Initfile() {
//gres.Dump()
path1, _ := os.Getwd()
diskConfigPath = filepath.Join(path1, "public", "config")
path = path1 + "/public/config/"
path = "config/"
MapConfig = getXml[Maps](path + "210.xml")

View File

@@ -0,0 +1,26 @@
package xmlres
import (
"encoding/json"
"testing"
)
func TestMoveUnmarshalJSONAcceptsNumericName(t *testing.T) {
var move Move
if err := json.Unmarshal([]byte(`{"ID":10001,"Name":1,"Category":1,"Type":8,"Power":35,"MaxPP":35,"Accuracy":95}`), &move); err != nil {
t.Fatalf("unmarshal move failed: %v", err)
}
if move.Name != "1" {
t.Fatalf("expected numeric name to convert to string, got %q", move.Name)
}
}
func TestEffectArgUnmarshalJSONAcceptsNumericSideEffectArg(t *testing.T) {
var cfg EffectArg
if err := json.Unmarshal([]byte(`{"SideEffects":{"SideEffect":[{"ID":1,"SideEffectArgcount":1,"SideEffectArg":3}]}}`), &cfg); err != nil {
t.Fatalf("unmarshal effect arg failed: %v", err)
}
if got := string(cfg.SideEffects.SideEffect[0].SideEffectArg); got != "3" {
t.Fatalf("expected numeric side effect arg to convert to string, got %q", got)
}
}

View File

@@ -115,7 +115,7 @@ type Move struct {
func (m *Move) UnmarshalJSON(data []byte) error {
type moveAlias struct {
ID int `json:"ID"`
Name string `json:"Name"`
Name rawFlexibleString `json:"Name"`
Category int `json:"Category"`
Type int `json:"Type"`
Power int `json:"Power"`
@@ -150,7 +150,7 @@ func (m *Move) UnmarshalJSON(data []byte) error {
*m = Move{
ID: aux.ID,
Name: aux.Name,
Name: string(aux.Name),
Category: aux.Category,
Type: aux.Type,
Power: aux.Power,

View File

@@ -184,6 +184,9 @@ func (f *FightC) collectAttackValues(inputs []*input.Input) []model.AttackValue
continue
}
attackValue := *fighter.AttackValue
if attackValue.SkillID == 0 {
continue
}
attackValue.ActorIndex = uint32(actorIndex)
values = append(values, attackValue)
}
@@ -462,11 +465,13 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
// })
return
}
if len(attackValueResult.FirstAttackInfo) > 0 || len(attackValueResult.SecondAttackInfo) > 0 {
f.BroadcastPlayers(func(p common.PlayerI) {
if !f.LegacyGroupProtocol {
f.sendFightPacket(p, fightPacketSkillResult, &attackValueResult)
}
})
}
f.Broadcast(func(fighter *input.Input) {
fighter.CanChange = 0
})

View File

@@ -484,13 +484,6 @@ func initfightready(in *input.Input) (model.FightUserInfo, []model.ReadyFightPet
if err != nil {
panic(err)
}
if i == 0 && in.CanCapture > 0 {
if in.CanCapture > 255 {
t[i].IsCapture = 255
} else {
t[i].IsCapture = uint8(in.CanCapture)
}
}
}
return userindo, t

View File

@@ -140,6 +140,8 @@ func init() {
g.Server().BindMiddleware("/admin/*/open/*", BaseAuthorityMiddlewareOpen)
g.Server().BindMiddleware("/rpc/*", BaseAuthorityMiddlewareOpen)
g.Server().BindMiddleware("/admin/*/comm/*", BaseAuthorityMiddlewareComm)
g.Server().BindMiddleware("/seer/game/cdk/*", BaseAuthorityMiddlewareComm)
g.Server().BindMiddleware("/seer/game/cdk/*", BaseAuthorityMiddleware)
g.Server().BindMiddleware("/admin/*", BaseAuthorityMiddleware)
// g.Server().BindMiddleware("/*", AutoI18n)
g.Server().BindMiddleware("/*", MiddlewareCORS)

View File

@@ -119,7 +119,6 @@ type ReadyFightPetInfo struct {
SkinID uint32 `fieldDesc:"精灵皮肤ID" `
ShinyLen uint32 `json:"-" struc:"sizeof=ShinyInfo"`
ShinyInfo []data.GlowFilter `json:"ShinyInfo,omitempty"`
IsCapture uint8 `struc:"uint8" json:"isCapture"`
}
type FightOverInfo struct {
//0 正常结束