Files
bl/logic/controller/action_炫彩碎片.go
xinian d83cf365ac
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed
更新说明
2026-04-05 23:13:06 +08:00

87 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/modules/player/model"
"math/rand"
"time"
"github.com/gogf/gf/v2/util/grand"
)
// Draw15To10WithBitSet 15抽10返回标记抽取结果的uint32位1表示选中
// 规则uint32的第n位0≤n≤14=1 → 选中第n+1号元素
func Draw15To10WithBitSet() uint32 {
// 初始化随机数生成器
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var resultBits uint32 // 核心结果:用位标记选中的元素
selectedCount := 0 // 已选中的数量
// 循环直到选中10个元素
for selectedCount < 10 {
// 随机生成0~14的位索引对应1~15号元素
randBitIdx := r.Intn(15)
// 构造掩码仅第randBitIdx位为1
mask := uint32(1) << randBitIdx
// 检查该位是否未被选中(避免重复)
if (resultBits & mask) == 0 {
resultBits |= mask // 标记该位为选中
selectedCount++ // 选中数+1
}
}
return resultBits
}
// GET_XUANCAI 处理控制器请求。
func (h Controller) GET_XUANCAI(data *C2s_GET_XUANCAI, c *player.Player) (result *S2C_GET_XUANCAI, err errorcode.ErrorCode) {
result = &S2C_GET_XUANCAI{}
selectedCount := 0 // 已选中的数量
res := c.Info.GetTask(13) //第一期
if res == model.Completed {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrDailyGiftLimit)
}
c.Info.SetTask(13, model.Completed)
selectedItems := make([]uint32, 0, 10)
itemMask := make(map[uint32]uint32, 10)
// 循环直到选中10个元素
for selectedCount < 10 {
// 随机生成0~14的位索引对应1~15号元素
randBitIdx := grand.Intn(15)
// 构造掩码仅第randBitIdx位为1
mask := uint32(1) << randBitIdx
// 检查该位是否未被选中(避免重复)
if (result.Status & mask) == 0 {
itemID := uint32(400686 + randBitIdx + 1)
selectedItems = append(selectedItems, itemID)
itemMask[itemID] = mask
selectedCount++ // 选中数+1
}
}
successItems, addErr := c.Service.Item.AddUniqueItems(selectedItems)
if addErr != nil {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError200007)
}
for _, itemID := range successItems {
result.Status |= itemMask[itemID]
}
return
}
// C2s_GET_XUANCAI 定义请求或响应数据结构。
type C2s_GET_XUANCAI struct {
Head common.TomeeHeader `cmd:"60001" struc:"skip"` //玩家登录
}
// OutInfo 表示地图热度的出站消息
type S2C_GET_XUANCAI struct {
Status uint32
}