feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
122 lines
3.6 KiB
Go
122 lines
3.6 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/item"
|
|
"blazing/logic/service/player"
|
|
"blazing/modules/player/model"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
const (
|
|
// ItemDefaultLeftTime 道具默认剩余时间(毫秒)
|
|
ItemDefaultLeftTime = 360000
|
|
// ItemNeuronID 神经元道具ID
|
|
ItemNeuronID = 300036
|
|
)
|
|
|
|
// 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)
|
|
|
|
items := c.Service.Item.Get(data.Param1, data.Param2)
|
|
for _, itemData := range items {
|
|
itemInfo := model.SingleItemInfo{
|
|
ItemId: itemData.ItemId,
|
|
ItemCnt: itemData.ItemCnt,
|
|
LeftTime: ItemDefaultLeftTime,
|
|
}
|
|
if itemInfo.ItemCnt != 0 {
|
|
result.ItemList = append(result.ItemList, itemInfo)
|
|
}
|
|
}
|
|
return result, 0
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
if c.Service.Item.CheakItem(data.ItemID) == 0 {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
var errcode errorcode.ErrorCode
|
|
if data.ItemID == ItemNeuronID {
|
|
errcode = h.handleNeuronItem(currentPet, c)
|
|
} else {
|
|
errcode = h.handleRegularPetItem(data.ItemID, currentPet)
|
|
}
|
|
if errcode != 0 {
|
|
return nil, errcode
|
|
}
|
|
|
|
c.Service.Item.UPDATE(data.ItemID, -1)
|
|
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
|
|
currentPet.CalculatePetPane(false)
|
|
copier.Copy(&result, currentPet)
|
|
|
|
return result, 0
|
|
}
|
|
|
|
// handleNeuronItem 处理神经元道具的特殊逻辑
|
|
func (h Controller) handleNeuronItem(currentPet *model.PetInfo, c *player.Player) errorcode.ErrorCode {
|
|
if currentPet.OldCatchTime == 0 {
|
|
return errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
originalCatchTime := currentPet.CatchTime
|
|
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
|
|
|
|
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
|
|
currentPet.CatchTime = originalCatchTime
|
|
currentPet.ShinyInfo = oldPet.Data.ShinyInfo
|
|
currentPet.EffectInfo = oldPet.Data.EffectInfo
|
|
|
|
return 0
|
|
}
|
|
|
|
// handleRegularPetItem 处理普通宠物道具
|
|
func (h Controller) handleRegularPetItem(itemID uint32, currentPet *model.PetInfo) errorcode.ErrorCode {
|
|
handler := item.PetItemRegistry.GetHandler(itemID)
|
|
if handler == nil {
|
|
return errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
if !handler(itemID, currentPet) {
|
|
return errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// ResetNature 重置宠物性格
|
|
// data: 包含道具ID和宠物捕获时间的输入信息
|
|
// c: 当前玩家对象
|
|
// 返回: 无数据和错误码
|
|
func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
_, currentPet, found := c.FindPet(data.CatchTime)
|
|
if !found {
|
|
return nil, errorcode.ErrorCodes.Err10401
|
|
}
|
|
|
|
if c.Service.Item.CheakItem(data.ItemId) <= 0 {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
|
|
currentPet.Nature = data.Nature
|
|
currentPet.CalculatePetPane(false)
|
|
c.Service.Item.UPDATE(data.ItemId, -1)
|
|
return result, 0
|
|
}
|