refactor: 重构战斗属性和特效应用逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-06 03:11:38 +08:00
committed by cnb
parent a16a06e389
commit 40ec827342
9 changed files with 166 additions and 39 deletions

View File

@@ -41,6 +41,35 @@ func (t *BattlePetEntity) Alive() bool {
}
func (t *BattlePetEntity) AddBattleAttr(attr int, value uint32) {
if t == nil || value == 0 {
return
}
switch attr {
case 0:
t.Info.MaxHp += value
t.Info.Hp += value
case 1, 2, 3, 4, 5:
t.Info.Prop[attr-1] += value
}
}
func (t *BattlePetEntity) ApplyInitEffectBonus(effect model.PetEffectInfo) {
if t == nil || effect.EID != 26 || len(effect.Args) < 2 {
return
}
for i := 0; i+1 < len(effect.Args); i += 2 {
attr := effect.Args[i]
value := effect.Args[i+1]
if value <= 0 {
continue
}
t.AddBattleAttr(attr, uint32(value))
}
}
// 创建精灵实例
func CreateBattlePetEntity(info model.PetInfo) *BattlePetEntity {
ret := &BattlePetEntity{}

View File

@@ -145,28 +145,6 @@ func (our *Input) SetCurPetAt(index int, pet *info.BattlePetEntity) {
our.CurPet[index] = pet
}
func applyInitPetEffectBonus(pet *info.BattlePetEntity, effect model.PetEffectInfo) {
if pet == nil || effect.EID != 26 || len(effect.Args) < 2 {
return
}
for i := 0; i+1 < len(effect.Args); i += 2 {
attr := effect.Args[i]
value := effect.Args[i+1]
if value <= 0 {
continue
}
switch attr {
case 0:
pet.Info.MaxHp += uint32(value)
pet.Info.Hp += uint32(value)
case 1, 2, 3, 4, 5:
pet.Info.Prop[attr-1] += uint32(value)
}
}
}
// 非原地交换收集非0血量精灵 + 0血量精灵拼接后返回
func (our *Input) SortPet() {
var nonZeroHP []*info.BattlePetEntity // 收集血量>0的精灵保持原顺序
@@ -189,7 +167,7 @@ func (our *Input) SortPet() {
t.Duration(-1)
applyInitPetEffectBonus(s, e1)
s.ApplyInitEffectBonus(e1)
our.AddEffect(our, t)
}

View File

@@ -154,7 +154,7 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) {
if ai.CanCapture > 0 {
opp.CanCapture = ai.CanCapture
}
opp.AttackValue.Prop = ai.Prop
ai.ApplyBattleProps(opp.AttackValue)
}
}
}

View File

@@ -14,8 +14,6 @@ import (
type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool
const maxHPUpEffectIdx uint16 = 60000
// RangeHandler 范围ID处理器用于ID区间匹配
type RangeHandler struct {
Start uint32
@@ -121,19 +119,9 @@ func handleNewSeIdxPetItem(itemid uint32, onpet *model.PetInfo) errorcode.ErrorC
}
if itemCfg.NewSeIdx == 0 {
if itemCfg.MaxHPUp > 0 {
for _, eff := range onpet.EffectInfo {
if eff.Status == 8 {
return errorcode.ErrorCodes.ErrCannotInjectPillAgain
}
if !onpet.AddMaxHPUpEffect(itemid, itemCfg.MaxHPUp) {
return errorcode.ErrorCodes.ErrCannotInjectPillAgain
}
onpet.EffectInfo = append(onpet.EffectInfo, model.PetEffectInfo{
ItemID: itemid,
Idx: maxHPUpEffectIdx,
Status: 8,
EID: 26,
Args: []int{0, itemCfg.MaxHPUp},
})
return 0
}
return errorcode.ErrorCodes.ErrItemUnusable

View File

@@ -44,6 +44,27 @@ func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo {
}
return ret
}
func (p *baseplayer) AddBattleProp(index int, level int8) {
if p == nil || index < 0 || index >= len(p.Prop) || level == 0 {
return
}
p.Prop[index] += level
if p.Prop[index] > 6 {
p.Prop[index] = 6
}
if p.Prop[index] < -6 {
p.Prop[index] = -6
}
}
func (p *baseplayer) ApplyBattleProps(target *model.AttackValue) {
if p == nil || target == nil {
return
}
target.Prop = p.Prop
}
func (f *baseplayer) InvitePlayer(ff common.PlayerI) {
}