refactor(common): 统一使用 common.TomeeHeader 替代 player.TomeeHeader

将多处
This commit is contained in:
2025-11-19 16:11:02 +08:00
parent 31439b707c
commit c0b09c92c4
57 changed files with 455 additions and 480 deletions

View File

@@ -58,7 +58,7 @@ func GetServerInfoList() []ServerInfo {
// CommendSvrInfo 初始连接请求信息结构体 // CommendSvrInfo 初始连接请求信息结构体
type CommendSvrInfo struct { type CommendSvrInfo struct {
//Handler player.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo //Handler common.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo
MaxOnlineID uint32 `struc:"sizeof=ServerList"` // 最大连接数 MaxOnlineID uint32 `struc:"sizeof=ServerList"` // 最大连接数
IsVip uint32 // 建议为0 IsVip uint32 // 建议为0
ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo

View File

@@ -493,7 +493,7 @@ var ErrorCodes = enum.New[struct {
ErrBatteryLowForDefense ErrorCode `enum:"18030"` ErrBatteryLowForDefense ErrorCode `enum:"18030"`
// 正在精灵对战中 // 正在精灵对战中
// 你们战队还没有报名参加对抗赛 // 你们战队还没有报名参加对抗赛
ErrInBattle ErrorCode `enum:"11024"` ErrInBattle ErrorCode `enum:"11024"`
ErrTeamNotRegistered ErrorCode `enum:"18221"` ErrTeamNotRegistered ErrorCode `enum:"18221"`
// 你的战队的其他成员已经报名参加保卫战,请耐心等待比赛集合令提示。 // 你的战队的其他成员已经报名参加保卫战,请耐心等待比赛集合令提示。
ErrTeammateRegistered ErrorCode `enum:"18222"` ErrTeammateRegistered ErrorCode `enum:"18222"`
@@ -606,6 +606,4 @@ var ErrorCodes = enum.New[struct {
ErrCannotInjectPillAgain ErrorCode `enum:"10504"` ErrCannotInjectPillAgain ErrorCode `enum:"10504"`
// 不能注入过多能量珠 // 不能注入过多能量珠
ErrTooManyEnergyOrbs ErrorCode `enum:"10505"` ErrTooManyEnergyOrbs ErrorCode `enum:"10505"`
// 登录服务器错误,请尝试登录上次登录的服务器进入游戏
ErrLoginServerError ErrorCode `enum:"500103"`
}]() }]()

View File

@@ -2,8 +2,8 @@ package controller
import ( import (
"blazing/cool" "blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/player"
"strings" "strings"
"bytes" "bytes"
@@ -102,7 +102,7 @@ func getcmd(t reflect.Type) []uint32 {
field := t.Field(i) field := t.Field(i)
//fmt.Printf("- 字段名: %s\n", field.Name) //fmt.Printf("- 字段名: %s\n", field.Name)
//fmt.Printf(" 类型: %v\n", field.Type) //fmt.Printf(" 类型: %v\n", field.Type)
if field.Type == reflect.TypeOf(player.TomeeHeader{}) { if field.Type == reflect.TypeOf(common.TomeeHeader{}) {
// fmt.Println(reflect.ValueOf(field)) // fmt.Println(reflect.ValueOf(field))
return gconv.SliceUint32(strings.Split(field.Tag.Get("cmd"), "|")) return gconv.SliceUint32(strings.Split(field.Tag.Get("cmd"), "|"))

View File

@@ -46,9 +46,6 @@ func processMonID(bm string) string {
// 挑战地图boss // 挑战地图boss
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !c.CanFight() {
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
}
var mo *model.PetInfo var mo *model.PetInfo
moinfo := &model.PlayerInfo{} moinfo := &model.PlayerInfo{}
@@ -94,11 +91,10 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
} }
} }
c.Fightinfo = &info.Fightinfo{
Status: info.BattleStatus.FIGHT_WITH_BOSS, c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_BOSS
Mode: info.BattleMode.MULTI_MODE, c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
}
ai := player.NewAI_player(moinfo) ai := player.NewAI_player(moinfo)
//给予打过一次的奖励 //给予打过一次的奖励
event := c.Done.SPT(c.Info.MapID, data.BossId, 1, func() { event := c.Done.SPT(c.Info.MapID, data.BossId, 1, func() {
@@ -115,9 +111,7 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla
// 战斗野怪 // 战斗野怪
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !c.CanFight() {
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
}
refpet := c.OgreInfo.Data[data.Number] refpet := c.OgreInfo.Data[data.Number]
if refpet.Id == 0 { if refpet.Id == 0 {
@@ -134,10 +128,9 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
moinfo.PetList = append(moinfo.PetList, *mo) moinfo.PetList = append(moinfo.PetList, *mo)
ai := player.NewAI_player(moinfo) ai := player.NewAI_player(moinfo)
c.Fightinfo = &info.Fightinfo{
Mode: info.BattleMode.MULTI_MODE, c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_NPC
Status: info.BattleStatus.FIGHT_WITH_NPC, c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
}
fight.NewFight(c, ai, func(foi *info.FightOverInfo) { fight.NewFight(c, ai, func(foi *info.FightOverInfo) {

View File

@@ -2,8 +2,8 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"sync/atomic"
"blazing/logic/service/common"
"blazing/logic/service/fight" "blazing/logic/service/fight"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/player" "blazing/logic/service/player"
@@ -15,12 +15,19 @@ import (
// 前端到后端无数据内容 空包 // 前端到后端无数据内容 空包
// 后端到前端无数据内容 空包 // 后端到前端无数据内容 空包
// 都需要通过2419包广播更新擂台状态 // 都需要通过2419包广播更新擂台状态
func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
if !c.CanFight() {
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
c.GetSpace().Owner.Nick = c.GetInfo().Nick
c.GetSpace().ARENA_Player = c //添加用户
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
return &c.GetSpace().Owner, 0
} }
space.GetSpace(c.Info.MapID).UP_ARENA(c, 1)
return return nil, errorcode.ErrorCodes.ErrChampionExists
} }
// public static const ARENA_FIGHT_OWENR:uint = 2418; // public static const ARENA_FIGHT_OWENR:uint = 2418;
@@ -29,27 +36,32 @@ func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Playe
// 后端到前端无数据内容 空包 // 后端到前端无数据内容 空包
// 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗 // 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗
// 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战 // 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战
func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
if !c.CanFight() { s := c.GetSpace()
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
}
space.GetSpace(c.Info.MapID).ARENA_join(func(ownerID common.PlayerI) common.PlayerI { //原子操作,修改擂台状态
c.Fightinfo = &info.Fightinfo{ if atomic.CompareAndSwapUint32(&s.Owner.Flag, 1, 2) {
Mode: info.BattleMode.SINGLE_MODE, //成功发起擂台挑战后才修改我放状态
Status: info.BattleStatus.FIGHT_WITH_PLAYER, c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
} c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_PLAYER
_, fighterr := fight.NewFight(c, ownerID, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
_, err = fight.NewFight(c, s.ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
}) ///开始对战,房主方以及被邀请方 }) ///开始对战,房主方以及被邀请方
if fighterr != nil { if err <= 0 { //发起战斗成功
return nil atomic.StoreUint32(&s.Owner.ChallengerID, c.GetInfo().UserID) //传回的指针赋值给ID
}
return c } else {
}) //发起失败,改回1
atomic.StoreUint32(&s.Owner.Flag, 1)
}
s.Broadcast(c, 2419, &s.Owner)
return &s.Owner, 0
}
return nil, errorcode.ErrorCodes.ErrChampionExists
return
} }
// 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包 // 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包
@@ -57,8 +69,7 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
// 后端到前端 // 后端到前端
func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) { func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
result = &space.GetSpace(c.Info.MapID).ARENA return &space.GetSpace(c.Info.MapID).Owner, 0
return
} }
// public static const ARENA_UPFIGHT:uint = 2420; // public static const ARENA_UPFIGHT:uint = 2420;
@@ -66,10 +77,17 @@ func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player)
// 前端到后端无数据内容 // 前端到后端无数据内容
// 后端到前端无数据内容 // 后端到前端无数据内容
// 都需要通过2419包广播更新擂台状态 // 都需要通过2419包广播更新擂台状态
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
space.GetSpace(c.Info.MapID).UP_ARENA(c, 0) //原子操作,修改擂台状态
//result = &info.S2C_ARENA_GET_INFO{} s := c.GetSpace()
return if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
s.ARENA_Player = nil
s.Broadcast(c, 2419, &s.Owner)
return &s.Owner, 0
}
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
} }
// public static const ARENA_OWENR_ACCE:uint = 2422; // public static const ARENA_OWENR_ACCE:uint = 2422;
@@ -78,8 +96,25 @@ func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (
// 后端到前端无数据内容 // 后端到前端无数据内容
// public static const ARENA_OWENR_OUT:uint = 2423; // public static const ARENA_OWENR_OUT:uint = 2423;
// 此包不清楚具体怎么触发 但已知此包为后端主动发送。不清楚什么情况下回用到 // 此包不清楚具体怎么触发 但已知此包为后端主动发送。不清楚什么情况下回用到
func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
space.GetSpace(c.Info.MapID).UP_ARENA(c, 2)
//result = &info.S2C_ARENA_GET_INFO{} s := c.GetSpace()
return if atomic.LoadUint32(&s.Owner.UserID) != c.GetInfo().UserID && c.GetInfo().UserID != atomic.LoadUint32(&s.Owner.ChallengerID) { //说明已经有人了
return nil, errorcode.ErrorCodes.Err24hBanCheatTool
}
if c.GetInfo().UserID == atomic.LoadUint32(&s.Owner.UserID) {
s.Owner.HostWins += 1 //连胜+1
} else {
s.Owner.HostWins = 0 //连胜重置
s.Owner.UserID = c.GetInfo().UserID //添加用户ID
s.Owner.Nick = c.GetInfo().Nick
s.ARENA_Player = c //添加用户
}
atomic.StoreUint32(&s.Owner.Flag, 1)
s.Broadcast(c, 2419, &s.Owner)
return &s.Owner, 0
} }

View File

@@ -3,6 +3,7 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service/common"
"blazing/logic/service/fight" "blazing/logic/service/fight"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/player" "blazing/logic/service/player"
@@ -11,30 +12,22 @@ import (
//大乱斗 //大乱斗
func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !c.CanFight(1) {
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
}
c.Fightinfo.Mode = info.BattleMode.PET_MELEE c.Fightinfo.Mode = info.BattleMode.PET_MELEE
c.Fightinfo.PlayerID = 0 c.Fightinfo.PlayerID = 0
g := c.Pet_joinFight() c.JoinFight(func(p common.PlayerI) bool {
if g != nil { fight.NewFight(p, c, func(foi *info.FightOverInfo) {
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
}) ///开始对战,房主方以及被邀请方 }) ///开始对战,房主方以及被邀请方
} return true
})
return return
} }
func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !c.CanFight() {
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
}
c.Fightinfo = &info.Fightinfo{ c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_PLAYER
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
switch data.Type { switch data.Type {
case 5: case 5:
@@ -42,21 +35,13 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
case 6: case 6:
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
} }
g := c.Pet_joinFight() c.JoinFight(func(p common.PlayerI) bool {
if g != nil { fight.NewFight(p, c, func(foi *info.FightOverInfo) {
switch data.Type {
case 5:
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
}) ///开始对战,房主方以及被邀请方 }) ///开始对战,房主方以及被邀请方
case 6: return true
fight.NewFight(g, c, func(foi *info.FightOverInfo) { })
}) ///开始对战,房主方以及被邀请方
}
}
return return
} }

View File

@@ -4,6 +4,7 @@ import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"sync/atomic" "sync/atomic"
"blazing/logic/service/common"
"blazing/logic/service/fight" "blazing/logic/service/fight"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/player" "blazing/logic/service/player"
@@ -12,18 +13,20 @@ import (
// 接收战斗或者取消战斗的包 // 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Status, 0, 1) { //邀请前提是自己没在战斗 if !atomic.CompareAndSwapUint32(&c.Fightinfo.Status, 0, 1) { //邀请前提是自己没在战斗
return nil, errorcode.ErrorCodes.ErrInBattle return nil, errorcode.ErrorCodes.ErrInBattle
} }
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok { c.Fightinfo.PlayerID = data.UserID
c.Fightinfo.Mode = data.Mode
err = c.AgreeBattle(data.UserID, data.Flag, func(p common.PlayerI) bool {
fight.NewFight(p1, c, func(foi *info.FightOverInfo) { _, err = fight.NewFight(p, c, func(foi *info.FightOverInfo) {
}) ///开始对战,房主方以及被邀请方 })
} return err <= 0
return nil, -1 })
return
} }
// 邀请其他人进行战斗 // 邀请其他人进行战斗

View File

@@ -34,7 +34,7 @@ func IsToday(t time.Time) bool {
func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.LoginMSInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.LoginMSInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
tt := data.CheakSession() tt := data.CheakSession()
if !tt { if !tt {
err = errorcode.ErrorCodes.ErrLoginServerError
defer c.Close() defer c.Close()
return return
} }
@@ -52,14 +52,14 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
t := player.GetPlayer(c, data.Head.UserID) t := player.GetPlayer(c, data.Head.UserID)
if t == nil { if t == nil {
cool.Loger.Error(context.Background(), "获取玩家失败", data.Head.UserID) cool.Loger.Error(context.Background(), "获取玩家失败", data.Head.UserID)
err = errorcode.ErrorCodes.ErrLoginServerError
defer c.Close() defer c.Close()
return return
} }
t.Service = blservice.NewUserService(data.Head.UserID) t.Service = blservice.NewUserService(data.Head.UserID)
t.Info = t.Service.Info.Person(data.Head.UserID) t.Info = t.Service.Info.Person(data.Head.UserID)
if t.Info == nil { if t.Info == nil {
err = errorcode.ErrorCodes.ErrLoginServerError defer c.Close()
return return
} }
t.Info.UserID = data.Head.UserID t.Info.UserID = data.Head.UserID
@@ -96,7 +96,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
result = user.NewOutInfo() //设置登录消息 result = user.NewOutInfo() //设置登录消息
result.PlayerInfo = *t.Info result.PlayerInfo = *t.Info
space.GetSpace(t.Info.MapID).EnterMap(t) space.GetSpace(t.Info.MapID).EnterMap(t)
return result, 0 return result, 0

View File

@@ -8,13 +8,13 @@ import (
) )
func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.WalkOutInfo, err errorcode.ErrorCode) { func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.WalkOutInfo, err errorcode.ErrorCode) {
result = &info.WalkOutInfo{
c.GetSpace().Walk(c, info.WalkOutInfo{
Flag: data.Flag, Flag: data.Flag,
Point: data.Point, Point: data.Point,
Path: data.Path, Path: data.Path,
UserID: c.Info.UserID, UserID: c.Info.UserID,
}) }
c.GetSpace().Walk(c, result)
c.Info.Pos = data.Point c.Info.Pos = data.Point
return return

View File

@@ -0,0 +1,114 @@
package common
import (
"bytes"
"encoding/binary"
"fmt"
"reflect"
"github.com/lunixbochs/struc"
)
// TomeeHeader 结构体字段定义
type TomeeHeader struct {
Len uint32 `json:"len"`
Version byte `json:"version" struc:"[1]byte"`
CMD uint32 `json:"cmdId" struc:"uint32"`
UserID uint32 `json:"userId"`
//Error uint32 `json:"error" struc:"[0]pad"`
Result uint32 `json:"result"`
Data []byte `json:"data" struc:"skip"` //组包忽略此字段// struc:"[0]pad"
//Return []byte `struc:"[0]pad"` //返回记录
}
func NewTomeeHeader(cmd uint32, userid uint32) *TomeeHeader {
return &TomeeHeader{
CMD: cmd,
// Len: 0,
Version: 49,
Result: 0,
}
}
// Pack 组包方法手动编码字节流兼容interface{}、nil、多层指针/接口
func (h *TomeeHeader) Pack(data any) []byte {
//h.Result = 0//默认置0
//t := reflect.TypeOf(data)
tv := reflect.ValueOf(data)
var datar []byte
// 处理指针类型
if tv.Kind() == reflect.Ptr {
//tv = t.Elem() // 获取指针指向的类型
tv = tv.Elem() // 获取指针指向的值
}
switch tv.Kind() {
case reflect.String:
datar = []byte(tv.String())
case reflect.Slice:
datar = data.([]byte)
//p.Conn.Write(p.pack(cmd, data.([]byte))) //写入数据
case reflect.Struct:
var data1 bytes.Buffer
err := struc.Pack(&data1, data)
if err != nil {
fmt.Println(err)
}
datar = data1.Bytes()
default:
datar = []byte{}
// fmt.Println(err, datar)
// p.Conn.Write(p.pack(cmd, data))
}
// 4. 手动打包包头+数据体
return h.packHeaderWithData(datar)
}
// packHeaderWithData 手动编码包头和数据体(静态指定偏移量,无自增变量)
// 包头固定结构(大端序):
// - 0-3 字节Len (uint32)
// - 4 字节Version (byte)
// - 5-8 字节CMD (uint32从uint64截断)
// - 9-12 字节UserID (uint32)
// - 13-16 字节Result (uint32)
// 17字节后数据体
func (h *TomeeHeader) packHeaderWithData(data []byte) []byte {
// 计算总长度包头17字节 + 数据体长度
dataLen := len(data)
h.Len = uint32(17 + dataLen)
// 预分配切片(总长度 = 包头 + 数据体),避免多次扩容
buf := make([]byte, h.Len)
// 1. 写入Len固定偏移0-3 字节,大端序)
binary.BigEndian.PutUint32(buf[0:4], h.Len)
// 2. 写入Version固定偏移4 字节)
buf[4] = h.Version
// 3. 写入CMD固定偏移5-8 字节,大端序)
binary.BigEndian.PutUint32(buf[5:9], uint32(h.CMD))
// 4. 写入UserID固定偏移9-12 字节,大端序)
binary.BigEndian.PutUint32(buf[9:13], h.UserID)
// 5. 写入Result固定偏移13-16 字节,大端序)
binary.BigEndian.PutUint32(buf[13:17], h.Result)
// 6. 写入数据体固定起始偏移17 字节,若有数据则拷贝)
if dataLen > 0 {
copy(buf[17:], data)
}
return buf
}

View File

@@ -15,5 +15,6 @@ type PlayerI interface {
InvitePlayer(PlayerI) InvitePlayer(PlayerI)
SetFightC(FightI) SetFightC(FightI)
QuitFight() QuitFight()
SendPackCmd(cmd uint32, b any)
SendPackCmd(uint32, any)
} }

