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
}

View File

@@ -3,6 +3,7 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/modules/player/service"
"sync/atomic"
"time"
@@ -29,6 +30,13 @@ func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info
println("进入地图", c.Info.UserID, c.Info.MapID)
}
defer func() {
if data.MapId > 10000 && data.MapId != c.Info.UserID {
c.Service.Done.UpdateRoom(1, 0)
service.NewDoneService(data.MapId).UpdateRoom(0, 1)
}
}()
// copier.CopyWithOption(result, c.Info, copier.Option{DeepCopy: true})
c.GetSpace().EnterMap(c)

View File

@@ -0,0 +1,70 @@
package item
import "blazing/logic/service/common"
// ==============================
// 双倍经验加速器相关协议 (cmd: 2327)
// ==============================
// C2S_USE_SPEEDUP_ITEM 前端→后端:使用双倍经验加速器请求
// cmd: 2327入站协议号
type C2S_USE_SPEEDUP_ITEM struct {
Head common.TomeeHeader `cmd:"2327" struc:"skip"` // 协议头skip 表示序列化时跳过
ItemID uint32 // 使用的双倍经验物品id
}
// S2C_USE_SPEEDUP_ITEM 后端→前端:使用双倍经验加速器回包
type S2C_USE_SPEEDUP_ITEM struct {
TwoTimes uint32 // 双倍经验加速器的剩余次数
ThreeTimes uint32 // 三倍经验加速器的剩余次数
}
// ==============================
// 能量吸收器相关协议 (cmd: 2331)
// ==============================
// C2S_USE_ENERGY_XISHOU 前端→后端:使用能量吸收器请求
// cmd: 2331入站协议号
type C2S_USE_ENERGY_XISHOU struct {
Head common.TomeeHeader `cmd:"2331" struc:"skip"` // 协议头skip 表示序列化时跳过
ItemID uint32 // 使用的能量吸收器物品id
}
// S2C_USE_ENERGY_XISHOU 后端→前端:使用能量吸收器回包
type S2C_USE_ENERGY_XISHOU struct {
EnergyTimes uint32 // 剩余能量吸收器次数
}
// ==============================
// 自动战斗仪相关协议 (cmd: 2329)
// ==============================
// C2S_USE_AUTO_FIGHT_ITEM 前端→后端:使用自动战斗仪请求
// cmd: 2329入站协议号
type C2S_USE_AUTO_FIGHT_ITEM struct {
Head common.TomeeHeader `cmd:"2329" struc:"skip"` // 协议头skip 表示序列化时跳过
ItemID uint32 // 使用的自动战斗仪物品id
}
// S2C_USE_AUTO_FIGHT_ITEM 后端→前端:使用自动战斗仪回包
type S2C_USE_AUTO_FIGHT_ITEM struct {
AutoFight uint32 // 开启自动战斗的flag前端看图参数为3需测试
AutoFightTimes uint32 // 战斗仪的剩余次数
}
// ==============================
// 开启/关闭自动战斗仪 (cmd: 2330)
// ==============================
// C2S_ON_OFF_AUTO_FIGHT 前端→后端:开启/关闭自动战斗仪请求包
// cmd: 2330入站协议号
type C2S_ON_OFF_AUTO_FIGHT struct {
Head common.TomeeHeader `cmd:"2330" struc:"skip"` // 协议头,序列化时跳过
Flag uint32 // 自动战斗开关0=关闭1=开启
}
// S2C_ON_OFF_AUTO_FIGHT 后端→前端:开启/关闭自动战斗仪回包
type S2C_ON_OFF_AUTO_FIGHT struct {
AutoFight uint32 // 自动战斗flag开启=3关闭=0需测试
AutoFightTimes uint32 // 自动战斗仪剩余次数
}

View File

@@ -70,14 +70,20 @@ func (p *Player) CanGetExp() int {
}
islogintime := (int64(time.Now().Unix()) - int64(p.Logintime))
// if p.Info.FightTime > 0 {
// return 8
// }
if islogintime <= (p.Info.TimeLimit - p.Info.TimeToday) {
return 1
} else {
if islogintime > (p.Info.TimeLimit - p.Info.TimeToday) {
return 0
}
base := 1
if p.Info.TwoTimes != 0 {
p.Info.TwoTimes--
base *= 2
}
if p.Info.ThreeTimes != 0 {
p.Info.ThreeTimes--
base *= 3
}
return base
}

View File

@@ -13,6 +13,7 @@ func NewShopService() *ShopService {
return &ShopService{
&cool.Service{
Model: model.NewShopConfig(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"desc", "product_name"},
},

View File

@@ -32,6 +32,7 @@ var MilestoneMode = enum.New[struct {
Moster EnumMilestone //野怪统计 地图ID->怪物ID
Task EnumMilestone
Pet EnumMilestone //宠物 属性->属性值->ID 击杀-捕捉-炫彩击杀-炫彩捕捉
Room EnumMilestone
}]()
const TableNameMilestone = "player_milestone"

View File

@@ -44,6 +44,21 @@ func (s *DoneService) UpdatePet(ptye model.PetInfo, res ...uint32) {
}
s.update(model.MilestoneMode.Pet, args, results)
}
func (s *DoneService) UpdateRoom(res ...uint32) {
args := []uint32{0}
r1 := s.get(model.MilestoneMode.Room, args)
results := make([]uint32, len(res))
if r1 != nil {
results = r1.Results
}
for i, v := range res {
results[i] += v
}
s.update(model.MilestoneMode.Room, args, results)
}
// 内部方法,实现更新