11
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
昔念
2026-02-14 07:36:05 +08:00
parent 24c413030f
commit 180d735706
7 changed files with 224 additions and 6 deletions

View File

@@ -122,3 +122,120 @@ func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Playe
c.Service.Item.UPDATE(data.ItemId, -1)
return result, 0
}
// ==============================
// 双倍经验加速器相关方法
// ==============================
// UseSpeedupItem 使用双倍经验加速器
// data: 包含使用的双倍经验物品ID的输入信息
// c: 当前玩家对象
// 返回: 无数据(响应包单独组装)和错误码
// 说明根据物品ID区分双倍/三倍经验加速器,使用后扣减道具并更新玩家剩余次数
func (h Controller) UseSpeedupItem(data *item.C2S_USE_SPEEDUP_ITEM, c *player.Player) (result *item.S2C_USE_SPEEDUP_ITEM, err errorcode.ErrorCode) {
// 1. 校验道具是否存在且数量充足
itemCount := c.Service.Item.CheakItem(data.ItemID)
if itemCount <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError // 道具不足复用系统错误码(可根据需求改为专属错误码)
}
result = &item.S2C_USE_SPEEDUP_ITEM{}
// 2. 核心业务逻辑根据物品ID更新双倍/三倍经验剩余次数
// (注:需根据你的道具配置表,补充 ItemID 与双倍/三倍的映射逻辑)
switch data.ItemID {
case 300027: // 假设1001是双倍经验加速器道具ID
if c.Info.TwoTimes != 0 {
return nil, errorcode.ErrorCodes.ErrItemInUse
}
c.Info.TwoTimes += 50 // 玩家对象新增 TwoTimesExp 字段存储双倍剩余次数
case 300051: // 假设1002是三倍经验加速器道具ID
if c.Info.ThreeTimes != 0 {
return nil, errorcode.ErrorCodes.ErrItemInUse
}
c.Info.ThreeTimes += 50 // 玩家对象新增 ThreeTimesExp 字段存储三倍剩余次数
default:
return nil, errorcode.ErrorCodes.ErrSystemError // 未知道具ID
}
// 3. 扣减道具(数量-1
c.Service.Item.UPDATE(data.ItemID, -1)
result.ThreeTimes = c.Info.ThreeTimes // 返回三倍经验剩余次数
result.TwoTimes = c.Info.TwoTimes // 返回双倍经验剩余次数
// 4. (可选)持久化玩家经验次数(根据你的项目存储逻辑补充)
// c.Service.Player.SaveExpTimes(c)
// 5. 返回无数据结果和成功错误码
return result, 0
}
// ==============================
// 能量吸收器相关方法
// ==============================
// UseEnergyXishou 使用能量吸收器
// data: 包含使用的能量吸收器物品ID的输入信息
// c: 当前玩家对象
// 返回: 无数据(响应包单独组装)和错误码
// 说明:使用后扣减道具并更新玩家能量吸收器剩余次数
func (h Controller) UseEnergyXishou(data *item.C2S_USE_ENERGY_XISHOU, c *player.Player) (result *item.S2C_USE_ENERGY_XISHOU, err errorcode.ErrorCode) {
// 1. 校验道具是否存在且数量充足
itemCount := c.Service.Item.CheakItem(data.ItemID)
if itemCount <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.Info.EnergyTime != 0 {
return nil, errorcode.ErrorCodes.ErrItemInUse
}
// 2. 核心业务逻辑:更新能量吸收器剩余次数
// 可根据道具ID配置不同的次数加成此处默认+1
c.Info.EnergyTime += 40 // 玩家对象新增 EnergyTimes 字段存储能量吸收剩余次数
// 3. 扣减道具(数量-1
c.Service.Item.UPDATE(data.ItemID, -1)
// 4. (可选)持久化玩家能量次数
// c.Service.Player.SaveEnergyTimes(c)
// 5. 返回无数据结果和成功错误码
return result, 0
}
// ==============================
// 自动战斗仪相关方法
// ==============================
// UseAutoFightItem 使用自动战斗仪
// data: 包含使用的自动战斗仪物品ID的输入信息
// c: 当前玩家对象
// 返回: 无数据(响应包单独组装)和错误码
// 说明使用后扣减道具开启自动战斗flag设为3并更新剩余次数
func (h Controller) UseAutoFightItem(data *item.C2S_USE_AUTO_FIGHT_ITEM, c *player.Player) (result *item.S2C_USE_AUTO_FIGHT_ITEM, err errorcode.ErrorCode) {
// 1. 校验道具是否存在且数量充足
itemCount := c.Service.Item.CheakItem(data.ItemID)
if itemCount <= 0 {
return nil, errorcode.ErrorCodes.ErrSystemError
}
if c.Info.AutoFightTime != 0 {
return nil, errorcode.ErrorCodes.ErrItemInUse
}
result = &item.S2C_USE_AUTO_FIGHT_ITEM{}
// 2. 核心业务逻辑:开启自动战斗 + 更新剩余次数
c.Info.AutoFight = 3 // 按需求设置自动战斗flag为3需测试
if data.ItemID == 300028 {
c.Info.AutoFightTime += 100
}
result.AutoFight = 1
switch data.ItemID {
case 300028:
c.Info.AutoFightTime += 100
case 300068:
c.Info.AutoFightTime += 50
}
result.AutoFightTimes = c.Info.AutoFightTime
// 3. 扣减道具(数量-1
c.Service.Item.UPDATE(data.ItemID, -1)
return result, 0
}