View File

@@ -8,7 +8,6 @@ import (
"blazing/logic/service/fight/action" "blazing/logic/service/fight/action"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/fight/input" "blazing/logic/service/fight/input"
"blazing/logic/service/player"
"context" "context"
"log" "log"
@@ -87,7 +86,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
f.Broadcast(func(ff *input.Input) { //先给自身广播 f.Broadcast(func(ff *input.Input) { //先给自身广播
if ff.Player.GetInfo().UserID == c.GetInfo().UserID { if ff.Player.GetInfo().UserID == c.GetInfo().UserID {
ff.Player.SendPackCmd(2407, ret.Reason) ff.Player.SendPackCmd(2407, &ret.Reason)
} }
}) })
@@ -203,9 +202,8 @@ func (f *FightC) handleNPCFightSpecial(startInfo *info.FightStartOutboundInfo) {
if catchRate > 0 { if catchRate > 0 {
startInfo.Info2.Catchable = 1 // 标记为可捕捉 startInfo.Info2.Catchable = 1 // 标记为可捕捉
// 标记AI对手允许被捕捉类型断言确保安全 // 标记AI对手允许被捕捉类型断言确保安全
if oppAI, ok := f.Opp.Player.(*player.AI_player); ok { f.Opp.CanCapture = true
oppAI.CanCapture = true
}
} }
} }
@@ -220,7 +218,7 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
// 通知双方玩家准备完成,即将开始战斗 // 通知双方玩家准备完成,即将开始战斗
ff.Player.SendPackCmd(2504, startInfo) ff.Player.SendPackCmd(2504, &startInfo)
}) })
// 标记战斗已启动(原注释逻辑) // 标记战斗已启动(原注释逻辑)

View File

