refactor(controller): 重构控制器函数命名和代码注释

- 重命名 EGG 函数为 EggGamePlay,更新宠物生成逻辑
- 重命名 Leiyi 函数为 GetLeiyiTrainStatus
- 重命名 Cacthpet 函数为 CatchPet,添加详细函数注释
- 为 ArenaSetOwner、ArenaFightOwner、ArenaGetInfo、ArenaUpfight、ArenaOwnerAcce
  等擂台相关函数添加注释前缀
- 重命名 PETKing 函数为 PetKing
- 重命名 FRESH_CHOICE_FIGHT_LEVEL 函数为 FreshChoiceFightLevel,添加详细参数说明
- 重命名 BuyMItem 函数为 BuyMultipleItems
- 重命名 ITEM_S
This commit is contained in:
2025-12-24 19:03:11 +08:00
parent 9baca27033
commit 502d497dce
32 changed files with 533 additions and 615 deletions

View File

@@ -10,28 +10,34 @@ import (
"github.com/jinzhu/copier"
)
func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
// GetUserItemList 获取用户道具列表
// data: 包含分页参数的输入信息
// c: 当前玩家对象
// 返回: 道具列表和错误码
func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
result = &item.ItemListOutboundInfo{}
result.ItemList = make([]model.SingleItemInfo, 0)
item := c.Service.Item.Get(data.Param1, data.Param2)
for _, v := range item {
var vv model.SingleItemInfo
vv.ItemId = v.ItemId
vv.ItemCnt = v.ItemCnt
vv.LeftTime = 360000
if vv.ItemCnt != 0 {
result.ItemList = append(result.ItemList, vv)
items := c.Service.Item.Get(data.Param1, data.Param2)
for _, itemData := range items {
var itemInfo model.SingleItemInfo
itemInfo.ItemId = itemData.ItemId
itemInfo.ItemCnt = itemData.ItemCnt
itemInfo.LeftTime = 360000
if itemInfo.ItemCnt != 0 {
result.ItemList = append(result.ItemList, itemInfo)
}
}
return result, 0
}
func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
_, onpet, ok := c.FindPet(data.CatchTime)
if !ok {
// UsePetItemOutOfFight 战斗外使用宠物道具
// data: 包含道具ID和宠物捕获时间的输入信息
// c: 当前玩家对象
// 返回: 使用后的宠物信息和错误码
func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *player.Player) (result *item.S2C_USE_PET_ITEM_OUT_OF_FIGHT, err errorcode.ErrorCode) {
_, currentPet, found := c.FindPet(data.CatchTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
@@ -40,48 +46,50 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
}
if data.ItemID == 300036 {
//神经元需要特殊处理
if onpet.OldCatchTime == 0 {
// 神经元需要特殊处理
if currentPet.OldCatchTime == 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
oldpetc := onpet.CatchTime
oldpet := c.Service.Pet.PetInfo_One_Unscoped(onpet.OldCatchTime)
oldPetCatchTime := currentPet.CatchTime
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
copier.CopyWithOption(onpet, oldpet.Data, copier.Option{DeepCopy: true})
onpet.CatchTime = oldpetc
onpet.EffectInfo = oldpet.Data.EffectInfo
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
currentPet.CatchTime = oldPetCatchTime
currentPet.EffectInfo = oldPet.Data.EffectInfo
} else {
hd := item.PetItemRegistry.GetHandler(data.ItemID)
if hd == nil {
handler := item.PetItemRegistry.GetHandler(data.ItemID)
if handler == nil {
return nil, errorcode.ErrorCodes.ErrSystemError
}
r := hd(data.ItemID, onpet)
if !r {
success := handler(data.ItemID, currentPet)
if !success {
return nil, errorcode.ErrorCodes.ErrSystemError
}
}
c.Service.Item.UPDATE(data.ItemID, -1)
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
onpet.CalculatePetPane(false)
copier.Copy(&result, onpet)
currentPet.CalculatePetPane(false)
copier.Copy(&result, currentPet)
return result, 0
}
// ResetNature 重置宠物性格
// data: 包含道具ID和宠物捕获时间的输入信息
// c: 当前玩家对象
// 返回: 无数据和错误码
func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
_, onpet, ok := c.FindPet(data.CatchTime)
if !ok {
_, currentPet, found := c.FindPet(data.CatchTime)
if !found {
return nil, errorcode.ErrorCodes.Err10401
}
onpet.Nature = data.Nature
onpet.CalculatePetPane(false)
currentPet.Nature = data.Nature
currentPet.CalculatePetPane(false)
c.Service.Item.UPDATE(data.ItemId, -1)
return result, 0
}