Files
bl/logic/controller/action_炫彩碎片.go
昔念 e4ad1745d4 ```
feat(utils): 添加切片元素计数功能

新增CountSliceElements函数用于统计切片中各元素的出现次数,
返回map[元素]出现次数的映射关系,支持任意可比较类型的切片元素。

fix(config): 调整地图配置模型默认值设置

修改MapPit结构体中的MinLevel和MaxLevel字段设置,
将数据库约束改为非空并设置默认值为1,确保等级范围配置的有效性。

refactor(item): 移除批量更新物品数量的功能

移除UPDATEM方法的实现代码,该方法原本用于批量更新多个物品的数量,
但存在逻辑问题且不再使用,故将其注释掉以避免后续误用。
```
2026-02-26 23:22:31 +08:00

75 lines
2.0 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
}
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)
// 循环直到选中10个元素
for selectedCount < 10 {
// 随机生成0~14的位索引对应1~15号元素
randBitIdx := grand.Intn(15)
// 构造掩码仅第randBitIdx位为1
mask := uint32(1) << randBitIdx
// 检查该位是否未被选中(避免重复)
if (result.Status & mask) == 0 {
c.ItemAdd(400686+int64(randBitIdx)+1, 1)
result.Status |= mask // 标记该位为选中
selectedCount++ // 选中数+1
}
}
return
}
type C2s_GET_XUANCAI struct {
Head common.TomeeHeader `cmd:"60001" struc:"skip"` //玩家登录
}
// OutInfo 表示地图热度的出站消息
type S2C_GET_XUANCAI struct {
Status uint32
}