@@ -1,21 +1,19 @@
package fight package fight
import ( import (
"blazing/logic/service/common"
_ "blazing/logic/service/fight/effect" _ "blazing/logic/service/fight/effect"
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
) )
// 野怪对战包 // 野怪对战包
type FightNpcMonsterInboundInfo struct { type FightNpcMonsterInboundInfo struct {
Head player.TomeeHeader `cmd:"2408" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2408" struc:"[0]pad"`
// Number 地图刷新怪物结构体对应的序号1-9的位置序号 // Number 地图刷新怪物结构体对应的序号1-9的位置序号
Number uint32 `fieldDesc:"地图刷新怪物结构体对应的序号 1 - 9 的位置序号" ` Number uint32 `fieldDesc:"地图刷新怪物结构体对应的序号 1 - 9 的位置序号" `
} }
type ChallengeBossInboundInfo struct { type ChallengeBossInboundInfo struct {
Head player.TomeeHeader `cmd:"2411" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2411" struc:"[0]pad"`
BossId uint32 `json:"bossId"` BossId uint32 `json:"bossId"`
} }
type NullOutboundInfo struct { type NullOutboundInfo struct {
@@ -23,40 +21,40 @@ type NullOutboundInfo struct {
// 准备战斗包 // 准备战斗包
type ReadyToFightInboundInfo struct { type ReadyToFightInboundInfo struct {
Head player.TomeeHeader `cmd:"2404" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2404" struc:"[0]pad"`
} }
// 战斗逃跑 // 战斗逃跑
type EscapeFightInboundInfo struct { type EscapeFightInboundInfo struct {
Head player.TomeeHeader `cmd:"2410" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2410" struc:"[0]pad"`
} }
// 精灵王 // 精灵王
type StartPetWarInboundInfo struct { type StartPetWarInboundInfo struct {
Head player.TomeeHeader `cmd:"2431" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2431" struc:"[0]pad"`
} }
type ARENA_SET_OWENR struct { type ARENA_SET_OWENR struct {
Head player.TomeeHeader `cmd:"2417" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2417" struc:"[0]pad"`
} }
type ARENA_FIGHT_OWENR struct { type ARENA_FIGHT_OWENR struct {
Head player.TomeeHeader `cmd:"2418" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2418" struc:"[0]pad"`
} }
type ARENA_GET_INFO struct { type ARENA_GET_INFO struct {
Head player.TomeeHeader `cmd:"2419" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2419" struc:"[0]pad"`
} }
type ARENA_UPFIGHT struct { type ARENA_UPFIGHT struct {
Head player.TomeeHeader `cmd:"2420" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2420" struc:"[0]pad"`
} }
type ARENA_OWENR_ACCE struct { type ARENA_OWENR_ACCE struct {
Head player.TomeeHeader `cmd:"2422" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2422" struc:"[0]pad"`
} }
// 表示"宠物王加入"的入站消息数据 // 表示"宠物王加入"的入站消息数据
type PetKingJoinInboundInfo struct { type PetKingJoinInboundInfo struct {
Head player.TomeeHeader `cmd:"2413" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2413" struc:"[0]pad"`
Type uint32 // 战斗类型5=单精灵6=多精灵11=精灵大师赛 (对应Java的@UInt long type) Type uint32 // 战斗类型5=单精灵6=多精灵11=精灵大师赛 (对应Java的@UInt long type)
FightType uint32 // 仅当Type为11时有效 (对应Java的@UInt long fightType) FightType uint32 // 仅当Type为11时有效 (对应Java的@UInt long fightType)
} }
@@ -64,22 +62,22 @@ type PetKingJoinInboundInfo struct {
// HandleFightInviteInboundInfo 处理战斗邀请的入站消息 // HandleFightInviteInboundInfo 处理战斗邀请的入站消息
type HandleFightInviteInboundInfo struct { type HandleFightInviteInboundInfo struct {
Head player.TomeeHeader `cmd:"2403" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2403" struc:"[0]pad"`
UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid
Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战 Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战
Mode info.EnumBattleMode `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6 Mode uint32 `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
} }
type InviteToFightInboundInfo struct { type InviteToFightInboundInfo struct {
Head player.TomeeHeader `cmd:"2401" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2401" struc:"[0]pad"`
UserID uint32 UserID uint32
// Mode 战斗类型 1 = 1v1 2 = 6v6 // Mode 战斗类型 1 = 1v1 2 = 6v6
Mode info.EnumBattleMode Mode uint32
} }
type InviteFightCancelInboundInfo struct { type InviteFightCancelInboundInfo struct {
Head player.TomeeHeader `cmd:"2402" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2402" struc:"[0]pad"`
} }
// 2502的回复包 PVP邀请消息 // 2502的回复包 PVP邀请消息
@@ -90,30 +88,30 @@ type NoteHandleFightInviteOutboundInfo struct {
} }
type UseSkillInInfo struct { type UseSkillInInfo struct {
Head player.TomeeHeader `cmd:"2405" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2405" struc:"[0]pad"`
// 技能id // 技能id
SkillId uint32 SkillId uint32
} }
type ChangePetInboundInfo struct { type ChangePetInboundInfo struct {
Head player.TomeeHeader `cmd:"2407" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2407" struc:"[0]pad"`
// CatchTime 捕捉时间 // CatchTime 捕捉时间
CatchTime uint32 `json:"catchTime"` CatchTime uint32 `json:"catchTime"`
} }
type CatchMonsterInboundInfo struct { type CatchMonsterInboundInfo struct {
Head player.TomeeHeader `cmd:"2409" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2409" struc:"[0]pad"`
// CapsuleId 胶囊id // CapsuleId 胶囊id
CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"` CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"`
} }
type LoadPercentInboundInfo struct { type LoadPercentInboundInfo struct {
Head player.TomeeHeader `cmd:"2441" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2441" struc:"[0]pad"`
Percent uint32 `fieldDescription:"加载百分比"` Percent uint32 `fieldDescription:"加载百分比"`
} }
// UsePetItemInboundInfo 对应Java的UsePetItemInboundInfo实现InboundMessage接口 // UsePetItemInboundInfo 对应Java的UsePetItemInboundInfo实现InboundMessage接口
type UsePetItemInboundInfo struct { type UsePetItemInboundInfo struct {
Head player.TomeeHeader `cmd:"2406" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2406" struc:"[0]pad"`
// 字段首字母大写以导出对应Java的可访问性配合@Data的getter/setter // 字段首字母大写以导出对应Java的可访问性配合@Data的getter/setter
CatchTime uint32 `description:"精灵捕获时间" codec:"catchTime"` // @UInt long 对应Go的uint32无符号64位 CatchTime uint32 `description:"精灵捕获时间" codec:"catchTime"` // @UInt long 对应Go的uint32无符号64位
ItemId uint32 `description:"使用的物品ID" codec:"itemId"` // 结构体标签模拟@FieldDescription和@AutoCodec注解 ItemId uint32 `description:"使用的物品ID" codec:"itemId"` // 结构体标签模拟@FieldDescription和@AutoCodec注解

View File

@@ -332,12 +332,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
for _, v := range f.Switch { for _, v := range f.Switch {
if ff.Player.GetInfo().UserID != v.PlayerID { if ff.Player.GetInfo().UserID != v.PlayerID {
ff.Player.SendPackCmd(2407, v.Reason)
ff.Player.SendPackCmd(2407, &v.Reason)
} }
} }
ff.Player.SendPackCmd(2505, &ret)
ff.Player.SendPackCmd(2005, ret)
}) })
f.Switch = []*action.ActiveSwitchAction{} f.Switch = []*action.ActiveSwitchAction{}
} }

View File

