refactor(fight): 重构战斗模块数据结构和逻辑
- 更新 FightPetInfo 和 AttackValue 结构体,优化精灵属性和状态表示 - 删除未使用的 start_test.go 文件 - 调整 FightC 结构体,整合战斗准备和状态管理 - 统一 SkillInfo 中 PP 字段命名
This commit is contained in:
@@ -26,12 +26,10 @@ type FightPetInfo struct {
|
|||||||
// 当前等级,@UInt long
|
// 当前等级,@UInt long
|
||||||
Level uint32 `fieldDesc:"当前等级" `
|
Level uint32 `fieldDesc:"当前等级" `
|
||||||
|
|
||||||
// 精灵是否能捕捉(1为能捕捉,0为不能捕捉),@UInt long
|
// 精灵是否能捕捉(1为能捕捉,0为不能捕捉),
|
||||||
Catchable uint32 `fieldDesc:"精灵是否能捕捉. 1为能捕捉 0为不能捕捉" `
|
Catchable uint32 `fieldDesc:"精灵是否能捕捉. 1为能捕捉 0为不能捕捉" `
|
||||||
|
//能力提升属性
|
||||||
// 战斗属性等级数组(6个单字节)
|
Prop PropDict
|
||||||
// byte[],固定长度6,存储buff等级、攻击、速度等属性
|
|
||||||
BattleLV [6]byte `fieldDesc:"这里实际上应该是6个单字节byte, 内容为buff等级 攻击 速度 特攻 防御 特防 命中等.但具体顺序未知可能需要测试. 具体数值为1-6等级" serialize:"fixedLength=6,type=byteArray"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttackValue 战斗中的攻击数值信息
|
// AttackValue 战斗中的攻击数值信息
|
||||||
@@ -46,11 +44,54 @@ type AttackValue struct {
|
|||||||
State uint32 `json:"state" fieldDescription:"固定值0 需要后续测试"`
|
State uint32 `json:"state" fieldDescription:"固定值0 需要后续测试"`
|
||||||
SkillList []model.SkillInfo `json:"skillList" fieldDescription:"根据精灵的数据插入技能 最多4条 不定长"`
|
SkillList []model.SkillInfo `json:"skillList" fieldDescription:"根据精灵的数据插入技能 最多4条 不定长"`
|
||||||
IsCritical uint32 `json:"isCritical" fieldDescription:"是否暴击"`
|
IsCritical uint32 `json:"isCritical" fieldDescription:"是否暴击"`
|
||||||
Status [20]byte `json:"status" fieldDescription:"20个字节 各种状态: 0:\"麻痹\",1:\"中毒\",2:\"烧伤\",4:\"寄生\",5:\"冻伤\",6:\"害怕\",7:\"疲惫\",8:\"睡眠\",9:\"石化\",10:\"混乱\",15:\"冰封\",16:\"流血\""`
|
Status StatusDict //精灵的状态
|
||||||
BattleLv [6]byte `json:"battleLv" fieldDescription:"6个单字节byte, 内容为buff等级 攻击 速度 特攻 防御 特防命中等. 但具体顺序未知可能需要测试. 具体数值为1-6等级"`
|
//能力提升属性
|
||||||
|
Prop PropDict
|
||||||
// OwnerMaxShield uint32 `json:"ownerMaxShield" fieldDescription:"我方最大护盾"`
|
// OwnerMaxShield uint32 `json:"ownerMaxShield" fieldDescription:"我方最大护盾"`
|
||||||
// OwnerCurrentShield uint32 `json:"ownerCurrentShield" fieldDescription:"我方当前护盾"`
|
// OwnerCurrentShield uint32 `json:"ownerCurrentShield" fieldDescription:"我方当前护盾"`
|
||||||
}
|
}
|
||||||
|
type StatusDict struct {
|
||||||
|
Paralysis_0 bool `struc:"[1]byte"` // 0: 麻痹
|
||||||
|
Poisoned_1 bool `struc:"[1]byte"` // 1: 中毒
|
||||||
|
Burned_2 bool `struc:"[1]byte"` // 2: 烧伤
|
||||||
|
DrainHP_3 bool `struc:"[1]byte"` // 3: 吸取对方的体力
|
||||||
|
DrainedHP_4 bool `struc:"[1]byte"` // 4: 被对方吸取体力
|
||||||
|
Frozen_5 bool `struc:"[1]byte"` // 5: 冻伤
|
||||||
|
Fear_6 bool `struc:"[1]byte"` // 6: 害怕
|
||||||
|
Tired_7 bool `struc:"[1]byte"` // 7: 疲惫
|
||||||
|
Sleep_8 bool `struc:"[1]byte"` // 8: 睡眠
|
||||||
|
Petrified_9 bool `struc:"[1]byte"` // 9: 石化
|
||||||
|
Confused_10 bool `struc:"[1]byte"` // 10: 混乱
|
||||||
|
Weakened_11 bool `struc:"[1]byte"` // 11: 衰弱
|
||||||
|
MountainGodGuard_12 bool `struc:"[1]byte"` // 12: 山神守护
|
||||||
|
Flammable_13 bool `struc:"[1]byte"` // 13: 易燃
|
||||||
|
Berserk_14 bool `struc:"[1]byte"` // 14: 狂暴
|
||||||
|
IceBound_15 bool `struc:"[1]byte"` // 15: 冰封
|
||||||
|
Bleeding_16 bool `struc:"[1]byte"` // 16: 流血
|
||||||
|
ImmuneToStatDrop_17 bool `struc:"[1]byte"` // 17: 免疫能力下降
|
||||||
|
ImmuneToAbnormal_18 bool `struc:"[1]byte"` // 18: 免疫异常状态
|
||||||
|
Paralyzed_19 bool `struc:"[1]byte"` // 19: 瘫痪
|
||||||
|
Blind_20 bool `struc:"[1]byte"` // 20: 失明
|
||||||
|
}
|
||||||
|
|
||||||
|
// 精灵的能力提升
|
||||||
|
type PropDict struct {
|
||||||
|
// 攻击(@UInt long → uint32)
|
||||||
|
Attack uint32 `struc:"[1]byte"`
|
||||||
|
// 防御(@UInt long → uint32)
|
||||||
|
Defence uint32 `struc:"[1]byte"`
|
||||||
|
// 特攻(@UInt long → uint32)
|
||||||
|
SpecialAttack uint32 `struc:"[1]byte"`
|
||||||
|
// 特防(@UInt long → uint32)
|
||||||
|
SpecialDefence uint32 `struc:"[1]byte"`
|
||||||
|
|
||||||
|
// 速度(@UInt long → uint32)
|
||||||
|
Speed uint32 `struc:"[1]byte"`
|
||||||
|
// 命中(@UInt long → uint32)
|
||||||
|
Accuracy uint32 `struc:"[1]byte"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BattleLevels 战斗属性等级结构体,对应原6字节数组
|
||||||
|
|
||||||
// NoteUseSkillOutboundInfo 战斗技能使用通知的出站信息结构体
|
// NoteUseSkillOutboundInfo 战斗技能使用通知的出站信息结构体
|
||||||
type NoteUseSkillOutboundInfo struct {
|
type NoteUseSkillOutboundInfo struct {
|
||||||
@@ -80,12 +121,6 @@ type FightUserInfo struct {
|
|||||||
|
|
||||||
// NoteReadyToFightInfo 战斗准备就绪消息结构体,NoteReadyToFightInfo
|
// NoteReadyToFightInfo 战斗准备就绪消息结构体,NoteReadyToFightInfo
|
||||||
type NoteReadyToFightInfo struct {
|
type NoteReadyToFightInfo struct {
|
||||||
MAXPET uint32 `struc:"skip"` //,最大精灵数
|
|
||||||
//战斗发起者ID
|
|
||||||
OwnerID uint32 `struc:"skip"`
|
|
||||||
|
|
||||||
AFinished bool `struc:"skip"`
|
|
||||||
BFinished bool `struc:"skip"`
|
|
||||||
// 战斗类型ID(与野怪战斗为3,与人战斗为1,前端似乎未使用)
|
// 战斗类型ID(与野怪战斗为3,与人战斗为1,前端似乎未使用)
|
||||||
// @UInt long
|
// @UInt long
|
||||||
FightId EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
FightId EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
package fight
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 记录A、B是否完成的标志
|
|
||||||
var (
|
|
||||||
aFinished bool
|
|
||||||
bFinished bool
|
|
||||||
mu sync.Mutex // 保护标志位的互斥锁
|
|
||||||
)
|
|
||||||
|
|
||||||
// 当A 战斗准备完成
|
|
||||||
func onAFinished() {
|
|
||||||
fmt.Println("A已完成,触发onAFinished")
|
|
||||||
checkBothFinished() // 检查是否两者都完成
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当B 战斗准备完成
|
|
||||||
func onBFinished() {
|
|
||||||
fmt.Println("B已完成,触发onBFinished")
|
|
||||||
checkBothFinished() // 检查是否两者都完成
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当A和B都 这时候给双方回复开始战斗包
|
|
||||||
func onBothFinished() {
|
|
||||||
fmt.Println("A和B都已完成,触发onBothFinished")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查A和B是否都完成,若都完成则调用onBothFinished
|
|
||||||
func checkBothFinished() {
|
|
||||||
mu.Lock()
|
|
||||||
defer mu.Unlock()
|
|
||||||
|
|
||||||
if aFinished && bFinished {
|
|
||||||
onBothFinished()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 模拟A的执行
|
|
||||||
func doA() {
|
|
||||||
fmt.Println("A开始执行...")
|
|
||||||
time.Sleep(2 * time.Second) // 模拟耗时操作
|
|
||||||
mu.Lock()
|
|
||||||
aFinished = true
|
|
||||||
mu.Unlock()
|
|
||||||
onAFinished() // A完成后调用
|
|
||||||
}
|
|
||||||
|
|
||||||
// 模拟B的执行
|
|
||||||
func doB() {
|
|
||||||
fmt.Println("B开始执行...")
|
|
||||||
time.Sleep(3 * time.Second) // 模拟耗时操作
|
|
||||||
mu.Lock()
|
|
||||||
bFinished = true
|
|
||||||
mu.Unlock()
|
|
||||||
onBFinished() // B完成后调用
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// 启动A和B的执行
|
|
||||||
go doA()
|
|
||||||
go doB()
|
|
||||||
|
|
||||||
// 等待一段时间,避免主程序提前退出
|
|
||||||
time.Sleep(4 * time.Second)
|
|
||||||
}
|
|
||||||
@@ -18,9 +18,15 @@ type PlayerI interface {
|
|||||||
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
|
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
|
||||||
}
|
}
|
||||||
type FightC struct {
|
type FightC struct {
|
||||||
Info *info.NoteReadyToFightInfo
|
Info *info.NoteReadyToFightInfo
|
||||||
Our PlayerI
|
Our PlayerI
|
||||||
Opp PlayerI
|
Opp PlayerI
|
||||||
|
MAXPET uint32 //,最大精灵数
|
||||||
|
//战斗发起者ID
|
||||||
|
OwnerID uint32
|
||||||
|
//玩家拥有者是否准备完成
|
||||||
|
AFinished bool
|
||||||
|
BFinished bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用技能
|
// 使用技能
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func GenPetInfo(id, dv, natureId, abilityTypeEnum, shinyid, level uint32) *PetIn
|
|||||||
tttt = LastFourElements(tttt) //获取最后四个技能,如果不足,那就取全部技能
|
tttt = LastFourElements(tttt) //获取最后四个技能,如果不足,那就取全部技能
|
||||||
for i := 0; i < len(tttt); i++ {
|
for i := 0; i < len(tttt); i++ {
|
||||||
p.SkillList[i].ID = tttt[i]
|
p.SkillList[i].ID = tttt[i]
|
||||||
p.SkillList[i].Pp = uint32(xmlres.SkillMap[int(tttt[i])].MaxPP)
|
p.SkillList[i].PP = uint32(xmlres.SkillMap[int(tttt[i])].MaxPP)
|
||||||
|
|
||||||
}
|
}
|
||||||
p.SkillListLen = uint32(len(tttt))
|
p.SkillListLen = uint32(len(tttt))
|
||||||
@@ -246,7 +246,7 @@ type PetEffectInfo struct {
|
|||||||
// SkillInfo 精灵技能信息结构(SkillInfo)
|
// SkillInfo 精灵技能信息结构(SkillInfo)
|
||||||
type SkillInfo struct {
|
type SkillInfo struct {
|
||||||
ID uint32
|
ID uint32
|
||||||
Pp uint32
|
PP uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName Pet's table name
|
// TableName Pet's table name
|
||||||
|
|||||||
Reference in New Issue
Block a user