Files
bl/logic/controller/pet_收集计划.go
昔念 a29a8ddec2
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(service): 宠物添加功能增加销售计数参数并优化价格更新逻辑

- 修改PetAdd方法签名,增加salecount参数用于追踪宠物销售次数
- 在多个控制器中统一调用PetAdd方法时传入0作为初始销售次数
- 临时禁用寒流枪活动中的宠物发放功能
- 优化UPdatePrice方法,添加错误处理和价格范围验证逻辑
- 调整宠物购买逻辑,使用免费金币系统并计算递增购买
2026-03-11 12:19:13 +08:00

104 lines
2.8 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/pet"
"blazing/logic/service/player"
"blazing/modules/player/model"
"github.com/pointernil/bitset32"
"github.com/samber/lo"
)
func (h Controller) IsCollect(
data *pet.C2S_IS_COLLECT, c *player.Player) (result *pet.S2C_IS_COLLECT, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.S2C_IS_COLLECT{
ID: data.Type,
}
c.Service.Task.Exec(uint32(1335), func(te *model.Task) bool {
r := bitset32.From(te.Data)
// 分支未完成时,标记完成并发放奖励
if r.Test(uint(data.Type)) {
result.IsCom = 1
}
return false
})
_, ok := lo.Find([]uint32{1, 2, 3, 4, 301}, func(item uint32) bool {
return data.Type == item
})
if ok {
res := c.Info.GetTask(1335 + int(data.Type)) //第一期
if res == model.Completed {
result.IsCom = 1
}
}
return result, 0
}
// 定义 Type 与合法 ID 集合的映射表,集中管理所有规则
var validTypeIDMap = map[int][]uint32{
1: {1, 4, 7}, // Type1合法ID为1、4、7
2: {71}, // Type2合法ID为71
3: {275}, // Type3合法ID为275
4: {669}, // Type4合法ID为669你之前提到的是670确认是否笔误
301: {1, 4, 7}, //精灵王计划
100: {856, 857, 858}, //测试
}
func (h Controller) Collect(
data *pet.C2S_PET_COLLECT, c *player.Player) (result *pet.S2C_PET_COLLECT, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.S2C_PET_COLLECT{ID: data.ID}
res := c.Info.GetTask(1335 + int(data.Type)) //第一期
_, ok := lo.Find([]uint32{1, 2, 3, 4, 301}, func(item uint32) bool {
return data.Type == item
})
if res == model.Completed && ok { //这块是为了兼容旧版本
c.Service.Task.Exec(uint32(1335), func(te *model.Task) bool {
r := bitset32.From(te.Data)
r.Set(uint(data.Type))
te.Data = r.Bytes()
return true
})
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
}
validIDs, ok := validTypeIDMap[int(data.Type)]
if !ok {
// Type不在映射表中返回系统错误
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
}
// 2. 判断ID是否在合法集合中
if !lo.Contains(validIDs, data.ID) {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrSystemError)
}
c.Service.Task.Exec(uint32(1335), func(te *model.Task) bool {
r := bitset32.From(te.Data)
// 分支未完成时,标记完成并发放奖励
if !r.Test(uint(data.Type)) {
r.Set(uint(data.Type))
te.Data = r.Bytes()
r := model.GenPetInfo(int(data.ID), -1, -1, 0, 1, nil, 0)
c.Service.Pet.PetAdd(r, 0)
result.CatchTime = r.CatchTime
return true
}
return false
})
if result.CatchTime == 0 {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrAwardAlreadyClaimed)
}
return result, 0
}