Files
bl/modules/player/controller/admin/pet.go
昔念 a6386daad8
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-04-22 00:39:41 +08:00

176 lines
4.4 KiB
Go

package admin
import (
"blazing/common/data"
"blazing/cool"
base "blazing/modules/base/service"
config "blazing/modules/config/service"
"blazing/modules/player/model"
"blazing/modules/player/service"
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
)
type PetBagController struct {
*cool.Controller
}
type PetGetReq struct {
g.Meta `path:"/genpet" method:"POST"`
UserID uint32 `json:"user_id"`
IsVIP int `json:"is_vip"`
PetTypeId int `json:"petTypeId" v:"required|min:1" comment:"Pet type ID"`
IndividualValue int `json:"individualValue" v:"required|between:-1,31" comment:"Individual value, -1 means random"`
NatureId int `json:"natureId" v:"required|between:-1,24" comment:"Nature ID, -1 means random"`
AbilityTypeEnum int `json:"abilityTypeEnum" v:"required|min:-1" comment:"Ability type, -1 means random"`
IsShiny int `json:"isShiny" v:"min:-1" comment:"Shiny config ID, -1 means random"`
Level int `json:"level" v:"required|between:1,100" comment:"Pet level"`
}
func init() {
var taskInfoController = &PetBagController{
&cool.Controller{
Prefix: "/admin/monster/bag",
Api: []string{"Delete", "Update", "Info", "List", "Page"},
Service: service.NewPetService(0),
},
}
cool.RegisterController(taskInfoController)
}
func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res *cool.BaseRes, err error) {
var shiny []data.GlowFilter
if req.IsShiny > 0 {
r := config.NewShinyService().GetShiny(req.IsShiny)
shiny = append(shiny, *r)
}
t := model.GenPetInfo(
req.PetTypeId,
req.IndividualValue,
req.NatureId,
req.AbilityTypeEnum,
req.Level,
shiny,
0,
)
t.CatchRect = 1
if req.IsShiny == -1 {
t.RandomByWeightShiny()
}
service.NewUserService(uint32(req.UserID)).Pet.PetAdd(t, 0)
return
}
type PetLevelReq struct {
g.Meta `path:"/getlevel" method:"GET"`
}
type PetLevelRes struct {
UserID int `json:"user_id"`
Level int `json:"level"`
ID int `json:"id"`
}
func (c *PetBagController) Level(ctx context.Context, req *PetLevelReq) (res *cool.BaseRes, err error) {
r := service.NewUserService(0).Pet.PetLevelAll()
res = &cool.BaseRes{}
ress := make([]PetLevelRes, 0)
for _, v := range r {
ress = append(ress, PetLevelRes{
UserID: int(v.PlayerID),
Level: int(v.Data.Level),
ID: int(v.Data.ID),
})
}
res.Data = ress
return
}
type PetStorageReq struct {
g.Meta `path:"/storage" method:"POST"`
IsVIP int `json:"is_vip"`
Free int `json:"free"`
}
func (c *PetBagController) Storage(ctx context.Context, req *PetStorageReq) (res *cool.BaseRes, err error) {
admin := cool.GetAdmin(ctx)
res = &cool.BaseRes{}
if req.Free < 0 || req.Free > 2 {
req.Free = 0
}
res.Data = service.NewPetService(uint32(admin.UserId)).StorageInfo(req.IsVIP, req.Free)
return
}
type PriseReq struct {
g.Meta `path:"/modpirse" method:"POST"`
Ctime uint32 `json:"catch_time"`
Price uint32 `json:"sale_price"`
Free uint32 `json:"free"`
}
func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *cool.BaseRes, err error) {
admin := cool.GetAdmin(ctx)
res = &cool.BaseRes{}
if req.Price < 5 {
req.Price = 5
}
if req.Free == 2 {
if base.NewBaseSysUserService().GetFreeGold(admin.UserId) < 0 {
err = fmt.Errorf("insufficient free gold")
return
}
}
err = service.NewPetService(uint32(admin.UserId)).UpdatePrice(req.Ctime, req.Price, req.Free)
return
}
type PetShowReq struct {
g.Meta `path:"/show" method:"POST"`
CatchTime uint32 `json:"catch_time"`
IsShow int `json:"is_show"` // 1=展示 0=取消展示
}
func (c *PetBagController) Show(ctx context.Context, req *PetShowReq) (res *cool.BaseRes, err error) {
admin := cool.GetAdmin(ctx)
res = &cool.BaseRes{}
if req.CatchTime == 0 {
err = fmt.Errorf("invalid catch_time")
return
}
if req.IsShow != 0 && req.IsShow != 1 {
req.IsShow = 0
}
petSvc := service.NewPetService(uint32(admin.UserId))
pet := petSvc.PetInfoOneByCatchTime(req.CatchTime)
if pet == nil {
err = fmt.Errorf("pet not found")
return
}
if !petSvc.UpdateIsShow(req.CatchTime, req.IsShow) {
err = fmt.Errorf("update failed")
}
return
}
type BuyPetReq struct {
g.Meta `path:"/buy" method:"POST"`
Cid uint32 `json:"id"`
}
func (c *PetBagController) BuyPet(ctx context.Context, req *BuyPetReq) (res *cool.BaseRes, err error) {
admin := cool.GetAdmin(ctx)
res = &cool.BaseRes{}
err = service.NewPetService(uint32(admin.UserId)).BuyPet(req.Cid)
return
}