修复大乱斗问题
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
昔念
2026-02-20 09:40:22 +08:00
parent 58440d5993
commit 53b18cfd0c
6 changed files with 37 additions and 17 deletions

View File

@@ -38,8 +38,8 @@ func CreateBattlePetEntity(info model.PetInfo, rand *rand.Rand) *BattlePetEntity
for i := 0; i < len(info.SkillList); i++ {
//todo 技能信息应该每回合进行深拷贝,保证每次的技能效果都是不一样的
ret.Skills[info.SkillList[i].ID] = CreateSkill(&info.SkillList[i], rand, ret)
// ret.Skills[info.SkillList[i].ID] = CreateSkill(&info.SkillList[i], rand, ret)
ret.Skills = append(ret.Skills, CreateSkill(&info.SkillList[i], rand, ret))
}
return ret

View File

@@ -4,9 +4,8 @@ import (
"blazing/common/data"
"blazing/common/socket/errorcode"
"blazing/common/utils"
"blazing/modules/config/service"
config "blazing/modules/config/model"
"blazing/modules/player/model"
"encoding/json"
"blazing/logic/service/common"
@@ -34,6 +33,7 @@ type FightC struct {
Our *input.Input //始终等于房主ID
Opp *input.Input //对手ID
Switch map[uint32]*action.ActiveSwitchAction
Melee []config.PetBaseConfig
startl sync.Once
rand *rand.Rand
StartTime time.Time
@@ -159,23 +159,19 @@ func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode
in.AllPet = in.AllPet[:1]
case info.BattleMode.PET_MELEE:
in.AllPet = make([]*info.BattlePetEntity, 0)
// if len(meetpet) == 0 {
// initmeetpet()
// }
r := service.NewMELEEService().Def()
if len(r) == 0 {
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
var meetpet []config.PetBaseConfig
if c.GetInfo().UserID == f.ownerID {
meetpet = f.Melee[:3]
} else {
meetpet = f.Melee[3:]
}
for i, v := range r {
for i, v := range meetpet {
if v.Lv == 0 {
v.Lv = 100
}
// var effect int
// if len(v.Effect) > 0 {
// effect = int(v.Effect[0])
// }
pet := model.GenPetInfo(int(v.MonID), 24, int(v.Nature), int(v.Effect[0]), int(v.Lv), nil, 0)
var color data.GlowFilter

View File

@@ -1,7 +1,24 @@
package input
import "blazing/logic/service/fight/info"
import (
"blazing/logic/service/fight/info"
"math/rand"
"time"
)
// Shuffle 打乱切片顺序,使用 Fisher-Yates 洗牌算法,泛型支持任意类型
func Shuffle[T any](slice []T) {
// 初始化随机数生成器,用当前时间作为种子,避免每次打乱结果相同
r := rand.New(rand.NewSource(time.Now().UnixNano()))
// 从后往前遍历,逐个交换
for i := len(slice) - 1; i > 0; i-- {
// 生成 0 到 i 之间的随机索引
j := r.Intn(i + 1)
// 交换 i 和 j 位置的元素
slice[i], slice[j] = slice[j], slice[i]
}
}
func (our *Input) GetAction() {
next := our.Exec(func(t Effect) bool {
@@ -58,6 +75,7 @@ func (our *Input) GetAction() {
}
}
Shuffle(skills)
if usedskill == nil {
for _, s := range skills {

View File

@@ -8,6 +8,7 @@ import (
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/player"
"blazing/modules/config/service"
"math/rand"
"time"
)
@@ -31,6 +32,9 @@ func NewFight(p1, p2 common.PlayerI, fn func(info.FightOverInfo)) (*FightC, erro
//这里应该挪到玩家初始化执行
f.ReadyInfo.Status = f.Info.Status
if f.Info.Mode == info.BattleMode.PET_MELEE {
f.Melee = service.NewMELEEService().Def()
}
var err errorcode.ErrorCode
f.Our, err = f.initplayer(p1)
if err > 0 {

View File

@@ -8,6 +8,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/samber/lo"
)
type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool
@@ -218,6 +219,7 @@ func init() {
PetItemRegistry.RegisterExact(300152, func(itemid uint32, onpet *model.PetInfo) bool {
onpet.SkinID = onpet.ID
onpet.ExtSkin = append(onpet.ExtSkin, onpet.ID) //添加到拓展皮肤列表
lo.Uniq(onpet.ExtSkin)
return true
})
//形态固定