refactor(controller): 替换BossCompletedTask为专用方法名 在战斗控制器中将p.BossCompletedTask替换为p.SptCompletedTask, 以及在塔沃控制器中将BossCompletedTask相关调用替换为TawerCompletedTask, 以更好地区分不同的任务完成逻辑。 --- fix(item_use): 添加nil检查防止程序崩溃 在处理神经元道具时,增加对oldPet对象的nil检查, 如果为空则返回系统错误码,避免程序出现
229 lines
6.6 KiB
Go
229 lines
6.6 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/data/xmlres"
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/cool"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/pet"
|
|
"blazing/logic/service/player"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
// GetPetInfo 获取精灵信息
|
|
// data: 包含精灵捕获时间的输入信息
|
|
// player: 当前玩家对象
|
|
// 返回: 精灵信息和错误码
|
|
func (h Controller) GetPetInfo(
|
|
data *pet.InInfo,
|
|
player *player.Player) (result *pet.OutInfo,
|
|
err errorcode.ErrorCode) {
|
|
_, petInfo, found := player.FindPet(data.CatchTime)
|
|
|
|
if found {
|
|
result = &pet.OutInfo{
|
|
PetInfo: *petInfo,
|
|
}
|
|
return result, 0
|
|
}
|
|
result = &pet.OutInfo{
|
|
PetInfo: player.Service.Pet.PetInfo_One(data.CatchTime).Data,
|
|
}
|
|
return result, 0
|
|
}
|
|
|
|
// GetPetList 获取仓库列表
|
|
// data: 空输入结构
|
|
// player: 当前玩家对象
|
|
// 返回: 精灵列表和错误码
|
|
func (h Controller) GetPetList(
|
|
data *pet.GetPetListInboundEmpty,
|
|
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
|
err errorcode.ErrorCode) {
|
|
result = &pet.GetPetListOutboundInfo{}
|
|
|
|
petList := player.Service.Pet.PetInfo(0) // 获取未放生的精灵
|
|
result.ShortInfoList = make([]pet.PetShortInfo, len(petList))
|
|
for i, petItem := range petList {
|
|
copier.Copy(&result.ShortInfoList[i], &petItem.Data)
|
|
}
|
|
return result, 0
|
|
}
|
|
|
|
// GetPetReleaseList 获取放生列表
|
|
// data: 空输入结构
|
|
// player: 当前玩家对象
|
|
// 返回: 放生精灵列表和错误码
|
|
func (h Controller) GetPetReleaseList(
|
|
data *pet.GetPetListFreeInboundEmpty,
|
|
player *player.Player) (result *pet.GetPetListOutboundInfo,
|
|
err errorcode.ErrorCode) {
|
|
result = &pet.GetPetListOutboundInfo{}
|
|
|
|
petList := player.Service.Pet.PetInfo(1) // 获取已放生的精灵
|
|
result.ShortInfoList = make([]pet.PetShortInfo, len(petList))
|
|
for i, petItem := range petList {
|
|
copier.Copy(&result.ShortInfoList[i], &petItem.Data)
|
|
}
|
|
return result, 0
|
|
}
|
|
|
|
// PetReleaseToWarehouse 将精灵从仓库包中放生
|
|
// data: 包含精灵ID和捕获时间的输入信息
|
|
// player: 当前玩家对象
|
|
// 返回: 无数据和错误码
|
|
func (h Controller) PetReleaseToWarehouse(
|
|
data *pet.PET_ROWEI, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
_, _, inBag := player.FindPet(data.CatchTime)
|
|
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
|
|
// 如果背包没找到,再放入背包
|
|
if inBag || freeForbidden == 1 {
|
|
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
|
|
}
|
|
|
|
player.Service.Pet.UPdateFree(data.CatchTime, 1)
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// PetRetrieveFromWarehouse 领回包
|
|
func (h Controller) PetRetrieveFromWarehouse(
|
|
data *pet.PET_RETRIEVE, player *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
|
|
//如果背包没找到,再放入背包
|
|
if _, _, ok := player.FindPet(data.CatchTime); !ok {
|
|
player.Service.Pet.UPdateFree(data.CatchTime, 0)
|
|
}
|
|
|
|
return nil, 0
|
|
|
|
}
|
|
|
|
// TogglePetBagWarehouse 精灵背包仓库切换
|
|
func (h Controller) TogglePetBagWarehouse(
|
|
data *pet.PetReleaseInboundInfo,
|
|
player *player.Player) (
|
|
result *pet.PetReleaseOutboundInfo,
|
|
err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
|
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
|
|
|
result = &pet.PetReleaseOutboundInfo{}
|
|
result.Flag = uint32(data.Flag)
|
|
//擂台住不能换精灵
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
}
|
|
switch data.Flag {
|
|
case 0:
|
|
|
|
index, pet, ok := player.FindPet(data.CatchTime)
|
|
if ok {
|
|
if cool.Config.ServerInfo.IsVip == 0 { //正式服才会真正放会精灵
|
|
player.Service.Pet.UPdate(*pet)
|
|
}
|
|
|
|
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
|
|
}
|
|
|
|
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
|
case 1:
|
|
if len(player.Info.PetList) < 6 {
|
|
//todo 背包
|
|
_, _, ok := player.FindPet(data.CatchTime)
|
|
|
|
//如果背包没找到,再放入背包
|
|
if !ok {
|
|
r := player.Service.Pet.PetInfo_One(data.CatchTime)
|
|
if r == nil {
|
|
return result, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
player.Info.PetList = append(player.Info.PetList, r.Data)
|
|
result.PetInfo = r.Data
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(player.Info.PetList) > 0 {
|
|
result.FirstPetTime = player.Info.PetList[0].CatchTime //设置首发
|
|
}
|
|
|
|
return result, 0
|
|
}
|
|
|
|
// PlayerShowPet 精灵展示
|
|
func (h Controller) PlayerShowPet(
|
|
data *pet.PetShowInboundInfo, player *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
result = &pet.PetShowOutboundInfo{}
|
|
_, currentPet, ok := player.FindPet(data.CatchTime)
|
|
|
|
if ok {
|
|
copier.Copy(&result, currentPet)
|
|
result.Flag = data.Flag
|
|
result.UserID = data.Head.UserID
|
|
defer player.GetSpace().Broadcast(player, data.Head.CMD, result)
|
|
}
|
|
return
|
|
|
|
}
|
|
|
|
// PetOneCure 单体治疗
|
|
func (h Controller) PetOneCure(
|
|
data *pet.PetOneCureInboundInfo, player *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
|
}
|
|
|
|
_, currentPet, ok := player.FindPet(data.CatchTime)
|
|
if ok {
|
|
defer currentPet.Cure()
|
|
|
|
}
|
|
|
|
return &pet.PetOneCureOutboundInfo{
|
|
CatchTime: data.CatchTime,
|
|
}, 0
|
|
|
|
}
|
|
|
|
// PetFirst 精灵首发
|
|
func (h Controller) PetFirst(
|
|
data *pet.PetDefaultInboundInfo, player *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
|
//擂台住不能换精灵
|
|
if player.GetSpace().Owner.UserID == player.Info.UserID {
|
|
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
|
}
|
|
|
|
result = &pet.PetDefaultOutboundInfo{}
|
|
|
|
index, _, ok := player.FindPet(data.CatchTime)
|
|
if ok && index != 0 {
|
|
|
|
player.Info.PetList[index], player.Info.PetList[0] = player.Info.PetList[0], player.Info.PetList[index]
|
|
|
|
result.IsDefault = 1
|
|
}
|
|
|
|
return result, 0
|
|
|
|
}
|
|
|
|
// SetPetExp 设置宠物经验
|
|
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, player *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
|
_, currentPet, found := player.FindPet(data.CatchTime)
|
|
if found && currentPet.Level < 100 {
|
|
|
|
player.AddPetExp(currentPet, data.Exp)
|
|
return &pet.PetSetExpOutboundInfo{
|
|
Exp: player.Info.ExpPool,
|
|
}, 0
|
|
}
|
|
|
|
return &pet.PetSetExpOutboundInfo{
|
|
Exp: player.Info.ExpPool,
|
|
}, errorcode.ErrorCodes.ErrSystemError
|
|
}
|