`` refactor(fight): 重构战斗初始化逻辑,移除MAXPET字段并优化宠物列表处理方式``

This commit is contained in:
1
2025-10-31 02:24:49 +00:00
parent 4ae06f5695
commit 7bc7776074
3 changed files with 25 additions and 31 deletions

View File

@@ -101,12 +101,9 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) bool {
}
temp := input.NewInput(f, c)
temp.AllPet = make([]*info.BattlePetEntity, 0)
temp.InitAttackValue()
for i := 0; i < len(c.GetInfo().PetList); i++ {
if f.Info.MAXPET == 0 || i < int(f.Info.MAXPET) {
temp.AllPet = append(temp.AllPet, info.CreateBattlePetEntity(&c.GetInfo().PetList[i], f.rand))
}
temp.AllPet = append(temp.AllPet, info.CreateBattlePetEntity(&c.GetInfo().PetList[i], f.rand))
}
@@ -123,6 +120,12 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) bool {
// 同类型(都>0或都=0保持原有顺序
return i < j
})
switch f.Info.Mode {
case info.BattleMode.SINGLE_MODE:
temp.AllPet = temp.AllPet[:1]
default:
}
if opp {
f.Opp = temp //这里是对方的
copier.Copy(&f.Info.OpponentInfo, f.Opp.Player.GetInfo())
@@ -165,11 +168,7 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla
f.ownerID = p1.GetInfo().UserID
f.Info.Status = status //房主
f.Info.Mode = mode
switch mode {
case info.BattleMode.SINGLE_MODE:
f.Info.MAXPET = 1
default:
}
f.StartTime = time.Now()
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
f.rand = rand.New(rand.NewSource(seed))
@@ -526,8 +525,8 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
f.First, f.Second = f.Our, f.Opp
}
f.First.InitAttackValue()
f.Second.InitAttackValue()
f.First.ResetAttackValue()
f.Second.ResetAttackValue()
switch {
case sattack != nil:

View File

@@ -99,14 +99,15 @@ func NewAttackValue(userid uint32) *AttackValue {
// AttackValue 战斗中的攻击数值信息
type AttackValue struct {
UserID uint32 `json:"userId" fieldDescription:"玩家的米米号 与野怪对战userid = 0"`
SkillID uint32 `json:"skillId" fieldDescription:"使用技能的id"`
AttackTime uint32 `json:"attackTime" fieldDescription:"是否击中 如果为0 则miss 如果为1 则击中,2为必中"`
LostHp uint32 `json:"lostHp" fieldDescription:"我方造成的伤害"`
GainHp int32 `json:"gainHp" fieldDescription:"我方获得血量"`
RemainHp int32 `json:"remainHp" fieldDescription:"我方剩余血量"`
MaxHp uint32 `json:"maxHp" fieldDescription:"我方最大血量"`
State uint32 `json:"state" fieldDescription:"固定值0 需要后续测试"`
UserID uint32 `json:"userId" fieldDescription:"玩家的米米号 与野怪对战userid = 0"`
SkillID uint32 `json:"skillId" fieldDescription:"使用技能的id"`
AttackTime uint32 `json:"attackTime" fieldDescription:"是否击中 如果为0 则miss 如果为1 则击中,2为必中"`
LostHp uint32 `json:"lostHp" fieldDescription:"我方造成的伤害"`
GainHp int32 `json:"gainHp" fieldDescription:"我方获得血量"`
RemainHp int32 `json:"remainHp" fieldDescription:"我方剩余血量"`
MaxHp uint32 `json:"maxHp" fieldDescription:"我方最大血量"`
//颜色
State uint32 `json:"state" `
SkillListLen uint32 `struc:"sizeof=SkillList"`
SkillList []model.SkillInfo `json:"skillList" fieldDescription:"根据精灵的数据插入技能 最多4条 不定长"`
IsCritical uint32 `json:"isCritical" fieldDescription:"是否暴击"`
@@ -198,7 +199,7 @@ type FightUserInfo struct {
// NoteReadyToFightInfo 战斗准备就绪消息结构体NoteReadyToFightInfo
type NoteReadyToFightInfo struct {
MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
//MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
// 战斗类型ID与野怪战斗为3与人战斗为1前端似乎未使用
// @UInt long
Status EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3与人战斗似乎是1" `

View File

@@ -54,21 +54,15 @@ func (i *Input) GetPetInfo() *info.BattlePetEntity {
return i.CurrentPet
}
func (i *Input) ResetAttackValue() {
i.AttackValue.SkillID = 0
}
// 这个每回合都会调用
func (i *Input) InitAttackValue() {
var old *info.AttackValue
if i.AttackValue != nil {
old = i.AttackValue
}
i.AttackValue = info.NewAttackValue(i.Player.GetInfo().UserID)
if old != nil {
i.AttackValue.Prop = old.Prop
i.AttackValue.Status = old.Status
i.AttackValue.SkillList = old.SkillList
}
}
func (i *Input) GetPet(id uint32) (ii *info.BattlePetEntity, Reason info.ChangePetInfo) {