2026-02-26 23:22:31 +08:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 23:13:06 +08:00
|
|
|
|
// GET_XUANCAI 处理控制器请求。
|
2026-02-26 23:22:31 +08:00
|
|
|
|
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)
|
2026-03-31 06:51:40 +08:00
|
|
|
|
selectedItems := make([]uint32, 0, 10)
|
|
|
|
|
|
itemMask := make(map[uint32]uint32, 10)
|
2026-02-26 23:22:31 +08:00
|
|
|
|
// 循环直到选中10个元素
|
|
|
|
|
|
for selectedCount < 10 {
|
|
|
|
|
|
// 随机生成0~14的位索引(对应1~15号元素)
|
|
|
|
|
|
randBitIdx := grand.Intn(15)
|
|
|
|
|
|
// 构造掩码:仅第randBitIdx位为1
|
|
|
|
|
|
mask := uint32(1) << randBitIdx
|
|
|
|
|
|
|
|
|
|
|
|
// 检查该位是否未被选中(避免重复)
|
|
|
|
|
|
if (result.Status & mask) == 0 {
|
2026-04-15 03:22:59 +08:00
|
|
|
|
result.Status |= mask
|
2026-03-31 06:51:40 +08:00
|
|
|
|
itemID := uint32(400686 + randBitIdx + 1)
|
|
|
|
|
|
selectedItems = append(selectedItems, itemID)
|
|
|
|
|
|
itemMask[itemID] = mask
|
2026-03-21 01:01:05 +08:00
|
|
|
|
selectedCount++ // 选中数+1
|
2026-02-26 23:22:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-31 06:51:40 +08:00
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
}
|
2026-02-26 23:22:31 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-05 23:13:06 +08:00
|
|
|
|
// C2s_GET_XUANCAI 定义请求或响应数据结构。
|
2026-02-26 23:22:31 +08:00
|
|
|
|
type C2s_GET_XUANCAI struct {
|
|
|
|
|
|
Head common.TomeeHeader `cmd:"60001" struc:"skip"` //玩家登录
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OutInfo 表示地图热度的出站消息
|
|
|
|
|
|
type S2C_GET_XUANCAI struct {
|
|
|
|
|
|
Status uint32
|
|
|
|
|
|
}
|