fix: 修复空提交问题

This commit is contained in:
1
2025-11-23 23:38:03 +00:00
parent aa4574b5eb
commit 240c349b8a
45 changed files with 113 additions and 4438 deletions

View File

@@ -3,7 +3,6 @@ package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"math/rand"
"strings"
"blazing/logic/service/fight"
@@ -39,7 +38,7 @@ func processMonID(bm string) string {
selected = monid[0]
default:
// 长度大于1时随机选取一个
randomIdx := rand.Intn(len(monid))
randomIdx := grand.Intn(len(monid))
selected = monid[randomIdx]
}
return selected

View File

@@ -3,12 +3,12 @@ package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"math/rand"
"time"
"blazing/logic/service/item"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
"github.com/gogf/gf/v2/util/grand"
)
func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
@@ -113,10 +113,7 @@ func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) (
}
}
rand.Seed(time.Now().UnixNano()) // UnixNano 精度更高,避免短时间内种子重复
// 2. 生成 1-10 的随机数rand.Intn(10) → 0-9+1 后范围变为 1-10
randomNum := rand.Intn(10) + 1
randomNum := grand.Intn(10) + 1
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
if t == nil {
t = make(map[uint32]uint32)

View File

@@ -17,24 +17,20 @@ func (h *Controller) GetPetInfo(
data *pet.InInfo,
c *player.Player) (result *pet.OutInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
_, tet, ok := c.FindPet(data.CatchTime)
for _, pi := range c.Info.PetList {
if pi.CatchTime == data.CatchTime {
result = &pet.OutInfo{
PetInfo: pi,
}
return result, 0
if ok {
result = &pet.OutInfo{
PetInfo: *tet,
}
}
if result == nil {
return result, 0
} else {
result = &pet.OutInfo{
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
}
}
return result, 0
}
@@ -73,46 +69,36 @@ func (h *Controller) PetRelease(
}
switch data.Flag {
case 0:
var temp []model.PetInfo
for _, v := range c.Info.PetList {
if v.CatchTime == uint32(data.CatchTime) {
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
t.Data = v
//t.InBag = 0
})
} else {
temp = append(temp, v)
}
index, _, ok := c.FindPet(data.CatchTime)
if ok {
c.Info.PetList = append(c.Info.PetList[:index], c.Info.PetList[index+1:]...)
}
c.Info.PetList = temp
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
case 1:
//todo 背包
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
if len(c.Info.PetList) < 6 {
//todo 背包
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
_, _, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
return item.CatchTime == uint32(data.CatchTime)
_, _, ok := c.FindPet(data.CatchTime)
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 {
//t.InBag = 1
c.Info.PetList = append(c.Info.PetList, t.Data)
result.PetInfo = t.Data
}
})
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 {
//t.InBag = 1
c.Info.PetList = append(c.Info.PetList, t.Data)
result.PetInfo = t.Data
}
})
}
}
if len(c.Info.PetList) > 0 {
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
}
//service.NewUserService(c.Info.UserID).PetAdd( *r)
return result, 0
}
@@ -120,16 +106,13 @@ func (h *Controller) PetRelease(
func (h *Controller) PlayerShowPet(
data *pet.PetShowInboundInfo, c *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetShowOutboundInfo{}
_, onpet, ok := c.FindPet(data.CatchTime)
for _, pi := range c.Info.PetList {
if pi.CatchTime == data.CatchTime {
copier.Copy(&result, pi)
result.Flag = data.Flag
result.UserID = data.Head.UserID
c.GetSpace().Broadcast(c, data.Head.CMD, result)
}
if ok {
copier.Copy(&result, onpet)
result.Flag = data.Flag
result.UserID = data.Head.UserID
c.GetSpace().Broadcast(c, data.Head.CMD, result)
}
return
@@ -139,9 +122,7 @@ func (h *Controller) PetOneCure(
if c.GetSpace().Owner.UserID == c.Info.UserID {
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
}
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
return item.CatchTime == data.CatchTime
})
_, onpet, ok := c.FindPet(data.CatchTime)
if ok {
onpet.Cure()
}
@@ -155,20 +136,21 @@ func (h *Controller) PetOneCure(
// 精灵首发
func (h *Controller) PetFirst(
data *pet.PetDefaultInboundInfo, c *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetDefaultOutboundInfo{}
var ttt []model.PetInfo
for index, pi := range c.Info.PetList {
if pi.CatchTime == data.CatchTime {
ttt = append(ttt, pi)
ttt = append(ttt, c.Info.PetList[:index]...)
ttt = append(ttt, c.Info.PetList[index+1:]...)
result.IsDefault = 1
break
}
//擂台住不能换精灵
if c.GetSpace().Owner.UserID == c.Info.UserID {
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
}
c.Info.PetList = ttt
result = &pet.PetDefaultOutboundInfo{}
index, _, ok := c.FindPet(data.CatchTime)
if ok && index != 0 {
c.Info.PetList[index], c.Info.PetList[0] = c.Info.PetList[0], c.Info.PetList[index]
result.IsDefault = 1
}
return result, 0
}
@@ -177,9 +159,7 @@ func (h *Controller) PetFirst(
// 返回:索引、元素指针、是否找到
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
return item.CatchTime == data.CatchTime
})
_, onpet, ok := c.FindPet(data.CatchTime)
if ok {
c.AddPetExp(onpet, data.Exp)
@@ -190,28 +170,18 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player)
}, 0
}
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
_, onpet, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
return item.CatchTime == data.CatchTime
})
_, onpet, ok := c.FindPet(data.CatchTime)
if ok {
_, _, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
_, HasSkill, ok := utils.FindWithIndex(onpet.SkillList, func(item model.SkillInfo) bool { //已经存在技能
return item.ID == data.ReplaceSkill
})
if ok {
return
}
for i := 0; i < len(onpet.SkillList); i++ {
if onpet.SkillList[i].ID == data.HasSkill {
onpet.SkillList[i].ID = data.ReplaceSkill
onpet.SkillList[i].PP = uint32(xmlres.SkillMap[int(onpet.SkillList[i].ID)].MaxPP)
}
if !ok {
HasSkill.ID = data.ReplaceSkill
HasSkill.PP = uint32(xmlres.SkillMap[int(HasSkill.ID)].MaxPP)
}
}
// onpet.SkillList = lo.UniqBy(onpet.SkillList, func(s model.SkillInfo) int {
// return int(s.ID)
// })
return &pet.ChangeSkillOutInfo{
CatchTime: data.CatchTime,
}, 0