diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index ff97a3eaa..29ec70c91 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -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 diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index 55398bb88..102dc283b 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -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 diff --git a/logic/service/fight/input/ai.go b/logic/service/fight/input/ai.go index fe825344f..12e162dc7 100644 --- a/logic/service/fight/input/ai.go +++ b/logic/service/fight/input/ai.go @@ -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 { diff --git a/logic/service/fight/new.go b/logic/service/fight/new.go index 6585b3cfa..645c17ea6 100644 --- a/logic/service/fight/new.go +++ b/logic/service/fight/new.go @@ -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 { diff --git a/logic/service/item/petuse.go b/logic/service/item/petuse.go index 5718db0cb..596ea0fbb 100644 --- a/logic/service/item/petuse.go +++ b/logic/service/item/petuse.go @@ -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 }) //形态固定 diff --git a/modules/config/service/melee.go b/modules/config/service/melee.go index 6df696350..ecc2d96e3 100644 --- a/modules/config/service/melee.go +++ b/modules/config/service/melee.go @@ -21,7 +21,7 @@ func (s *MELEEService) Def() []model.PetBaseConfig { var pets []model.PetBaseConfig m := cool.DBM(s.Model) - m.OrderRandom().Limit(3).Scan(&pets) + m.OrderRandom().Limit(6).Scan(&pets) return pets // return ret.Interface().([]model.PetFusion)