refactor: 优化蛋卡抽奖逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-03-24 01:52:56 +08:00
committed by cnb
parent 0aba7e7ccb
commit b3cc06cd38
3 changed files with 8 additions and 13 deletions

View File

@@ -46,11 +46,9 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
result.PetID = newPet.ID result.PetID = newPet.ID
} }
items := service.NewItemService().GetEgg(data1.EggNum) items := service.NewItemService().GetEgg(int(data1.EggNum))
for _, item := range items { for _, item := range items {
if item.ItemId == 0 {
continue
}
c.ItemAdd(item.ItemId, item.ItemCnt) c.ItemAdd(item.ItemId, item.ItemCnt)
result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt}) result.ListInfo = append(result.ListInfo, data.ItemInfo{ItemId: item.ItemId, ItemCnt: item.ItemCnt})
} }

View File

@@ -24,10 +24,8 @@ func init() {
count = 10 count = 10
} }
var rets []string var rets []string
for _, v := range service.NewItemService().GetEgg(int64(count)) { for _, v := range service.NewItemService().GetEgg(count) {
if v.ItemId == 0 {
continue
}
var buf strings.Builder var buf strings.Builder
buf.WriteString(xmlres.ItemsMAP[int(v.ItemId)].Name) buf.WriteString(xmlres.ItemsMAP[int(v.ItemId)].Name)
buf.WriteString(": " + gconv.String(v.ItemCnt)) buf.WriteString(": " + gconv.String(v.ItemCnt))

View File

@@ -2,7 +2,6 @@ package service
import ( import (
"blazing/common/data" "blazing/common/data"
"blazing/common/utils"
"blazing/cool" "blazing/cool"
"blazing/modules/config/model" "blazing/modules/config/model"
@@ -39,13 +38,13 @@ func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
} }
return res return res
} }
func (s *ItemService) GetEgg(count int64) []data.ItemInfo { func (s *ItemService) GetEgg(count int) []data.ItemInfo {
var item []model.ItemGift var item []model.ItemGift
dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item) dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item)
rr := utils.RandomSlice(item, int(count)) var res []data.ItemInfo
var res = make([]data.ItemInfo, len(rr)) for i := 0; i < count; i++ {
for _, v := range rr { v := item[grand.Intn(len(item))]
if v.ItemMaxCount != 0 { if v.ItemMaxCount != 0 {
v.ItemMinCount = int64(grand.N(int(v.ItemMinCount), int(v.ItemMaxCount))) v.ItemMinCount = int64(grand.N(int(v.ItemMinCount), int(v.ItemMaxCount)))
res = append(res, data.ItemInfo{ItemId: v.ItemID, ItemCnt: v.ItemMinCount}) res = append(res, data.ItemInfo{ItemId: v.ItemID, ItemCnt: v.ItemMinCount})