diff --git a/modules/player/controller/admin/pet.go b/modules/player/controller/admin/pet.go index 8743dc86..63c2959d 100644 --- a/modules/player/controller/admin/pet.go +++ b/modules/player/controller/admin/pet.go @@ -1,4 +1,4 @@ -package admin +package admin import ( "blazing/common/data" @@ -16,51 +16,67 @@ import ( 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:"缁墽浼掔猾璇茬€稩D閿涘苯绻€婵夘偓绱濆锝嗘殻閺佸府绱欓張鈧亸?閿涘本妫?閹存牞绀嬮弫鎵閸ㄥ绱氶敍灞筋嚠鎼存摜enPetInfo閻ㄥ埇d閸欏倹鏆?` - IndividualValue int `json:"individualValue" v:"required|between:-1,31" comment:"缁墽浼掓稉顏冪秼閸婄》绱濊箛鍛綖閿涘矁瀵栭崶?1~31閿?1鐞涖劎銇氶梾蹇旀簚閻㈢喐鍨氬鈥查嚋娴f搫绱?~31娑撳搫娴愮€规艾鈧》绱濋崘鍐茬暰閸╄櫣顢呯仦鐐粹偓褌绗傞梽鎰剁礆"` - NatureId int `json:"natureId" v:"required|between:-1,24" comment:"缁墽浼掗幀褎鐗窱D閿涘苯绻€婵夘偓绱濋懠鍐ㄦ纯-1~24閿?1鐞涖劎銇氶梾蹇旀簚閿?~24鐎电懓绨?5缁夊秴娴愮€规碍鈧勭壐閿涘苯濂栭崫宥呯潣閹冨閹存劧绱?` - AbilityTypeEnum int `json:"abilityTypeEnum" v:"required|min:-1" comment:"缁墽浼掗悧瑙勨偓褏琚崹濠璂閿涘苯绻€婵夘偓绱濋張鈧亸蹇撯偓?1閿?1鐞涖劎銇氶梾蹇旀簚闁瀚?娑擃亞澹掗幀褝绱?閸欏﹣浜掓稉濠佽礋閸ュ搫鐣鹃悧瑙勨偓顪廌閿涘矂娓舵稉宥眑ayerEffectMAP閸栧綊鍘ら敍?` - IsShiny int `json:"isShiny" v:"min:-1" comment:"缁墽浼掑鍌濆閿涘牓妫崗澶涚礆ID閿涘苯绻€婵夘偓绱濋張鈧亸蹇撯偓?1閿?1鐞涖劎銇氶梾蹇旀簚閿?閸欏﹣浜掓稉濠佽礋閸ュ搫鐣惧鍌濆閻樿埖鈧緤绱濈粙鈧張澶岀翱閻忕數澹掑▓濠傤樆鐟?鐏炵偞鈧嶇礆閿涘苯甯悰銊ュ礋hidden娴e棝娓舵穱婵堟殌韫囧懎锝為柅鏄忕帆"` - Level int `json:"level" v:"required|between:1,100" comment:"缁墽浼掔粵澶岄獓閿涘苯绻€婵夘偓绱濋懠鍐ㄦ纯1~100閿涘牆鐖剁憴鍕埗閹村繒鐡戠痪褌绗傞梽鎰剁礉瑜板崬鎼风划鍓т紥瑜版挸澧犵仦鐐粹偓褍宸辨惔锔肩礆"` + 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 task_info_controller = &PetBagController{ + var taskInfoController = &PetBagController{ &cool.Controller{ Prefix: "/admin/monster/bag", Api: []string{"Delete", "Update", "Info", "List", "Page"}, - Service: service.NewPetService(0), //閸ョ姳璐焢age瀹歌尙绮℃潻鍥ㄦ姢閿涘本澧嶆禒銉ㄧ箹闁插矂娓剁憰浣规暭閹? + Service: service.NewPetService(0), }, } - // 濞夈劌鍞界捄顖滄暠 - cool.RegisterController(task_info_controller) + + 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 //娴狅綀銆冩潻娆愭Ц娴滃搫浼愰崥鍫熷灇閻? + 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) { - // m := gmap.New() r := service.NewUserService(0).Pet.PetLevelAll() res = &cool.BaseRes{} ress := make([]PetLevelRes, 0) @@ -71,11 +87,9 @@ func (c *PetBagController) Level(ctx context.Context, req *PetLevelReq) (res *co Level: int(v.Data.Level), ID: int(v.Data.ID), }) - } res.Data = ress return - } type PetStorageReq struct { @@ -91,16 +105,6 @@ func (c *PetBagController) Storage(ctx context.Context, req *PetStorageReq) (res return } -type PetLevelReq struct { - g.Meta `path:"/getlevel" method:"GET"` - // 閺傛澘顤冮敍姘辩翱閻忕數娴夐崗鍐插棘閺佸府绱欑€瑰苯鍙忕€靛綊缍堥懛顏勭暰娑斿銆冮崡鏇㈠帳缂冾噯绱?} -type PetLevelRes struct { - UserID int `json:"user_id"` - //缁涘楠嘝etLevelRes - Level int `json:"level"` - //ID - ID int `json:"id"` -} type PriseReq struct { g.Meta `path:"/modpirse" method:"POST"` Ctime uint32 `json:"catch_time"` @@ -116,17 +120,13 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co req.Price = 5 } if req.Free == 2 { - if base.NewBaseSysUserService().GetFreeGold(admin.UserId) < 0 { - err = fmt.Errorf("闁叉垵绔垫稉宥堝喕") + err = fmt.Errorf("insufficient free gold") return } - } err = service.NewPetService(uint32(admin.UserId)).UpdatePrice(req.Ctime, req.Price, req.Free) - return - } type BuyPetReq struct { @@ -138,10 +138,6 @@ func (c *PetBagController) BuyPet(ctx context.Context, req *BuyPetReq) (res *coo admin := cool.GetAdmin(ctx) res = &cool.BaseRes{} - err = service.NewPetService(uint32(admin.UserId)).BuyPet(req.Cid) - return - } - diff --git a/modules/player/service/pet.go b/modules/player/service/pet.go index b5935d42..a8be2974 100644 --- a/modules/player/service/pet.go +++ b/modules/player/service/pet.go @@ -1,4 +1,4 @@ -package service +package service import ( "blazing/cool" @@ -34,7 +34,7 @@ RETURNING max_ts;`, service.NewBaseSysUserService().Model.TableName()) } arr := ret.Array() if len(arr) == 0 { - return 0, fmt.Errorf("鐢熸垚鎹曟崏鏃堕棿澶辫触: 鏃犺繑鍥炴暟鎹?) + return 0, fmt.Errorf("generate catch time failed: empty result") } return arr[0].Uint32(), nil } @@ -58,6 +58,16 @@ func (s *PetService) PetInfo(flag int) []model.Pet { return tt } +func (s *PetService) StorageInfo(isVip int) []model.Pet { + var tt []model.Pet + if err := s.dbm_fix(s.Model).Where("free", 0).Where("is_vip", isVip).Scan(&tt); err != nil { + return nil + } + for i := range tt { + tt[i].Data.CatchTime = tt[i].CatchTime + } + return tt +} func (s *PetService) PetCount(flag int) int { ret, err := s.dbm(s.Model).Where("free", flag).Count() if err != nil { @@ -107,16 +117,16 @@ func (s *PetService) UpdatePrice(catchTime, price, free uint32) error { func (s *PetService) BuyPet(pid uint32) error { tt := NewPetService(0).PetInfoOneByID(pid) if tt == nil { - return fmt.Errorf("娌℃湁姝ょ簿鐏?) + return fmt.Errorf("pet not found") } if tt.IsVip != 0 { - return fmt.Errorf("涓嶅厑璁镐氦鏄?) + return fmt.Errorf("pet cannot be traded") } if tt.Free != 2 { - return fmt.Errorf("鏈笂鏋?) + return fmt.Errorf("pet is not on sale") } if tt.SalePrice == 0 { - return fmt.Errorf("鏈缃环鏍?) + return fmt.Errorf("pet sale price is not set") } if !tt.UpdateTime.AddDate(0, 0, 1).Before(gtime.Now()) { return fmt.Errorf("鏈埌璐拱鏃堕棿") @@ -285,4 +295,3 @@ func NewPetService(userid uint32) *PetService { }, } } -