2025-08-20 22:50:55 +08:00
|
|
|
|
package controller
|
2025-08-24 17:33:19 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-11 01:07:00 +08:00
|
|
|
|
"blazing/common/data/xmlres"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
"blazing/common/socket/errorcode"
|
2025-11-24 11:56:20 +08:00
|
|
|
|
"blazing/logic/service/fight"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
"blazing/logic/service/pet"
|
2025-09-14 01:35:16 +08:00
|
|
|
|
"blazing/logic/service/player"
|
2025-09-04 02:00:57 +08:00
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
"blazing/modules/blazing/model"
|
2025-09-01 01:31:42 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
2025-08-24 17:33:19 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
// 获取精灵信息
|
|
|
|
|
|
func (h *Controller) GetPetInfo(
|
|
|
|
|
|
data *pet.InInfo,
|
2025-09-14 01:35:16 +08:00
|
|
|
|
c *player.Player) (result *pet.OutInfo,
|
2025-08-30 21:59:52 +08:00
|
|
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-23 23:38:03 +00:00
|
|
|
|
_, tet, ok := c.FindPet(data.CatchTime)
|
2025-09-11 02:44:21 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok {
|
|
|
|
|
|
result = &pet.OutInfo{
|
|
|
|
|
|
PetInfo: *tet,
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
return result, 0
|
|
|
|
|
|
} else {
|
2025-09-11 02:44:21 +08:00
|
|
|
|
result = &pet.OutInfo{
|
2025-11-16 20:30:17 +00:00
|
|
|
|
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
|
2025-09-11 02:44:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-09-11 02:44:21 +08:00
|
|
|
|
return result, 0
|
2025-08-30 21:59:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 01:03:46 +08:00
|
|
|
|
// 获取仓库列表
|
|
|
|
|
|
func (h *Controller) GetPetList(
|
|
|
|
|
|
data *pet.GetPetListInboundEmpty,
|
2025-09-14 01:35:16 +08:00
|
|
|
|
c *player.Player) (result *pet.GetPetListOutboundInfo,
|
2025-09-01 01:03:46 +08:00
|
|
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
|
|
|
|
result = &pet.GetPetListOutboundInfo{}
|
|
|
|
|
|
|
2025-11-16 20:30:17 +00:00
|
|
|
|
tt := c.Service.Pet.PetInfo(0) //获得未放生的精灵
|
2025-09-01 01:03:46 +08:00
|
|
|
|
result.ShortInfoList = make([]pet.PetShortInfo, len(tt))
|
|
|
|
|
|
for i, v := range tt {
|
|
|
|
|
|
|
2025-10-13 18:51:41 +08:00
|
|
|
|
copier.Copy(&result.ShortInfoList[i], &v.Data)
|
2025-09-01 01:31:42 +08:00
|
|
|
|
|
2025-09-01 01:03:46 +08:00
|
|
|
|
}
|
2025-09-01 01:31:42 +08:00
|
|
|
|
return result, 0
|
2025-09-01 01:03:46 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 11:56:20 +08:00
|
|
|
|
// 获取放生列表
|
|
|
|
|
|
func (h *Controller) PET_ROWEI_LIST(
|
|
|
|
|
|
data *pet.GetPetListFreeInboundEmpty,
|
|
|
|
|
|
c *player.Player) (result *pet.GetPetListOutboundInfo,
|
|
|
|
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
|
|
|
|
result = &pet.GetPetListOutboundInfo{}
|
|
|
|
|
|
|
|
|
|
|
|
tt := c.Service.Pet.PetInfo(1) //获得未放生的精灵
|
|
|
|
|
|
result.ShortInfoList = make([]pet.PetShortInfo, len(tt))
|
|
|
|
|
|
for i, v := range tt {
|
|
|
|
|
|
|
|
|
|
|
|
copier.Copy(&result.ShortInfoList[i], &v.Data)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 放生包
|
|
|
|
|
|
func (h *Controller) PET_ROWEI(
|
|
|
|
|
|
data *pet.PET_ROWEI, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
|
|
|
|
|
|
|
|
|
|
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
|
|
|
|
|
|
|
|
|
|
|
_, _, ok := c.FindPet(data.CatchTime)
|
2025-12-06 23:59:00 +08:00
|
|
|
|
r := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
2025-11-24 11:56:20 +08:00
|
|
|
|
//如果背包没找到,再放入背包
|
2025-12-06 23:59:00 +08:00
|
|
|
|
if !ok && t.CatchTime != 0 && r == 0 {
|
2025-11-24 11:56:20 +08:00
|
|
|
|
t.Free = 1
|
2025-12-06 23:59:00 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
err = errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
2025-11-24 11:56:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-12-06 23:59:00 +08:00
|
|
|
|
return nil, err
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 领回包
|
|
|
|
|
|
func (h *Controller) PET_RETRIEVE(
|
|
|
|
|
|
data *pet.PET_RETRIEVE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
|
|
|
|
|
|
|
|
|
|
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
|
|
|
|
|
|
|
|
|
|
|
_, _, ok := c.FindPet(data.CatchTime)
|
|
|
|
|
|
|
|
|
|
|
|
//如果背包没找到,再放入背包
|
|
|
|
|
|
if !ok && t.CatchTime != 0 {
|
|
|
|
|
|
t.Free = 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
// 精灵背包仓库切换
|
|
|
|
|
|
func (h *Controller) PetRelease(
|
|
|
|
|
|
data *pet.PetReleaseInboundInfo,
|
2025-09-14 01:35:16 +08:00
|
|
|
|
c *player.Player) (
|
2025-08-30 21:59:52 +08:00
|
|
|
|
result *pet.PetReleaseOutboundInfo,
|
|
|
|
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-08-31 06:53:42 +00:00
|
|
|
|
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
|
|
|
|
|
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
2025-11-20 05:57:29 +08:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
result = &pet.PetReleaseOutboundInfo{}
|
2025-09-01 01:03:46 +08:00
|
|
|
|
result.Flag = uint32(data.Flag)
|
2025-11-20 05:57:29 +08:00
|
|
|
|
//擂台住不能换精灵
|
|
|
|
|
|
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
|
|
|
|
}
|
2025-08-31 06:53:42 +00:00
|
|
|
|
switch data.Flag {
|
|
|
|
|
|
case 0:
|
2025-11-05 17:06:08 +00:00
|
|
|
|
|
2025-11-25 12:29:50 +08:00
|
|
|
|
index, v, ok := c.FindPet(data.CatchTime)
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok {
|
2025-11-25 12:29:50 +08:00
|
|
|
|
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
|
|
|
|
|
t.Data = *v
|
|
|
|
|
|
//t.InBag = 0
|
|
|
|
|
|
|
|
|
|
|
|
})
|
2025-11-23 23:38:03 +00:00
|
|
|
|
c.Info.PetList = append(c.Info.PetList[:index], c.Info.PetList[index+1:]...)
|
2025-08-31 06:53:42 +00:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-11-05 17:06:08 +00:00
|
|
|
|
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
2025-08-31 06:53:42 +00:00
|
|
|
|
case 1:
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if len(c.Info.PetList) < 6 {
|
|
|
|
|
|
//todo 背包
|
|
|
|
|
|
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
2025-11-13 02:43:00 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
_, _, ok := c.FindPet(data.CatchTime)
|
2025-11-13 02:43:00 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
//如果背包没找到,再放入背包
|
|
|
|
|
|
if !ok && t.CatchTime != 0 {
|
|
|
|
|
|
//t.InBag = 1
|
|
|
|
|
|
c.Info.PetList = append(c.Info.PetList, t.Data)
|
|
|
|
|
|
result.PetInfo = t.Data
|
|
|
|
|
|
}
|
2025-09-23 15:01:52 +00:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-08-31 06:53:42 +00:00
|
|
|
|
|
2025-09-07 05:58:47 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-09-07 05:58:47 +08:00
|
|
|
|
if len(c.Info.PetList) > 0 {
|
|
|
|
|
|
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
|
|
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
return result, 0
|
2025-08-24 17:33:19 +08:00
|
|
|
|
}
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
|
|
|
|
|
// 精灵展示
|
|
|
|
|
|
func (h *Controller) PlayerShowPet(
|
2025-09-14 01:35:16 +08:00
|
|
|
|
data *pet.PetShowInboundInfo, c *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-20 21:37:37 +08:00
|
|
|
|
result = &pet.PetShowOutboundInfo{}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
_, onpet, ok := c.FindPet(data.CatchTime)
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
if ok {
|
|
|
|
|
|
copier.Copy(&result, onpet)
|
|
|
|
|
|
result.Flag = data.Flag
|
|
|
|
|
|
result.UserID = data.Head.UserID
|
2025-11-29 19:26:56 +08:00
|
|
|
|
defer c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
2025-11-18 20:52:04 +00:00
|
|
|
|
return
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-11-24 11:56:20 +08:00
|
|
|
|
|
|
|
|
|
|
// 单体治疗
|
2025-09-11 01:07:00 +08:00
|
|
|
|
func (h *Controller) PetOneCure(
|
2025-09-14 01:35:16 +08:00
|
|
|
|
data *pet.PetOneCureInboundInfo, c *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-20 05:57:29 +08:00
|
|
|
|
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
|
|
|
|
|
}
|
2025-11-25 12:29:50 +08:00
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
_, onpet, ok := c.FindPet(data.CatchTime)
|
2025-09-21 17:01:31 +00:00
|
|
|
|
if ok {
|
2025-11-29 19:26:56 +08:00
|
|
|
|
defer onpet.Cure()
|
|
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-21 17:01:31 +00:00
|
|
|
|
return &pet.PetOneCureOutboundInfo{
|
|
|
|
|
|
CatchTime: data.CatchTime,
|
|
|
|
|
|
}, 0
|
2025-09-11 01:07:00 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-12 19:21:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 精灵首发
|
|
|
|
|
|
func (h *Controller) PetFirst(
|
2025-09-14 01:35:16 +08:00
|
|
|
|
data *pet.PetDefaultInboundInfo, c *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
2025-11-23 23:38:03 +00:00
|
|
|
|
//擂台住不能换精灵
|
|
|
|
|
|
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-12 19:21:39 +08:00
|
|
|
|
result = &pet.PetDefaultOutboundInfo{}
|
|
|
|
|
|
|
2025-11-23 23:38:03 +00:00
|
|
|
|
index, _, ok := c.FindPet(data.CatchTime)
|
|
|
|
|
|
if ok && index != 0 {
|
|
|
|
|
|
|
|
|
|
|
|
c.Info.PetList[index], c.Info.PetList[0] = c.Info.PetList[0], c.Info.PetList[index]
|
|
|
|
|
|
|
|
|
|
|
|
result.IsDefault = 1
|
2025-09-12 19:21:39 +08:00
|
|
|
|
}
|
2025-11-23 23:38:03 +00:00
|
|
|
|
|
2025-09-12 19:21:39 +08:00
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-21 17:01:31 +00:00
|
|
|
|
|
|
|
|
|
|
// FindWithIndex 遍历slice,找到第一个满足条件的元素
|
|
|
|
|
|
// 返回:索引、元素指针、是否找到
|
2025-10-26 20:56:03 +08:00
|
|
|
|
|
2025-09-26 13:33:55 +08:00
|
|
|
|
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-23 23:38:03 +00:00
|
|
|
|
_, onpet, ok := c.FindPet(data.CatchTime)
|
2025-09-26 13:33:55 +08:00
|
|
|
|
if ok {
|
|
|
|
|
|
|
2025-11-29 19:26:56 +08:00
|
|
|
|
defer c.AddPetExp(onpet, data.Exp)
|
2025-09-26 13:33:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-13 19:46:19 +08:00
|
|
|
|
return &pet.PetSetExpOutboundInfo{
|
2025-10-16 19:15:11 +00:00
|
|
|
|
Exp: c.Info.ExpPool,
|
2025-10-13 19:46:19 +08:00
|
|
|
|
}, 0
|
2025-09-26 13:33:55 +08:00
|
|
|
|
}
|
2025-11-08 01:12:53 +08:00
|
|
|
|
|
|
|
|
|
|
func (h Controller) PetBargeList(data *pet.PetBargeListInboundInfo, c *player.Player) (result *pet.PetBargeListOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
|
|
|
|
|
|
|
return &pet.PetBargeListOutboundInfo{
|
|
|
|
|
|
PetBargeList: make([]pet.PetBargeListInfo, 0),
|
|
|
|
|
|
}, 0
|
|
|
|
|
|
}
|