refactor: 重构宠物初始化逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

提取宠物配置初始化到ConfigBoss方法,简化initplayer代码
This commit is contained in:
xinian
2026-03-07 11:30:17 +08:00
committed by cnb
parent 2dab20653f
commit bbaa71f4b2
4 changed files with 59 additions and 69 deletions

View File

@@ -5,7 +5,9 @@ import (
"blazing/common/data/xmlres"
"blazing/common/utils"
"blazing/cool"
"encoding/json"
"blazing/modules/config/model"
"blazing/modules/config/service"
"errors"
"fmt"
@@ -118,6 +120,50 @@ type PetInfo struct {
ExtSkin []uint32 `struc:"skip"` //可用皮肤
}
func (pet *PetInfo) ConfigBoss(bm model.PetBaseConfig) {
var color data.GlowFilter
err := json.Unmarshal([]byte(bm.Color), &color)
if err == nil && color.Alpha != 0 {
pet.ShinyInfo = append(pet.ShinyInfo, color)
}
if bm.Hp != 0 {
pet.Hp = uint32(bm.Hp)
pet.MaxHp = uint32(bm.Hp)
}
if len(bm.Prop) == 5 {
for i := 0; i < 5; i++ {
if bm.Prop[i] != 0 {
pet.Prop[i] = bm.Prop[i]
}
}
//monster.Prop = [5]uint32(bm.Prop)
}
if len(bm.SKill) != 0 {
for i := 0; i < 4; i++ {
if bm.SKill[i] != 0 {
pet.SkillList[i].ID = bm.SKill[i]
}
}
}
effects := service.NewEffectService().Args(bm.Effect)
for _, v := range effects {
pet.EffectInfo = append(pet.EffectInfo, PetEffectInfo{
Idx: uint16(v.SeIdx),
EID: gconv.Uint16(v.Eid),
Args: gconv.Ints(v.Args),
})
}
}
func (pet *PetInfo) Type() int {
return xmlres.PetMAP[int(pet.ID)].Type