@@ -23,14 +23,20 @@ import (
// } // }
// 战斗模式 // 战斗模式
type EnumBattleMode int
var BattleMode = enum.New[struct { var BattleMode = enum.New[struct {
PET_MELEE EnumBattleMode `enum:"3"` //乱斗模式 PET_MELEE uint32 `enum:"3"` //乱斗模式
SINGLE_MODE EnumBattleMode `enum:"1"` // 单人模式 SINGLE_MODE uint32 `enum:"1"` // 单人模式
MULTI_MODE EnumBattleMode `enum:"2"` // 多人模式 MULTI_MODE uint32 `enum:"2"` // 多人模式
}]()
var BattleStatus = enum.New[struct {
// 原ActionScript中的常量映射
FIGHT_WITH_NPC uint32 `enum:"3"` // 与NPC战斗
FIGHT_WITH_BOSS uint32 `enum:"2"` // 与BOSS战斗
FIGHT_WITH_PLAYER uint32 `enum:"1"` // 与玩家战斗PVP
Null uint32 `enum:"0"`
}]() }]()
// 玩家离线数据 // 玩家离线数据
type PlayerOfflineData struct { type PlayerOfflineData struct {
@@ -71,15 +77,11 @@ var BattleOverReason = enum.New[struct {
// 战斗模式 // 战斗模式
var BattleMode_PVP = enum.New[struct {
PVP_1V1 EnumBattleMode `enum:"1"`
PVP_6V6 EnumBattleMode `enum:"2"`
}]()
var Playerinvitemap map[uint32][]Playerinvite = make(map[uint32][]Playerinvite) //玩家邀请信息 ,比如一个玩家被多人邀请对战 var Playerinvitemap map[uint32][]Playerinvite = make(map[uint32][]Playerinvite) //玩家邀请信息 ,比如一个玩家被多人邀请对战
type Playerinvite struct { //挂载到[]Playerinvite上? 被邀请者->邀请者 type Playerinvite struct { //挂载到[]Playerinvite上? 被邀请者->邀请者
InviteID uint32 // 邀请者 InviteID uint32 // 邀请者
InviteTime EnumBattleMode //游戏模式 InviteTime uint32 //游戏模式
} }
// 能力操作类型枚举 // 能力操作类型枚举

View File

@@ -27,7 +27,7 @@ type NoteInviteToFightOutboundInfo struct {
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称 Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
// Mode 战斗模式 1 = 1v1 2 = 6v6 // Mode 战斗模式 1 = 1v1 2 = 6v6
Mode EnumBattleMode `codec:"true"` Mode uint32 `codec:"true"`
} }
type S2C_NOTE_HANDLE_FIGHT_INVITE struct { type S2C_NOTE_HANDLE_FIGHT_INVITE struct {
@@ -45,8 +45,9 @@ type S2C_NOTE_HANDLE_FIGHT_INVITE struct {
} }
type Fightinfo struct { type Fightinfo struct {
PlayerID uint32 PlayerID uint32
Mode EnumBattleMode // 战斗模式 1 = 1v1 2 = 6v6 3大乱斗
Type EnumBattleMode //战斗类型 Mode uint32
Type uint32 //战斗类型
//0无战斗1PVP2,BOOS,3PVE //0无战斗1PVP2,BOOS,3PVE
Status uint32 Status uint32
@@ -206,8 +207,8 @@ type NoteReadyToFightInfo struct {
//MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"` //MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
// 战斗类型ID与野怪战斗为3与人战斗为1前端似乎未使用 // 战斗类型ID与野怪战斗为3与人战斗为1前端似乎未使用
// @UInt long // @UInt long
Status EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3与人战斗似乎是1" ` Status uint32 `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3与人战斗似乎是1" `
Mode EnumBattleMode `struc:"skip"` //Mode uint32 `struc:"skip"`
// 我方信息 // 我方信息
OurInfo FightUserInfo `fieldDesc:"我方信息" serialize:"struct"` OurInfo FightUserInfo `fieldDesc:"我方信息" serialize:"struct"`
// Our *socket.Player `struc:"skip"` // Our *socket.Player `struc:"skip"`

View File

@@ -1,6 +1,7 @@
package fight package fight
import ( import (
"blazing/common/socket/errorcode"
"blazing/cool" "blazing/cool"
"blazing/logic/service/common" "blazing/logic/service/common"
@@ -94,7 +95,8 @@ func (f *FightC) IsFirst(play common.PlayerI) bool {
// 加载进度 // 加载进度
func (f *FightC) LoadPercent(c common.PlayerI, percent int32) { func (f *FightC) LoadPercent(c common.PlayerI, percent int32) {
f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, info.LoadPercentOutboundInfo{
f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, &info.LoadPercentOutboundInfo{
Id: c.GetInfo().UserID, Id: c.GetInfo().UserID,
Percent: uint32(percent), Percent: uint32(percent),
}) })
@@ -178,7 +180,7 @@ func initfightready(in *input.Input) (info.FightUserInfo, []info.ReadyFightPetIn
} }
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方 // 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, error) { func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, errorcode.ErrorCode) {
f := &FightC{} f := &FightC{}
f.ownerID = p1.GetInfo().UserID f.ownerID = p1.GetInfo().UserID
f.callback = fn //战斗结束的回调 f.callback = fn //战斗结束的回调
@@ -191,7 +193,7 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, err
//这里应该挪到玩家初始化执行 //这里应该挪到玩家初始化执行
f.ReadyInfo.Mode = f.Info.Mode f.ReadyInfo.Status = f.Info.Status
f.Our, f.Opp = f.initplayer(p1), f.initplayer(p2) f.Our, f.Opp = f.initplayer(p1), f.initplayer(p2)
@@ -205,12 +207,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, err
f.Opp.Finished = true //PVE 默认boss数据直接加载完成 f.Opp.Finished = true //PVE 默认boss数据直接加载完成
} }
f.Our.SetOPP(f.Opp) f.Broadcast(func(ff *input.Input) {
f.Opp.SetOPP(f.Our) ff.SetOPP(f.GetInputByPlayer(ff.Player, true))
})
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2503, f.ReadyInfo) ff.Player.SendPackCmd(2503, &f.ReadyInfo)
}) })
// 60秒后判断战斗是否开始 // 60秒后判断战斗是否开始
@@ -228,14 +232,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, err
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
//todo 将血量和技能pp传回enterturn //todo 将血量和技能pp传回enterturn
ff.Player.SendPackCmd(2506, f.FightOverInfo) ff.Player.SendPackCmd(2506, &f.FightOverInfo)
ff.Player.QuitFight() ff.Player.QuitFight()
}) })
} }
}) })
return f, nil return f, 0
} }
// 被击败的ID // 被击败的ID

View File

@@ -18,6 +18,7 @@ type Input struct {
AllPet []*info.BattlePetEntity AllPet []*info.BattlePetEntity
Player common.PlayerI Player common.PlayerI
Opp *Input Opp *Input
CanCapture bool
Finished bool //是否加载完成 Finished bool //是否加载完成
*info.AttackValue *info.AttackValue
FightC common.FightI FightC common.FightI

View File

@@ -64,7 +64,8 @@ func (f *FightC) battleLoop() {
} }
} }
ff.Player.SendPackCmd(2506, f.FightOverInfo) ff.Player.SendPackCmd(2506, &f.FightOverInfo)
ff.Player.QuitFight() ff.Player.QuitFight()
//待退出玩家战斗状态 //待退出玩家战斗状态
@@ -216,22 +217,25 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
} }
switch { switch {
case gconv.Int(item.Bonus) != 0: case gconv.Int(item.Bonus) != 0:
our, ok1 := f.Our.Player.(*player.Player)
opp, ok2 := f.Opp.Player.(*player.AI_player) if f.Opp.CanCapture { //可以捕捉
if ok1 && ok2 && opp.CanCapture {
ok, res := f.Our.Capture(f.Opp.CurrentPet, a.ItemID, -1) ok, res := f.Our.Capture(f.Opp.CurrentPet, a.ItemID, -1)
our := f.Our.Player.(*player.Player)
if ok { if ok {
fmt.Println(res) fmt.Println(res)
our.Service.Pet.PetAdd(f.Opp.CurrentPet.Info) our.Service.Pet.PetAdd(f.Opp.CurrentPet.Info)
our.CatchPetInfo(info.CatchMonsterOutboundInfo{
our.SendPack(common.NewTomeeHeader(2409, f.ownerID).Pack(info.CatchMonsterOutboundInfo{
CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime), CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime),
PetId: uint32(f.Opp.CurrentPet.ID), PetId: uint32(f.Opp.CurrentPet.ID),
}) }))
//f.WinnerId = 0 //捕捉成功不算胜利 //f.WinnerId = 0 //捕捉成功不算胜利
f.closefight = true f.closefight = true
} else { } else {
our.CatchPetInfo(info.CatchMonsterOutboundInfo{}) our.SendPack(common.NewTomeeHeader(2409, f.ownerID).Pack(info.CatchMonsterOutboundInfo{}))
} }
} }
case gconv.Int(item.HP) != 0: case gconv.Int(item.HP) != 0:
@@ -244,22 +248,24 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
f.GetInputByAction(a, false).Heal(f.GetInputByAction(a, false), a, decimal.NewFromInt(int64(addhp))) f.GetInputByAction(a, false).Heal(f.GetInputByAction(a, false), a, decimal.NewFromInt(int64(addhp)))
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{ ff.Player.SendPackCmd(2406, &info.UsePetIteminfo{
UserID: f.GetInputByAction(a, false).UserID, UserID: f.GetInputByAction(a, false).UserID,
ChangeHp: int32(addhp), ChangeHp: int32(addhp),
ItemID: uint32(item.ID), ItemID: uint32(item.ID),
UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp), UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp),
}) })
}) })
case gconv.Int(item.PP) != 0: case gconv.Int(item.PP) != 0:
f.GetInputByAction(a, false).HealPP(item.PP) f.GetInputByAction(a, false).HealPP(item.PP)
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{ ff.Player.SendPackCmd(2406, &info.UsePetIteminfo{
UserID: f.GetInputByAction(a, false).UserID, UserID: f.GetInputByAction(a, false).UserID,
ItemID: uint32(item.ID), ItemID: uint32(item.ID),
UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp), UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp),
}) })
}) })
default: default:

View File

@@ -1,10 +1,10 @@
package friend package friend
import "blazing/logic/service/player" import "blazing/logic/service/common"
//基地查看好友列表 //基地查看好友列表
type SeeOnlineInboundInfo struct { type SeeOnlineInboundInfo struct {
Head player.TomeeHeader `cmd:"2157" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2157" struc:"[0]pad"`
UserIdsLen uint32 `json:"userIdsLen" struc:"sizeof=UserIds"` UserIdsLen uint32 `json:"userIdsLen" struc:"sizeof=UserIds"`
UserIds []uint32 `json:"userIds" ` UserIds []uint32 `json:"userIds" `

View File

@@ -1,9 +1,9 @@
package item package item
import "blazing/logic/service/player" import "blazing/logic/service/common"
type BuyInboundInfo struct { type BuyInboundInfo struct {
Head player.TomeeHeader `cmd:"2601" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2601" struc:"[0]pad"`
//物品ID //物品ID
ItemId uint32 ItemId uint32
//物品数量 //物品数量
@@ -20,7 +20,7 @@ type BuyOutboundInfo struct {
Level uint32 Level uint32
} }
type BuyMultiInboundInfo struct { type BuyMultiInboundInfo struct {
Head player.TomeeHeader `cmd:"2606" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2606" struc:"[0]pad"`
ItemListLen uint32 `struc:"sizeof=ItemIds"` ItemListLen uint32 `struc:"sizeof=ItemIds"`
ItemIds []uint32 `json:"itemIds" description:"购买的物品ID列表"` // @UInt Long对应uint64List对应切片 ItemIds []uint32 `json:"itemIds" description:"购买的物品ID列表"` // @UInt Long对应uint64List对应切片
} }

View File

@@ -1,7 +1,7 @@
package item package item
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
@@ -11,7 +11,7 @@ type ChangePlayerClothOutboundInfo struct {
ClothList []model.PeopleItemInfo `description:"玩家装备列表" codec:"list"` // List<PeopleItemInfo> -> 指针切片 ClothList []model.PeopleItemInfo `description:"玩家装备列表" codec:"list"` // List<PeopleItemInfo> -> 指针切片
} }
type ChangePlayerClothInboundInfo struct { type ChangePlayerClothInboundInfo struct {
Head player.TomeeHeader `cmd:"2604" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2604" struc:"[0]pad"`
ClothesLen uint32 `struc:"sizeof=ClothList" fieldDesc:"穿戴装备的信息" json:"clothes_len"` ClothesLen uint32 `struc:"sizeof=ClothList" fieldDesc:"穿戴装备的信息" json:"clothes_len"`
ClothList []uint32 `description:"玩家装备列表" codec:"list"` ClothList []uint32 `description:"玩家装备列表" codec:"list"`
} }

View File

@@ -1,13 +1,13 @@
package item package item
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
// 实现了入站消息接口Go中通过方法集隐式实现 // 实现了入站消息接口Go中通过方法集隐式实现
type ItemListInboundInfo struct { type ItemListInboundInfo struct {
Head player.TomeeHeader `cmd:"2605" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2605" struc:"[0]pad"`
// 查询物品id的开始 // 查询物品id的开始
Param1 uint32 Param1 uint32
// 查询物品id的结尾 // 查询物品id的结尾
@@ -23,7 +23,7 @@ type ItemListOutboundInfo struct {
} }
type GoldOnlineRemainInboundInfo struct { type GoldOnlineRemainInboundInfo struct {
Head player.TomeeHeader `cmd:"1105|1106" struc:"[0]pad"` Head common.TomeeHeader `cmd:"1105|1106" struc:"[0]pad"`
} }
type GoldOnlineRemainOutboundInfo struct { type GoldOnlineRemainOutboundInfo struct {
@@ -35,7 +35,7 @@ type GoldOnlineRemainOutboundInfo struct {
// ExpTotalRemainInboundInfo 累计经验相关的入站信息 // ExpTotalRemainInboundInfo 累计经验相关的入站信息
type ExpTotalRemainInboundInfo struct { type ExpTotalRemainInboundInfo struct {
// Head 消息头部信息cmd保持原标识如需调整可根据实际需求修改 // Head 消息头部信息cmd保持原标识如需调整可根据实际需求修改
Head player.TomeeHeader `cmd:"2319" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2319" struc:"[0]pad"`
} }
// ExpTotalRemainOutboundInfo 累计经验相关的出站信息 // ExpTotalRemainOutboundInfo 累计经验相关的出站信息

View File

@@ -1,16 +1,16 @@
package item package item
import "blazing/logic/service/player" import "blazing/logic/service/common"
type TalkCountInboundInfo struct { type TalkCountInboundInfo struct {
Head player.TomeeHeader `cmd:"2701" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2701" struc:"[0]pad"`
ID uint32 `description:"奖品的Type, 即ID" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription ID uint32 `description:"奖品的Type, 即ID" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription
} }
type TalkCountOutboundInfo struct { type TalkCountOutboundInfo struct {
GiftCount uint32 `description:"已领取奖励的次数" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription GiftCount uint32 `description:"已领取奖励的次数" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription
} }
type TalkCateInboundInfo struct { type TalkCateInboundInfo struct {
Head player.TomeeHeader `cmd:"2702" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2702" struc:"[0]pad"`
ID uint32 `description:"奖品的Type, 即ID" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription ID uint32 `description:"奖品的Type, 即ID" codec:"uint"` // @UInt long -> uint64字段描述对应@FieldDescription
} }
type DayTalkInfo struct { type DayTalkInfo struct {

View File

@@ -1,12 +1,12 @@
package maphot package maphot
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/logic/service/space" "blazing/logic/service/space"
) )
type InInfo struct { type InInfo struct {
Head player.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录
} }
// OutInfo 表示地图热度的出站消息 // OutInfo 表示地图热度的出站消息

View File

@@ -1,17 +1,16 @@
package maps package maps
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type LeaveMapInboundInfo struct { type LeaveMapInboundInfo struct {
Head player.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图 Head common.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图
} }
type InInfo struct { type InInfo struct {
Head player.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图 Head common.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图
// 地图类型 // 地图类型
MapType uint32 MapType uint32

View File

@@ -1,9 +1,7 @@
package maps package maps
import ( import "blazing/logic/service/common"
"blazing/logic/service/player"
)
type ListMapPlayerInboundInfo struct { type ListMapPlayerInboundInfo struct {
Head player.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图 Head common.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图
} }

View File

@@ -1,13 +1,12 @@
package maps package maps
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type WalkInInfo struct { type WalkInInfo struct {
Head player.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包 Head common.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包
// Flag: 0为走1为飞行模式@UInt long // Flag: 0为走1为飞行模式@UInt long
Flag uint32 Flag uint32

View File

@@ -1,6 +1,6 @@
package nono package nono
import "blazing/logic/service/player" import "blazing/logic/service/common"
// NonoOutboundInfo 用于表示Nono相关的出站信息 // NonoOutboundInfo 用于表示Nono相关的出站信息
type NonoOutboundInfo struct { type NonoOutboundInfo struct {
@@ -54,13 +54,13 @@ type NonoOutboundInfo struct {
} }
type NonoInboundInfo struct { type NonoInboundInfo struct {
Head player.TomeeHeader `cmd:"9003" struc:"[0]pad"` Head common.TomeeHeader `cmd:"9003" struc:"[0]pad"`
// 米米号 // 米米号
UserID uint32 UserID uint32
} }
type NonoFollowOrHomeInInfo struct { type NonoFollowOrHomeInInfo struct {
Head player.TomeeHeader `cmd:"9019" struc:"[0]pad"` Head common.TomeeHeader `cmd:"9019" struc:"[0]pad"`
// Flag 1为跟随 0为收回 且如果为收回收回 那么后续结构不需要发送 // Flag 1为跟随 0为收回 且如果为收回收回 那么后续结构不需要发送
// 对应Java的@UInt long类型在Go中使用uint64 // 对应Java的@UInt long类型在Go中使用uint64
@@ -86,7 +86,7 @@ type NonoFollowOutInfo struct {
Power uint32 `fieldDescription:"能量值 前端显示除以1000后的值" uint:"true"` Power uint32 `fieldDescription:"能量值 前端显示除以1000后的值" uint:"true"`
} }
type SwitchFlyingInboundInfo struct { type SwitchFlyingInboundInfo struct {
Head player.TomeeHeader `cmd:"2112" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2112" struc:"[0]pad"`
Type uint32 `description:"开关, 0为取消飞行模式, 大于0为开启飞行模式" codec:"auto" uint:"true"` // 对应@FieldDescription、@UInt、@AutoCodec Type uint32 `description:"开关, 0为取消飞行模式, 大于0为开启飞行模式" codec:"auto" uint:"true"` // 对应@FieldDescription、@UInt、@AutoCodec
} }
type SwitchFlyingOutboundInfo struct { type SwitchFlyingOutboundInfo struct {
@@ -94,7 +94,7 @@ type SwitchFlyingOutboundInfo struct {
Type uint32 `description:"开关, 0为取消飞行模式, 大于0为开启飞行模式" codec:"auto" uint:"true"` // 对应@FieldDescription、@UInt、@AutoCodec Type uint32 `description:"开关, 0为取消飞行模式, 大于0为开启飞行模式" codec:"auto" uint:"true"` // 对应@FieldDescription、@UInt、@AutoCodec
} }
type PetCureInboundInfo struct { type PetCureInboundInfo struct {
Head player.TomeeHeader `cmd:"2306" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2306" struc:"[0]pad"`
} }
type PetCureOutboundEmpty struct { type PetCureOutboundEmpty struct {
} }

View File

@@ -1,10 +1,10 @@
package pet package pet
import "blazing/logic/service/player" import "blazing/logic/service/common"
// PetBargeListInboundInfo 对应Java的PetBargeListInboundInfo实现InboundMessage接口 // PetBargeListInboundInfo 对应Java的PetBargeListInboundInfo实现InboundMessage接口
type PetBargeListInboundInfo struct { type PetBargeListInboundInfo struct {
Head player.TomeeHeader `cmd:"2309" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2309" struc:"[0]pad"`
StartPetId uint32 `description:"开始精灵id" codec:"startPetId"` // @UInt long 对应Go的uint32无符号64位 StartPetId uint32 `description:"开始精灵id" codec:"startPetId"` // @UInt long 对应Go的uint32无符号64位
EndPetId uint32 `description:"结束精灵id" codec:"endPetId"` // 字段标签模拟注解功能(描述、编解码标识) EndPetId uint32 `description:"结束精灵id" codec:"endPetId"` // 字段标签模拟注解功能(描述、编解码标识)
} }

View File

@@ -1,10 +1,10 @@
package pet package pet
import "blazing/logic/service/player" import "blazing/logic/service/common"
// 实现InboundMessage接口用于处理宠物设置经验的入站消息 // 实现InboundMessage接口用于处理宠物设置经验的入站消息
type PetSetExpInboundInfo struct { type PetSetExpInboundInfo struct {
Head player.TomeeHeader `cmd:"2318" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2318" struc:"[0]pad"`
// CatchTime 精灵获取时间对应Java的@UInt long // CatchTime 精灵获取时间对应Java的@UInt long
CatchTime uint32 `fieldDescription:"精灵获取时间" uint:"true" autoCodec:"true"` CatchTime uint32 `fieldDescription:"精灵获取时间" uint:"true" autoCodec:"true"`

View File

@@ -1,9 +1,9 @@
package pet package pet
import "blazing/logic/service/player" import "blazing/logic/service/common"
type GetPetListInboundEmpty struct { type GetPetListInboundEmpty struct {
Head player.TomeeHeader `cmd:"2303" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2303" struc:"[0]pad"`
} }
type GetPetListOutboundInfo struct { type GetPetListOutboundInfo struct {
ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"` ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"`

View File

@@ -1,12 +1,12 @@
package pet package pet
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type InInfo struct { type InInfo struct {
Head player.TomeeHeader `cmd:"2301" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2301" struc:"[0]pad"`
CatchTime uint32 CatchTime uint32
} }
@@ -25,13 +25,13 @@ type PetReleaseOutboundInfo struct {
// 放入背包或者加入仓库 // 放入背包或者加入仓库
type PetReleaseInboundInfo struct { type PetReleaseInboundInfo struct {
Head player.TomeeHeader `cmd:"2304" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2304" struc:"[0]pad"`
CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"` CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"`
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库1为放入背包" autoCodec:"true" uint:"true"` Flag uint32 `json:"flag" fieldDescription:"0为放入仓库1为放入背包" autoCodec:"true" uint:"true"`
} }
type PetShowInboundInfo struct { type PetShowInboundInfo struct {
Head player.TomeeHeader `cmd:"2305" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2305" struc:"[0]pad"`
CatchTime uint32 `codec:"catchTime" inboundMessageType:"Pet_Show"` CatchTime uint32 `codec:"catchTime" inboundMessageType:"Pet_Show"`
Flag uint32 `codec:"flag"` Flag uint32 `codec:"flag"`
@@ -48,7 +48,7 @@ type PetShowOutboundInfo struct {
Reserved1 [3]uint32 Reserved1 [3]uint32
} }
type PetOneCureInboundInfo struct { type PetOneCureInboundInfo struct {
Head player.TomeeHeader `cmd:"2310" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2310" struc:"[0]pad"`
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"` CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"`
} // PetOneCureOutboundInfo 宠物单个治疗出站消息 } // PetOneCureOutboundInfo 宠物单个治疗出站消息
type PetOneCureOutboundInfo struct { type PetOneCureOutboundInfo struct {
@@ -58,7 +58,7 @@ type PetOneCureOutboundInfo struct {
// PetDefaultInboundInfo // PetDefaultInboundInfo
// 实现了InboundMessage接口 // 实现了InboundMessage接口
type PetDefaultInboundInfo struct { type PetDefaultInboundInfo struct {
Head player.TomeeHeader `cmd:"2308" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2308" struc:"[0]pad"`
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true" autoCodec:"true" inboundMessageType:"Pet_Default"` CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true" autoCodec:"true" inboundMessageType:"Pet_Default"`
} }

View File

@@ -1,10 +1,10 @@
package pet package pet
import "blazing/logic/service/player" import "blazing/logic/service/common"
// ChangeSkillInfo 技能变更信息 // ChangeSkillInfo 技能变更信息
type ChangeSkillInfo struct { type ChangeSkillInfo struct {
Head player.TomeeHeader `cmd:"2312" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2312" struc:"[0]pad"`
CatchTime uint32 `json:"catchTime"` // 精灵生成时间 CatchTime uint32 `json:"catchTime"` // 精灵生成时间
Reserved uint32 `json:"reserved"` // 填充字段默认为1 Reserved uint32 `json:"reserved"` // 填充字段默认为1
Reserved1 uint32 `json:"reserved1"` // 填充字段默认为1 Reserved1 uint32 `json:"reserved1"` // 填充字段默认为1

View File

@@ -1,6 +1,7 @@
package player package player
import ( import (
"blazing/logic/service/common"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
@@ -9,7 +10,6 @@ type AI_player struct {
baseplayer baseplayer
petinfo []model.PetInfo //精灵信息 petinfo []model.PetInfo //精灵信息
CanCapture bool
} }
func (p *AI_player) Getfightinfo() info.Fightinfo { func (p *AI_player) Getfightinfo() info.Fightinfo {
@@ -34,3 +34,9 @@ func (p *AI_player) GetPetInfo() []model.PetInfo {
func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) { func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) {
} }
func (f *AI_player) InvitePlayer(ff common.PlayerI) {
}
func (p *AI_player) QuitFight() {
}

View File

@@ -5,7 +5,6 @@ import (
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"math/rand" "math/rand"
"sync/atomic"
"time" "time"
) )
@@ -38,7 +37,6 @@ func (f *baseplayer) SetFightC(ff common.FightI) {
f.FightC = ff f.FightC = ff
} }
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext { func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
return f.PlayerCaptureContext return f.PlayerCaptureContext
} }

View File

@@ -1,30 +1,8 @@
package player package player
import ( import "blazing/logic/service/common"
"blazing/logic/service/fight/info"
maps "blazing/logic/service/maps/info"
)
func (p *Player) SendLeaveMapInfo(b maps.LeaveMapOutboundInfo) {
t1 := NewTomeeHeader(2002, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendEnterMapInfo(b maps.OutInfo) {
t1 := NewTomeeHeader(2001, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendPackCmd(cmd uint32, b any) { func (p *Player) SendPackCmd(cmd uint32, b any) {
p.SendPack(NewTomeeHeader(cmd, p.Info.UserID).Pack(&b)) p.SendPack(common.NewTomeeHeader(cmd, p.Info.UserID).Pack(b))
}
func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
t1 := NewTomeeHeader(2409, p.Info.UserID)
p.SendPack(t1.Pack(&b))
} }

View File

@@ -1,6 +1,7 @@
package player package player
import ( import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common" "blazing/logic/service/common"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"sync/atomic" "sync/atomic"
@@ -15,7 +16,7 @@ func (p *Player) InvitePlayerToBattle() {
v.InvitePlayer(p) v.InvitePlayer(p)
v.SendPackCmd(2501, info.NoteInviteToFightOutboundInfo{ v.SendPackCmd(2501, &info.NoteInviteToFightOutboundInfo{
UserID: p.Info.UserID, UserID: p.Info.UserID,
Nick: p.Info.Nick, Nick: p.Info.Nick,
Mode: p.Fightinfo.Mode, Mode: p.Fightinfo.Mode,
@@ -27,30 +28,30 @@ func (p *Player) InvitePlayerToBattle() {
}) })
} }
func (p *Player) Pet_joinFight(fn func(p common.PlayerI)) { func (p *Player) JoinFight(fn func(p common.PlayerI) bool) {
p.GetSpace().User.Range(func(key uint32, v common.PlayerI) bool { p.GetSpace().User.Range(func(key uint32, v common.PlayerI) bool {
if v != p { if v.GetInfo().UserID != p.Info.UserID {
//确认是乱斗模式 //确认是乱斗模式
if v.GetInfo() == p.GetInfo() { if v.Getfightinfo() == p.Getfightinfo() {
p.Fightinfo = nil //先将自身的准备信息置空
//value.PVPinfo = nil // p.Fightinfo = nil //先将自身的准备信息置空
lw = value // //value.PVPinfo = nil
return true // lw = value
return fn(v) //如果发起成功就停止,否则继续遍历队列
} }
} }
return false return false
}) })
return lw
} }
func (p *Player) SendLoadPercent(b info.LoadPercentOutboundInfo) { func (p *Player) SendLoadPercent(b info.LoadPercentOutboundInfo) {
t1 := NewTomeeHeader(2441, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样 p.SendPack(common.NewTomeeHeader(2441, p.Info.UserID).Pack(&b)) //准备包由各自发,因为协议不一样
} }
// 同意对战 // 同意对战
@@ -65,69 +66,36 @@ func (p *Player) SendLoadPercent(b info.LoadPercentOutboundInfo) {
// //
// bool是否成功仅同意且符合条件时为true // bool是否成功仅同意且符合条件时为true
// common.PlayerI对应的邀请者玩家成功时有效 // common.PlayerI对应的邀请者玩家成功时有效
func (lw *Player) AgreeBattle(userid, flag uint32, mode info.EnumBattleMode) (bool, common.PlayerI) { func (p *Player) AgreeBattle(userid, flag uint32, fn func(p common.PlayerI) bool) errorcode.ErrorCode {
// 处理完毕后清空收到的邀请列表原defer逻辑保留 // 处理完毕后清空收到的邀请列表原defer逻辑保留
defer func() { defer func() {
lw.HavePVPinfo = make([]common.PlayerI, 0) p.HavePVPinfo = make([]common.PlayerI, 0)
}() }()
// 遍历收到的邀请,寻找目标邀请者
var inviter *Player
for _, p := range lw.HavePVPinfo {
if p == nil || p.Getfightinfo().PlayerID != userid {
continue // 跳过空指针或非目标邀请者
}
inviter = p
break // 找到目标后退出循环
}
// 未找到对应的邀请者(如邀请已过期、不存在)
if inviter == nil {
return false, nil
}
// 构建响应消息(统一创建,避免重复代码)
respHeader := NewTomeeHeader(2502, inviter.Info.UserID)
resp := &info.S2C_NOTE_HANDLE_FIGHT_INVITE{ resp := &info.S2C_NOTE_HANDLE_FIGHT_INVITE{
UserID: lw.Info.UserID, UserID: p.Info.UserID,
Nick: lw.Info.Nick, Nick: p.Info.Nick,
} }
// 检查邀请者的邀请是否有效(对方已取消邀请) for _, o := range p.HavePVPinfo {
if inviter.Fightinfo == nil { if o != nil && o.Getfightinfo() == p.Fightinfo {
resp.Result = 4 // 邀请已取消 resp.Result = flag
inviter.SendPack(respHeader.Pack(resp)) // 检查邀请者的邀请是否有效(对方已取消邀请)
return false, nil if atomic.LoadUint32(&o.GetInfo().UserID) == 0 {
} resp.Result = 4 // 邀请已取消
// 检查战斗模式是否匹配 }
if inviter.Fightinfo.Mode != mode { //把不在线和不满足出战要求放到战斗检测里
return false, nil // 模式不匹配,不响应(或根据业务加错误码) //flasg本身就是00
} if fn(o) { //发起成功
return -1 //返回
} else { //发起失败
resp.Result = 3
o.SendPackCmd(2502, &resp)
return -1 //返回
}
// 处理拒绝逻辑 }
if flag == 0 {
resp.Result = 0 // 拒绝邀请
inviter.SendPack(respHeader.Pack(resp))
return false, nil
}
// 处理同意逻辑:检查自身状态
if !lw.IsLogin {
resp.Result = 4 // 玩家未登录(复用原错误码)
inviter.SendPack(respHeader.Pack(resp))
return false, nil
} }
return errorcode.ErrorCodes.ErrSystemError
// 检查双方是否可战斗
if !lw.CanFight() || !inviter.CanFight() {
resp.Result = 3 // 不可战斗(如正在战斗中)
inviter.SendPack(respHeader.Pack(resp))
return false, nil
}
// 所有条件满足,同意战斗
resp.Result = 1 // 成功同意
inviter.SendPack(respHeader.Pack(resp))
return true, inviter
} }

View File

@@ -2,8 +2,8 @@ package player
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/common/utils/bytearray"
"blazing/cool" "blazing/cool"
"blazing/logic/service/common"
"encoding/binary" "encoding/binary"
"sync" "sync"
@@ -22,87 +22,33 @@ import (
"github.com/panjf2000/gnet/v2/pkg/logging" "github.com/panjf2000/gnet/v2/pkg/logging"
) )
// TomeeHeader 结构体字段定义 // getUnderlyingValue 递归解析reflect.Value解包指针、interface{}到底层具体类型
type TomeeHeader struct { func getUnderlyingValue(val reflect.Value) (reflect.Value, error) {
Len uint32 `json:"len"` for {
Version byte `json:"version" struc:"[1]byte"` switch val.Kind() {
CMD uint32 `json:"cmdId" struc:"uint32"` // 解包指针:获取指针指向的值
UserID uint32 `json:"userId"` case reflect.Ptr:
//Error uint32 `json:"error" struc:"[0]pad"` if val.IsNil() {
return reflect.Value{}, nil
}
val = val.Elem()
Result uint32 `json:"result"` // 解包interface{}:获取接口包裹的动态值
Data []byte `json:"data" struc:"skip"` //组包忽略此字段// struc:"[0]pad" case reflect.Interface:
//Return []byte `struc:"[0]pad"` //返回记录 if val.IsNil() {
} return reflect.Value{}, nil
}
val = val.Elem()
func NewTomeeHeader(cmd uint32, userid uint32) *TomeeHeader { // 非指针/接口类型,终止递归
default:
return &TomeeHeader{ return val, nil
CMD: cmd,
// Len: 0,
Version: 49,
Result: 0,
}
}
// Pack 将给定的数据打包成一个字节切片。
// 该方法处理的数据类型包括指针、切片和结构体。
// 对于指针类型,会解引用以获取实际值。
// 切片类型直接转换为字节切片。
// 结构体类型使用struc库进行序列化。
// 最后将数据长度、版本号、命令码、用户ID和结果代码一并打包进返回的字节切片中。
func (h *TomeeHeader) Pack(data any) []byte { //组包
//h.Result = 0//默认置0
//t := reflect.TypeOf(data)
tv := reflect.ValueOf(data)
var datar []byte
// 处理指针类型
if tv.Kind() == reflect.Ptr {
//tv = t.Elem() // 获取指针指向的类型
tv = tv.Elem() // 获取指针指向的值
}
switch tv.Kind() {
case reflect.String:
datar = []byte(tv.String())
case reflect.Slice:
datar = data.([]byte)
//p.Conn.Write(p.pack(cmd, data.([]byte))) //写入数据
case reflect.Struct:
var data1 bytes.Buffer
err := struc.Pack(&data1, data)
if err != nil {
fmt.Println(err)
} }
datar = data1.Bytes()
default:
datar = []byte{}
// fmt.Println(err, datar)
// p.Conn.Write(p.pack(cmd, data))
} }
h.Len = uint32(len(datar) + 17)
by := bytearray.CreateByteArray(nil)
by.WriteUInt32(h.Len)
by.WriteByte(h.Version)
by.WriteUInt32(uint32(h.CMD))
by.WriteUInt32(h.UserID)
by.WriteUInt32(h.Result)
by.Write(datar)
return by.Bytes()
} }
// 遍历结构体方法并执行RECV_cmd // 遍历结构体方法并执行RECV_cmd
func (h *ClientData) Recv(data TomeeHeader) { func (h *ClientData) Recv(data common.TomeeHeader) {
cmdlister, ok := cool.CmdCache.Load(data.CMD) cmdlister, ok := cool.CmdCache.Load(data.CMD)
if !ok { if !ok {
@@ -237,7 +183,7 @@ func (h *ClientData) OnEvent(v []byte) {
} }
}() }()
var header TomeeHeader var header common.TomeeHeader
// 解析Len0-3字节 // 解析Len0-3字节
header.Len = binary.BigEndian.Uint32(v[0:4]) header.Len = binary.BigEndian.Uint32(v[0:4])
// 解析Version第4字节 // 解析Version第4字节

View File

@@ -3,6 +3,7 @@ package player
import ( import (
"blazing/common/data/xmlres" "blazing/common/data/xmlres"
"blazing/common/utils" "blazing/common/utils"
"blazing/logic/service/common"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
@@ -58,7 +59,7 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
} }
petinfo.SkillList = petinfo.SkillList[:4] //归正到4 petinfo.SkillList = petinfo.SkillList[:4] //归正到4
t1 := NewTomeeHeader(2508, p.Info.UserID) t1 := common.NewTomeeHeader(2508, p.Info.UserID)
rrr := &info.PetUpdateOutboundInfo{} rrr := &info.PetUpdateOutboundInfo{}
var petinfwo info.UpdatePropInfo var petinfwo info.UpdatePropInfo

View File

@@ -137,7 +137,7 @@ func (p *Player) SpawnMonsters() {
// 获取当前地图的怪物配置 // 获取当前地图的怪物配置
// 创建数据包 // 创建数据包
tt := NewTomeeHeader(2004, p.Info.UserID) tt := common.NewTomeeHeader(2004, p.Info.UserID)
p.genMonster(p.Info.MapID) //生成野怪 p.genMonster(p.Info.MapID) //生成野怪
@@ -277,7 +277,7 @@ func (p *Player) ItemAdd(t ...model.SingleItemInfo) (result []model.SingleItemIn
if !ok { if !ok {
cool.Loger.Error(context.TODO(), "物品不存在", v.ItemId) cool.Loger.Error(context.TODO(), "物品不存在", v.ItemId)
t1 := NewTomeeHeader(2601, p.Info.UserID) t1 := common.NewTomeeHeader(2601, p.Info.UserID)
t1.Result = uint32(errorcode.ErrorCodes.ErrBaseItemTypeLimit) t1.Result = uint32(errorcode.ErrorCodes.ErrBaseItemTypeLimit)
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样 p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
@@ -289,7 +289,7 @@ func (p *Player) ItemAdd(t ...model.SingleItemInfo) (result []model.SingleItemIn
if p.Service.Item.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) { if p.Service.Item.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) {
cool.Loger.Error(context.TODO(), "物品超过拥有最大限制", v.ItemId) cool.Loger.Error(context.TODO(), "物品超过拥有最大限制", v.ItemId)
t1 := NewTomeeHeader(2601, p.Info.UserID) t1 := common.NewTomeeHeader(2601, p.Info.UserID)
t1.Result = uint32(errorcode.ErrorCodes.ErrTooManyOfItem) t1.Result = uint32(errorcode.ErrorCodes.ErrTooManyOfItem)
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样 p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
@@ -307,7 +307,7 @@ func (player1 *Player) Kick() {
if player1.IsLogin { if player1.IsLogin {
//取成功,否则创建 //取成功,否则创建
//player1.Save() //先保存数据再返回 //player1.Save() //先保存数据再返回
head := NewTomeeHeader(1001, player1.Info.UserID) head := common.NewTomeeHeader(1001, player1.Info.UserID)
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere) head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
//实际上这里有个问题,会造成重复保存问题 //实际上这里有个问题,会造成重复保存问题

View File

@@ -1,6 +1,6 @@
package room package room
import "blazing/logic/service/player" import "blazing/logic/service/common"
// FitmentShowInfo 表示家具展示信息 // FitmentShowInfo 表示家具展示信息
type FitmentShowInfo struct { type FitmentShowInfo struct {
@@ -18,7 +18,7 @@ type FitmentShowInfo struct {
// FitmentUseringInboundInfo FitmentUseringInboundInfo类实现InboundMessage接口 // FitmentUseringInboundInfo FitmentUseringInboundInfo类实现InboundMessage接口
type FitmentUseringInboundInfo struct { type FitmentUseringInboundInfo struct {
Head player.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录
// 需要获取基地信息的目标玩家账号ID // 需要获取基地信息的目标玩家账号ID
TargetUserID uint32 `json:"targetUserId"` TargetUserID uint32 `json:"targetUserId"`
} }
@@ -45,12 +45,12 @@ type PetRoomListOutboundInfo struct {
} }
type PetRoomListInboundInfo struct { type PetRoomListInboundInfo struct {
Head player.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录
// 需要获取基地信息的目标玩家账号ID // 需要获取基地信息的目标玩家账号ID
TargetUserID uint32 `json:"targetUserId"` TargetUserID uint32 `json:"targetUserId"`
} }
type FitmentAllInboundEmpty struct { type FitmentAllInboundEmpty struct {
Head player.TomeeHeader `cmd:"10007" struc:"[0]pad"` Head common.TomeeHeader `cmd:"10007" struc:"[0]pad"`
} }
type FitmentAllOutboundInfo struct { type FitmentAllOutboundInfo struct {
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"` FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`

View File

@@ -1,68 +1,9 @@
package space package space
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/common"
"sync/atomic"
)
type ARENA struct { type ARENA struct {
Flag uint32 // 0=清除ArenaInfoflag为0时其他字段全为空 1=站上擂台的信息 2=挑战中的信息 Flag uint32 // 0=清除ArenaInfoflag为0时其他字段全为空 1=站上擂台的信息 2=挑战中的信息
Id uint32 UserID uint32
Nick string `struc:"[16]byte"` Nick string `struc:"[16]byte"`
HostWins uint32 // 应该是擂台人的连胜数 HostWins uint32 // 应该是擂台人的连胜数
ChallengerID uint32 // 挑战者的userid ChallengerID uint32 // 挑战者的userid
} }
func (s *Space) ARENA_join(tt func(c common.PlayerI) common.PlayerI) errorcode.ErrorCode {
//原子操作,修改擂台状态
if atomic.CompareAndSwapUint32(&s.ARENA.Flag, 1, 2) {
r := tt(s.ARENA_Player)
if r != nil {
atomic.SwapUint32(&s.ARENA.ChallengerID, r.GetInfo().UserID) //传回的指针赋值给ID
}
return 0
}
return errorcode.ErrorCodes.ErrChampionExists
}
// flag 0 取消 1为加入 2为替换挑战方
func (s *Space) UP_ARENA(c common.PlayerI, FLAG uint32) {
switch FLAG {
case 0:
if s.ARENA.Id != c.GetInfo().UserID { //说明不是自己退出
return
}
s.ARENA = info.S2C_ARENA_GET_INFO{}
s.ARENA_Player = nil
case 1:
if s.ARENA.Id != 0 { //说明已经有人了
return
}
s.ARENA.Flag = 1
s.ARENA.Id = c.GetInfo().UserID //添加用户ID
s.ARENA.Nick = c.GetInfo().Nick
s.ARENA_Player = c //添加用户
case 2: //胜利替换
if s.ARENA.Flag != 2 { //说明没进入挑战
return
}
if s.ARENA.Id != c.GetInfo().UserID && c.GetInfo().UserID != s.ARENA.ChallengerID { //说明已经有人了
return
}
if c.GetInfo().UserID == s.ARENA.Id {
s.ARENA.HostWins += 1 //连胜+1
}
s.ARENA.Flag = 1
s.ARENA.Id = c.GetInfo().UserID //添加用户ID
s.ARENA.Nick = c.GetInfo().Nick
s.ARENA_Player = c //添加用户
}
s.Broadcast(c, 2419, s.ARENA)
}

View File

@@ -37,8 +37,12 @@ func (s *Space) LeaveMap(c common.PlayerI) {
return return
} }
s.UP_ARENA(c, 0) //退出擂台 if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
s.ARENA_Player = nil
s.Broadcast(c, 2419, &s.Owner)
}
s.Broadcast(c, 2002, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID}) s.Broadcast(c, 2002, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
s.User.Delete(c.GetInfo().UserID) s.User.Delete(c.GetInfo().UserID)
@@ -54,11 +58,10 @@ func (s *Space) EnterMap(c common.PlayerI) {
out := info.NewOutInfo() out := info.NewOutInfo()
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true}) copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
s.Broadcast(c, 2001, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
s.User.Store(c.GetInfo().UserID, c) s.User.Store(c.GetInfo().UserID, c)
s.UserInfo.Store(c.GetInfo().UserID, *out) s.UserInfo.Store(c.GetInfo().UserID, *out)
s.Broadcast(c, 2001, out)
if s.SuperValue != nil { if s.SuperValue != nil {
atomic.AddInt32(s.SuperValue, 1) atomic.AddInt32(s.SuperValue, 1)
} }
@@ -77,7 +80,7 @@ func (s *Space) GetInfo() []maps.OutInfo {
var limiter = rate.NewLimiter(rate.Limit(10), 5) var limiter = rate.NewLimiter(rate.Limit(10), 5)
func (s *Space) Walk(c common.PlayerI, info info.WalkOutInfo) { func (s *Space) Walk(c common.PlayerI, info *info.WalkOutInfo) {
// cool.Limiter.Take() // cool.Limiter.Take()
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5) //r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
if !limiter.Allow() { if !limiter.Allow() {

View File

@@ -19,7 +19,7 @@ type Space struct {
SuperValue *int32 SuperValue *int32
//ID uint32 // 地图ID //ID uint32 // 地图ID
Name string //地图名称 Name string //地图名称
ARENA ARENA Owner ARENA
ARENA_Player common.PlayerI ARENA_Player common.PlayerI
} }

View File

@@ -1,13 +1,13 @@
package systemtime package systemtime
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"time" "time"
) )
// LoginSidInfo 登录携带的凭证结构体 // LoginSidInfo 登录携带的凭证结构体
type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head player.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录
} }

View File

@@ -1,11 +1,11 @@
package task package task
import "blazing/logic/service/player" import "blazing/logic/service/common"
// AcceptTaskInboundInfo // AcceptTaskInboundInfo
// 用于接收任务的入站信息 // 用于接收任务的入站信息
type AcceptTaskInboundInfo struct { type AcceptTaskInboundInfo struct {
Head player.TomeeHeader `cmd:"2201|2231" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2201|2231" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID
} }

View File

@@ -1,11 +1,11 @@
package task package task
import "blazing/logic/service/player" import "blazing/logic/service/common"
// AddTaskBufInboundInfo // AddTaskBufInboundInfo
// 用于接收添加任务缓冲区的入站信息 // 用于接收添加任务缓冲区的入站信息
type AddTaskBufInboundInfo struct { type AddTaskBufInboundInfo struct {
Head player.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID
TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息, TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息,
} }

View File

@@ -1,9 +1,9 @@
package task package task
import "blazing/logic/service/player" import "blazing/logic/service/common"
type CompleteTaskInboundInfo struct { type CompleteTaskInboundInfo struct {
Head player.TomeeHeader `cmd:"2202|2233" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2202|2233" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID
OutState uint32 `json:"outState" ` // 当前状态1表示完成任务 OutState uint32 `json:"outState" ` // 当前状态1表示完成任务
} }

View File

@@ -1,10 +1,10 @@
package task package task
import "blazing/logic/service/player" import "blazing/logic/service/common"
// DeleteTaskInboundInfo // DeleteTaskInboundInfo
type DeleteTaskInboundInfo struct { type DeleteTaskInboundInfo struct {
Head player.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64 TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64
} }
type DeleteTaskOutboundInfo struct { type DeleteTaskOutboundInfo struct {

View File

@@ -1,7 +1,7 @@
package task package task
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"encoding/binary" "encoding/binary"
"errors" "errors"
@@ -9,7 +9,7 @@ import (
) )
type GetTaskBufInboundInfo struct { type GetTaskBufInboundInfo struct {
Head player.TomeeHeader `cmd:"2203|2234" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2203|2234" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID
} }

View File

@@ -1,9 +1,9 @@
package user package user
import "blazing/logic/service/player" import "blazing/logic/service/common"
type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head player.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录
// 玩家昵称,@ArraySerialize注解 // 玩家昵称,@ArraySerialize注解
Nickname string `struc:"[16]byte"` // 固定长度16字节 Nickname string `struc:"[16]byte"` // 固定长度16字节
@@ -17,7 +17,7 @@ type CreatePlayerOutInfo struct {
} }
type ChangePlayerNameInboundInfo struct { type ChangePlayerNameInboundInfo struct {
Head player.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录
// 玩家昵称 // 玩家昵称
Nickname string `struc:"[16]byte"` // 固定长度16字节 Nickname string `struc:"[16]byte"` // 固定长度16字节

View File

@@ -1,13 +1,11 @@
package user package user
import ( import "blazing/logic/service/common"
"blazing/logic/service/player"
)
//var _ entity.Blazingservice = (*SidInfo)(nil) //var _ entity.Blazingservice = (*SidInfo)(nil)
type SidInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type SidInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head player.TomeeHeader `cmd:"105" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"105" struc:"[0]pad"` //玩家登录
Sid []byte `struc:"[20]byte"` // 登录会话ID固定长度16字节 Sid []byte `struc:"[20]byte"` // 登录会话ID固定长度16字节
// ret []byte `struc:"[0]pad"` // ret []byte `struc:"[0]pad"`

View File

@@ -1,12 +1,12 @@
package user package user
import ( import (
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type SimUserInfoInboundInfo struct { type SimUserInfoInboundInfo struct {
Head player.TomeeHeader `cmd:"2051" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2051" struc:"[0]pad"`
UserId uint32 `fieldDescription:"米米号" uint:"true" codec:"true"` UserId uint32 `fieldDescription:"米米号" uint:"true" codec:"true"`
} }
type SimUserInfoOutboundInfo struct { type SimUserInfoOutboundInfo struct {
@@ -71,7 +71,7 @@ type SimUserInfoOutboundInfo struct {
Clothes []model.PeopleItemInfo `codec:"true"` Clothes []model.PeopleItemInfo `codec:"true"`
} }
type MoreUserInfoInboundInfo struct { type MoreUserInfoInboundInfo struct {
Head player.TomeeHeader `cmd:"2052" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2052" struc:"[0]pad"`
UserId uint32 `fieldDescription:"米米号" uint:"true" codec:"true"` UserId uint32 `fieldDescription:"米米号" uint:"true" codec:"true"`
} }
type MoreUserInfoOutboundInfo struct { type MoreUserInfoOutboundInfo struct {
@@ -121,7 +121,7 @@ type MoreUserInfoOutboundInfo struct {
// AimatInboundInfo 对应Java的AimatInboundInfo类 // AimatInboundInfo 对应Java的AimatInboundInfo类
type AimatInboundInfo struct { type AimatInboundInfo struct {
Head player.TomeeHeader `cmd:"2104" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2104" struc:"[0]pad"`
ItemId uint32 `description:"物品id 射击激光 物品id为0" codec:"auto" uint:"true"` ItemId uint32 `description:"物品id 射击激光 物品id为0" codec:"auto" uint:"true"`
ShootType uint32 `description:"射击类型 未知 给0" codec:"auto" uint:"true"` ShootType uint32 `description:"射击类型 未知 给0" codec:"auto" uint:"true"`
Point model.Pos `description:"射击的坐标 x y" codec:"auto"` // 默认值对应@Builder.Default Point model.Pos `description:"射击的坐标 x y" codec:"auto"` // 默认值对应@Builder.Default

View File

@@ -2,7 +2,7 @@ package user
import ( import (
"blazing/common/data/share" "blazing/common/data/share"
"blazing/logic/service/player" "blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"context" "context"
@@ -13,7 +13,7 @@ import (
// LoginSidInfo 登录携带的凭证结构体 // LoginSidInfo 登录携带的凭证结构体
type MAIN_LOGIN_IN struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type MAIN_LOGIN_IN struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head player.TomeeHeader `cmd:"1001" struc:"[0]pad"` //玩家登录 Head common.TomeeHeader `cmd:"1001" struc:"[0]pad"` //玩家登录
Sid []byte `struc:"[16]byte"` // 登录会话ID固定长度16字节 Sid []byte `struc:"[16]byte"` // 登录会话ID固定长度16字节

View File

@@ -1,9 +1,9 @@
package user package user
import "blazing/logic/service/player" import "blazing/logic/service/common"
type ChatInboundInfo struct { type ChatInboundInfo struct {
Head player.TomeeHeader `cmd:"2102" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2102" struc:"[0]pad"`
Reserve uint32 `json:"reserve" fieldDescription:"填充 默认值为0" uint:"true"` // @UInt long reserve无符号长整数 Reserve uint32 `json:"reserve" fieldDescription:"填充 默认值为0" uint:"true"` // @UInt long reserve无符号长整数
MessageLen uint32 `struc:"sizeof=Message"` MessageLen uint32 `struc:"sizeof=Message"`
Message string `json:"message" fieldDescription:"消息内容, 结束符为utf-8的数字0"` // 消息内容包含utf-8空字符('\x00')作为结束符 Message string `json:"message" fieldDescription:"消息内容, 结束符为utf-8的数字0"` // 消息内容包含utf-8空字符('\x00')作为结束符
@@ -16,7 +16,7 @@ type ChatOutboundInfo struct {
Message string `description:"这里的内容没有结束符" codec:"string"` // String -> string Message string `description:"这里的内容没有结束符" codec:"string"` // String -> string
} }
type ChangeColorInboundInfo struct { type ChangeColorInboundInfo struct {
Head player.TomeeHeader `cmd:"2063" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2063" struc:"[0]pad"`
Color uint32 `codec:"color"` // 更改的颜色 rgb (对应Java的@UInt long) Color uint32 `codec:"color"` // 更改的颜色 rgb (对应Java的@UInt long)
} }
@@ -27,7 +27,7 @@ type ChangeColorOutboundInfo struct {
Coins uint32 `codec:"coins"` // 扣除200豆子后返回的剩余豆子 (对应Java的@UInt long) Coins uint32 `codec:"coins"` // 扣除200豆子后返回的剩余豆子 (对应Java的@UInt long)
} }
type ChangeDoodleInboundInfo struct { type ChangeDoodleInboundInfo struct {
Head player.TomeeHeader `cmd:"2062" struc:"[0]pad"` Head common.TomeeHeader `cmd:"2062" struc:"[0]pad"`
Id uint32 `codec:"id"` // 涂鸦ID (对应Java的@UInt long) Id uint32 `codec:"id"` // 涂鸦ID (对应Java的@UInt long)
Color uint32 `codec:"color"` // 前端发来的更改的颜色rgb值 (对应Java的@UInt long) Color uint32 `codec:"color"` // 前端发来的更改的颜色rgb值 (对应Java的@UInt long)
} }
@@ -39,7 +39,7 @@ type ChangeDoodleOutboundInfo struct {
Coins uint32 `codec:"coins"` // 扣除对应豆子后返回的剩余豆子 (对应Java的@UInt long) Coins uint32 `codec:"coins"` // 扣除对应豆子后返回的剩余豆子 (对应Java的@UInt long)
} }
type ChangeNONOColorInboundInfo struct { type ChangeNONOColorInboundInfo struct {
Head player.TomeeHeader `cmd:"9012" struc:"[0]pad"` Head common.TomeeHeader `cmd:"9012" struc:"[0]pad"`
Color uint32 `codec:"color"` // 更改的颜色 rgb (对应Java的@UInt long) Color uint32 `codec:"color"` // 更改的颜色 rgb (对应Java的@UInt long)
} }

View File

@@ -2,7 +2,7 @@ package model
// TeamInfo 战队信息结构 // TeamInfo 战队信息结构
type TeamInfo struct { type TeamInfo struct {
//Head player.TomeeHeader `cmd:"1001" struc:"[0]pad"` // 命令头 //Head common.TomeeHeader `cmd:"1001" struc:"[0]pad"` // 命令头
ID uint32 `struc:"uint32" default:"0"` // 默认值0 ID uint32 `struc:"uint32" default:"0"` // 默认值0
Priv uint32 `struc:"uint32" default:"1"` // 默认值1 Priv uint32 `struc:"uint32" default:"1"` // 默认值1
SuperCore uint32 `struc:"uint32" default:"1"` // 默认值1 SuperCore uint32 `struc:"uint32" default:"1"` // 默认值1