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

@@ -12,96 +12,96 @@ import (
"github.com/jinzhu/copier"
)
// 获取精灵信息
func (h *Controller) GetPetInfo(
// GetPetInfo 获取精灵信息
// data: 包含精灵捕获时间的输入信息
// c: 当前玩家对象
// 返回: 精灵信息和错误码
func (h Controller) GetPetInfo(
data *pet.InInfo,
c *player.Player) (result *pet.OutInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
_, tet, ok := c.FindPet(data.CatchTime)
err errorcode.ErrorCode) {
_, petInfo, found := c.FindPet(data.CatchTime)
if ok {
if found {
result = &pet.OutInfo{
PetInfo: *tet,
PetInfo: *petInfo,
}
return result, 0
} else {
result = &pet.OutInfo{
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
}
}
result = &pet.OutInfo{
PetInfo: c.Service.Pet.PetInfo_One(data.CatchTime).Data,
}
return result, 0
}
// 获取仓库列表
func (h *Controller) GetPetList(
// GetPetList 获取仓库列表
// data: 空输入结构
// c: 当前玩家对象
// 返回: 精灵列表和错误码
func (h Controller) GetPetList(
data *pet.GetPetListInboundEmpty,
c *player.Player) (result *pet.GetPetListOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
err errorcode.ErrorCode) {
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)
petList := c.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
}
// 获取放生列表
func (h *Controller) PET_ROWEI_LIST(
// GetPetReleaseList 获取放生列表
// data: 空输入结构
// c: 当前玩家对象
// 返回: 放生精灵列表和错误码
func (h Controller) GetPetReleaseList(
data *pet.GetPetListFreeInboundEmpty,
c *player.Player) (result *pet.GetPetListOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的
err errorcode.ErrorCode) {
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)
petList := c.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
}
// 放生
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)
r := xmlres.PetMAP[int(data.ID)].FreeForbidden
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 && r == 0 {
t.Free = 1
// PetReleaseToWarehouse 将精灵从仓库包中放生
// data: 包含精灵ID和捕获时间的输入信息
// c: 当前玩家对象
// 返回: 无数据和错误码
func (h Controller) PetReleaseToWarehouse(
data *pet.PET_ROWEI, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(pet *model.PetEX) {
_, _, inBag := c.FindPet(data.CatchTime)
freeForbidden := xmlres.PetMAP[int(data.ID)].FreeForbidden
// 如果背包没找到,再放入背包
if !inBag && pet.CatchTime != 0 && freeForbidden == 0 {
pet.Free = 1
} else {
err = errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
}
})
return nil, err
}
// 领回包
func (h *Controller) PET_RETRIEVE(
// PetRetrieveFromWarehouse 领回包
func (h Controller) PetRetrieveFromWarehouse(
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) {
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(pet *model.PetEX) {
_, _, ok := c.FindPet(data.CatchTime)
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 {
t.Free = 0
if !ok && pet.CatchTime != 0 {
pet.Free = 0
}
})
@@ -110,8 +110,8 @@ func (h *Controller) PET_RETRIEVE(
}
// 精灵背包仓库切换
func (h *Controller) PetRelease(
// TogglePetBagWarehouse 精灵背包仓库切换
func (h Controller) TogglePetBagWarehouse(
data *pet.PetReleaseInboundInfo,
c *player.Player) (
result *pet.PetReleaseOutboundInfo,
@@ -128,10 +128,10 @@ func (h *Controller) PetRelease(
switch data.Flag {
case 0:
index, v, ok := c.FindPet(data.CatchTime)
index, pet, ok := c.FindPet(data.CatchTime)
if ok {
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
t.Data = *v
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petData *model.PetEX) {
petData.Data = *pet
//t.InBag = 0
})
@@ -142,15 +142,15 @@ func (h *Controller) PetRelease(
case 1:
if len(c.Info.PetList) < 6 {
//todo 背包
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(petData *model.PetEX) {
_, _, ok := c.FindPet(data.CatchTime)
//如果背包没找到,再放入背包
if !ok && t.CatchTime != 0 {
if !ok && petData.CatchTime != 0 {
//t.InBag = 1
c.Info.PetList = append(c.Info.PetList, t.Data)
result.PetInfo = t.Data
c.Info.PetList = append(c.Info.PetList, petData.Data)
result.PetInfo = petData.Data
}
})
@@ -165,14 +165,14 @@ func (h *Controller) PetRelease(
return result, 0
}
// 精灵展示
func (h *Controller) PlayerShowPet(
// PlayerShowPet 精灵展示
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)
_, currentPet, ok := c.FindPet(data.CatchTime)
if ok {
copier.Copy(&result, onpet)
copier.Copy(&result, currentPet)
result.Flag = data.Flag
result.UserID = data.Head.UserID
defer c.GetSpace().Broadcast(c, data.Head.CMD, result)
@@ -181,16 +181,16 @@ func (h *Controller) PlayerShowPet(
}
// 单体治疗
func (h *Controller) PetOneCure(
// PetOneCure 单体治疗
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
}
_, onpet, ok := c.FindPet(data.CatchTime)
_, currentPet, ok := c.FindPet(data.CatchTime)
if ok {
defer onpet.Cure()
defer currentPet.Cure()
}
@@ -200,8 +200,8 @@ func (h *Controller) PetOneCure(
}
// 精灵首发
func (h *Controller) PetFirst(
// PetFirst 精灵首发
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 {
@@ -226,10 +226,10 @@ func (h *Controller) PetFirst(
// 返回:索引、元素指针、是否找到
func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) (result *pet.PetSetExpOutboundInfo, err errorcode.ErrorCode) {
_, onpet, ok := c.FindPet(data.CatchTime)
if ok && onpet.Level < 100 {
_, currentPet, ok := c.FindPet(data.CatchTime)
if ok && currentPet.Level < 100 {
c.AddPetExp(onpet, data.Exp)
c.AddPetExp(currentPet, data.Exp)
return &pet.PetSetExpOutboundInfo{
Exp: c.Info.ExpPool,
}, 0
@@ -240,8 +240,8 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player)
}, errorcode.ErrorCodes.ErrSystemError
}
// 精灵图鉴
func (h Controller) PetBargeList(data *pet.PetBargeListInboundInfo, c *player.Player) (result *pet.PetBargeListOutboundInfo, err errorcode.ErrorCode) {
// GetPetBargeList 精灵图鉴
func (h Controller) GetPetBargeList(data *pet.PetBargeListInboundInfo, c *player.Player) (result *pet.PetBargeListOutboundInfo, err errorcode.ErrorCode) {
return &pet.PetBargeListOutboundInfo{
PetBargeList: make([]pet.PetBargeListInfo, 0),