- 在 `Item` 结构体中新增 `NatureProbs` 字段,用于支持性格概率配置 - 重构 `ItemUsePet` 控制器方法,引入处理器注册机制统一管理道具效果 - 修复神经元相关道具的特殊处理逻辑,增强代码可维护性 - 调整 `S2C_USE_PET_ITEM_OUT_OF_FIGHT` 响应结构体,增加技能列表长度字段 - 修改 `ResetNature` 方法命名及判断条件,提升语义清晰度与健壮性 - 新增 `PetInfo_One_Unscoped` 查询方法以支持软删除数据访问 - 实
139 lines
2.9 KiB
Go
139 lines
2.9 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/blazing/model"
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
// 获取精灵信息 0是仓库,1是放生
|
|
func (s *PetService) PetInfo(flag int) []model.PetEX {
|
|
var tt []model.PetEX
|
|
err := cool.DBM(s.Model).Where("player_id", s.userid).Where("free", flag).Scan(&tt)
|
|
if err != nil {
|
|
return []model.PetEX{}
|
|
}
|
|
|
|
for i := 0; i < len(tt); i++ {
|
|
tt[i].Data.CatchTime = tt[i].CatchTime
|
|
|
|
}
|
|
|
|
return tt
|
|
|
|
}
|
|
|
|
func (s *PetService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) {
|
|
|
|
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
|
var tt model.PetEX
|
|
m.Scan(&tt)
|
|
if tt.CatchTime == 0 {
|
|
return
|
|
}
|
|
tt.Data.CatchTime = tt.CatchTime
|
|
t(&tt)
|
|
_, err := m.OnConflict("catch_time").Update(tt)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
func (s *PetService) PetInfo_One(cachetime uint32) model.PetEX {
|
|
|
|
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
|
|
var tt model.PetEX
|
|
|
|
m.Scan(&tt)
|
|
tt.Data.CatchTime = tt.CatchTime
|
|
return tt
|
|
}
|
|
func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX {
|
|
|
|
m := cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()
|
|
var tt model.PetEX
|
|
|
|
m.Scan(&tt)
|
|
tt.Data.CatchTime = tt.CatchTime
|
|
return tt
|
|
}
|
|
func (s *PetService) Pet_del(cachetime uint32) {
|
|
|
|
cool.DBM(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Delete()
|
|
|
|
}
|
|
func (s *PetService) PetAdd(y *model.PetInfo) {
|
|
|
|
for {
|
|
m1 := cool.DBM(s.Model).Where("player_id", s.userid)
|
|
var player model.PetEX
|
|
player.PlayerID = s.userid
|
|
player.Data = *y
|
|
player.CatchTime = y.CatchTime
|
|
player.Free = 0
|
|
|
|
_, err := m1.Insert(player)
|
|
if err != nil {
|
|
fmt.Println("添加失败id自增1继续添加")
|
|
y.CatchTime += 1 //自增保持时间排序
|
|
continue
|
|
}
|
|
break
|
|
}
|
|
|
|
}
|
|
func (s *PetService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
|
admin := cool.GetAdmin(ctx)
|
|
userId := admin.UserId
|
|
s.userid = uint32(userId)
|
|
if method == "Update" {
|
|
|
|
if gconv.Uint(param["free"]) != 0 {
|
|
err = fmt.Errorf("修改失败")
|
|
}
|
|
if userId != gconv.Uint(param["player_id"]) {
|
|
err = fmt.Errorf("修改失败")
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type PetService struct {
|
|
BaseService
|
|
}
|
|
|
|
func NewPetService(userid uint32) *PetService {
|
|
return &PetService{
|
|
BaseService: BaseService{
|
|
userid: userid,
|
|
Service: &cool.Service{
|
|
Model: model.NewPet(),
|
|
PageQueryOp: &cool.QueryOp{
|
|
Where: func(ctx context.Context) [][]interface{} {
|
|
var (
|
|
admin = cool.GetAdmin(ctx)
|
|
userId = admin.UserId
|
|
)
|
|
if userId != 10001 {
|
|
return [][]interface{}{
|
|
{"player_id", userId, true},
|
|
{"free", 1, true},
|
|
}
|
|
} else {
|
|
return [][]interface{}{
|
|
{"player_id", userId, true},
|
|
{"free", 1, true},
|
|
}
|
|
}
|
|
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|