```
refactor(common): 统一使用 common.TomeeHeader 替代 player.TomeeHeader 将多处
This commit is contained in:
@@ -58,7 +58,7 @@ func GetServerInfoList() []ServerInfo {
|
||||
|
||||
// CommendSvrInfo 初始连接请求信息结构体
|
||||
type CommendSvrInfo struct {
|
||||
//Handler player.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo
|
||||
//Handler common.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo
|
||||
MaxOnlineID uint32 `struc:"sizeof=ServerList"` // 最大连接数
|
||||
IsVip uint32 // 建议为0
|
||||
ServerInfoLen uint32 `struc:"sizeof=ServerList"` // 服务器信息长度 ServerInfo
|
||||
|
||||
@@ -493,7 +493,7 @@ var ErrorCodes = enum.New[struct {
|
||||
ErrBatteryLowForDefense ErrorCode `enum:"18030"`
|
||||
// 正在精灵对战中
|
||||
// 你们战队还没有报名参加对抗赛
|
||||
ErrInBattle ErrorCode `enum:"11024"`
|
||||
ErrInBattle ErrorCode `enum:"11024"`
|
||||
ErrTeamNotRegistered ErrorCode `enum:"18221"`
|
||||
// 你的战队的其他成员已经报名参加保卫战,请耐心等待比赛集合令提示。
|
||||
ErrTeammateRegistered ErrorCode `enum:"18222"`
|
||||
@@ -606,6 +606,4 @@ var ErrorCodes = enum.New[struct {
|
||||
ErrCannotInjectPillAgain ErrorCode `enum:"10504"`
|
||||
// 不能注入过多能量珠
|
||||
ErrTooManyEnergyOrbs ErrorCode `enum:"10505"`
|
||||
// 登录服务器错误,请尝试登录上次登录的服务器进入游戏
|
||||
ErrLoginServerError ErrorCode `enum:"500103"`
|
||||
}]()
|
||||
|
||||
@@ -2,8 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
|
||||
"blazing/logic/service/player"
|
||||
"strings"
|
||||
|
||||
"bytes"
|
||||
@@ -102,7 +102,7 @@ func getcmd(t reflect.Type) []uint32 {
|
||||
field := t.Field(i)
|
||||
//fmt.Printf("- 字段名: %s\n", field.Name)
|
||||
//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))
|
||||
|
||||
return gconv.SliceUint32(strings.Split(field.Tag.Get("cmd"), "|"))
|
||||
|
||||
@@ -46,9 +46,6 @@ func processMonID(bm string) string {
|
||||
|
||||
// 挑战地图boss
|
||||
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
|
||||
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,
|
||||
Mode: info.BattleMode.MULTI_MODE,
|
||||
}
|
||||
c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_BOSS
|
||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||
|
||||
ai := player.NewAI_player(moinfo)
|
||||
//给予打过一次的奖励
|
||||
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) {
|
||||
if !c.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
||||
}
|
||||
|
||||
refpet := c.OgreInfo.Data[data.Number]
|
||||
if refpet.Id == 0 {
|
||||
|
||||
@@ -134,10 +128,9 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
||||
moinfo.PetList = append(moinfo.PetList, *mo)
|
||||
ai := player.NewAI_player(moinfo)
|
||||
c.Fightinfo = &info.Fightinfo{
|
||||
Mode: info.BattleMode.MULTI_MODE,
|
||||
Status: info.BattleStatus.FIGHT_WITH_NPC,
|
||||
}
|
||||
|
||||
c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_NPC
|
||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||
|
||||
fight.NewFight(c, ai, func(foi *info.FightOverInfo) {
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"sync/atomic"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/player"
|
||||
@@ -15,12 +15,19 @@ import (
|
||||
// 前端到后端无数据内容 空包
|
||||
// 后端到前端无数据内容 空包
|
||||
// 都需要通过2419包广播更新擂台状态
|
||||
func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !c.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
||||
func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
||||
|
||||
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;
|
||||
@@ -29,27 +36,32 @@ func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Playe
|
||||
// 后端到前端无数据内容 空包
|
||||
// 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗
|
||||
// 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战
|
||||
func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
if !c.CanFight() {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
||||
}
|
||||
func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
||||
s := c.GetSpace()
|
||||
|
||||
space.GetSpace(c.Info.MapID).ARENA_join(func(ownerID common.PlayerI) common.PlayerI {
|
||||
c.Fightinfo = &info.Fightinfo{
|
||||
Mode: info.BattleMode.SINGLE_MODE,
|
||||
Status: info.BattleStatus.FIGHT_WITH_PLAYER,
|
||||
}
|
||||
_, fighterr := fight.NewFight(c, ownerID, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||
//原子操作,修改擂台状态
|
||||
if atomic.CompareAndSwapUint32(&s.Owner.Flag, 1, 2) {
|
||||
//成功发起擂台挑战后才修改我放状态
|
||||
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
||||
c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_PLAYER
|
||||
|
||||
_, err = fight.NewFight(c, s.ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
if fighterr != nil {
|
||||
return nil
|
||||
}
|
||||
return c
|
||||
})
|
||||
if err <= 0 { //发起战斗成功
|
||||
atomic.StoreUint32(&s.Owner.ChallengerID, c.GetInfo().UserID) //传回的指针赋值给ID
|
||||
|
||||
} 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) {
|
||||
|
||||
result = &space.GetSpace(c.Info.MapID).ARENA
|
||||
return
|
||||
return &space.GetSpace(c.Info.MapID).Owner, 0
|
||||
}
|
||||
|
||||
// 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包广播更新擂台状态
|
||||
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||
space.GetSpace(c.Info.MapID).UP_ARENA(c, 0)
|
||||
//result = &info.S2C_ARENA_GET_INFO{}
|
||||
return
|
||||
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
||||
//原子操作,修改擂台状态
|
||||
s := c.GetSpace()
|
||||
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;
|
||||
@@ -78,8 +96,25 @@ func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (
|
||||
// 后端到前端无数据内容
|
||||
// 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) {
|
||||
space.GetSpace(c.Info.MapID).UP_ARENA(c, 2)
|
||||
//result = &info.S2C_ARENA_GET_INFO{}
|
||||
return
|
||||
func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
||||
|
||||
s := c.GetSpace()
|
||||
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
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/fight/info"
|
||||
"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) {
|
||||
if !c.CanFight(1) {
|
||||
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
||||
}
|
||||
|
||||
c.Fightinfo.Mode = info.BattleMode.PET_MELEE
|
||||
c.Fightinfo.PlayerID = 0
|
||||
g := c.Pet_joinFight()
|
||||
if g != nil {
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
c.JoinFight(func(p common.PlayerI) bool {
|
||||
fight.NewFight(p, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
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{
|
||||
|
||||
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
|
||||
c.Fightinfo.Status = info.BattleStatus.FIGHT_WITH_PLAYER
|
||||
|
||||
switch data.Type {
|
||||
case 5:
|
||||
@@ -42,21 +35,13 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
|
||||
case 6:
|
||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||
}
|
||||
g := c.Pet_joinFight()
|
||||
if g != nil {
|
||||
switch data.Type {
|
||||
case 5:
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
c.JoinFight(func(p common.PlayerI) bool {
|
||||
fight.NewFight(p, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
|
||||
case 6:
|
||||
fight.NewFight(g, c, func(foi *info.FightOverInfo) {
|
||||
|
||||
}) ///开始对战,房主方以及被邀请方
|
||||
}
|
||||
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"sync/atomic"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/fight/info"
|
||||
"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) {
|
||||
|
||||
|
||||
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Status, 0, 1) { //邀请前提是自己没在战斗
|
||||
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 nil, -1
|
||||
})
|
||||
return err <= 0
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 邀请其他人进行战斗
|
||||
|
||||
@@ -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应该是空的
|
||||
tt := data.CheakSession()
|
||||
if !tt {
|
||||
err = errorcode.ErrorCodes.ErrLoginServerError
|
||||
|
||||
defer c.Close()
|
||||
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)
|
||||
if t == nil {
|
||||
cool.Loger.Error(context.Background(), "获取玩家失败", data.Head.UserID)
|
||||
err = errorcode.ErrorCodes.ErrLoginServerError
|
||||
|
||||
defer c.Close()
|
||||
return
|
||||
}
|
||||
t.Service = blservice.NewUserService(data.Head.UserID)
|
||||
t.Info = t.Service.Info.Person(data.Head.UserID)
|
||||
if t.Info == nil {
|
||||
err = errorcode.ErrorCodes.ErrLoginServerError
|
||||
defer c.Close()
|
||||
return
|
||||
}
|
||||
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.PlayerInfo = *t.Info
|
||||
space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
|
||||
return result, 0
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
)
|
||||
|
||||
func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.WalkOutInfo, err errorcode.ErrorCode) {
|
||||
|
||||
c.GetSpace().Walk(c, info.WalkOutInfo{
|
||||
result = &info.WalkOutInfo{
|
||||
Flag: data.Flag,
|
||||
Point: data.Point,
|
||||
Path: data.Path,
|
||||
UserID: c.Info.UserID,
|
||||
})
|
||||
}
|
||||
c.GetSpace().Walk(c, result)
|
||||
|
||||
c.Info.Pos = data.Point
|
||||
return
|
||||
|
||||
114
logic/service/common/pack.go
Normal file
114
logic/service/common/pack.go
Normal 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
|
||||
}
|
||||
@@ -15,5 +15,6 @@ type PlayerI interface {
|
||||
InvitePlayer(PlayerI)
|
||||
SetFightC(FightI)
|
||||
QuitFight()
|
||||
SendPackCmd(cmd uint32, b any)
|
||||
|
||||
SendPackCmd(uint32, any)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"blazing/logic/service/fight/action"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/player"
|
||||
"context"
|
||||
"log"
|
||||
|
||||
@@ -87,7 +86,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||||
|
||||
f.Broadcast(func(ff *input.Input) { //先给自身广播
|
||||
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 {
|
||||
startInfo.Info2.Catchable = 1 // 标记为可捕捉
|
||||
// 标记AI对手允许被捕捉(类型断言确保安全)
|
||||
if oppAI, ok := f.Opp.Player.(*player.AI_player); ok {
|
||||
oppAI.CanCapture = true
|
||||
}
|
||||
f.Opp.CanCapture = true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +218,7 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
|
||||
|
||||
// 通知双方玩家准备完成,即将开始战斗
|
||||
|
||||
ff.Player.SendPackCmd(2504, startInfo)
|
||||
ff.Player.SendPackCmd(2504, &startInfo)
|
||||
})
|
||||
|
||||
// 标记战斗已启动(原注释逻辑)
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
_ "blazing/logic/service/fight/effect"
|
||||
"blazing/logic/service/fight/info"
|
||||
|
||||
"blazing/logic/service/player"
|
||||
)
|
||||
|
||||
// 野怪对战包
|
||||
type FightNpcMonsterInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2408" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2408" struc:"[0]pad"`
|
||||
// Number 地图刷新怪物结构体对应的序号(1-9的位置序号)
|
||||
|
||||
Number uint32 `fieldDesc:"地图刷新怪物结构体对应的序号 1 - 9 的位置序号" `
|
||||
}
|
||||
type ChallengeBossInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2411" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2411" struc:"[0]pad"`
|
||||
BossId uint32 `json:"bossId"`
|
||||
}
|
||||
type NullOutboundInfo struct {
|
||||
@@ -23,40 +21,40 @@ type NullOutboundInfo struct {
|
||||
|
||||
// 准备战斗包
|
||||
type ReadyToFightInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2404" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2404" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
// 战斗逃跑
|
||||
type EscapeFightInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2410" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2410" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
// 精灵王
|
||||
type StartPetWarInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2431" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2431" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
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 {
|
||||
Head player.TomeeHeader `cmd:"2418" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2418" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
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 {
|
||||
Head player.TomeeHeader `cmd:"2420" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2420" struc:"[0]pad"`
|
||||
}
|
||||
type ARENA_OWENR_ACCE struct {
|
||||
Head player.TomeeHeader `cmd:"2422" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2422" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
// 表示"宠物王加入"的入站消息数据
|
||||
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)
|
||||
FightType uint32 // 仅当Type为11时有效 (对应Java的@UInt long fightType)
|
||||
}
|
||||
@@ -64,22 +62,22 @@ type PetKingJoinInboundInfo struct {
|
||||
// HandleFightInviteInboundInfo 处理战斗邀请的入站消息
|
||||
|
||||
type HandleFightInviteInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2403" struc:"[0]pad"`
|
||||
UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid
|
||||
Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战
|
||||
Mode info.EnumBattleMode `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
|
||||
Head common.TomeeHeader `cmd:"2403" struc:"[0]pad"`
|
||||
UserID uint32 `json:"userId" codec:"userId,uint"` // 邀请我对战人的userid
|
||||
Flag uint32 `json:"flag" codec:"flag,uint"` // 1为同意对战 0为取消对战
|
||||
Mode uint32 `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
|
||||
}
|
||||
|
||||
type InviteToFightInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2401" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2401" struc:"[0]pad"`
|
||||
|
||||
UserID uint32
|
||||
|
||||
// Mode 战斗类型 1 = 1v1 2 = 6v6
|
||||
Mode info.EnumBattleMode
|
||||
Mode uint32
|
||||
}
|
||||
type InviteFightCancelInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2402" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2402" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
// 2502的回复包 PVP邀请消息
|
||||
@@ -90,30 +88,30 @@ type NoteHandleFightInviteOutboundInfo struct {
|
||||
}
|
||||
|
||||
type UseSkillInInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2405" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2405" struc:"[0]pad"`
|
||||
// 技能id,
|
||||
SkillId uint32
|
||||
}
|
||||
type ChangePetInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2407" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2407" struc:"[0]pad"`
|
||||
// CatchTime 捕捉时间
|
||||
CatchTime uint32 `json:"catchTime"`
|
||||
}
|
||||
type CatchMonsterInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2409" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2409" struc:"[0]pad"`
|
||||
// CapsuleId 胶囊id
|
||||
|
||||
CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"`
|
||||
}
|
||||
|
||||
type LoadPercentInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2441" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2441" struc:"[0]pad"`
|
||||
Percent uint32 `fieldDescription:"加载百分比"`
|
||||
}
|
||||
|
||||
// UsePetItemInboundInfo 对应Java的UsePetItemInboundInfo,实现InboundMessage接口
|
||||
type UsePetItemInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2406" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2406" struc:"[0]pad"`
|
||||
// 字段首字母大写以导出(对应Java的可访问性,配合@Data的getter/setter)
|
||||
CatchTime uint32 `description:"精灵捕获时间" codec:"catchTime"` // @UInt long 对应Go的uint32(无符号64位)
|
||||
ItemId uint32 `description:"使用的物品ID" codec:"itemId"` // 结构体标签模拟@FieldDescription和@AutoCodec注解
|
||||
|
||||
@@ -332,12 +332,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
for _, v := range f.Switch {
|
||||
|
||||
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{}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,20 @@ import (
|
||||
// }
|
||||
|
||||
// 战斗模式
|
||||
type EnumBattleMode int
|
||||
|
||||
var BattleMode = enum.New[struct {
|
||||
PET_MELEE EnumBattleMode `enum:"3"` //乱斗模式
|
||||
SINGLE_MODE EnumBattleMode `enum:"1"` // 单人模式
|
||||
MULTI_MODE EnumBattleMode `enum:"2"` // 多人模式
|
||||
PET_MELEE uint32 `enum:"3"` //乱斗模式
|
||||
SINGLE_MODE uint32 `enum:"1"` // 单人模式
|
||||
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 {
|
||||
@@ -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) //玩家邀请信息 ,比如一个玩家被多人邀请对战
|
||||
|
||||
type Playerinvite struct { //挂载到[]Playerinvite上? 被邀请者->邀请者
|
||||
InviteID uint32 // 邀请者
|
||||
InviteTime EnumBattleMode //游戏模式
|
||||
InviteID uint32 // 邀请者
|
||||
InviteTime uint32 //游戏模式
|
||||
}
|
||||
|
||||
// 能力操作类型枚举
|
||||
|
||||
@@ -27,7 +27,7 @@ type NoteInviteToFightOutboundInfo struct {
|
||||
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
|
||||
// Mode 战斗模式 1 = 1v1 2 = 6v6
|
||||
|
||||
Mode EnumBattleMode `codec:"true"`
|
||||
Mode uint32 `codec:"true"`
|
||||
}
|
||||
|
||||
type S2C_NOTE_HANDLE_FIGHT_INVITE struct {
|
||||
@@ -45,8 +45,9 @@ type S2C_NOTE_HANDLE_FIGHT_INVITE struct {
|
||||
}
|
||||
type Fightinfo struct {
|
||||
PlayerID uint32
|
||||
Mode EnumBattleMode
|
||||
Type EnumBattleMode //战斗类型
|
||||
// 战斗模式 1 = 1v1 2 = 6v6 3大乱斗
|
||||
Mode uint32
|
||||
Type uint32 //战斗类型
|
||||
|
||||
//0无战斗,1PVP,2,BOOS,3PVE
|
||||
Status uint32
|
||||
@@ -206,8 +207,8 @@ type NoteReadyToFightInfo struct {
|
||||
//MAXPET uint32 `struc:"skip"` // 最大精灵数 struc:"skip"`
|
||||
// 战斗类型ID(与野怪战斗为3,与人战斗为1,前端似乎未使用)
|
||||
// @UInt long
|
||||
Status EnumBattleMode `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||||
Mode EnumBattleMode `struc:"skip"`
|
||||
Status uint32 `fieldDesc:"战斗类型ID 但前端好像没有用到 与野怪战斗为3,与人战斗似乎是1" `
|
||||
//Mode uint32 `struc:"skip"`
|
||||
// 我方信息
|
||||
OurInfo FightUserInfo `fieldDesc:"我方信息" serialize:"struct"`
|
||||
// Our *socket.Player `struc:"skip"`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fight
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
|
||||
"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) {
|
||||
f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, info.LoadPercentOutboundInfo{
|
||||
|
||||
f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, &info.LoadPercentOutboundInfo{
|
||||
Id: c.GetInfo().UserID,
|
||||
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.ownerID = p1.GetInfo().UserID
|
||||
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)
|
||||
|
||||
@@ -205,12 +207,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, err
|
||||
f.Opp.Finished = true //PVE 默认boss数据直接加载完成
|
||||
}
|
||||
|
||||
f.Our.SetOPP(f.Opp)
|
||||
f.Opp.SetOPP(f.Our)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
ff.SetOPP(f.GetInputByPlayer(ff.Player, true))
|
||||
|
||||
})
|
||||
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
|
||||
ff.Player.SendPackCmd(2503, f.ReadyInfo)
|
||||
ff.Player.SendPackCmd(2503, &f.ReadyInfo)
|
||||
|
||||
})
|
||||
// 60秒后判断战斗是否开始
|
||||
@@ -228,14 +232,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, err
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
//todo 将血量和技能pp传回enterturn
|
||||
|
||||
ff.Player.SendPackCmd(2506, f.FightOverInfo)
|
||||
ff.Player.SendPackCmd(2506, &f.FightOverInfo)
|
||||
ff.Player.QuitFight()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return f, nil
|
||||
return f, 0
|
||||
}
|
||||
|
||||
// 被击败的ID
|
||||
|
||||
@@ -18,6 +18,7 @@ type Input struct {
|
||||
AllPet []*info.BattlePetEntity
|
||||
Player common.PlayerI
|
||||
Opp *Input
|
||||
CanCapture bool
|
||||
Finished bool //是否加载完成
|
||||
*info.AttackValue
|
||||
FightC common.FightI
|
||||
|
||||
@@ -64,7 +64,8 @@ func (f *FightC) battleLoop() {
|
||||
}
|
||||
|
||||
}
|
||||
ff.Player.SendPackCmd(2506, f.FightOverInfo)
|
||||
ff.Player.SendPackCmd(2506, &f.FightOverInfo)
|
||||
|
||||
ff.Player.QuitFight()
|
||||
|
||||
//待退出玩家战斗状态
|
||||
@@ -216,22 +217,25 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
||||
}
|
||||
switch {
|
||||
case gconv.Int(item.Bonus) != 0:
|
||||
our, ok1 := f.Our.Player.(*player.Player)
|
||||
opp, ok2 := f.Opp.Player.(*player.AI_player)
|
||||
if ok1 && ok2 && opp.CanCapture {
|
||||
|
||||
if f.Opp.CanCapture { //可以捕捉
|
||||
ok, res := f.Our.Capture(f.Opp.CurrentPet, a.ItemID, -1)
|
||||
our := f.Our.Player.(*player.Player)
|
||||
if ok {
|
||||
fmt.Println(res)
|
||||
|
||||
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),
|
||||
PetId: uint32(f.Opp.CurrentPet.ID),
|
||||
})
|
||||
}))
|
||||
//f.WinnerId = 0 //捕捉成功不算胜利
|
||||
|
||||
f.closefight = true
|
||||
} else {
|
||||
our.CatchPetInfo(info.CatchMonsterOutboundInfo{})
|
||||
our.SendPack(common.NewTomeeHeader(2409, f.ownerID).Pack(info.CatchMonsterOutboundInfo{}))
|
||||
|
||||
}
|
||||
}
|
||||
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.Broadcast(func(ff *input.Input) {
|
||||
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
|
||||
ff.Player.SendPackCmd(2406, &info.UsePetIteminfo{
|
||||
UserID: f.GetInputByAction(a, false).UserID,
|
||||
ChangeHp: int32(addhp),
|
||||
ItemID: uint32(item.ID),
|
||||
UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp),
|
||||
})
|
||||
|
||||
})
|
||||
case gconv.Int(item.PP) != 0:
|
||||
f.GetInputByAction(a, false).HealPP(item.PP)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
|
||||
ff.Player.SendPackCmd(2406, &info.UsePetIteminfo{
|
||||
UserID: f.GetInputByAction(a, false).UserID,
|
||||
|
||||
ItemID: uint32(item.ID),
|
||||
UserHp: uint32(f.GetInputByAction(a, false).CurrentPet.Info.Hp),
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package friend
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
//基地查看好友列表
|
||||
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"`
|
||||
UserIds []uint32 `json:"userIds" `
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package item
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
type BuyInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2601" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2601" struc:"[0]pad"`
|
||||
//物品ID
|
||||
ItemId uint32
|
||||
//物品数量
|
||||
@@ -20,7 +20,7 @@ type BuyOutboundInfo struct {
|
||||
Level uint32
|
||||
}
|
||||
type BuyMultiInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2606" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2606" struc:"[0]pad"`
|
||||
ItemListLen uint32 `struc:"sizeof=ItemIds"`
|
||||
ItemIds []uint32 `json:"itemIds" description:"购买的物品ID列表"` // @UInt Long对应uint64,List对应切片
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package item
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ type ChangePlayerClothOutboundInfo struct {
|
||||
ClothList []model.PeopleItemInfo `description:"玩家装备列表" codec:"list"` // List<PeopleItemInfo> -> 指针切片
|
||||
}
|
||||
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"`
|
||||
ClothList []uint32 `description:"玩家装备列表" codec:"list"`
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package item
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
// 实现了入站消息接口(Go中通过方法集隐式实现)
|
||||
type ItemListInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2605" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2605" struc:"[0]pad"`
|
||||
// 查询物品id的开始,
|
||||
Param1 uint32
|
||||
// 查询物品id的结尾
|
||||
@@ -23,7 +23,7 @@ type ItemListOutboundInfo 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 {
|
||||
@@ -35,7 +35,7 @@ type GoldOnlineRemainOutboundInfo struct {
|
||||
// ExpTotalRemainInboundInfo 累计经验相关的入站信息
|
||||
type ExpTotalRemainInboundInfo struct {
|
||||
// Head 消息头部信息,cmd保持原标识(如需调整可根据实际需求修改)
|
||||
Head player.TomeeHeader `cmd:"2319" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2319" struc:"[0]pad"`
|
||||
}
|
||||
|
||||
// ExpTotalRemainOutboundInfo 累计经验相关的出站信息
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package item
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
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
|
||||
}
|
||||
type TalkCountOutboundInfo struct {
|
||||
GiftCount uint32 `description:"已领取奖励的次数" codec:"uint"` // @UInt long -> uint64,字段描述对应@FieldDescription
|
||||
}
|
||||
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
|
||||
}
|
||||
type DayTalkInfo struct {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package maphot
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/space"
|
||||
)
|
||||
|
||||
type InInfo struct {
|
||||
Head player.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录
|
||||
Head common.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录
|
||||
}
|
||||
|
||||
// OutInfo 表示地图热度的出站消息
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type LeaveMapInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图
|
||||
Head common.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图
|
||||
}
|
||||
|
||||
type InInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图
|
||||
Head common.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图
|
||||
// 地图类型
|
||||
MapType uint32
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
)
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
type ListMapPlayerInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图
|
||||
Head common.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package maps
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
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 uint32
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package nono
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// NonoOutboundInfo 用于表示Nono相关的出站信息
|
||||
type NonoOutboundInfo struct {
|
||||
@@ -54,13 +54,13 @@ type NonoOutboundInfo struct {
|
||||
}
|
||||
|
||||
type NonoInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"9003" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"9003" struc:"[0]pad"`
|
||||
|
||||
// 米米号
|
||||
UserID uint32
|
||||
}
|
||||
type NonoFollowOrHomeInInfo struct {
|
||||
Head player.TomeeHeader `cmd:"9019" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"9019" struc:"[0]pad"`
|
||||
|
||||
// Flag 1为跟随 0为收回 且如果为收回收回 那么后续结构不需要发送
|
||||
// 对应Java的@UInt long类型,在Go中使用uint64
|
||||
@@ -86,7 +86,7 @@ type NonoFollowOutInfo struct {
|
||||
Power uint32 `fieldDescription:"能量值 前端显示除以1000后的值" uint:"true"`
|
||||
}
|
||||
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 SwitchFlyingOutboundInfo struct {
|
||||
@@ -94,7 +94,7 @@ type SwitchFlyingOutboundInfo struct {
|
||||
Type uint32 `description:"开关, 0为取消飞行模式, 大于0为开启飞行模式" codec:"auto" uint:"true"` // 对应@FieldDescription、@UInt、@AutoCodec
|
||||
}
|
||||
type PetCureInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2306" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2306" struc:"[0]pad"`
|
||||
}
|
||||
type PetCureOutboundEmpty struct {
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package pet
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// PetBargeListInboundInfo 对应Java的PetBargeListInboundInfo,实现InboundMessage接口
|
||||
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位)
|
||||
EndPetId uint32 `description:"结束精灵id" codec:"endPetId"` // 字段标签模拟注解功能(描述、编解码标识)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package pet
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// 实现InboundMessage接口,用于处理宠物设置经验的入站消息
|
||||
type PetSetExpInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2318" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2318" struc:"[0]pad"`
|
||||
// CatchTime 精灵获取时间,对应Java的@UInt long
|
||||
CatchTime uint32 `fieldDescription:"精灵获取时间" uint:"true" autoCodec:"true"`
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package pet
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
type GetPetListInboundEmpty struct {
|
||||
Head player.TomeeHeader `cmd:"2303" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2303" struc:"[0]pad"`
|
||||
}
|
||||
type GetPetListOutboundInfo struct {
|
||||
ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"`
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package pet
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type InInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2301" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2301" struc:"[0]pad"`
|
||||
|
||||
CatchTime uint32
|
||||
}
|
||||
@@ -25,13 +25,13 @@ type PetReleaseOutboundInfo 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"`
|
||||
Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"`
|
||||
}
|
||||
|
||||
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"`
|
||||
Flag uint32 `codec:"flag"`
|
||||
@@ -48,7 +48,7 @@ type PetShowOutboundInfo struct {
|
||||
Reserved1 [3]uint32
|
||||
}
|
||||
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"`
|
||||
} // PetOneCureOutboundInfo 宠物单个治疗出站消息
|
||||
type PetOneCureOutboundInfo struct {
|
||||
@@ -58,7 +58,7 @@ type PetOneCureOutboundInfo struct {
|
||||
// PetDefaultInboundInfo
|
||||
// 实现了InboundMessage接口
|
||||
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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package pet
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// ChangeSkillInfo 技能变更信息
|
||||
type ChangeSkillInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2312" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"2312" struc:"[0]pad"`
|
||||
CatchTime uint32 `json:"catchTime"` // 精灵生成时间
|
||||
Reserved uint32 `json:"reserved"` // 填充字段,默认为1
|
||||
Reserved1 uint32 `json:"reserved1"` // 填充字段,默认为1
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
@@ -9,7 +10,6 @@ type AI_player struct {
|
||||
baseplayer
|
||||
petinfo []model.PetInfo //精灵信息
|
||||
|
||||
CanCapture bool
|
||||
}
|
||||
|
||||
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 (f *AI_player) InvitePlayer(ff common.PlayerI) {
|
||||
|
||||
}
|
||||
func (p *AI_player) QuitFight() {
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/modules/blazing/model"
|
||||
"math/rand"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -38,7 +37,6 @@ func (f *baseplayer) SetFightC(ff common.FightI) {
|
||||
f.FightC = ff
|
||||
}
|
||||
|
||||
|
||||
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
|
||||
return f.PlayerCaptureContext
|
||||
}
|
||||
|
||||
@@ -1,30 +1,8 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"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)) //准备包由各自发,因为协议不一样
|
||||
|
||||
}
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
func (p *Player) SendPackCmd(cmd uint32, b any) {
|
||||
|
||||
p.SendPack(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))
|
||||
|
||||
p.SendPack(common.NewTomeeHeader(cmd, p.Info.UserID).Pack(b))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/info"
|
||||
"sync/atomic"
|
||||
@@ -15,7 +16,7 @@ func (p *Player) InvitePlayerToBattle() {
|
||||
|
||||
v.InvitePlayer(p)
|
||||
|
||||
v.SendPackCmd(2501, info.NoteInviteToFightOutboundInfo{
|
||||
v.SendPackCmd(2501, &info.NoteInviteToFightOutboundInfo{
|
||||
UserID: p.Info.UserID,
|
||||
Nick: p.Info.Nick,
|
||||
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 {
|
||||
|
||||
if v != p {
|
||||
if v.GetInfo().UserID != p.Info.UserID {
|
||||
//确认是乱斗模式
|
||||
|
||||
if v.GetInfo() == p.GetInfo() {
|
||||
p.Fightinfo = nil //先将自身的准备信息置空
|
||||
//value.PVPinfo = nil
|
||||
lw = value
|
||||
return true
|
||||
if v.Getfightinfo() == p.Getfightinfo() {
|
||||
|
||||
// p.Fightinfo = nil //先将自身的准备信息置空
|
||||
// //value.PVPinfo = nil
|
||||
// lw = value
|
||||
return fn(v) //如果发起成功就停止,否则继续遍历队列
|
||||
}
|
||||
|
||||
}
|
||||
return false
|
||||
})
|
||||
return lw
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
// 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 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{
|
||||
UserID: lw.Info.UserID,
|
||||
Nick: lw.Info.Nick,
|
||||
UserID: p.Info.UserID,
|
||||
Nick: p.Info.Nick,
|
||||
}
|
||||
|
||||
// 检查邀请者的邀请是否有效(对方已取消邀请)
|
||||
if inviter.Fightinfo == nil {
|
||||
resp.Result = 4 // 邀请已取消
|
||||
inviter.SendPack(respHeader.Pack(resp))
|
||||
return false, nil
|
||||
}
|
||||
for _, o := range p.HavePVPinfo {
|
||||
if o != nil && o.Getfightinfo() == p.Fightinfo {
|
||||
resp.Result = flag
|
||||
// 检查邀请者的邀请是否有效(对方已取消邀请)
|
||||
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
|
||||
}
|
||||
|
||||
// 检查双方是否可战斗
|
||||
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
|
||||
return errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package player
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/common/utils/bytearray"
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
"encoding/binary"
|
||||
"sync"
|
||||
|
||||
@@ -22,87 +22,33 @@ import (
|
||||
"github.com/panjf2000/gnet/v2/pkg/logging"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
// getUnderlyingValue 递归解析reflect.Value,解包指针、interface{}到底层具体类型
|
||||
func getUnderlyingValue(val reflect.Value) (reflect.Value, error) {
|
||||
for {
|
||||
switch val.Kind() {
|
||||
// 解包指针:获取指针指向的值
|
||||
case reflect.Ptr:
|
||||
if val.IsNil() {
|
||||
return reflect.Value{}, nil
|
||||
}
|
||||
val = val.Elem()
|
||||
|
||||
Result uint32 `json:"result"`
|
||||
Data []byte `json:"data" struc:"skip"` //组包忽略此字段// struc:"[0]pad"
|
||||
//Return []byte `struc:"[0]pad"` //返回记录
|
||||
}
|
||||
// 解包interface{}:获取接口包裹的动态值
|
||||
case reflect.Interface:
|
||||
if val.IsNil() {
|
||||
return reflect.Value{}, nil
|
||||
}
|
||||
val = val.Elem()
|
||||
|
||||
func NewTomeeHeader(cmd uint32, userid uint32) *TomeeHeader {
|
||||
|
||||
return &TomeeHeader{
|
||||
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)
|
||||
// 非指针/接口类型,终止递归
|
||||
default:
|
||||
return val, nil
|
||||
}
|
||||
|
||||
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
|
||||
func (h *ClientData) Recv(data TomeeHeader) {
|
||||
func (h *ClientData) Recv(data common.TomeeHeader) {
|
||||
|
||||
cmdlister, ok := cool.CmdCache.Load(data.CMD)
|
||||
if !ok {
|
||||
@@ -237,7 +183,7 @@ func (h *ClientData) OnEvent(v []byte) {
|
||||
|
||||
}
|
||||
}()
|
||||
var header TomeeHeader
|
||||
var header common.TomeeHeader
|
||||
// 解析Len(0-3字节)
|
||||
header.Len = binary.BigEndian.Uint32(v[0:4])
|
||||
// 解析Version(第4字节)
|
||||
|
||||
@@ -3,6 +3,7 @@ package player
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/utils"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight/info"
|
||||
|
||||
"blazing/modules/blazing/model"
|
||||
@@ -58,7 +59,7 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
|
||||
}
|
||||
petinfo.SkillList = petinfo.SkillList[:4] //归正到4
|
||||
|
||||
t1 := NewTomeeHeader(2508, p.Info.UserID)
|
||||
t1 := common.NewTomeeHeader(2508, p.Info.UserID)
|
||||
rrr := &info.PetUpdateOutboundInfo{}
|
||||
|
||||
var petinfwo info.UpdatePropInfo
|
||||
|
||||
@@ -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) //生成野怪
|
||||
|
||||
@@ -277,7 +277,7 @@ func (p *Player) ItemAdd(t ...model.SingleItemInfo) (result []model.SingleItemIn
|
||||
if !ok {
|
||||
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)
|
||||
|
||||
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) {
|
||||
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)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
@@ -307,7 +307,7 @@ func (player1 *Player) Kick() {
|
||||
if player1.IsLogin {
|
||||
//取成功,否则创建
|
||||
//player1.Save() //先保存数据再返回
|
||||
head := NewTomeeHeader(1001, player1.Info.UserID)
|
||||
head := common.NewTomeeHeader(1001, player1.Info.UserID)
|
||||
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
|
||||
//实际上这里有个问题,会造成重复保存问题
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package room
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// FitmentShowInfo 表示家具展示信息
|
||||
type FitmentShowInfo struct {
|
||||
@@ -18,7 +18,7 @@ type FitmentShowInfo struct {
|
||||
|
||||
// FitmentUseringInboundInfo FitmentUseringInboundInfo类,实现InboundMessage接口
|
||||
type FitmentUseringInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录
|
||||
Head common.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录
|
||||
// 需要获取基地信息的目标玩家账号ID
|
||||
TargetUserID uint32 `json:"targetUserId"`
|
||||
}
|
||||
@@ -45,12 +45,12 @@ type PetRoomListOutboundInfo struct {
|
||||
}
|
||||
|
||||
type PetRoomListInboundInfo struct {
|
||||
Head player.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录
|
||||
Head common.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录
|
||||
// 需要获取基地信息的目标玩家账号ID
|
||||
TargetUserID uint32 `json:"targetUserId"`
|
||||
}
|
||||
type FitmentAllInboundEmpty struct {
|
||||
Head player.TomeeHeader `cmd:"10007" struc:"[0]pad"`
|
||||
Head common.TomeeHeader `cmd:"10007" struc:"[0]pad"`
|
||||
}
|
||||
type FitmentAllOutboundInfo struct {
|
||||
FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"`
|
||||
|
||||
@@ -1,68 +1,9 @@
|
||||
package space
|
||||
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/common"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type ARENA struct {
|
||||
Flag uint32 // 0=清除ArenaInfo(flag为0时其他字段全为空) 1=站上擂台的信息 2=挑战中的信息
|
||||
Id uint32
|
||||
UserID uint32
|
||||
Nick string `struc:"[16]byte"`
|
||||
HostWins uint32 // 应该是擂台人的连胜数
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
@@ -37,8 +37,12 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
||||
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.User.Delete(c.GetInfo().UserID)
|
||||
@@ -54,11 +58,10 @@ func (s *Space) EnterMap(c common.PlayerI) {
|
||||
|
||||
out := info.NewOutInfo()
|
||||
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.UserInfo.Store(c.GetInfo().UserID, *out)
|
||||
s.Broadcast(c, 2001, out)
|
||||
|
||||
if s.SuperValue != nil {
|
||||
atomic.AddInt32(s.SuperValue, 1)
|
||||
}
|
||||
@@ -77,7 +80,7 @@ func (s *Space) GetInfo() []maps.OutInfo {
|
||||
|
||||
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()
|
||||
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
|
||||
if !limiter.Allow() {
|
||||
|
||||
@@ -19,7 +19,7 @@ type Space struct {
|
||||
SuperValue *int32
|
||||
//ID uint32 // 地图ID
|
||||
Name string //地图名称
|
||||
ARENA ARENA
|
||||
Owner ARENA
|
||||
ARENA_Player common.PlayerI
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package systemtime
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
// LoginSidInfo 登录携带的凭证结构体
|
||||
type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
|
||||
Head player.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录
|
||||
Head common.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package task
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// AcceptTaskInboundInfo
|
||||
// 用于接收任务的入站信息
|
||||
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,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package task
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// AddTaskBufInboundInfo
|
||||
// 用于接收添加任务缓冲区的入站信息
|
||||
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,
|
||||
TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package task
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
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,
|
||||
OutState uint32 `json:"outState" ` // 当前状态,1表示完成任务,
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package task
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
// DeleteTaskInboundInfo
|
||||
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
|
||||
}
|
||||
type DeleteTaskOutboundInfo struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package user
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
|
||||
Head player.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录
|
||||
Head common.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录
|
||||
|
||||
// 玩家昵称,@ArraySerialize注解
|
||||
Nickname string `struc:"[16]byte"` // 固定长度16字节
|
||||
@@ -17,7 +17,7 @@ type CreatePlayerOutInfo 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字节
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
)
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
//var _ entity.Blazingservice = (*SidInfo)(nil)
|
||||
|
||||
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字节
|
||||
// ret []byte `struc:"[0]pad"`
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
type SimUserInfoOutboundInfo struct {
|
||||
@@ -71,7 +71,7 @@ type SimUserInfoOutboundInfo struct {
|
||||
Clothes []model.PeopleItemInfo `codec:"true"`
|
||||
}
|
||||
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"`
|
||||
}
|
||||
type MoreUserInfoOutboundInfo struct {
|
||||
@@ -121,7 +121,7 @@ type MoreUserInfoOutboundInfo struct {
|
||||
|
||||
// AimatInboundInfo 对应Java的AimatInboundInfo类
|
||||
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"`
|
||||
ShootType uint32 `description:"射击类型 未知 给0" codec:"auto" uint:"true"`
|
||||
Point model.Pos `description:"射击的坐标 x y" codec:"auto"` // 默认值对应@Builder.Default
|
||||
|
||||
@@ -2,7 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"blazing/common/data/share"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/common"
|
||||
|
||||
"blazing/modules/blazing/model"
|
||||
"context"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// LoginSidInfo 登录携带的凭证结构体
|
||||
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字节
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package user
|
||||
|
||||
import "blazing/logic/service/player"
|
||||
import "blazing/logic/service/common"
|
||||
|
||||
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,无符号长整数
|
||||
MessageLen uint32 `struc:"sizeof=Message"`
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ type ChangeColorOutboundInfo struct {
|
||||
Coins uint32 `codec:"coins"` // 扣除200豆子后返回的剩余豆子 (对应Java的@UInt long)
|
||||
}
|
||||
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)
|
||||
Color uint32 `codec:"color"` // 前端发来的更改的颜色rgb值 (对应Java的@UInt long)
|
||||
}
|
||||
@@ -39,7 +39,7 @@ type ChangeDoodleOutboundInfo struct {
|
||||
Coins uint32 `codec:"coins"` // 扣除对应豆子后返回的剩余豆子 (对应Java的@UInt long)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package model
|
||||
|
||||
// TeamInfo 战队信息结构
|
||||
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
|
||||
Priv uint32 `struc:"uint32" default:"1"` // 默认值1
|
||||
SuperCore uint32 `struc:"uint32" default:"1"` // 默认值1
|
||||
|
||||
Reference in New Issue
Block a user