refactor: 优化代码结构和逻辑
This commit is contained in:
@@ -22,16 +22,8 @@ const (
|
||||
// c: 当前玩家对象
|
||||
// 返回: 道具列表和错误码
|
||||
func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &item.ItemListOutboundInfo{}
|
||||
|
||||
items := c.Service.Item.Get(data.Param1, data.Param2)
|
||||
result.ItemList = make([]model.SingleItemInfo, len(items))
|
||||
for i, itemData := range items {
|
||||
result.ItemList[i] = model.SingleItemInfo{
|
||||
ItemId: itemData.ItemId,
|
||||
ItemCnt: uint32(itemData.ItemCnt),
|
||||
LeftTime: ItemDefaultLeftTime,
|
||||
}
|
||||
result = &item.ItemListOutboundInfo{
|
||||
ItemList: c.Service.Item.GetUserItemList(data.Param1, data.Param2, ItemDefaultLeftTime),
|
||||
}
|
||||
return result, 0
|
||||
}
|
||||
@@ -48,7 +40,7 @@ func (h Controller) UsePetItemOutOfFight(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGH
|
||||
|
||||
itemID := uint32(data.ItemID)
|
||||
if c.Service.Item.CheakItem(itemID) == 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
itemCfg, ok := xmlres.ItemsMAP[int(itemID)]
|
||||
@@ -195,7 +187,7 @@ func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Playe
|
||||
}
|
||||
|
||||
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
currentHP := currentPet.Hp
|
||||
@@ -218,7 +210,7 @@ func (h Controller) UseSpeedupItem(data *item.C2S_USE_SPEEDUP_ITEM, c *player.Pl
|
||||
// 1. 校验道具是否存在且数量充足
|
||||
itemCount := c.Service.Item.CheakItem(data.ItemID)
|
||||
if itemCount <= 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError // 道具不足复用系统错误码(可根据需求改为专属错误码)
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
|
||||
result = &item.S2C_USE_SPEEDUP_ITEM{}
|
||||
@@ -275,7 +267,7 @@ func (h Controller) UseEnergyXishou(data *item.C2S_USE_ENERGY_XISHOU, c *player.
|
||||
// 1. 校验道具是否存在且数量充足
|
||||
itemCount := c.Service.Item.CheakItem(data.ItemID)
|
||||
if itemCount <= 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
if c.Info.EnergyTime != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
@@ -311,7 +303,7 @@ func (h Controller) UseAutoFightItem(data *item.C2S_USE_AUTO_FIGHT_ITEM, c *play
|
||||
itemCount := c.Service.Item.CheakItem(data.ItemID)
|
||||
|
||||
if itemCount <= 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
return nil, errorcode.ErrorCodes.ErrInsufficientItems
|
||||
}
|
||||
if c.Info.AutoFightTime != 0 {
|
||||
return nil, errorcode.ErrorCodes.ErrItemInUse
|
||||
|
||||
Reference in New Issue
Block a user