diff --git a/logic/controller/action_炫彩碎片.go b/logic/controller/action_炫彩碎片.go new file mode 100644 index 000000000..1b0b424ca --- /dev/null +++ b/logic/controller/action_炫彩碎片.go @@ -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 +}