Files
bl/logic/controller/pet.go
昔念 0ca743a592 feat(fight): 添加捕捉宠物功能并优化物品系统
- 新增 Capture 函数处理捕捉宠物逻辑
- 修改 ChangePet 函数返回值
- 优化物品添加和查询逻辑
- 增加新消息类型 CatchMonsterOutboundInfo
- 调整战斗循环处理捕捉逻辑
待修复技能丢失问题
2025-09-11 02:44:21 +08:00

146 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/pet"
"blazing/modules/blazing/model"
"github.com/jinzhu/copier"
)
// 获取精灵信息
func (h *Controller) GetPetInfo(
data *pet.InInfo,
c *service.Player) (result *pet.OutInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
for _, pi := range c.Info.PetList {
if pi.CatchTime == data.CatchTime {
result = &pet.OutInfo{
PetInfo: pi,
}
}
}
if result == nil {
result = &pet.OutInfo{
PetInfo: c.Service.GetPetInfo(data.CatchTime),
}
}
return result, 0
}
// 获取仓库列表
func (h *Controller) GetPetList(
data *pet.GetPetListInboundEmpty,
c *service.Player) (result *pet.GetPetListOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.GetPetListOutboundInfo{}
tt := c.Service.GetPetList(0) //获得未放生的精灵
result.ShortInfoList = make([]pet.PetShortInfo, len(tt))
for i, v := range tt {
copier.Copy(&result.ShortInfoList[i], &v)
}
return result, 0
}
// 精灵背包仓库切换
func (h *Controller) PetRelease(
data *pet.PetReleaseInboundInfo,
c *service.Player) (
result *pet.PetReleaseOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
//这里只修改,因为添加和移除背包在宠物获取时已经做了
result = &pet.PetReleaseOutboundInfo{}
result.Flag = uint32(data.Flag)
t := c.Service.PetM(int(data.CatchTime), int(data.Flag))
switch data.Flag {
case 0:
removeIndex := -1
for i, v := range c.Info.PetList {
if v.CatchTime == uint32(data.CatchTime) {
removeIndex = i
break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
}
}
if removeIndex != -1 {
c.Info.PetList = append(c.Info.PetList[:removeIndex], c.Info.PetList[removeIndex+1:]...)
}
case 1:
//todo 背包
c.Info.PetList = append(c.Info.PetList, t)
result.PetInfo = t
}
if len(c.Info.PetList) > 0 {
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
}
//service.NewUserService(c.Info.UserID).PetAdd( *r)
return result, 0
}
// 精灵展示
func (h *Controller) PlayerShowPet(
data *pet.PetShowInboundInfo, c *service.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
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(
data *pet.PetOneCureInboundInfo, c *service.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetOneCureOutboundInfo{
data.CatchTime,
}
var temp []model.PetInfo
for _, pi := range c.Info.PetList {
if pi.CatchTime == data.CatchTime {
pi.Hp = pi.MaxHp
// 恢复技能PP值
var skillList [4]model.SkillInfo
for i, skill := range pi.SkillList {
// 跳过无效技能
if skill.ID == 0 {
continue
}
// 恢复至最大PP值从配置表获取
if maxPP, ok := xmlres.SkillMap[int(skill.ID)]; ok {
skill.PP = uint32(maxPP.MaxPP)
skillList[i] = skill
}
}
pi.SkillList = skillList
}
temp = append(temp, pi)
}
c.Info.PetList = temp
return result, 0
}