refactor: 重构战斗属性和特效应用逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -44,7 +44,7 @@ func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Playe
|
||||
ai := player.NewAI_player(monsterInfo)
|
||||
ai.CanCapture = resolveBossCaptureRate(bossConfigs[0].IsCapture, leadMonsterID)
|
||||
ai.BossScript = bossConfigs[0].Script
|
||||
ai.Prop[0] = 2
|
||||
ai.AddBattleProp(0, 2)
|
||||
|
||||
var fightC *fight.FightC
|
||||
fightC, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) {
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user