```
feat(utils): 添加切片元素计数功能 新增CountSliceElements函数用于统计切片中各元素的出现次数, 返回map[元素]出现次数的映射关系,支持任意可比较类型的切片元素。 fix(config): 调整地图配置模型默认值设置 修改MapPit结构体中的MinLevel和MaxLevel字段设置, 将数据库约束改为非空并设置默认值为1,确保等级范围配置的有效性。 refactor(item): 移除批量更新物品数量的功能 移除UPDATEM方法的实现代码,该方法原本用于批量更新多个物品的数量, 但存在逻辑问题且不再使用,故将其注释掉以避免后续误用。 ```
This commit is contained in:
74
logic/controller/action_炫彩碎片.go
Normal file
74
logic/controller/action_炫彩碎片.go
Normal file
@@ -0,0 +1,74 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user