This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
70
logic/service/item/auto.go
Normal file
70
logic/service/item/auto.go
Normal 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 // 自动战斗仪剩余次数
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ func NewShopService() *ShopService {
|
||||
return &ShopService{
|
||||
&cool.Service{
|
||||
Model: model.NewShopConfig(),
|
||||
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
KeyWordField: []string{"desc", "product_name"},
|
||||
},
|
||||
|
||||
@@ -32,6 +32,7 @@ var MilestoneMode = enum.New[struct {
|
||||
Moster EnumMilestone //野怪统计 地图ID->怪物ID
|
||||
Task EnumMilestone
|
||||
Pet EnumMilestone //宠物 属性->属性值->ID 击杀-捕捉-炫彩击杀-炫彩捕捉
|
||||
Room EnumMilestone
|
||||
}]()
|
||||
|
||||
const TableNameMilestone = "player_milestone"
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
// 内部方法,实现更新
|
||||
|
||||
Reference in New Issue
Block a user