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-09-14 01:35:16 +08:00
|
|
|
|
|
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-09-11 02:44:21 +08:00
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
for _, pi := range c.Info.PetList {
|
|
|
|
|
|
if pi.CatchTime == data.CatchTime {
|
2025-09-11 02:44:21 +08:00
|
|
|
|
result = &pet.OutInfo{
|
2025-09-11 01:07:00 +08:00
|
|
|
|
PetInfo: pi,
|
2025-09-11 02:44:21 +08:00
|
|
|
|
}
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
2025-08-24 17:33:19 +08:00
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
}
|
2025-09-11 02:44:21 +08:00
|
|
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
|
|
|
|
|
|
|
|
result = &pet.OutInfo{
|
|
|
|
|
|
PetInfo: c.Service.GetPetInfo(data.CatchTime),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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-09-11 01:07:00 +08:00
|
|
|
|
tt := c.Service.GetPetList(0) //获得未放生的精灵
|
2025-09-01 01:03:46 +08:00
|
|
|
|
result.ShortInfoList = make([]pet.PetShortInfo, len(tt))
|
|
|
|
|
|
for i, v := range tt {
|
|
|
|
|
|
|
2025-09-01 01:31:42 +08:00
|
|
|
|
copier.Copy(&result.ShortInfoList[i], &v)
|
|
|
|
|
|
|
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-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+移除背包 设置首发等于取到首发精灵后重新排序
|
|
|
|
|
|
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
|
|
|
|
|
result = &pet.PetReleaseOutboundInfo{}
|
2025-09-01 01:03:46 +08:00
|
|
|
|
result.Flag = uint32(data.Flag)
|
|
|
|
|
|
|
2025-09-11 01:07:00 +08:00
|
|
|
|
t := c.Service.PetM(int(data.CatchTime), int(data.Flag))
|
2025-08-31 06:53:42 +00:00
|
|
|
|
switch data.Flag {
|
|
|
|
|
|
case 0:
|
2025-09-07 05:58:47 +08:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
removeIndex := -1
|
|
|
|
|
|
for i, v := range c.Info.PetList {
|
|
|
|
|
|
if v.CatchTime == uint32(data.CatchTime) {
|
|
|
|
|
|
removeIndex = i
|
|
|
|
|
|
break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
|
|
|
|
|
}
|
2025-08-30 21:59:52 +08:00
|
|
|
|
|
2025-08-31 06:53:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
if removeIndex != -1 {
|
|
|
|
|
|
c.Info.PetList = append(c.Info.PetList[:removeIndex], c.Info.PetList[removeIndex+1:]...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
//todo 背包
|
2025-09-01 01:03:46 +08:00
|
|
|
|
c.Info.PetList = append(c.Info.PetList, t)
|
|
|
|
|
|
result.PetInfo = t
|
2025-08-31 06:53:42 +00:00
|
|
|
|
|
2025-09-07 05:58:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
if len(c.Info.PetList) > 0 {
|
|
|
|
|
|
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
|
|
|
|
|
|
}
|
2025-08-31 06:53:42 +00:00
|
|
|
|
//service.NewUserService(c.Info.UserID).PetAdd( *r)
|
|
|
|
|
|
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-09-11 01:07:00 +08:00
|
|
|
|
results := pet.PetShowOutboundInfo{}
|
|
|
|
|
|
|
|
|
|
|
|
for _, pi := range c.Info.PetList {
|
|
|
|
|
|
if pi.CatchTime == data.CatchTime {
|
|
|
|
|
|
copier.Copy(&results, pi)
|
|
|
|
|
|
results.Flag = data.Flag
|
|
|
|
|
|
results.UserID = data.Head.UserID
|
|
|
|
|
|
data.Broadcast(c.Info.MapID, results) //同步广播
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, -1
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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-09-11 01:07:00 +08:00
|
|
|
|
|
2025-09-21 17:01:31 +00:00
|
|
|
|
_, onpet, ok := FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
|
|
|
|
|
|
return item.CatchTime == data.CatchTime
|
|
|
|
|
|
})
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
onpet.Hp = onpet.MaxHp
|
|
|
|
|
|
for i := 0; i < 4; i++ {
|
2025-09-22 13:30:16 +00:00
|
|
|
|
maxPP, ok := xmlres.SkillMap[int(onpet.SkillList[i].ID)]
|
2025-09-21 17:01:31 +00:00
|
|
|
|
// 恢复至最大PP值(从配置表获取)
|
2025-09-22 13:30:16 +00:00
|
|
|
|
if onpet.SkillList[i].ID != 0 && ok {
|
2025-09-21 17:01:31 +00:00
|
|
|
|
onpet.SkillList[i].PP = uint32(maxPP.MaxPP)
|
|
|
|
|
|
|
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-09-12 19:21:39 +08:00
|
|
|
|
result = &pet.PetDefaultOutboundInfo{}
|
|
|
|
|
|
var ttt []model.PetInfo
|
|
|
|
|
|
|
|
|
|
|
|
for index, pi := range c.Info.PetList {
|
|
|
|
|
|
if pi.CatchTime == data.CatchTime {
|
|
|
|
|
|
ttt = append(ttt, pi)
|
|
|
|
|
|
ttt = append(ttt, c.Info.PetList[:index]...)
|
|
|
|
|
|
ttt = append(ttt, c.Info.PetList[index+1:]...)
|
|
|
|
|
|
result.IsDefault = 1
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
c.Info.PetList = ttt
|
|
|
|
|
|
return result, 0
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-21 17:01:31 +00:00
|
|
|
|
|
|
|
|
|
|
// FindWithIndex 遍历slice,找到第一个满足条件的元素
|
|
|
|
|
|
// 返回:索引、元素指针、是否找到
|
|
|
|
|
|
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
|
|
|
|
|
|
for i := range slice {
|
|
|
|
|
|
if predicate(slice[i]) {
|
|
|
|
|
|
return i, &slice[i], true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1, nil, false
|
|
|
|
|
|
}
|