fix(fight): 使用模型层方法生成精灵信息 refactor(controller): 移除冗余变量与内联XML读取逻辑 refactor(pet): 重构经验更新与进化逻辑 refactor(item): 校验并扣减使用道具数量 feat(item): 新增金豆购买商品协议结构体 feat(user): 迁移角色服装变更逻辑至user控制器 feat(pet): 增加技能排序协议定义 refactor(utils): 移除未使用的工具函数引用 chore(config): 更新地图怪物配置信息 详细变更内容包括: - 在`xmlres/file.go`中初始化`GoldProductMap`并加载相关配置。 - 将`GenPetInfo`方法从玩家服务迁移至`model`包以统一管理。 - 合并部分不必要的局部变量声明,并优化XML资源加载方式。 - 拆分精灵升级与进化方法,明确调用职责。 - 在战斗和治疗等操作前增加货币校验及扣除逻辑。 - 补充金豆购买相关的客户端/服务端通信结构体。 - 调整技能选择逻辑避免潜在索引越界问题。 - 更新部分注释说明和代码结构以提升可维护性。
246 lines
6.1 KiB
Go
246 lines
6.1 KiB
Go
package controller
|
||
|
||
import (
|
||
"blazing/common/data/xmlres"
|
||
"blazing/common/socket/errorcode"
|
||
"blazing/logic/service/fight"
|
||
"blazing/logic/service/pet"
|
||
"blazing/logic/service/player"
|
||
|
||
"blazing/modules/blazing/model"
|
||
|
||
"github.com/jinzhu/copier"
|
||
)
|
||
|
||
// 获取精灵信息
|
||
func (h *Controller) GetPetInfo(
|
||
data *pet.InInfo,
|
||
c *player.Player) (result *pet.OutInfo,
|
||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
_, tet, ok := c.FindPet(data.CatchTime)
|
||
|
||
if ok {
|
||
result = &pet.OutInfo{
|
||
PetInfo: *tet,
|
||
}
|
||
return result, 0
|
||
} else {
|
||
result = &pet.OutInfo{
|
||
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
|
||
}
|
||
|
||
}
|
||
|
||
return result, 0
|
||
}
|
||
|
||
// 获取仓库列表
|
||
func (h *Controller) GetPetList(
|
||
data *pet.GetPetListInboundEmpty,
|
||
c *player.Player) (result *pet.GetPetListOutboundInfo,
|
||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
result = &pet.GetPetListOutboundInfo{}
|
||
|
||
tt := c.Service.Pet.PetInfo(0) //获得未放生的精灵
|
||
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_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)
|
||
|
||
//如果背包没找到,再放入背包
|
||
if !ok && t.CatchTime != 0 && xmlres.PetMAP[int(data.ID)].FreeForbidden == 0 {
|
||
t.Free = 1
|
||
}
|
||
|
||
})
|
||
|
||
return nil, 0
|
||
|
||
}
|
||
|
||
// 领回包
|
||
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
|
||
|
||
}
|
||
|
||
// 精灵背包仓库切换
|
||
func (h *Controller) PetRelease(
|
||
data *pet.PetReleaseInboundInfo,
|
||
c *player.Player) (
|
||
result *pet.PetReleaseOutboundInfo,
|
||
err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
|
||
//这里只修改,因为添加和移除背包在宠物获取时已经做了
|
||
|
||
result = &pet.PetReleaseOutboundInfo{}
|
||
result.Flag = uint32(data.Flag)
|
||
//擂台住不能换精灵
|
||
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||
}
|
||
switch data.Flag {
|
||
case 0:
|
||
|
||
index, v, ok := c.FindPet(data.CatchTime)
|
||
if ok {
|
||
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||
t.Data = *v
|
||
//t.InBag = 0
|
||
|
||
})
|
||
c.Info.PetList = append(c.Info.PetList[:index], c.Info.PetList[index+1:]...)
|
||
}
|
||
|
||
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
|
||
case 1:
|
||
if len(c.Info.PetList) < 6 {
|
||
//todo 背包
|
||
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
|
||
|
||
_, _, ok := c.FindPet(data.CatchTime)
|
||
|
||
//如果背包没找到,再放入背包
|
||
if !ok && t.CatchTime != 0 {
|
||
//t.InBag = 1
|
||
c.Info.PetList = append(c.Info.PetList, t.Data)
|
||
result.PetInfo = t.Data
|
||
}
|
||
|
||
})
|
||
}
|
||
|
||
}
|
||
|
||
if len(c.Info.PetList) > 0 {
|
||
result.FirstPetTime = c.Info.PetList[0].CatchTime //设置首发
|
||
}
|
||
|
||
return result, 0
|
||
}
|
||
|
||
// 精灵展示
|
||
func (h *Controller) PlayerShowPet(
|
||
data *pet.PetShowInboundInfo, c *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
result = &pet.PetShowOutboundInfo{}
|
||
_, onpet, ok := c.FindPet(data.CatchTime)
|
||
|
||
if ok {
|
||
copier.Copy(&result, onpet)
|
||
result.Flag = data.Flag
|
||
result.UserID = data.Head.UserID
|
||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||
}
|
||
return
|
||
|
||
}
|
||
|
||
// 单体治疗
|
||
func (h *Controller) PetOneCure(
|
||
data *pet.PetOneCureInboundInfo, c *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
||
return result, errorcode.ErrorCodes.ErrChampionCannotHeal
|
||
}
|
||
|
||
if !c.UseCoins(20) {
|
||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||
}
|
||
_, onpet, ok := c.FindPet(data.CatchTime)
|
||
if ok {
|
||
onpet.Cure()
|
||
}
|
||
|
||
return &pet.PetOneCureOutboundInfo{
|
||
CatchTime: data.CatchTime,
|
||
}, 0
|
||
|
||
}
|
||
|
||
// 精灵首发
|
||
func (h *Controller) PetFirst(
|
||
data *pet.PetDefaultInboundInfo, c *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
|
||
//擂台住不能换精灵
|
||
if c.GetSpace().Owner.UserID == c.Info.UserID {
|
||
return result, errorcode.ErrorCodes.ErrChampionCannotSwitch
|
||
}
|
||
|
||
result = &pet.PetDefaultOutboundInfo{}
|
||
|
||
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
|
||
}
|
||
|
||
return result, 0
|
||
|
||
}
|
||
|
||
// FindWithIndex 遍历slice,找到第一个满足条件的元素
|
||
// 返回:索引、元素指针、是否找到
|
||
|
||
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
|
||
_, onpet, ok := c.FindPet(data.CatchTime)
|
||
if ok {
|
||
|
||
c.AddPetExp(onpet, data.Exp)
|
||
}
|
||
|
||
return &pet.PetSetExpOutboundInfo{
|
||
Exp: c.Info.ExpPool,
|
||
}, 0
|
||
}
|
||
|
||
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
|
||
}
|