refactor(logic): 重构逻辑层代码

- 移除未使用的 SocketHandler_Tomee.go、ai.go、effect_1.go 文件
- 更新 player 包名引用,替换原 service 包
- 调整 TomeeHeader 和相关处理逻辑至 player 包
- 更新各控制器中的 Player 引用为 player 包中的类型
- 移除冗余的 GetPlayer 方法,使用新逻辑
This commit is contained in:
2025-09-14 01:35:16 +08:00
parent 910e866456
commit 5e01837f78
66 changed files with 604 additions and 518 deletions

View File

@@ -6,10 +6,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"blazing/common/data/share" "blazing/logic/service/player"
"blazing/logic/service"
"blazing/logic/service/maps"
"github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/os/glog"
"github.com/panjf2000/gnet/v2" "github.com/panjf2000/gnet/v2"
@@ -43,21 +40,15 @@ func (s *Server) Stop() error {
func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) { func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
atomic.AddInt64(&s.connected, -1) atomic.AddInt64(&s.connected, -1)
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String()) //logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
v, ok := c.Context().(*service.ClientData) v, ok := c.Context().(*player.ClientData)
if !ok { if !ok {
return return
} }
if v.Player != nil { if v.Player != nil {
glog.Debug(context.Background(), v.Player.Info.UserID, "断开连接")
maps.LeaveMap(v.Player) v.Player.Save() //保存玩家数据
v.Player.IsLogin = false
service.Mainplayer.Delete(v.Player.Info.UserID)
share.ShareManager.DeleteUserOnline(v.Player.Info.UserID) //设置用户登录服务器
v.Player.Save() //保存玩家数据
} }
//} //}
@@ -78,7 +69,7 @@ func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
func (s *Server) OnOpen(conn gnet.Conn) (out []byte, action gnet.Action) { func (s *Server) OnOpen(conn gnet.Conn) (out []byte, action gnet.Action) {
if conn.Context() == nil { if conn.Context() == nil {
conn.SetContext(service.NewClientData()) //注入data conn.SetContext(player.NewClientData()) //注入data
} }
atomic.AddInt64(&s.connected, 1) atomic.AddInt64(&s.connected, 1)
@@ -91,7 +82,7 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
return gnet.Close return gnet.Close
} }
ws := c.Context().(*service.ClientData).Wsmsg ws := c.Context().(*player.ClientData).Wsmsg
if ws.Tcp { //升级失败时候防止缓冲区溢出 if ws.Tcp { //升级失败时候防止缓冲区溢出
s.handleTcp(c) s.handleTcp(c)
return gnet.None return gnet.None
@@ -175,7 +166,7 @@ const CROSS_DOMAIN = "<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy><cros
const TEXT = "<policy-file-request/>\x00" const TEXT = "<policy-file-request/>\x00"
func handle(c gnet.Conn) { func handle(c gnet.Conn) {
clientdata := c.Context().(*service.ClientData) clientdata := c.Context().(*player.ClientData)
if clientdata.IsCrossDomain { if clientdata.IsCrossDomain {
return return

View File

@@ -2,55 +2,12 @@ package socket
import ( import (
"blazing/common/socket/codec" "blazing/common/socket/codec"
"blazing/common/socket/errorcode"
"blazing/logic/service"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"
"github.com/panjf2000/gnet/pkg/pool/goroutine" "github.com/panjf2000/gnet/pkg/pool/goroutine"
"github.com/panjf2000/gnet/v2" "github.com/panjf2000/gnet/v2"
) )
func GetPlayer(c *service.Conn, userid uint32) *service.Player { //TODO 这里待优化,可能存在内存泄漏问题
c.Mu.Lock()
defer c.Mu.Unlock()
//检查player初始化是否为conn初始后取map防止二次连接后存在两个player
clientdata := c.MainConn.Context().(*service.ClientData)
if clientdata.Player != nil {
return clientdata.Player
}
clientdata.Player = service.NewPlayer(
service.WithConn(c), //注入conn
)
// gff := socket.NewClientData()
// gff.Player = clientdata.Player
// c.MainConn.SetContext(gff)
service.Mainplayer.Store(userid, clientdata.Player)
return clientdata.Player
// return nil
}
func KickPlayer(userid uint32) { //踢出玩家
//TODO 返回错误码
//var player *entity.Player
if player1, ok := service.Mainplayer.Load((userid)); ok {
//取成功,否则创建
head := service.NewTomeeHeader(1001, userid)
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
player1.SendPack(head.Pack(nil))
player1.MainConn.MainConn.Close()
// clientdata.Player = player
}
//return player
// return nil
}
type Handler interface { type Handler interface {
Handle(gnet.Conn, []byte) Handle(gnet.Conn, []byte)
} }

View File

@@ -3,21 +3,23 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/cool" "blazing/cool"
"blazing/logic/service"
"blazing/logic/service/common"
"blazing/logic/service/login" "blazing/logic/service/login"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
blservice "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service"
"strings" "strings"
) )
// 处理命令: 1001 // 处理命令: 1001
func (h *Controller) CreatePlayer(data *login.CreatePlayerInboundInfo, c *service.Conn) (result *login.CreatePlayerOutInfo, err errorcode.ErrorCode) { func (h *Controller) CreatePlayer(data *login.CreatePlayerInboundInfo, c *player.Conn) (result *login.CreatePlayerOutInfo, err errorcode.ErrorCode) {
blservice.NewUserService(data.Head.UserID).Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color) blservice.NewUserService(data.Head.UserID).Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
return result, 0 return result, 0
} }
func (h *Controller) ChangePlayerName(data *login.ChangePlayerNameInboundInfo, c *service.Player) (result *login.ChangePlayerNameOutboundInfo, err errorcode.ErrorCode) { func (h *Controller) ChangePlayerName(data *login.ChangePlayerNameInboundInfo, c *player.Player) (result *login.ChangePlayerNameOutboundInfo, err errorcode.ErrorCode) {
newnice := cool.Filter.Replace(strings.Trim(data.Nickname, "\x00"), '*') newnice := cool.Filter.Replace(strings.Trim(data.Nickname, "\x00"), '*')
c.Info.Nick = newnice c.Info.Nick = newnice
@@ -25,7 +27,7 @@ func (h *Controller) ChangePlayerName(data *login.ChangePlayerNameInboundInfo, c
Nickname: newnice, Nickname: newnice,
UserID: c.ID(), UserID: c.ID(),
} }
space.GetSpace(c.MapID()).Range(func(playerID uint32, player service.PlayerI) bool { space.GetSpace(c.MapID()).Range(func(playerID uint32, player common.PlayerI) bool {
player.SendPack(data.Head.Pack(&result)) player.SendPack(data.Head.Pack(&result))
return true return true

View File

@@ -2,11 +2,11 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/friend" "blazing/logic/service/friend"
"blazing/logic/service/player"
) )
func (h Controller) OnSeeOnline(data *friend.SeeOnlineInboundInfo, c *service.Player) (result *friend.SeeOnlineOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnSeeOnline(data *friend.SeeOnlineInboundInfo, c *player.Player) (result *friend.SeeOnlineOutboundInfo, err errorcode.ErrorCode) {
result = &friend.SeeOnlineOutboundInfo{} result = &friend.SeeOnlineOutboundInfo{}
result.Friends = make([]friend.OnlineInfo, 0) result.Friends = make([]friend.OnlineInfo, 0)
return return

View File

@@ -1,11 +1,11 @@
package controller package controller
import ( import (
"blazing/common/socket"
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/cool" "blazing/cool"
"blazing/logic/service"
"blazing/logic/service/player"
"os" "os"
"strings" "strings"
"time" "time"
@@ -38,7 +38,7 @@ type LogicClient struct {
func (h *LogicClient) KickPerson(a int) error { func (h *LogicClient) KickPerson(a int) error {
fmt.Println("检测到踢人请求", a) fmt.Println("检测到踢人请求", a)
socket.KickPlayer(uint32(a)) player.KickPlayer(uint32(a))
return nil return nil
} }
func (h *LogicClient) QuitSelf(a int) error { func (h *LogicClient) QuitSelf(a int) error {
@@ -50,9 +50,9 @@ func (h *LogicClient) QuitSelf(a int) error {
for { for {
//entity.ConutPlayer() //entity.ConutPlayer()
fmt.Println("当前在线人数", service.ConutPlayer()) fmt.Println("当前在线人数", player.ConutPlayer())
if service.ConutPlayer() <= 0 { if player.ConutPlayer() <= 0 {
//执行退出逻辑 //执行退出逻辑
os.Exit(1) os.Exit(1)
} }
@@ -107,7 +107,7 @@ func init() { //默认初始化扫描
} }
glog.Debug(context.Background(), "注册方法", func_cmd, method.Name) glog.Debug(context.Background(), "注册方法", func_cmd, method.Name)
// fmt.Println(methodValue.Interface().(func(gnet.Conn, service.TomeeHeader))) // fmt.Println(methodValue.Interface().(func(gnet.Conn, player.TomeeHeader)))
_, ok := cool.CmdCache.LoadOrStore(func_cmd, methodValue) //TODO 待实现对不同用户初始化方法以取消全局cmdcache _, ok := cool.CmdCache.LoadOrStore(func_cmd, methodValue) //TODO 待实现对不同用户初始化方法以取消全局cmdcache
if ok { //方法已存在init if ok { //方法已存在init
@@ -136,7 +136,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(service.TomeeHeader{}) { if field.Type == reflect.TypeOf(player.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"), "|"))
@@ -158,7 +158,7 @@ func getcmd(t reflect.Type) []uint32 {
} }
// 遍历结构体方法并执行RECV_cmd // 遍历结构体方法并执行RECV_cmd
func Recv(c *service.Conn, data service.TomeeHeader) { func Recv(c *player.Conn, data player.TomeeHeader) {
cmdlister, ok := cool.CmdCache.Load(data.CMD) cmdlister, ok := cool.CmdCache.Load(data.CMD)
if !ok { if !ok {
@@ -189,8 +189,8 @@ func Recv(c *service.Conn, data service.TomeeHeader) {
if nameField.IsValid() && nameField.CanSet() { if nameField.IsValid() && nameField.CanSet() {
nameField.Set(reflect.ValueOf(data)) nameField.Set(reflect.ValueOf(data))
} }
if cmdlister.Type().In(1) == reflect.TypeOf(&service.Player{}) { if cmdlister.Type().In(1) == reflect.TypeOf(&player.Player{}) {
t := socket.GetPlayer(c, data.UserID) t := player.GetPlayer(c, data.UserID)
// fmt.Println(data.CMD, "接收 变量的地址 ", &t.Info, t.Info.UserID) // fmt.Println(data.CMD, "接收 变量的地址 ", &t.Info, t.Info.UserID)
err := t.WaitForLoginWithCtx(context.Background()) err := t.WaitForLoginWithCtx(context.Background())
if err != nil { if err != nil {

View File

@@ -3,33 +3,14 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/fight" "blazing/logic/service/fight"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/player"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"github.com/jinzhu/copier"
) )
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
ttt := info.NoteReadyToFightInfo{
FightId: 3,
}
copier.Copy(&ttt.OurInfo, &c.Info)
len := len(c.Info.PetList)
ttt.OurPetList = make([]info.ReadyFightPetInfo, len)
for i := 0; i < len; i++ {
err := copier.CopyWithOption(&ttt.OurPetList[i], &c.Info.PetList[i], copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err != nil {
panic(err)
}
}
ttt.OpponentInfo = info.FightUserInfo{UserID: 0}
refpet := c.OgreInfo.Data[data.Number] refpet := c.OgreInfo.Data[data.Number]
if refpet.Id == 0 { if refpet.Id == 0 {
@@ -41,59 +22,51 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
[]int{0}, //野怪没特性 []int{0}, //野怪没特性
[]int{int(refpet.Shiny)}, []int{int(refpet.Shiny)},
[]int{int(refpet.Lv)}) []int{int(refpet.Lv)})
ttt.OpponentPetList = make([]info.ReadyFightPetInfo, 1)
err1 := copier.CopyWithOption(&ttt.OpponentPetList[0], &mo, copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err1 != nil {
panic(err)
}
if c.FightC != nil { if c.FightC != nil {
return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight
} }
ai := service.NewAI_player(*mo) ai := player.NewAI_player(model.PlayerInfo{}, *mo)
service.NewFight(ttt, c, ai) fight.NewFight(info.BattleMode.PVE, c, ai)
c.FightC.OwnerID = c.Info.UserID
return nil, -1 return nil, -1
} }
// 准备战斗 // 准备战斗
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.ReadyFight(c) c.FightC.ReadyFight(c)
return nil, -1 return nil, -1
} }
// 接收战斗或者取消战斗的包 // 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
return nil, -1 return nil, -1
} }
// 使用技能包 // 使用技能包
func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.UseSkill(c, int32(data.SkillId)) c.FightC.UseSkill(c, int32(data.SkillId))
return nil, 0 return nil, 0
} }
// 战斗逃跑 // 战斗逃跑
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.Escape(c) c.FightC.Escape(c)
return nil, 0 return nil, 0
} }
// 切换精灵 // 切换精灵
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *service.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.ChangePet(c, int32(data.CatchTime)) c.FightC.ChangePet(c, data.CatchTime)
return nil, -1 return nil, -1
} }
// 切换精灵 // 切换精灵
func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *service.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) {
c.FightC.Capture(c, (data.CapsuleId)) c.FightC.Capture(c, (data.CapsuleId))
return nil, -1 return nil, -1

View File

@@ -2,12 +2,13 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/commendsvr" "blazing/logic/service/commendsvr"
"blazing/logic/service/player"
) )
// 处理命令: 105 // 处理命令: 105
func (h *Controller) GetServer(data *commendsvr.SidInfo, c *service.Conn) (result *commendsvr.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) GetServer(data *commendsvr.SidInfo, c *player.Conn) (result *commendsvr.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = commendsvr.NewInInfo() result = commendsvr.NewInInfo()
result.ServerList = commendsvr.GetServerInfoList() result.ServerList = commendsvr.GetServerInfoList()
return return

View File

@@ -2,12 +2,13 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/item" "blazing/logic/service/item"
"blazing/logic/service/player"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *service.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) { func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *player.Player) (result *item.ItemListOutboundInfo, err errorcode.ErrorCode) {
result = &item.ItemListOutboundInfo{} result = &item.ItemListOutboundInfo{}
result.ItemList = make([]model.SingleItemInfo, 0) result.ItemList = make([]model.SingleItemInfo, 0)
@@ -22,7 +23,7 @@ func (h Controller) UserItemList(data *item.ItemListInboundInfo, c *service.Play
return result, 0 return result, 0
} }
func (h Controller) PlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, c *service.Player) (result *item.GoldOnlineRemainOutboundInfo, err errorcode.ErrorCode) { func (h Controller) PlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, c *player.Player) (result *item.GoldOnlineRemainOutboundInfo, err errorcode.ErrorCode) {
return &item.GoldOnlineRemainOutboundInfo{ return &item.GoldOnlineRemainOutboundInfo{

View File

@@ -2,13 +2,13 @@ package controller
import ( import (
"blazing/common/data/share" "blazing/common/data/share"
"blazing/common/socket"
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service" "blazing/logic/service/common"
"blazing/logic/service/login" "blazing/logic/service/login"
"blazing/logic/service/maps" "blazing/logic/service/maps"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
blservice "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service"
@@ -29,12 +29,12 @@ func IsToday(t time.Time) bool {
} }
// 处理命令: 1001 // 处理命令: 1001
func (h *Controller) Login(data *login.InInfo, c *service.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) Login(data *login.InInfo, c *player.Conn) (result *login.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
if tt := data.CheakSession(); tt { //说明sid正确 if tt := data.CheakSession(); tt { //说明sid正确
h.RPCClient.Kick(data.Head.UserID) //先踢人 h.RPCClient.Kick(data.Head.UserID) //先踢人
t := socket.GetPlayer(c, data.Head.UserID) t := player.GetPlayer(c, data.Head.UserID)
t.Service = blservice.NewUserService(data.Head.UserID) t.Service = blservice.NewUserService(data.Head.UserID)
t.Info = t.Service.Person() t.Info = t.Service.Person()
t.Info.UserID = data.Head.UserID t.Info.UserID = data.Head.UserID
@@ -74,8 +74,8 @@ func (h *Controller) Login(data *login.InInfo, c *service.Conn) (result *login.O
tt := maps.NewOutInfo() tt := maps.NewOutInfo()
//copier.Copy(t.Info, tt) //copier.Copy(t.Info, tt)
t1 := service.NewTomeeHeader(2001, t.Info.UserID) t1 := player.NewTomeeHeader(2001, t.Info.UserID)
defer space.GetSpace(t.Info.MapID).Set(t.Info.UserID, t).Range(func(playerID uint32, player service.PlayerI) bool { defer space.GetSpace(t.Info.MapID).Set(t.Info.UserID, t).Range(func(playerID uint32, player common.PlayerI) bool {
player.SendPack(t1.Pack(&tt)) player.SendPack(t1.Pack(&tt))
return true return true

View File

@@ -2,16 +2,18 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/common"
"blazing/logic/service/maphot" "blazing/logic/service/maphot"
"blazing/logic/service/maps" "blazing/logic/service/maps"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
"time" "time"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
) )
func (h *Controller) MapEnter(data *maps.InInfo, c *service.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) MapEnter(data *maps.InInfo, c *player.Player) (result *maps.OutInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
c.Info.MapID = data.MapId //登录地图 c.Info.MapID = data.MapId //登录地图
space.GetSpace(c.Info.MapID).Set(c.Info.UserID, c) //添加玩家 space.GetSpace(c.Info.MapID).Set(c.Info.UserID, c) //添加玩家
@@ -57,7 +59,7 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *service.Player) (result *map
}(c.StopChan, int(c.Info.MapID)) }(c.StopChan, int(c.Info.MapID))
return nil, -1 return nil, -1
} }
func (h Controller) MapHot(data *maphot.InInfo, c *service.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) { func (h Controller) MapHot(data *maphot.InInfo, c *player.Player) (result *maphot.OutInfo, err errorcode.ErrorCode) {
result = &maphot.OutInfo{ result = &maphot.OutInfo{
@@ -66,10 +68,10 @@ func (h Controller) MapHot(data *maphot.InInfo, c *service.Player) (result *maph
return return
} }
func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *service.Player) (result *maps.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *player.Player) (result *space.LeaveMapOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
//result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()} //result = &maps.LeaveMapOutboundInfo{UserID: c.GetUserID()}
data.Broadcast(c.Info.MapID, maps.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播 data.Broadcast(c.Info.MapID, space.LeaveMapOutboundInfo{UserID: c.Info.UserID}) //同步广播
space.GetSpace(c.Info.MapID).Delete(c.Info.UserID) space.GetSpace(c.Info.MapID).Delete(c.Info.UserID)
// 如果有正在运行的刷怪协程,发送停止信号 // 如果有正在运行的刷怪协程,发送停止信号
if c.StopChan != nil { if c.StopChan != nil {
@@ -79,12 +81,12 @@ func (h *Controller) MapLeave(data *maps.LeaveMapInboundInfo, c *service.Player)
c.Info.MapID = 0 // 重置当前地图 c.Info.MapID = 0 // 重置当前地图
return nil, -1 return nil, -1
} }
func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *service.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *player.Player) (result *maps.ListMapPlayerOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &maps.ListMapPlayerOutboundInfo{} result = &maps.ListMapPlayerOutboundInfo{}
result.Player = make([]maps.OutInfo, 0) result.Player = make([]maps.OutInfo, 0)
space.GetSpace(c.Info.MapID).Range(func(userID uint32, player service.PlayerI) bool { space.GetSpace(c.Info.MapID).Range(func(userID uint32, player common.PlayerI) bool {
result1 := maps.NewOutInfo() result1 := maps.NewOutInfo()
copier.Copy(result1, player) copier.Copy(result1, player)
result.Player = append(result.Player, *result1) result.Player = append(result.Player, *result1)

View File

@@ -3,8 +3,9 @@ package controller
import ( import (
"blazing/common/data/xmlres" "blazing/common/data/xmlres"
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/pet" "blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
@@ -14,7 +15,7 @@ import (
// 获取精灵信息 // 获取精灵信息
func (h *Controller) GetPetInfo( func (h *Controller) GetPetInfo(
data *pet.InInfo, data *pet.InInfo,
c *service.Player) (result *pet.OutInfo, c *player.Player) (result *pet.OutInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的 err errorcode.ErrorCode) { //这个时候player应该是空的
for _, pi := range c.Info.PetList { for _, pi := range c.Info.PetList {
@@ -39,7 +40,7 @@ func (h *Controller) GetPetInfo(
// 获取仓库列表 // 获取仓库列表
func (h *Controller) GetPetList( func (h *Controller) GetPetList(
data *pet.GetPetListInboundEmpty, data *pet.GetPetListInboundEmpty,
c *service.Player) (result *pet.GetPetListOutboundInfo, c *player.Player) (result *pet.GetPetListOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的 err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.GetPetListOutboundInfo{} result = &pet.GetPetListOutboundInfo{}
@@ -57,7 +58,7 @@ func (h *Controller) GetPetList(
// 精灵背包仓库切换 // 精灵背包仓库切换
func (h *Controller) PetRelease( func (h *Controller) PetRelease(
data *pet.PetReleaseInboundInfo, data *pet.PetReleaseInboundInfo,
c *service.Player) ( c *player.Player) (
result *pet.PetReleaseOutboundInfo, result *pet.PetReleaseOutboundInfo,
err errorcode.ErrorCode) { //这个时候player应该是空的 err errorcode.ErrorCode) { //这个时候player应该是空的
//放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序 //放入背包=数据库置1+添加到背包+pet release发包 仓库=数据库置0+移除背包 设置首发等于取到首发精灵后重新排序
@@ -96,7 +97,7 @@ func (h *Controller) PetRelease(
// 精灵展示 // 精灵展示
func (h *Controller) PlayerShowPet( func (h *Controller) PlayerShowPet(
data *pet.PetShowInboundInfo, c *service.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 data *pet.PetShowInboundInfo, c *player.Player) (result *pet.PetShowOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
results := pet.PetShowOutboundInfo{} results := pet.PetShowOutboundInfo{}
for _, pi := range c.Info.PetList { for _, pi := range c.Info.PetList {
@@ -112,7 +113,7 @@ func (h *Controller) PlayerShowPet(
} }
func (h *Controller) PetOneCure( func (h *Controller) PetOneCure(
data *pet.PetOneCureInboundInfo, c *service.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 data *pet.PetOneCureInboundInfo, c *player.Player) (result *pet.PetOneCureOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetOneCureOutboundInfo{ result = &pet.PetOneCureOutboundInfo{
data.CatchTime, data.CatchTime,
} }
@@ -146,7 +147,7 @@ func (h *Controller) PetOneCure(
// 精灵首发 // 精灵首发
func (h *Controller) PetFirst( func (h *Controller) PetFirst(
data *pet.PetDefaultInboundInfo, c *service.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 data *pet.PetDefaultInboundInfo, c *player.Player) (result *pet.PetDefaultOutboundInfo, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.PetDefaultOutboundInfo{} result = &pet.PetDefaultOutboundInfo{}
var ttt []model.PetInfo var ttt []model.PetInfo

View File

@@ -2,12 +2,13 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/player"
"blazing/logic/service/room" "blazing/logic/service/room"
) )
// 获取基地物品 // 获取基地物品
func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *service.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *player.Player) (result *room.FitmentUseringOutboundInfo, err errorcode.ErrorCode) {
result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID} result = &room.FitmentUseringOutboundInfo{UserId: c.Info.UserID, RoomId: data.TargetUserID}
result.Fitments = make([]room.FitmentShowInfo, 0) result.Fitments = make([]room.FitmentShowInfo, 0)
@@ -17,14 +18,14 @@ func (h Controller) OnFitmentUsering(data *room.FitmentUseringInboundInfo, c *se
} }
// 获取基地展示精灵 // 获取基地展示精灵
func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *service.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnGetRoomPetShowInfo(data *room.PetRoomListInboundInfo, c *player.Player) (result *room.PetRoomListOutboundInfo, err errorcode.ErrorCode) {
result = &room.PetRoomListOutboundInfo{} result = &room.PetRoomListOutboundInfo{}
result.Pets = make([]room.PetShowInfo, 0) result.Pets = make([]room.PetShowInfo, 0)
return return
} }
// 获取自己房间的家具 // 获取自己房间的家具
func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *service.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) { func (h Controller) OnGetFitmentAll(data *room.FitmentAllInboundEmpty, c *player.Player) (result *room.FitmentAllOutboundInfo, err errorcode.ErrorCode) {
result = &room.FitmentAllOutboundInfo{} result = &room.FitmentAllOutboundInfo{}
result.Fitments = make([]room.FitmentItemInfo, 0) result.Fitments = make([]room.FitmentItemInfo, 0)

View File

@@ -2,11 +2,12 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/player"
"blazing/logic/service/systemtime" "blazing/logic/service/systemtime"
) )
func (h Controller) SystemTimeInfo(data *systemtime.InInfo, c *service.Player) (result *systemtime.OutInfo, err errorcode.ErrorCode) { func (h Controller) SystemTimeInfo(data *systemtime.InInfo, c *player.Player) (result *systemtime.OutInfo, err errorcode.ErrorCode) {
return systemtime.NewOutInfo(), 0 return systemtime.NewOutInfo(), 0
} }

View File

@@ -2,7 +2,8 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service"
"blazing/logic/service/player"
"blazing/logic/service/task" "blazing/logic/service/task"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"math/rand" "math/rand"
@@ -12,7 +13,7 @@ import (
/** /**
* 接受任务 * 接受任务
*/ */
func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *service.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) { func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *player.Player) (result *task.AcceptTaskOutboundInfo, err errorcode.ErrorCode) {
//isdaliy := false //isdaliy := false
// if data.Head.CMD != 2201 { //判断是每日任务 // if data.Head.CMD != 2201 { //判断是每日任务
// //isdaliy = true // //isdaliy = true
@@ -30,7 +31,7 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *service.Play
/** /**
* 更新任务步骤 * 更新任务步骤
*/ */
func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *service.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) { func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) {
// isdaliy := false // isdaliy := false
// if data.Head.CMD != 2204 { //判断是每日任务 // if data.Head.CMD != 2204 { //判断是每日任务
// isdaliy = true // isdaliy = true
@@ -64,7 +65,7 @@ func randInt0To24() int {
/** /**
* 完成任务 * 完成任务
*/ */
func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *service.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.Player) (result *task.CompleteTaskOutboundInfo, err errorcode.ErrorCode) {
if c.Info.TaskList[data.TaskId-1] != 1 { //如果任务没有接受或者已经完成Complete_Task if c.Info.TaskList[data.TaskId-1] != 1 { //如果任务没有接受或者已经完成Complete_Task
@@ -117,7 +118,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *service
/** /**
* 获取任务状态 * 获取任务状态
*/ */
func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *service.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *player.Player) (result *task.GetTaskBufOutboundInfo, err errorcode.ErrorCode) {
info, _ := c.Service.TaskInfo(data.TaskId) info, _ := c.Service.TaskInfo(data.TaskId)
result = &task.GetTaskBufOutboundInfo{} result = &task.GetTaskBufOutboundInfo{}
result.TaskId = data.TaskId result.TaskId = data.TaskId
@@ -129,7 +130,7 @@ func (h Controller) Get_Task_Buf(data *task.GetTaskBufInboundInfo, c *service.Pl
/** /**
* 删除任务 * 删除任务
*/ */
func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *service.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Delete_Task(data *task.DeleteTaskInboundInfo, c *player.Player) (result *task.DeleteTaskOutboundInfo, err errorcode.ErrorCode) {
// if data.Head.CMD == 2205 { //判断不是每日任务 // if data.Head.CMD == 2205 { //判断不是每日任务

View File

@@ -2,16 +2,16 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/logic/service" "blazing/logic/service/maps"
"blazing/logic/service/space" "blazing/logic/service/player"
"context" "context"
"github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/os/glog"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
) )
func (h Controller) Walk(data *space.InInfo, c *service.Player) (result *space.OutInfo, err errorcode.ErrorCode) { func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *maps.WalkOutInfo, err errorcode.ErrorCode) {
result = &space.OutInfo{} result = &maps.WalkOutInfo{}
err1 := copier.Copy(result, data) err1 := copier.Copy(result, data)
result.UserID = data.Head.UserID result.UserID = data.Head.UserID
glog.Debug(context.Background(), err1) glog.Debug(context.Background(), err1)

View File

@@ -8,7 +8,7 @@ import (
"github.com/gogf/gf/v2/os/gproc" "github.com/gogf/gf/v2/os/gproc"
_ "blazing/contrib/drivers/pgsql" _ "blazing/contrib/drivers/pgsql"
"blazing/logic/service" "blazing/logic/service/fight"
"blazing/cool" "blazing/cool"
@@ -18,7 +18,7 @@ import (
) )
func signalHandlerForMain(sig os.Signal) { func signalHandlerForMain(sig os.Signal) {
service.Fightpool.Release() fight.Fightpool.Release()
fmt.Println("MainProcess is shutting down due to signal:", sig.String()) fmt.Println("MainProcess is shutting down due to signal:", sig.String())
} }

View File

@@ -6,7 +6,8 @@ import (
"blazing/cool" "blazing/cool"
"blazing/logic/controller" "blazing/logic/controller"
"blazing/logic/service" "blazing/logic/service/player"
blservice "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service"
"fmt" "fmt"
@@ -63,7 +64,7 @@ func isPortAvailable(port int) bool {
// 如果id是0,那就是login server // 如果id是0,那就是login server
func Start(serverid uint16) { func Start(serverid uint16) {
//ants.NewPool(100) //ants.NewPool(100)
head := service.NewTomeeHandler() head := player.NewTomeeHandler()
head.Callback = controller.Recv head.Callback = controller.Recv
if serverid != 0 { //logic服务器 if serverid != 0 { //logic服务器
// 确定端口 // 确定端口

View File

@@ -2,7 +2,7 @@ package commendsvr
import ( import (
"blazing/cool" "blazing/cool"
"blazing/logic/service" "blazing/logic/service/player"
baseservice "blazing/modules/base/service" baseservice "blazing/modules/base/service"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
@@ -12,7 +12,7 @@ import (
//var _ entity.Blazingservice = (*SidInfo)(nil) //var _ entity.Blazingservice = (*SidInfo)(nil)
type SidInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type SidInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head service.TomeeHeader `cmd:"105" struc:"[0]pad"` //玩家登录 Head player.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"`
@@ -22,7 +22,7 @@ type SidInfo struct { //这里直接使用组合来实现将传入的原始头
// CommendSvrInfo 初始连接请求信息结构体 // CommendSvrInfo 初始连接请求信息结构体
type CommendSvrInfo struct { type CommendSvrInfo struct {
//Handler service.TomeeHeader //` struc:"[0]pad"` //消息头 ,这里为传入的头部数据,遍历此头部实现解析CommendSvrInfo //Handler player.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
@@ -38,7 +38,7 @@ type CommendSvrInfo struct {
// IsVip 和 ServerInfoLen 字段被初始化为 0 // IsVip 和 ServerInfoLen 字段被初始化为 0
func NewInInfo() *CommendSvrInfo { func NewInInfo() *CommendSvrInfo {
return &CommendSvrInfo{ return &CommendSvrInfo{
// Handler: service.TomeeHeader{}, // Handler: player.TomeeHeader{},
// MaxOnlineID: 100, // MaxOnlineID: 100,
IsVip: 0, IsVip: 0,
ServerInfoLen: 0, ServerInfoLen: 0,

View File

@@ -0,0 +1,13 @@
package common
import "blazing/logic/service/fight/info"
type FightI interface {
Escape(c PlayerI) //逃跑
UseSkill(c PlayerI, id int32) //使用技能
GetCurrPET(c PlayerI) *info.BattlePetEntity //当前精灵
Ownerid() uint32
ReadyFight(c PlayerI) //是否准备战斗
ChangePet(c PlayerI, id uint32)
Capture(c PlayerI, id uint32)
}

View File

@@ -0,0 +1,21 @@
package common
import (
"blazing/logic/service/fight/info"
"blazing/modules/blazing/model"
)
type PlayerI interface {
ID() uint32
MapID() uint32
GetAction()
GetPetInfo() []model.PetInfo
SendPack(b []byte) error
SendReadyToFightInfo(info.FightStartOutboundInfo)
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
SendFightEndInfo(info.FightOverInfo)
GetInfo() model.PlayerInfo
SendAttackValue(info.AttackValueS)
SendChangePet(info.ChangePetInfo)
SetFightC(FightI)
}

View File

@@ -1,6 +1,8 @@
package info package fight
import ( import (
"blazing/logic/service/common"
"blazing/logic/service/fight/info"
"time" "time"
"github.com/tnnmigga/enum" "github.com/tnnmigga/enum"
@@ -69,10 +71,10 @@ type BattleActionI interface {
// SelectSkillAction 选择技能的战斗动作 // SelectSkillAction 选择技能的战斗动作
type SelectSkillAction struct { type SelectSkillAction struct {
PlayerID uint32 // 玩家ID PlayerID uint32 // 玩家ID
Skill *BattleSkillEntity // 使用的技能 Skill *info.BattleSkillEntity // 使用的技能
PetInfo *BattlePetEntity // 使用技能的宠物 PetInfo *info.BattlePetEntity // 使用技能的宠物
Attack AttackValue Attack info.AttackValue
} }
func (s *SelectSkillAction) GetPlayerID() uint32 { func (s *SelectSkillAction) GetPlayerID() uint32 {
@@ -88,7 +90,7 @@ func (s *SelectSkillAction) Priority() int {
type ActiveSwitchAction struct { type ActiveSwitchAction struct {
PlayerID uint32 // 玩家ID PlayerID uint32 // 玩家ID
Reason ChangePetInfo Reason info.ChangePetInfo
// CurrentPet BattlePetEntity // 当前在场宠物 // CurrentPet BattlePetEntity // 当前在场宠物
// TargetPet BattlePetEntity // 要切换上场的宠物 // TargetPet BattlePetEntity // 要切换上场的宠物
// SwitchReason string // 切换原因 // SwitchReason string // 切换原因
@@ -107,12 +109,9 @@ func (a *ActiveSwitchAction) GetPlayerID() uint32 {
// UsePotionAction 使用药剂的战斗动作 // UsePotionAction 使用药剂的战斗动作
type UseItemAction struct { type UseItemAction struct {
PlayerID uint32 // 玩家ID PlayerID uint32 // 玩家ID
ItemID uint32 // 药剂ID ItemID uint32 // 药剂ID
TargetPet BattlePetEntity // 药剂作用目标宠物 TargetPet info.BattlePetEntity // 药剂作用目标宠物
}
type PlayerI interface {
SendPack(b []byte) error
} }
// Priority 返回动作优先级 // Priority 返回动作优先级
@@ -126,15 +125,15 @@ func (e *UseItemAction) GetPlayerID() uint32 {
// EscapeAction 逃跑的战斗动作 // EscapeAction 逃跑的战斗动作
type EscapeAction struct { type EscapeAction struct {
PlayerID uint32 // 玩家ID PlayerID uint32 // 玩家ID
Reason FightOverInfo Reason info.FightOverInfo
Our PlayerI Our common.PlayerI
Opp PlayerI Opp common.PlayerI
} }
func (e *EscapeAction) GetPlayerID() uint32 { func (e *EscapeAction) GetPlayerID() uint32 {
return e.PlayerID return e.PlayerID
} }
func (e *EscapeAction) GetInfo() FightOverInfo { func (e *EscapeAction) GetInfo() info.FightOverInfo {
return e.Reason return e.Reason
} }
@@ -145,9 +144,9 @@ func (e *EscapeAction) Priority() int {
// SystemGiveUpAction 系统强制放弃出手的动作 // SystemGiveUpAction 系统强制放弃出手的动作
type SystemGiveUpAction struct { type SystemGiveUpAction struct {
PlayerID uint32 // 玩家ID PlayerID uint32 // 玩家ID
Reason string // 放弃原因如没有PP值、宠物全部倒下等 Reason string // 放弃原因如没有PP值、宠物全部倒下等
LastPet BattlePetEntity // 最后在场的宠物 LastPet info.BattlePetEntity // 最后在场的宠物
} }
func (s *SystemGiveUpAction) GetPlayerID() uint32 { func (s *SystemGiveUpAction) GetPlayerID() uint32 {
@@ -169,7 +168,7 @@ func (s *SystemGiveUpAction) Broadcast() {
type PlayerOfflineAction struct { type PlayerOfflineAction struct {
PlayerID uint32 // 掉线玩家ID PlayerID uint32 // 掉线玩家ID
OfflineTime time.Time // 掉线时间 OfflineTime time.Time // 掉线时间
Reason FightOverInfo Reason info.FightOverInfo
} }
// Priority 返回动作优先级 // Priority 返回动作优先级

View File

@@ -1,13 +1,13 @@
package fight package fight
import ( import (
"blazing/logic/service" _ "blazing/logic/service/fight/effect"
_ "blazing/logic/service/fight/battle/effect" "blazing/logic/service/player"
) )
// 野怪对战包 // 野怪对战包
type FightNpcMonsterInboundInfo struct { type FightNpcMonsterInboundInfo struct {
Head service.TomeeHeader `cmd:"2408" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2408" struc:"[0]pad"`
// Number 地图刷新怪物结构体对应的序号1-9的位置序号 // Number 地图刷新怪物结构体对应的序号1-9的位置序号
// @UInt long类型使用uint32保持无符号特性 // @UInt long类型使用uint32保持无符号特性
Number uint32 `fieldDesc:"地图刷新怪物结构体对应的序号 1 - 9 的位置序号" ` Number uint32 `fieldDesc:"地图刷新怪物结构体对应的序号 1 - 9 的位置序号" `
@@ -18,21 +18,21 @@ type NullOutboundInfo struct {
// 准备战斗包 // 准备战斗包
type ReadyToFightInboundInfo struct { type ReadyToFightInboundInfo struct {
Head service.TomeeHeader `cmd:"2404" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2404" struc:"[0]pad"`
} }
// 战斗逃跑 // 战斗逃跑
type EscapeFightInboundInfo struct { type EscapeFightInboundInfo struct {
Head service.TomeeHeader `cmd:"2410" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2410" struc:"[0]pad"`
} }
// HandleFightInviteInboundInfo 处理战斗邀请的入站消息 // HandleFightInviteInboundInfo 处理战斗邀请的入站消息
// 回空包就行 // 回空包就行
type HandleFightInviteInboundInfo struct { type HandleFightInviteInboundInfo struct {
Head service.TomeeHeader `cmd:"2403" struc:"[0]pad"` Head player.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 uint32 `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6 Mode uint32 `json:"mode" codec:"mode,uint"` // 战斗类型 1 = 1v1 2 = 6v6
} }
// 2502的回复包 PVP邀请消息 // 2502的回复包 PVP邀请消息
@@ -44,17 +44,17 @@ type NoteHandleFightInviteOutboundInfo struct {
// 实现入站消息接口Go中通过方法集隐式实现 // 实现入站消息接口Go中通过方法集隐式实现
type UseSkillInboundInfo struct { type UseSkillInboundInfo struct {
Head service.TomeeHeader `cmd:"2405" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2405" struc:"[0]pad"`
// 技能id // 技能id
SkillId uint32 SkillId uint32
} }
type ChangePetInboundInfo struct { type ChangePetInboundInfo struct {
Head service.TomeeHeader `cmd:"2407" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2407" struc:"[0]pad"`
// CatchTime 捕捉时间 // CatchTime 捕捉时间
CatchTime uint32 `json:"catchTime"` CatchTime uint32 `json:"catchTime"`
} }
type CatchMonsterInboundInfo struct { type CatchMonsterInboundInfo struct {
Head service.TomeeHeader `cmd:"2409" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2409" struc:"[0]pad"`
// CapsuleId 胶囊id // CapsuleId 胶囊id
// 对应Java的@UInt long类型映射为uint64 // 对应Java的@UInt long类型映射为uint64
CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"` CapsuleId uint32 `json:"capsuleId" fieldDescription:"胶囊id" uint:"true"`

View File

@@ -1,8 +1,7 @@
package effect package effect
import ( import (
"blazing/logic/service/fight/battle/node" "blazing/logic/service/fight/node"
"blazing/logic/service/fight/info"
) )
/** /**
@@ -13,7 +12,7 @@ type Effect1 struct {
} }
func init() { func init() {
info.InitEffect(1, &Effect1{}) node.InitEffect(1, &Effect1{})
} }

View File

@@ -1,8 +1,7 @@
package effect package effect
import ( import (
"blazing/logic/service/fight/battle/node" "blazing/logic/service/fight/node"
"blazing/logic/service/fight/info"
) )
/** /**
@@ -14,7 +13,7 @@ type Effect62 struct {
} }
func init() { func init() {
info.InitEffect(62, &Effect62{ node.InitEffect(62, &Effect62{
EffectNode: node.EffectNode{ EffectNode: node.EffectNode{
ArgSize: 1, ArgSize: 1,
}, },

View File

@@ -1,8 +1,7 @@
package effect package effect
import ( import (
"blazing/logic/service/fight/battle/node" "blazing/logic/service/fight/node"
"blazing/logic/service/fight/info"
) )
/** /**
@@ -13,7 +12,7 @@ type Effect67 struct {
} }
func init() { func init() {
info.InitEffect(67, &Effect67{ node.InitEffect(67, &Effect67{
EffectNode: node.EffectNode{ EffectNode: node.EffectNode{
ArgSize: 1, ArgSize: 1,
}, },

View File

@@ -1,8 +1,7 @@
package effect package effect
import ( import (
"blazing/logic/service/fight/battle/node" "blazing/logic/service/fight/node"
"blazing/logic/service/fight/info"
) )
/** /**
@@ -10,7 +9,7 @@ import (
*/ */
func init() { func init() {
info.InitEffect(9, &Effect9{ node.InitEffect(9, &Effect9{
EffectNode: node.EffectNode{ EffectNode: node.EffectNode{
ArgSize: 2, ArgSize: 2,
}, },

View File

@@ -1,19 +1,18 @@
package effect package effect
import ( import (
"blazing/logic/service/fight/battle/node" "blazing/logic/service/fight/node"
"blazing/logic/service/fight/info"
) )
func init() { func init() {
//技能使用成功时m%自身XX等级+/-n //技能使用成功时m%自身XX等级+/-n
info.InitEffect(4, NewEffectStat(false)) node.InitEffect(4, NewEffectStat(false))
//技能使用成功时m%对方XX等级+/-n //技能使用成功时m%对方XX等级+/-n
info.InitEffect(5, NewEffectStat(true)) node.InitEffect(5, NewEffectStat(true))
} }
func NewEffectStat(b bool) info.Effect { func NewEffectStat(b bool) node.Effect {
return &EffectStat{ return &EffectStat{
node.EffectNode{ node.EffectNode{

View File

@@ -1,13 +1,17 @@
package service package fight
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/logic/service/fight/input"
"blazing/logic/service/fight/node"
"blazing/logic/service/player"
"fmt" "fmt"
"math" "math"
"math/rand" "math/rand"
"sort"
"time" "time"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"
@@ -17,50 +21,26 @@ import (
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
type PlayerI interface {
ID() uint32
MapID() uint32
GetAction()
GetPetInfo() []model.PetInfo
SendPack(b []byte) error
SendReadyToFightInfo(info.FightStartOutboundInfo)
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
SendFightEndInfo(info.FightOverInfo)
SendAttackValue(info.AttackValueS)
SendChangePet(info.ChangePetInfo)
SetFightC(*FightC)
}
type Input struct {
CanChange bool //是否可以死亡切换CanChange
CurrentPet *info.BattlePetEntity //当前精灵
AllPet []*info.BattlePetEntity
Player PlayerI
Finished bool //是否加载完成
}
func (i *Input) GetPetInfo() *info.BattlePetEntity {
return i.CurrentPet
}
type FightC struct { type FightC struct {
Info info.NoteReadyToFightInfo Info info.NoteReadyToFightInfo
OwnerID uint32 // 战斗发起者ID ownerID uint32 // 战斗发起者ID
Our *Input //始终等于房主ID Our *input.Input //始终等于房主ID
Opp *Input //对手ID Opp *input.Input //对手ID
rand *rand.Rand rand *rand.Rand
StartTime time.Time StartTime time.Time
actionChan chan info.BattleActionI // 所有操作统一从这里进入 actionChan chan BattleActionI // 所有操作统一从这里进入
Round int //回合数 Round int //回合数
EffectS info.NodeManager //effects容器 EffectS node.NodeManager //effects容器
First *BPET First *input.Input
Second *BPET Second *input.Input
} }
func (f *FightC) GetInputByPlayer(c PlayerI, isOpposite bool) *Input { func (f *FightC) Ownerid() uint32 {
return f.ownerID
}
func (f *FightC) GetInputByPlayer(c common.PlayerI, isOpposite bool) *input.Input {
// 判断当前玩家是否为我方玩家 // 判断当前玩家是否为我方玩家
isOurPlayer := c == f.Our.Player isOurPlayer := c == f.Our.Player
@@ -71,7 +51,7 @@ func (f *FightC) GetInputByPlayer(c PlayerI, isOpposite bool) *Input {
return f.Our return f.Our
} }
func (f *FightC) GetInputByAction(c info.BattleActionI, isOpposite bool) *Input { func (f *FightC) GetInputByAction(c BattleActionI, isOpposite bool) *input.Input {
// 判断动作所属玩家是否为我方 // 判断动作所属玩家是否为我方
isOurAction := c.GetPlayerID() == f.Our.Player.ID() isOurAction := c.GetPlayerID() == f.Our.Player.ID()
@@ -83,8 +63,8 @@ func (f *FightC) GetInputByAction(c info.BattleActionI, isOpposite bool) *Input
} }
// 玩家逃跑 // 玩家逃跑
func (f *FightC) Escape(c PlayerI) { func (f *FightC) Escape(c common.PlayerI) {
ret := &info.EscapeAction{ ret := &EscapeAction{
PlayerID: c.ID(), PlayerID: c.ID(),
Reason: info.FightOverInfo{ Reason: info.FightOverInfo{
@@ -96,8 +76,8 @@ func (f *FightC) Escape(c PlayerI) {
} }
// 玩家掉线 // 玩家掉线
func (f *FightC) Offline(c PlayerI) { func (f *FightC) Offline(c common.PlayerI) {
ret := &info.PlayerOfflineAction{ ret := &PlayerOfflineAction{
PlayerID: c.ID(), PlayerID: c.ID(),
Reason: info.FightOverInfo{ Reason: info.FightOverInfo{
@@ -109,37 +89,24 @@ func (f *FightC) Offline(c PlayerI) {
} }
// 切换精灵 主动和被驱逐 // 切换精灵 主动和被驱逐
func (f *FightC) ChangePet(c PlayerI, id int32) { func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
ret := &info.ActiveSwitchAction{ ret := &ActiveSwitchAction{
PlayerID: c.ID(), PlayerID: c.ID(),
} }
rett := func(t *Input) *info.BattlePetEntity { f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id)
for _, v := range t.AllPet {
if v.Info.CatchTime == uint32(id) {
copier.Copy(&ret.Reason, &v.Info)
ret.Reason.UserId = c.ID()
return v
}
}
return nil
}
f.GetInputByPlayer(c, false).CurrentPet = rett(f.GetInputByPlayer(c, false))
f.actionChan <- ret f.actionChan <- ret
} }
// 玩家使用技能 // 玩家使用技能
func (f *FightC) UseSkill(c PlayerI, id int32) { func (f *FightC) UseSkill(c common.PlayerI, id int32) {
if id == 0 { if id == 0 {
f.actionChan <- &info.SystemGiveUpAction{PlayerID: c.ID()} f.actionChan <- &SystemGiveUpAction{PlayerID: c.ID()}
return return
} }
ret := &info.SelectSkillAction{ ret := &SelectSkillAction{
PlayerID: c.ID(), PlayerID: c.ID(),
} }
ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
@@ -155,13 +122,23 @@ func (f *FightC) UseSkill(c PlayerI, id int32) {
} }
// 玩家使用技能 // 玩家使用技能
func (f *FightC) Capture(c PlayerI, id uint32) { func (f *FightC) Capture(c common.PlayerI, id uint32) {
f.actionChan <- &UseItemAction{PlayerID: c.ID(), ItemID: id}
}
// 玩家使用技能
func (f *FightC) GetCurrPET(c common.PlayerI) *info.BattlePetEntity {
if f.Our.Player.ID() == c.ID() {
return f.Our.CurrentPet
} else {
return f.Opp.CurrentPet
}
f.actionChan <- &info.UseItemAction{PlayerID: c.ID(), ItemID: id}
} }
// 战斗准备 // 战斗准备
func (f *FightC) ReadyFight(c PlayerI) { func (f *FightC) ReadyFight(c common.PlayerI) {
rett := info.FightStartOutboundInfo{} rett := info.FightStartOutboundInfo{}
copier.Copy(&rett.Info1, &f.Info.OurPetList[0]) // 复制自己的信息 copier.Copy(&rett.Info1, &f.Info.OurPetList[0]) // 复制自己的信息
@@ -188,7 +165,7 @@ func (f *FightC) ReadyFight(c PlayerI) {
//判断捕捉率大于0 //判断捕捉率大于0
if gconv.Int(xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate) > 0 { if gconv.Int(xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate) > 0 {
rett.Info2.Catchable = 1 rett.Info2.Catchable = 1
t, _ := f.Opp.Player.(*AI_player) t, _ := f.Opp.Player.(*player.AI_player)
t.CanCapture = true t.CanCapture = true
} }
@@ -203,54 +180,135 @@ func init() {
Fightpool, _ = ants.NewPool(math.MaxInt32) Fightpool, _ = ants.NewPool(math.MaxInt32)
//defer p.Release() //defer p.Release()
} }
func (f *FightC) initplayer(c common.PlayerI, opp bool) {
temp := &input.Input{Player: c}
temp.AllPet = make([]*info.BattlePetEntity, 0)
for i := 0; i < len(c.GetPetInfo()); i++ {
if f.Info.MAXPET == 0 || i < int(f.Info.MAXPET) {
temp.AllPet = append(temp.AllPet, info.CreateBattlePetEntity(&c.GetPetInfo()[i], f.rand))
}
}
// for k, v := range c.GetPetInfo() {
// if f.Info.MAXPET == 0 || k < int(f.Info.MAXPET) {
// temppet := v //这里必须先复制,否则会导致字段混乱
// temp.AllPet = append(temp.AllPet, info.CreateBattlePetEntity(&temppet, f.rand))
// }
// }
// // 排序:血量>0的放前面血量=0的放后面同类型保持原有顺序
sort.Slice(temp.AllPet, func(i, j int) bool {
x, y := temp.AllPet[i], temp.AllPet[j]
// 若x血量>0且y血量=0则x排在前
if x.Info.Hp > 0 && y.Info.Hp <= 0 {
return true
}
// 若x血量=0且y血量>0则x排在后
if x.Info.Hp <= 0 && y.Info.Hp > 0 {
return false
}
// 同类型(都>0或都=0保持原有顺序
return i < j
})
if opp {
f.Opp = temp //这里是对方的
copier.Copy(&f.Info.OpponentInfo, f.Opp.Player.GetInfo())
f.Info.OpponentPetList = make([]info.ReadyFightPetInfo, len(temp.AllPet))
for i := 0; i < len(temp.AllPet); i++ {
err := copier.CopyWithOption(&f.Info.OpponentPetList[i], temp.AllPet[i].Info, copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err != nil {
panic(err)
}
}
} else {
f.Our = temp
copier.Copy(&f.Info.OurInfo, f.Our.Player.GetInfo())
f.Info.OurPetList = make([]info.ReadyFightPetInfo, len(temp.AllPet))
for i := 0; i < len(temp.AllPet); i++ {
err := copier.CopyWithOption(&f.Info.OurPetList[i], &temp.AllPet[i].Info, copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err != nil {
panic(err)
}
}
}
for _, v := range temp.AllPet {
if v.Info.Hp == 0 {
v.NotAlive = true
}
}
temp.CurrentPet = temp.AllPet[0]
c.SetFightC(f)
}
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方 // 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
func NewFight(i info.NoteReadyToFightInfo, p1 PlayerI, p2 PlayerI) *FightC { func NewFight(i info.EnumBattleMode, p1 common.PlayerI, p2 common.PlayerI) *FightC {
f := &FightC{} f := &FightC{}
f.OwnerID = p1.ID() f.ownerID = p1.ID()
f.Info = i //房主 f.Info.FightId = i //房主
seed := f.StartTime.UnixNano() ^ int64(p1.ID()) ^ int64(p2.ID()) // ^ int64(f.Round) // 用异或运算混合多维度信息 seed := f.StartTime.UnixNano() ^ int64(p1.ID()) ^ int64(p2.ID()) // ^ int64(f.Round) // 用异或运算混合多维度信息
f.rand = rand.New(rand.NewSource(seed)) f.rand = rand.New(rand.NewSource(seed))
f.Info = info.NoteReadyToFightInfo{
f.Our = &Input{ FightId: i,
CurrentPet: info.CreateBattlePetEntity(&p1.GetPetInfo()[0], f.rand),
Player: p1,
} }
for k, v := range p1.GetPetInfo() { f.initplayer(p1, false)
if i.MAXPET == 0 || k < int(i.MAXPET) { //todo 待测试
f.Our.AllPet = append(f.Our.AllPet, info.CreateBattlePetEntity(&v, f.rand))
}
} f.initplayer(p2, true)
f.Opp = &Input{
CurrentPet: info.CreateBattlePetEntity(&p2.GetPetInfo()[0], f.rand),
Player: p2,
}
for k, v := range p2.GetPetInfo() {
if i.MAXPET == 0 || k < int(i.MAXPET) {
f.Opp.AllPet = append(f.Opp.AllPet, info.CreateBattlePetEntity(&v, f.rand))
}
}
p1.SetFightC(f) //给我方追加战斗容器
p2.SetFightC(f) //给对方增加战斗容器
defer func() { defer func() {
rr := Fightpool.Submit(f.battleLoop) rr := Fightpool.Submit(f.battleLoop)
if rr != nil { if rr != nil {
panic(rr) panic(rr)
} }
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendNoteReadyToFightInfo(i) ff.Player.SendNoteReadyToFightInfo(f.Info)
}) })
}() }()
//go f.battleLoop() // 起战斗循环 //go f.battleLoop() // 起战斗循环
return f return f
} }
// 被击败的ID
func (b *FightC) IsWin(c *input.Input, cache uint32) bool {
var tt []*info.BattlePetEntity
bbb := b.Our.AllPet
if c.Player.ID() == b.ownerID { //如果是房主
bbb = b.Opp.AllPet
} else {
bbb = b.Our.AllPet
}
for _, v := range bbb {
if v.Info.CatchTime == cache {
v.NotAlive = true
}
tt = append(tt, v)
}
for _, v := range tt {
if !v.NotAlive { //如果存活
return false
}
}
return true
}
// 广播,并是否结束回合 // 广播,并是否结束回合
func (f *FightC) Broadcast(t func(ff *Input)) { func (f *FightC) Broadcast(t func(ff *input.Input)) {
t(f.Our) t(f.Our)
@@ -261,7 +319,7 @@ func (f *FightC) Broadcast(t func(ff *Input)) {
// 战斗回合循环 // 战斗回合循环
func (f *FightC) battleLoop() { func (f *FightC) battleLoop() {
f.StartTime = time.Now() f.StartTime = time.Now()
f.actionChan = make(chan info.BattleActionI, 2) // 初始化全局操作通道 f.actionChan = make(chan BattleActionI, 2) // 初始化全局操作通道
fmt.Println("战斗开始精灵", f.Our.Player.GetPetInfo()[0].CatchTime) fmt.Println("战斗开始精灵", f.Our.Player.GetPetInfo()[0].CatchTime)
//战斗开始前操作 //战斗开始前操作
@@ -272,7 +330,7 @@ func (f *FightC) battleLoop() {
if f.actionChan == nil { //回合数超过250,战斗平局结束f.Round > 250 || if f.actionChan == nil { //回合数超过250,战斗平局结束f.Round > 250 ||
break break
} }
actions := make(map[uint32]info.BattleActionI) // 每个玩家一条记录 actions := make(map[uint32]BattleActionI) // 每个玩家一条记录
timeout := time.After(60 * time.Second) timeout := time.After(60 * time.Second)
for len(actions) < 2 { for len(actions) < 2 {
@@ -287,9 +345,9 @@ func (f *FightC) battleLoop() {
continue continue
} }
if a, isExpelled := action.(*info.ActiveSwitchAction); isExpelled { if a, isExpelled := action.(*ActiveSwitchAction); isExpelled {
//fmt.Println("对方死亡切换") //fmt.Println("对方死亡切换")
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendChangePet(a.Reason) ff.Player.SendChangePet(a.Reason)
}) })
@@ -322,10 +380,10 @@ func (f *FightC) battleLoop() {
fmt.Println("回合操作超时") fmt.Println("回合操作超时")
if _, exists := actions[f.Our.Player.ID()]; !exists { if _, exists := actions[f.Our.Player.ID()]; !exists {
actions[f.Our.Player.ID()] = &info.SystemGiveUpAction{PlayerID: f.Our.Player.ID()} //系统选择出手 actions[f.Our.Player.ID()] = &SystemGiveUpAction{PlayerID: f.Our.Player.ID()} //系统选择出手
} }
if _, exists := actions[f.Opp.Player.ID()]; !exists { if _, exists := actions[f.Opp.Player.ID()]; !exists {
actions[f.Opp.Player.ID()] = &info.SystemGiveUpAction{PlayerID: f.Opp.Player.ID()} //系统选择出手 actions[f.Opp.Player.ID()] = &SystemGiveUpAction{PlayerID: f.Opp.Player.ID()} //系统选择出手
} }
} }
} }
@@ -335,35 +393,35 @@ func (f *FightC) battleLoop() {
p1Action := actions[f.Our.Player.ID()] p1Action := actions[f.Our.Player.ID()]
p2Action := actions[f.Opp.Player.ID()] p2Action := actions[f.Opp.Player.ID()]
fmt.Println("开始结算回合") fmt.Println("开始结算回合")
var BattleActionI [2]info.BattleActionI var BattleActionI [2]BattleActionI
BattleActionI[0], BattleActionI[1] = info.Compare(p1Action, p2Action) BattleActionI[0], BattleActionI[1] = Compare(p1Action, p2Action)
switch faction := BattleActionI[0].(type) { switch faction := BattleActionI[0].(type) {
case *info.EscapeAction: //优先逃跑 case *EscapeAction: //优先逃跑
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因 ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因
}) })
break break
case *info.PlayerOfflineAction: //单方掉线 case *PlayerOfflineAction: //单方掉线
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因 ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因
}) })
break break
case *info.ActiveSwitchAction: //切换上场的 case *ActiveSwitchAction: //切换上场的
f.enterturn(BattleActionI[1], nil) //切换,相当于后手直接出手 f.enterturn(BattleActionI[1], nil) //切换,相当于后手直接出手
case *info.UseItemAction: //使用道具 case *UseItemAction: //使用道具
fmt.Println(faction.ItemID) fmt.Println(faction.ItemID)
switch { switch {
case faction.ItemID >= 30001 && faction.ItemID <= 300010: //胶囊 case faction.ItemID >= 30001 && faction.ItemID <= 300010: //胶囊
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
//todo 将血量和技能pp传回enterturn //todo 将血量和技能pp传回enterturn
tt, ok := ff.Player.(*Player) tt, ok := ff.Player.(*player.Player)
mo, ism := f.Opp.Player.(*AI_player) mo, ism := f.Opp.Player.(*player.AI_player)
if ok { //如果获取玩家 if ok { //如果获取玩家
@@ -381,7 +439,7 @@ func (f *FightC) battleLoop() {
ff.Player.SendFightEndInfo(info.FightOverInfo{ ff.Player.SendFightEndInfo(info.FightOverInfo{
WinnerId: f.OwnerID, WinnerId: f.ownerID,
}) })
}) })
@@ -395,7 +453,7 @@ func (f *FightC) battleLoop() {
fmt.Println("ItemID 不在指定范围内") fmt.Println("ItemID 不在指定范围内")
} }
case *info.SelectSkillAction: //选择技能 case *SelectSkillAction: //选择技能
//回合前操作,比如挂载buff //回合前操作,比如挂载buff
f.enterturn(BattleActionI[0], BattleActionI[1]) f.enterturn(BattleActionI[0], BattleActionI[1])
@@ -407,53 +465,12 @@ func (f *FightC) battleLoop() {
} }
type BPET struct {
*Input
//*info.SelectSkillAction //技能实体
*info.BattlePetEntity //精灵实体
*info.AttackValue
*FightC
info.BattleActionI
Damage decimal.Decimal //造成伤害
}
// 被击败的ID
func (b *BPET) IsWin(cache uint32) bool {
fmt.Println("当前回合", b.FightC.Round, "开始检查战斗是否结束")
var tt []info.ReadyFightPetInfo
bbb := b.FightC.Info.OurPetList
if b.Input.Player.ID() == b.FightC.OwnerID { //如果是房主
bbb = b.FightC.Info.OpponentPetList
} else {
bbb = b.FightC.Info.OurPetList
}
for _, v := range bbb {
if v.CatchTime == cache {
v.NotAlive = true
}
tt = append(tt, v)
}
for _, v := range tt {
if !v.NotAlive { //如果存活
return false
}
}
return true
}
// 解析并 施加effect // 解析并 施加effect
func (f *FightC) parseskill(id *info.SelectSkillAction) { func (f *FightC) parseskill(id *SelectSkillAction) {
temparg := id.Skill.SideEffectArgS temparg := id.Skill.SideEffectArgS
for _, v := range id.Skill.SideEffectS { for _, v := range id.Skill.SideEffectS {
t, ok := info.NodeM[v] t, ok := node.NodeM[v]
if ok { //获取成功 if ok { //获取成功
@@ -461,43 +478,33 @@ func (f *FightC) parseskill(id *info.SelectSkillAction) {
t.SetArgs(temparg[:args]) //设置入参 t.SetArgs(temparg[:args]) //设置入参
//如果不是是房主方,说明施加的对象是反的,比如本来是false,实际上是给邀请方施加的 //如果不是是房主方,说明施加的对象是反的,比如本来是false,实际上是给邀请方施加的
//所以这里要对target取反 //所以这里要对target取反
if id.GetPlayerID() != f.OwnerID { if id.GetPlayerID() != f.ownerID {
t.SetOwner(!t.GetOwner()) t.SetOwner(!t.GetOwner())
} }
temparg = temparg[args:] temparg = temparg[args:]
f.EffectS.AddEffect(deepcopy.Copy(t).(info.Effect)) f.EffectS.AddEffect(deepcopy.Copy(t).(node.Effect))
} }
} }
} }
// 创建BPET实例的辅助函数 func (f *FightC) initAttackers(fattack, sattack BattleActionI) {
func (f *FightC) newBPET(input *Input) *BPET {
return &BPET{
FightC: f,
Input: input,
BattlePetEntity: input.CurrentPet,
AttackValue: info.NewAttackValue(input.Player.ID()),
}
}
func (f *FightC) initAttackers(fattack, sattack info.BattleActionI) {
// 伤害值 // 伤害值
// 根据攻击方归属设置当前战斗的主/次攻击方属性 // 根据攻击方归属设置当前战斗的主/次攻击方属性
var first, second *Input // 定义临时变量存储主/次攻击方
if fattack.GetPlayerID() == f.OwnerID { if fattack.GetPlayerID() == f.ownerID {
first, second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方 f.First, f.Second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方
} else { } else {
first, second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方 f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方
} }
// 统一赋值,减少重复代码 // 统一赋值,减少重复代码
f.First = f.newBPET(first) f.First.InitAttackValue()
f.Second = f.newBPET(second) f.Second.InitAttackValue()
fmt.Println("先手", f.First.CurrentPet.Info.CatchTime, "后手", f.Second.CurrentPet.Info.CatchTime) fmt.Println("先手", f.First.CurrentPet.Info.CatchTime, "后手", f.Second.CurrentPet.Info.CatchTime)
@@ -505,28 +512,28 @@ func (f *FightC) initAttackers(fattack, sattack info.BattleActionI) {
} }
// 处理技能攻击逻辑 // 处理技能攻击逻辑
func (f *FightC) processSkillAttack(attacker, defender *BPET, skill *info.SelectSkillAction) { func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *SelectSkillAction) {
f.parseskill(skill) //解析effect f.parseskill(skill) //解析effect
// 记录技能信息 // 记录技能信息
attacker.AttackValue.SkillID = uint32(skill.Skill.ID) //获取技能ID attacker.AttackValue.SkillID = uint32(skill.Skill.ID) //获取技能ID
attacker.AttackValue.AttackTime = skill.Skill.AttackTime() //计算命中 attacker.AttackValue.AttackTime = skill.Skill.AttackTime() //计算命中
f.EffectS.Exec(func(t info.Effect) bool { //计算闪避 闪避就是命中率重新计算的结果 f.EffectS.Exec(func(t node.Effect) bool { //计算闪避 闪避就是命中率重新计算的结果
//闪避本质上是算对方的命中重写函数? //闪避本质上是算对方的命中重写函数?
if attacker.UserID == f.Our.Player.ID() { if attacker.UserID == f.Our.Player.ID() {
} }
if !t.GetOwner() { //先获取对方的 if !t.GetOwner() { //先获取对方的
return t.AttackTime() return t.AttackTime(attacker, defender)
} }
return true return true
}) })
if attacker.AttackValue.AttackTime == 1 { //如果命中 if attacker.AttackValue.AttackTime == 1 { //如果命中
spower := skill.Skill.CalculatePower(defender.BattlePetEntity) spower := skill.Skill.CalculatePower(defender.CurrentPet)
attacker.Damage = spower attacker.Damage = spower
CritRate := utils.Max(skill.Skill.CritRate, 1) CritRate := utils.Max(skill.Skill.CritRate, 1)
CritRateR := f.rand.Int31n(16) CritRateR := f.rand.Int31n(16)
@@ -567,20 +574,23 @@ func (f *FightC) processSkillAttack(attacker, defender *BPET, skill *info.Select
} }
func (f *FightC) enterturn(fattack, sattack info.BattleActionI) { func (f *FightC) enterturn(fattack, sattack BattleActionI) {
f.initAttackers(fattack, sattack) //初始化先后手 f.initAttackers(fattack, sattack) //初始化先后手
var attacker, defender *BPET var attacker, defender *input.Input
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
var attackeraction BattleActionI
if i == 0 { // if i == 0 { //
attacker, defender = f.First, f.Second attacker, defender = f.First, f.Second
attacker.BattleActionI, defender.BattleActionI = fattack, sattack attackeraction = fattack
//attacker.BattleActionI, defender.BattleActionI = fattack, sattack
} else { } else {
attacker, defender = f.Second, f.First attacker, defender = f.Second, f.First
attackeraction = sattack
} }
skill, ok := attacker.BattleActionI.(*info.SelectSkillAction) skill, ok := attackeraction.(*SelectSkillAction)
if !ok { //还有系统选择放弃出手的 if !ok { //还有系统选择放弃出手的
continue continue
@@ -597,15 +607,15 @@ func (f *FightC) enterturn(fattack, sattack info.BattleActionI) {
) )
skill.Skill.Info.PP-- //减少PP skill.Skill.Info.PP-- //减少PP
if defender.CurrentPet.Info.Hp == 0 { if defender.CurrentPet.Info.Hp == 0 {
defender.CanChange = true //被打死就可以切精灵了 defender.CanChange = true //被打死就可以切精灵了
if attacker.IsWin(defender.CurrentPet.Info.CatchTime) { //然后检查是否战斗结束 if f.IsWin(attacker, defender.CurrentPet.Info.CatchTime) { //然后检查是否战斗结束
var WinnerId uint32 var WinnerId uint32
if i == 0 { if i == 0 {
WinnerId = f.First.Player.ID() WinnerId = f.First.Player.ID()
} else { } else {
WinnerId = f.Second.Player.ID() WinnerId = f.Second.Player.ID()
} }
defer f.Broadcast(func(ff *Input) { defer f.Broadcast(func(ff *input.Input) {
//todo 将血量和技能pp传回enterturn //todo 将血量和技能pp传回enterturn
ff.Player.SendFightEndInfo(info.FightOverInfo{ ff.Player.SendFightEndInfo(info.FightOverInfo{
@@ -619,7 +629,7 @@ func (f *FightC) enterturn(fattack, sattack info.BattleActionI) {
} }
f.Broadcast(func(ff *Input) { f.Broadcast(func(ff *input.Input) {
ret := info.AttackValueS{ ret := info.AttackValueS{
FAttack: *f.First.AttackValue, FAttack: *f.First.AttackValue,
SAttack: *f.Second.AttackValue, SAttack: *f.Second.AttackValue,

View File

@@ -114,6 +114,7 @@ type BattlePetEntity struct {
Status StatusDict //精灵的状态 Status StatusDict //精灵的状态
//能力提升属性 //能力提升属性
Prop PropDict Prop PropDict
NotAlive bool `struc:"skip"`
DamageZone map[EnumCategory]map[EnumsZoneType]map[EnumsZoneType][]float64 // 三维map 伤害类型-》增还是减-》加还是乘-》值 DamageZone map[EnumCategory]map[EnumsZoneType]map[EnumsZoneType][]float64 // 三维map 伤害类型-》增还是减-》加还是乘-》值
} }

View File

@@ -195,8 +195,7 @@ func (t *NoteReadyToFightInfo) onBothFinished() {
// ReadyFightPetInfo 准备战斗的精灵信息结构体ReadyFightPetInfo类 // ReadyFightPetInfo 准备战斗的精灵信息结构体ReadyFightPetInfo类
type ReadyFightPetInfo struct { type ReadyFightPetInfo struct {
// 精灵ID@UInt long // 精灵ID@UInt long
ID uint32 `fieldDesc:"精灵ID" ` ID uint32 `fieldDesc:"精灵ID" `
NotAlive bool `struc:"skip"`
// 精灵等级,@UInt long // 精灵等级,@UInt long
Level uint32 `fieldDesc:"精灵等级" ` Level uint32 `fieldDesc:"精灵等级" `

View File

@@ -0,0 +1,44 @@
package input
import (
"blazing/logic/service/common"
"blazing/logic/service/fight/info"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal"
)
type Input struct {
CanChange bool //是否可以死亡切换CanChange
CurrentPet *info.BattlePetEntity //当前精灵
AllPet []*info.BattlePetEntity
Player common.PlayerI
Finished bool //是否加载完成
*info.AttackValue
FightC common.FightI
// info.BattleActionI
Damage decimal.Decimal //造成伤害
}
func (i *Input) GetPetInfo() *info.BattlePetEntity {
return i.CurrentPet
}
func (i *Input) InitAttackValue() {
i.AttackValue = info.NewAttackValue(i.Player.ID())
}
func (i *Input) GetPet(id uint32) (ii *info.BattlePetEntity, Reason info.ChangePetInfo) {
for _, v := range i.AllPet {
if v.Info.CatchTime == uint32(id) {
copier.Copy(&Reason, &v.Info)
Reason.UserId = i.Player.ID()
ii = v
}
}
return
}

View File

@@ -1,6 +1,7 @@
package node package node
import ( import (
"blazing/logic/service/fight/input"
"context" "context"
) )
@@ -67,7 +68,7 @@ func (this *EffectNode) GetArgSize() int {
return this.ArgSize return this.ArgSize
} }
func (this *EffectNode) AttackTime() bool { func (this *EffectNode) AttackTime(*input.Input, *input.Input) bool {
return true return true

View File

@@ -1,6 +1,7 @@
package info package node
import ( import (
"blazing/logic/service/fight/input"
"reflect" "reflect"
) )
@@ -19,10 +20,10 @@ type Effect interface {
OnDamage() bool // 造成伤害时触发 OnDamage() bool // 造成伤害时触发
SetArgs(param []int) //设置参数 SetArgs(param []int) //设置参数
Shield() bool // 护盾值变化时触发 Shield() bool // 护盾值变化时触发
PostDamage() bool // 伤害结算后触发(血量扣除后) PostDamage() bool // 伤害结算后触发(血量扣除后)
AttackTime() bool //闪避率计算,,实际上是修改命中的判断 AttackTime(*input.Input, *input.Input) bool //闪避率计算,,实际上是修改命中的判断
OnCritPostDamage() bool // 暴击伤害结算后触发 OnCritPostDamage() bool // 暴击伤害结算后触发
OnHit() bool // 技能命中时触发 OnHit() bool // 技能命中时触发
OnMiss() bool // 技能未命中时触发 OnMiss() bool // 技能未命中时触发

View File

@@ -1,10 +1,10 @@
package friend package friend
import "blazing/logic/service" import "blazing/logic/service/player"
//基地查看好友列表 //基地查看好友列表
type SeeOnlineInboundInfo struct { type SeeOnlineInboundInfo struct {
Head service.TomeeHeader `cmd:"2157" struc:"[0]pad"` Head player.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,13 +1,13 @@
package item package item
import ( import (
"blazing/logic/service" "blazing/logic/service/player"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
// 实现了入站消息接口Go中通过方法集隐式实现 // 实现了入站消息接口Go中通过方法集隐式实现
type ItemListInboundInfo struct { type ItemListInboundInfo struct {
Head service.TomeeHeader `cmd:"2605" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2605" struc:"[0]pad"`
// 查询物品id的开始对应Java的@UInt long // 查询物品id的开始对应Java的@UInt long
Param1 uint32 `fieldDesc:"查询物品id的开始" messageType:"Item_List"` Param1 uint32 `fieldDesc:"查询物品id的开始" messageType:"Item_List"`
// 查询物品id的结尾对应Java的@UInt long // 查询物品id的结尾对应Java的@UInt long
@@ -25,7 +25,7 @@ type ItemListOutboundInfo struct {
// SingleItemInfo 单个物品信息结构体对应Java的SingleItemInfo类 // SingleItemInfo 单个物品信息结构体对应Java的SingleItemInfo类
type GoldOnlineRemainInboundInfo struct { type GoldOnlineRemainInboundInfo struct {
Head service.TomeeHeader `cmd:"1106" struc:"[0]pad"` Head player.TomeeHeader `cmd:"1106" struc:"[0]pad"`
} }
// GoldOnlineRemainOutboundInfo 对应Java的GoldOnlineRemainOutboundInfo // GoldOnlineRemainOutboundInfo 对应Java的GoldOnlineRemainOutboundInfo

View File

@@ -2,7 +2,7 @@ package login
import ( import (
"blazing/common/data/share" "blazing/common/data/share"
"blazing/logic/service" "blazing/logic/service/player"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"context" "context"
@@ -13,7 +13,7 @@ import (
// LoginSidInfo 登录携带的凭证结构体 // LoginSidInfo 登录携带的凭证结构体
type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head service.TomeeHeader `cmd:"1001" struc:"[0]pad"` //玩家登录 Head player.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 login package login
import "blazing/logic/service" import "blazing/logic/service/player"
type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化
Head service.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录 Head player.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 service.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录 Head player.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录
// 玩家昵称,@ArraySerialize注解 // 玩家昵称,@ArraySerialize注解
Nickname string `struc:"[16]byte"` // 固定长度16字节 Nickname string `struc:"[16]byte"` // 固定长度16字节

View File

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

View File

@@ -2,7 +2,9 @@ package maps
import ( import (
"blazing/common/data/xmlres" "blazing/common/data/xmlres"
"blazing/logic/service"
"blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
@@ -15,7 +17,7 @@ import (
) )
type InInfo struct { type InInfo struct {
Head service.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图 Head player.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图
// 地图类型 // 地图类型
MapType uint32 MapType uint32
@@ -29,7 +31,7 @@ type InInfo struct {
func (t *InInfo) Broadcast(mapid uint32, o OutInfo) { func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
space.GetSpace(mapid).Range(func(playerID uint32, player service.PlayerI) bool { space.GetSpace(mapid).Range(func(playerID uint32, player common.PlayerI) bool {
t.Head.Result = 0 t.Head.Result = 0
player.SendPack(t.Head.Pack(&o)) player.SendPack(t.Head.Pack(&o))
@@ -38,7 +40,7 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
} }
// 刷怪具体实现 // 刷怪具体实现
func (t *InInfo) SpawnMonsters(c *service.Player, isfrist bool) { func (t *InInfo) SpawnMonsters(c *player.Player, isfrist bool) {
// 获取当前地图的怪物配置 // 获取当前地图的怪物配置
if c == nil || c.Info.MapID == 0 { //用户离线 if c == nil || c.Info.MapID == 0 { //用户离线
@@ -55,7 +57,7 @@ func (t *InInfo) SpawnMonsters(c *service.Player, isfrist bool) {
} }
// 创建数据包 // 创建数据包
tt := service.NewTomeeHeader(2004, c.Info.UserID) tt := player.NewTomeeHeader(2004, c.Info.UserID)
if isfrist { if isfrist {
t.monsters = generateThreeUniqueNumbers() t.monsters = generateThreeUniqueNumbers()
@@ -81,16 +83,16 @@ func RandomStringFromSlice(s []string) string {
} }
// 应该根据怪物信息决定后端生成 // 应该根据怪物信息决定后端生成
func (t *InInfo) genMonster(mapid uint32) *service.OgreInfo { func (t *InInfo) genMonster(mapid uint32) *player.OgreInfo {
// 设置怪物信息 // 设置怪物信息
t1 := service.OgreInfo{} t1 := player.OgreInfo{}
mapss, ok := xmlres.MonsterMap[gconv.Int(mapid)] mapss, ok := xmlres.MonsterMap[gconv.Int(mapid)]
if ok && mapss.Monsters != nil { if ok && mapss.Monsters != nil {
for i, m := range mapss.Monsters.Monsters { //这里是9个 for i, m := range mapss.Monsters.Monsters { //这里是9个
id := strings.Split(m.ID, " ") id := strings.Split(m.ID, " ")
lv := strings.Split(m.Lv, " ") lv := strings.Split(m.Lv, " ")
ttt := service.OgrePetInfo{ ttt := player.OgrePetInfo{
Id: gconv.Uint32(RandomStringFromSlice(id)), Id: gconv.Uint32(RandomStringFromSlice(id)),
} }
if ttt.Id != 0 { if ttt.Id != 0 {
@@ -103,7 +105,7 @@ func (t *InInfo) genMonster(mapid uint32) *service.OgreInfo {
} }
t2 := service.OgreInfo{} t2 := player.OgreInfo{}
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
t2.Data[t.monsters[i]] = t1.Data[t.monsters[i]] t2.Data[t.monsters[i]] = t1.Data[t.monsters[i]]

View File

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

View File

@@ -1,37 +1,21 @@
package maps package maps
import ( import (
"blazing/logic/service" "blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
) )
type LeaveMapOutboundInfo struct {
// 米米号
UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"`
}
type LeaveMapInboundInfo struct { type LeaveMapInboundInfo struct {
Head service.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图 Head player.TomeeHeader `cmd:"2002" struc:"[0]pad"` //切换地图
} }
func (t *LeaveMapInboundInfo) Broadcast(mapid uint32, o LeaveMapOutboundInfo) { func (t *LeaveMapInboundInfo) Broadcast(mapid uint32, o space.LeaveMapOutboundInfo) {
space.GetSpace(mapid).Range(func(playerID uint32, player service.PlayerI) bool { space.GetSpace(mapid).Range(func(playerID uint32, player common.PlayerI) bool {
t.Head.Result = 0 t.Head.Result = 0
player.SendPack(t.Head.Pack(&o)) player.SendPack(t.Head.Pack(&o))
return true return true
}) })
} }
func LeaveMap(c service.PlayerI) {
t := service.NewTomeeHeader(2002, c.ID())
space.GetSpace(c.MapID()).Range(func(playerID uint32, player service.PlayerI) bool {
player.SendPack(t.Pack(&LeaveMapOutboundInfo{UserID: c.ID()}))
return true
})
space.GetSpace(c.MapID()).Delete(c.ID())
}

View File

@@ -1,12 +1,15 @@
package space package maps
import ( import (
"blazing/logic/service" "blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type InInfo struct { type WalkInInfo struct {
Head service.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包 Head player.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包
// Flag: 0为走1为飞行模式@UInt long // Flag: 0为走1为飞行模式@UInt long
Flag uint32 Flag uint32
@@ -17,12 +20,12 @@ type InInfo struct {
Reverse2 string `struc:"[2]byte"` Reverse2 string `struc:"[2]byte"`
} }
func (t *InInfo) Broadcast(mapid uint32, o OutInfo) { func (t *WalkInInfo) Broadcast(mapid uint32, o WalkOutInfo) {
//tt := planetmap //tt := planetmap
//g.Dump(GetSpace(mapid).Len()) //g.Dump(GetSpace(mapid).Len())
GetSpace(mapid).Range(func(playerID uint32, player service.PlayerI) bool { space.GetSpace(mapid).Range(func(playerID uint32, player common.PlayerI) bool {
t.Head.Result = 0 t.Head.Result = 0
tt := t.Head.Pack(&o) tt := t.Head.Pack(&o)
player.SendPack(tt) player.SendPack(tt)
@@ -32,7 +35,7 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) {
} }
// PeopleWalkOutboundInfo PeopleWalkOutboundInfo类实现OutboundMessage接口 // PeopleWalkOutboundInfo PeopleWalkOutboundInfo类实现OutboundMessage接口
type OutInfo struct { type WalkOutInfo struct {
// Flag: 0为走1为飞行模式 // Flag: 0为走1为飞行模式
Flag uint32 `fieldDesc:"0为走1为飞行模式" codec:"uint"` Flag uint32 `fieldDesc:"0为走1为飞行模式" codec:"uint"`

View File

@@ -1,6 +1,6 @@
package nono package nono
import "blazing/logic/service" import "blazing/logic/service/player"
// NonoOutboundInfo 用于表示Nono相关的出站信息 // NonoOutboundInfo 用于表示Nono相关的出站信息
type NonoOutboundInfo struct { type NonoOutboundInfo struct {
@@ -55,7 +55,7 @@ type NonoOutboundInfo struct {
type NonoInboundInfo struct { type NonoInboundInfo struct {
// 消息头部命令ID对应MessageCommandIDRegistry.Nono_Info // 消息头部命令ID对应MessageCommandIDRegistry.Nono_Info
Head service.TomeeHeader `cmd:"9003" struc:"[0]pad"` Head player.TomeeHeader `cmd:"9003" struc:"[0]pad"`
// 米米号对应Java的@UInt long类型 // 米米号对应Java的@UInt long类型
UserID uint32 `fieldDescription:"米米号" struc:"uint32" uint:"true"` UserID uint32 `fieldDescription:"米米号" struc:"uint32" uint:"true"`

View File

@@ -1,9 +1,9 @@
package pet package pet
import "blazing/logic/service" import "blazing/logic/service/player"
type GetPetListInboundEmpty struct { type GetPetListInboundEmpty struct {
Head service.TomeeHeader `cmd:"2303" struc:"[0]pad"` Head player.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,13 +1,14 @@
package pet package pet
import ( import (
"blazing/logic/service" "blazing/logic/service/common"
"blazing/logic/service/player"
"blazing/logic/service/space" "blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type InInfo struct { type InInfo struct {
Head service.TomeeHeader `cmd:"2301" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2301" struc:"[0]pad"`
CatchTime uint32 CatchTime uint32
} }
@@ -26,13 +27,13 @@ type PetReleaseOutboundInfo struct {
// 放入背包或者加入仓库 // 放入背包或者加入仓库
type PetReleaseInboundInfo struct { type PetReleaseInboundInfo struct {
Head service.TomeeHeader `cmd:"2304" struc:"[0]pad"` Head player.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 service.TomeeHeader `cmd:"2305" struc:"[0]pad"` Head player.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"`
@@ -40,7 +41,7 @@ type PetShowInboundInfo struct {
func (t *PetShowInboundInfo) Broadcast(mapid uint32, o PetShowOutboundInfo) { func (t *PetShowInboundInfo) Broadcast(mapid uint32, o PetShowOutboundInfo) {
space.GetSpace(mapid).Range(func(playerID uint32, player service.PlayerI) bool { space.GetSpace(mapid).Range(func(playerID uint32, player common.PlayerI) bool {
t.Head.Result = 0 t.Head.Result = 0
player.SendPack(t.Head.Pack(&o)) player.SendPack(t.Head.Pack(&o))
@@ -59,8 +60,8 @@ type PetShowOutboundInfo struct {
Reserved1 [3]uint32 Reserved1 [3]uint32
} }
type PetOneCureInboundInfo struct { type PetOneCureInboundInfo struct {
Head service.TomeeHeader `cmd:"2310" struc:"[0]pad"` Head player.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 {
CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"` CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"`
@@ -69,8 +70,8 @@ type PetOneCureOutboundInfo struct {
// PetDefaultInboundInfo 对应Java的PetDefaultInboundInfo类 // PetDefaultInboundInfo 对应Java的PetDefaultInboundInfo类
// 实现了InboundMessage接口 // 实现了InboundMessage接口
type PetDefaultInboundInfo struct { type PetDefaultInboundInfo struct {
Head service.TomeeHeader `cmd:"2308" struc:"[0]pad"` Head player.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"`
} }
// PetDefaultOutboundInfo 对应Java的PetDefaultOutboundInfo类 // PetDefaultOutboundInfo 对应Java的PetDefaultOutboundInfo类

View File

@@ -1,4 +1,4 @@
package service package player
import ( import (
"blazing/common/utils/bytearray" "blazing/common/utils/bytearray"

View File

@@ -1,25 +1,30 @@
package service package player
import ( import (
"blazing/common/data/xmlres"
"blazing/logic/service/common"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"fmt" "fmt"
) )
type AI_player struct { type AI_player struct {
FightC *FightC //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool
petinfo []model.PetInfo //精灵信息 petinfo []model.PetInfo //精灵信息
info model.PlayerInfo
CanCapture bool CanCapture bool
} }
func NewAI_player(m model.PetInfo) *AI_player { func NewAI_player(i model.PlayerInfo, m model.PetInfo) *AI_player {
ret := &AI_player{} ret := &AI_player{}
ret.petinfo = make([]model.PetInfo, 0) ret.petinfo = make([]model.PetInfo, 0)
ret.petinfo = append(ret.petinfo, m) ret.petinfo = append(ret.petinfo, m)
ret.info = i
ret.info.Nick = xmlres.PetMAP[int(m.ID)].DefName
return ret return ret
} }
func (f *AI_player) SetFightC(ff *FightC) { func (f *AI_player) SetFightC(ff common.FightI) {
f.FightC = ff f.FightC = ff
} }
@@ -56,13 +61,18 @@ func (f *AI_player) SendFightEndInfo(_ info.FightOverInfo) {
} }
func (f *AI_player) GetAction() { func (f *AI_player) GetAction() {
f.FightC.UseSkill(f, int32(f.FightC.Opp.CurrentPet.Skills[0].ID)) //使用1#技能,实际上要按照四个技能权重去使用 //使用1#技能,实际上要按照四个技能权重去使用
f.FightC.UseSkill(f, int32(f.FightC.GetCurrPET(f).Skills[0].ID))
} }
func (p *AI_player) End() { func (p *AI_player) End() {
p.FightC = nil p.FightC = nil
return return
} }
func (p *AI_player) GetInfo() model.PlayerInfo {
return p.info
}
func (p *AI_player) GetPetInfo() []model.PetInfo { func (p *AI_player) GetPetInfo() []model.PetInfo {

View File

@@ -1,9 +1,13 @@
package service package player
import ( import (
"blazing/common/data/share"
"blazing/common/utils" "blazing/common/utils"
"blazing/logic/service/common"
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
"blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
blservice "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service"
"context" "context"
@@ -14,6 +18,7 @@ import (
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
"github.com/panjf2000/gnet/pkg/logging" "github.com/panjf2000/gnet/pkg/logging"
"github.com/tnnmigga/enum" "github.com/tnnmigga/enum"
) )
@@ -95,7 +100,7 @@ type Player struct {
Playerinvite uint32 //当前邀请的玩家ID Playerinvite uint32 //当前邀请的玩家ID
Onlinetime uint32 //当前登录时间 Onlinetime uint32 //当前登录时间
OgreInfo *OgreInfo OgreInfo *OgreInfo
FightC *FightC //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool
Service *blservice.UserService Service *blservice.UserService
//FightInfo info.NoteReadyToFightInfo //FightInfo info.NoteReadyToFightInfo
} }
@@ -198,7 +203,7 @@ func (p *Player) SendFightEndInfo(b info.FightOverInfo) {
t1 := NewTomeeHeader(2506, p.Info.UserID) t1 := NewTomeeHeader(2506, p.Info.UserID)
p.SendPack(t1.Pack(&b)) p.SendPack(t1.Pack(&b))
p.FightC = nil p.SetFightC(nil)
} }
func (p *Player) GetPetInfo() []model.PetInfo { func (p *Player) GetPetInfo() []model.PetInfo {
@@ -211,13 +216,31 @@ func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
} }
func (f *Player) SetFightC(ff *FightC) { func (f *Player) SetFightC(ff common.FightI) {
f.FightC = ff f.FightC = ff
} }
func LeaveMap(c common.PlayerI) {
t := NewTomeeHeader(2002, c.ID())
space.GetSpace(c.MapID()).Range(func(playerID uint32, player common.PlayerI) bool {
player.SendPack(t.Pack(&space.LeaveMapOutboundInfo{UserID: c.ID()}))
return true
})
space.GetSpace(c.MapID()).Delete(c.ID())
}
// Save 保存玩家数据 // Save 保存玩家数据
func (p *Player) Save() { func (p *Player) Save() {
glog.Debug(context.Background(), p.Info.UserID, "断开连接")
LeaveMap(p)
p.IsLogin = false
Mainplayer.Delete(p.Info.UserID)
share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器
if p.FightC != nil { if p.FightC != nil {
p.FightC.Escape(p) //玩家逃跑 p.FightC.Escape(p) //玩家逃跑

View File

@@ -0,0 +1,44 @@
package player
import "blazing/common/socket/errorcode"
func GetPlayer(c *Conn, userid uint32) *Player { //TODO 这里待优化,可能存在内存泄漏问题
c.Mu.Lock()
defer c.Mu.Unlock()
//检查player初始化是否为conn初始后取map防止二次连接后存在两个player
clientdata := c.MainConn.Context().(*ClientData)
if clientdata.Player != nil {
return clientdata.Player
}
clientdata.Player = NewPlayer(
WithConn(c), //注入conn
)
// gff := socket.NewClientData()
// gff.Player = clientdata.Player
// c.MainConn.SetContext(gff)
Mainplayer.Store(userid, clientdata.Player)
return clientdata.Player
// return nil
}
func KickPlayer(userid uint32) { //踢出玩家
//TODO 返回错误码
//var player *entity.Player
if player1, ok := Mainplayer.Load((userid)); ok {
//取成功,否则创建
head := NewTomeeHeader(1001, userid)
head.Result = uint32(errorcode.ErrorCodes.ErrAccountLoggedInElsewhere)
player1.SendPack(head.Pack(nil))
player1.MainConn.MainConn.Close()
// clientdata.Player = player
}
//return player
// return nil
}

View File

@@ -1,4 +1,4 @@
package service package player
import ( import (
"bytes" "bytes"

View File

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

@@ -3,7 +3,8 @@ package space
import ( import (
"blazing/common/data/xmlres" "blazing/common/data/xmlres"
"blazing/common/utils" "blazing/common/utils"
"blazing/logic/service"
"blazing/logic/service/common"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"sync" "sync"
@@ -11,25 +12,25 @@ import (
// Space 针对Player的并发安全map键为uint32类型 // Space 针对Player的并发安全map键为uint32类型
type Space struct { type Space struct {
mu sync.RWMutex // 读写锁,读多写少场景更高效 mu sync.RWMutex // 读写锁,读多写少场景更高效
data map[uint32]service.PlayerI // 存储玩家数据的map键为玩家ID data map[uint32]common.PlayerI // 存储玩家数据的map键为玩家ID
CanRefresh bool //是否能够刷怪 CanRefresh bool //是否能够刷怪
ID uint32 // 地图ID ID uint32 // 地图ID
Name string //地图名称 Name string //地图名称
DefaultPos model.Pos //默认位置DefaultPos DefaultPos model.Pos //默认位置DefaultPos
Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 Positions map[uint32]model.Pos //从上一个地图跳转后默认位置
} }
// NewSyncMap 创建一个新的玩家同步map // NewSyncMap 创建一个新的玩家同步map
func NewSpace() *Space { func NewSpace() *Space {
return &Space{ return &Space{
data: make(map[uint32]service.PlayerI), data: make(map[uint32]common.PlayerI),
} }
} }
// Get 根据玩家ID获取玩家实例 // Get 根据玩家ID获取玩家实例
// 读操作使用RLock允许多个goroutine同时读取 // 读操作使用RLock允许多个goroutine同时读取
func (m *Space) Get(playerID uint32) (service.PlayerI, bool) { func (m *Space) Get(playerID uint32) (common.PlayerI, bool) {
m.mu.RLock() m.mu.RLock()
defer m.mu.RUnlock() defer m.mu.RUnlock()
val, exists := m.data[playerID] val, exists := m.data[playerID]
@@ -38,7 +39,7 @@ func (m *Space) Get(playerID uint32) (service.PlayerI, bool) {
// Set 存储玩家实例按ID // Set 存储玩家实例按ID
// 写操作使用Lock独占锁保证数据一致性 // 写操作使用Lock独占锁保证数据一致性
func (m *Space) Set(playerID uint32, player service.PlayerI) *Space { func (m *Space) Set(playerID uint32, player common.PlayerI) *Space {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
m.data[playerID] = player m.data[playerID] = player
@@ -64,7 +65,7 @@ func (m *Space) Len() int {
// Range 遍历所有玩家并执行回调函数 // Range 遍历所有玩家并执行回调函数
// 读操作使用RLock遍历过程中不会阻塞其他读操作 // 读操作使用RLock遍历过程中不会阻塞其他读操作
func (m *Space) Range(f func(playerID uint32, player service.PlayerI) bool) { func (m *Space) Range(f func(playerID uint32, player common.PlayerI) bool) {
m.mu.RLock() m.mu.RLock()
defer m.mu.RUnlock() defer m.mu.RUnlock()
for id, player := range m.data { for id, player := range m.data {
@@ -113,3 +114,7 @@ func GetSpace(id uint32) *Space {
} }
var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据 var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据
type LeaveMapOutboundInfo struct {
// 米米号
UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"`
}

View File

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

View File

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

View File

@@ -1,13 +1,13 @@
package task package task
import "blazing/logic/service" import "blazing/logic/service/player"
// AddTaskBufInboundInfo 对应Java的AddTaskBufInboundInfo类 // AddTaskBufInboundInfo 对应Java的AddTaskBufInboundInfo类
// 用于接收添加任务缓冲区的入站信息 // 用于接收添加任务缓冲区的入站信息
type AddTaskBufInboundInfo struct { type AddTaskBufInboundInfo struct {
Head service.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID对应Java的@UInt long TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID对应Java的@UInt long
TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息对应Java的@ArraySerialize注解 TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息对应Java的@ArraySerialize注解
} }
type AddTaskBufOutboundInfo struct { type AddTaskBufOutboundInfo struct {
// 该结构体没有字段对应Java中的空类 // 该结构体没有字段对应Java中的空类

View File

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

View File

@@ -1,11 +1,11 @@
package task package task
import "blazing/logic/service" import "blazing/logic/service/player"
// DeleteTaskInboundInfo 对应Java的DeleteTaskInboundInfo类 // DeleteTaskInboundInfo 对应Java的DeleteTaskInboundInfo类
type DeleteTaskInboundInfo struct { type DeleteTaskInboundInfo struct {
Head service.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"` Head player.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"`
TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64对应Java的@UInt long TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64对应Java的@UInt long
} }
type DeleteTaskOutboundInfo struct { type DeleteTaskOutboundInfo struct {
TaskId uint32 `json:"taskId" description:"任务ID"` // 对应@UInt long和@FieldDescription TaskId uint32 `json:"taskId" description:"任务ID"` // 对应@UInt long和@FieldDescription

View File

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

View File

@@ -2,7 +2,7 @@ package model
// TeamInfo 战队信息结构 // TeamInfo 战队信息结构
type TeamInfo struct { type TeamInfo struct {
//Head service.TomeeHeader `cmd:"1001" struc:"[0]pad"` // 命令头 //Head player.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