修改广播逻辑

This commit is contained in:
1
2025-11-18 20:52:04 +00:00
parent 4ab6b726a7
commit 6c32a5d7ac
19 changed files with 100 additions and 218 deletions

View File

@@ -18,7 +18,7 @@ type UserModel interface {
type Model struct { type Model struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
CreateTime *gtime.Time ` gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间 CreateTime *gtime.Time ` gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间
UpdateTime *gtime.Time ` orm:"autoUpdateTime=true"  gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间 UpdateTime *gtime.Time `orm:"autoUpdateTime=true" gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间
DeletedAt *gtime.Time `gorm:"index" json:"deletedAt"` DeletedAt *gtime.Time `gorm:"index" json:"deletedAt"`
} }

View File

@@ -6,7 +6,7 @@ import (
"github.com/tnnmigga/enum" "github.com/tnnmigga/enum"
) )
// ErrorCode 错误码枚举类型 // ErrorCode 错误码枚举类型 -1 就是不回包0是默认包
type ErrorCode int32 type ErrorCode int32
func (t ErrorCode) Code() string { return fmt.Sprintf("%d", t) } func (t ErrorCode) Code() string { return fmt.Sprintf("%d", t) }

View File

@@ -4,9 +4,7 @@ import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/cool" "blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/player" "blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/logic/service/user" "blazing/logic/service/user"
blservice "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service"
"strings" "strings"
@@ -29,11 +27,7 @@ func (h *Controller) ChangePlayerName(data *user.ChangePlayerNameInboundInfo, c
Nickname: newnice, Nickname: newnice,
UserID: c.Info.UserID, UserID: c.Info.UserID,
} }
c.GetSpace().Broadcast(c, data.Head.CMD, result)
space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
player.SendPack(data.Head.Pack(&result))
return false
})
return result, 0 return result, 0
} }

View File

@@ -6,10 +6,8 @@ import (
"math/rand" "math/rand"
"time" "time"
"blazing/logic/service/common"
"blazing/logic/service/item" "blazing/logic/service/item"
"blazing/logic/service/player" "blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
@@ -76,14 +74,10 @@ func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, c
result.ClothList = append(result.ClothList, model.PeopleItemInfo{ID: v, Level: 1}) result.ClothList = append(result.ClothList, model.PeopleItemInfo{ID: v, Level: 1})
} }
c.Info.Clothes = result.ClothList c.Info.Clothes = result.ClothList
space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
// fmt.Println("ChangePlayerCloth", playerID, data.Head.Pack(result))
data.Head.Result = 0
player.SendPack(data.Head.Pack(result))
return false
}) c.GetSpace().Broadcast(c, data.Head.CMD, result)
return nil, -1
return
} }
func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) {
result = &item.TalkCountOutboundInfo{} result = &item.TalkCountOutboundInfo{}

View File

@@ -96,7 +96,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
result = user.NewOutInfo() //设置登录消息 result = user.NewOutInfo() //设置登录消息
result.PlayerInfo = *t.Info result.PlayerInfo = *t.Info
go space.GetSpace(t.Info.MapID).EnterMap(t) space.GetSpace(t.Info.MapID).EnterMap(t)
return result, 0 return result, 0

View File

@@ -121,11 +121,12 @@ func (h *Controller) PlayerShowPet(
copier.Copy(&results, pi) copier.Copy(&results, pi)
results.Flag = data.Flag results.Flag = data.Flag
results.UserID = data.Head.UserID results.UserID = data.Head.UserID
data.Broadcast(c.Info.MapID, results) //同步广播 c.GetSpace().Broadcast(c, data.Head.CMD, results)
} }
} }
return result, -1 return
} }
func (h *Controller) PetOneCure( func (h *Controller) PetOneCure(

View File

@@ -3,9 +3,7 @@ package controller
import ( import (
"blazing/common/socket/errorcode" "blazing/common/socket/errorcode"
"blazing/cool" "blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/player" "blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/logic/service/user" "blazing/logic/service/user"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
@@ -36,25 +34,19 @@ func (h Controller) UserMoreInfo(data *user.MoreUserInfoInboundInfo, c *player.P
} }
func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
result = &user.AimatOutboundInfo{
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
ret := &user.AimatOutboundInfo{
ItemId: data.ItemId, ItemId: data.ItemId,
Point: data.Point, Point: data.Point,
ShootType: data.ShootType, ShootType: data.ShootType,
UserId: c.Info.UserID, UserId: c.Info.UserID,
} }
data.Head.Result = 0 c.GetSpace().Broadcast(c, data.Head.CMD, result)
player.SendPack(data.Head.Pack(ret))
return false
})
return nil, -1 return
} }
func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) { func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
result = &user.ChatOutboundInfo{ result = &user.ChatOutboundInfo{
Message: string([]byte(data.Message)[:data.MessageLen-1]), Message: string([]byte(data.Message)[:data.MessageLen-1]),
@@ -62,12 +54,8 @@ func (h Controller) Chat(data *user.ChatInboundInfo, c *player.Player) (result *
SenderId: c.Info.UserID, SenderId: c.Info.UserID,
} }
result.Message = cool.Filter.Replace(result.Message, '*') result.Message = cool.Filter.Replace(result.Message, '*')
data.Head.Result = 0 c.GetSpace().Broadcast(c, data.Head.CMD, result)
v.SendPack(data.Head.Pack(result)) return
return false
})
return nil, -1
} }
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
@@ -76,20 +64,15 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
} }
c.Info.Color = data.Color c.Info.Color = data.Color
c.Info.Texture = 0 c.Info.Texture = 0
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
data.Head.Result = 0
result = &user.ChangeColorOutboundInfo{ result = &user.ChangeColorOutboundInfo{
UserId: c.Info.UserID, UserId: c.Info.UserID,
Color: data.Color, Color: data.Color,
Coins: c.Info.Coins, Coins: c.Info.Coins,
Texture: c.Info.Texture, Texture: c.Info.Texture,
} }
v.SendPack(data.Head.Pack(result)) c.GetSpace().Broadcast(c, data.Head.CMD, result)
return false
})
return nil, -1 return
} }
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
if !c.UseCoins(200) { //如果花不了200,直接返回 if !c.UseCoins(200) { //如果花不了200,直接返回
@@ -97,19 +80,15 @@ func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *pl
} }
c.Info.Texture = data.Id c.Info.Texture = data.Id
c.Info.Color = data.Color c.Info.Color = data.Color
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
data.Head.Result = 0
result = &user.ChangeDoodleOutboundInfo{ result = &user.ChangeDoodleOutboundInfo{
UserId: c.Info.UserID, UserId: c.Info.UserID,
Color: c.Info.Color, Color: c.Info.Color,
Coins: c.Info.Coins, Coins: c.Info.Coins,
Texture: c.Info.Texture, Texture: c.Info.Texture,
} }
v.SendPack(data.Head.Pack(result)) c.GetSpace().Broadcast(c, data.Head.CMD, result)
return false
})
return nil, -1 return
} }
func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, c *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) { func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, c *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) {
//c.Info.Coins -= 200 //c.Info.Coins -= 200

View File

@@ -9,7 +9,7 @@ import (
func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.WalkOutInfo, err errorcode.ErrorCode) { func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.WalkOutInfo, err errorcode.ErrorCode) {
go c.GetSpace().Walk(info.WalkOutInfo{ c.GetSpace().Walk(c, info.WalkOutInfo{
Flag: data.Flag, Flag: data.Flag,
Point: data.Point, Point: data.Point,
Path: data.Path, Path: data.Path,
@@ -17,5 +17,5 @@ func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.
}) })
c.Info.Pos = data.Point c.Info.Pos = data.Point
return nil, -1 return
} }

View File

@@ -2,26 +2,18 @@ package common
import ( import (
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
maps "blazing/logic/service/maps/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
type PlayerI interface { type PlayerI interface {
GetPlayerCaptureContext() *info.PlayerCaptureContext GetPlayerCaptureContext() *info.PlayerCaptureContext
Roll(int, int) (bool, float64, float64) Roll(int, int) (bool, float64, float64)
SendPack(b []byte) error //SendPack(b []byte) error
Getfightinfo() info.PVPinfo Getfightinfo() info.PVPinfo
SendReadyToFightInfo(info.FightStartOutboundInfo)
SendNoteReadyToFightInfo(info.NoteReadyToFightInfo)
Send_ARENA_GET_INFO(b info.S2C_ARENA_GET_INFO)
SendFightEndInfo(info.FightOverInfo)
GetInfo() *model.PlayerInfo GetInfo() *model.PlayerInfo
SendAttackValue(info.AttackValueS)
SendChangePet(info.ChangePetInfo)
SendUsePetItemInfo(info.UsePetIteminfo)
SendLoadPercent(info.LoadPercentOutboundInfo)
SetFightC(FightI) SetFightC(FightI)
SendLeaveMapInfo(b maps.LeaveMapOutboundInfo)
SendEnterMapInfo(b maps.OutInfo) SendPackCmd(cmd uint32, b any)
SendWalkMapInfo(b maps.WalkOutInfo)
} }

View File

@@ -87,7 +87,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
f.Broadcast(func(ff *input.Input) { //先给自身广播 f.Broadcast(func(ff *input.Input) { //先给自身广播
if ff.Player.GetInfo().UserID == c.GetInfo().UserID { if ff.Player.GetInfo().UserID == c.GetInfo().UserID {
ff.Player.SendChangePet(ret.Reason) ff.Player.SendPackCmd(2407, ret.Reason)
} }
}) })
@@ -216,9 +216,12 @@ func (f *FightC) startBattle(startInfo info.FightStartOutboundInfo) {
log.Panic(context.Background(), "战斗循环提交失败", "error", err) log.Panic(context.Background(), "战斗循环提交失败", "error", err)
} }
f.Broadcast(func(ff *input.Input) {
// 通知双方玩家准备完成,即将开始战斗 // 通知双方玩家准备完成,即将开始战斗
f.Our.Player.SendReadyToFightInfo(startInfo)
f.Opp.Player.SendReadyToFightInfo(startInfo) ff.Player.SendPackCmd(2504, startInfo)
})
// 标记战斗已启动(原注释逻辑) // 标记战斗已启动(原注释逻辑)
// f.running = true // f.running = true

View File

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

View File

@@ -99,10 +99,11 @@ func (f *FightC) IsFirst(play common.PlayerI) bool {
// 加载进度 // 加载进度
func (f *FightC) LoadPercent(c common.PlayerI, percent int32) { func (f *FightC) LoadPercent(c common.PlayerI, percent int32) {
f.GetInputByPlayer(c, true).Player.SendLoadPercent(info.LoadPercentOutboundInfo{ f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, info.LoadPercentOutboundInfo{
Id: c.GetInfo().UserID, Id: c.GetInfo().UserID,
Percent: uint32(percent), Percent: uint32(percent),
}) })
} }
func (f *FightC) initplayer(c common.PlayerI) *input.Input { func (f *FightC) initplayer(c common.PlayerI) *input.Input {
@@ -182,16 +183,18 @@ func initfightready(in *input.Input) (info.FightUserInfo, []info.ReadyFightPetIn
} }
// 创建新战斗,邀请方和被邀请方,或者玩家和野怪方 // 创建新战斗,邀请方和被邀请方,或者玩家和野怪方
func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC { func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) (*FightC, error) {
f := &FightC{} f := &FightC{}
f.ownerID = p1.GetInfo().UserID f.ownerID = p1.GetInfo().UserID
f.callback = fn f.callback = fn //战斗结束的回调
f.quit = make(chan struct{}) f.quit = make(chan struct{})
f.over = make(chan struct{}) f.over = make(chan struct{})
f.StartTime = time.Now() f.StartTime = time.Now()
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息 seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
f.rand = rand.New(rand.NewSource(seed)) f.rand = rand.New(rand.NewSource(seed))
f.Info = p1.Getfightinfo() f.Info = p1.Getfightinfo()
//这里应该挪到玩家初始化执行
p1.(*player.Player).PVPinfo = nil //清空战斗消息 p1.(*player.Player).PVPinfo = nil //清空战斗消息
f.ReadyInfo.Mode = f.Info.Mode f.ReadyInfo.Mode = f.Info.Mode
@@ -213,13 +216,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC {
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendNoteReadyToFightInfo(f.ReadyInfo) ff.Player.SendPackCmd(2503, f.ReadyInfo)
}) })
// 60秒后判断战斗是否开始 // 60秒后判断战斗是否开始
cool.Cron.AfterFunc(60*time.Second, func() { cool.Cron.AfterFunc(60*time.Second, func() {
if !f.Our.Finished || !f.Opp.Finished { //如果有任一没有加载完成 if !f.Our.Finished || !f.Opp.Finished { //如果有任一没有加载完成
f.closefight = true //阻止继续添加action
f.Reason = info.BattleOverReason.PlayerOVerTime f.Reason = info.BattleOverReason.PlayerOVerTime
switch { switch {
case !f.Opp.Finished: //邀请方没加载完成 先判断邀请方,如果都没加载完成,就算做房主胜利 case !f.Opp.Finished: //邀请方没加载完成 先判断邀请方,如果都没加载完成,就算做房主胜利
@@ -230,14 +234,14 @@ func NewFight(p1, p2 common.PlayerI, fn func(*info.FightOverInfo)) *FightC {
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
//todo 将血量和技能pp传回enterturn //todo 将血量和技能pp传回enterturn
ff.Player.SendFightEndInfo(f.FightOverInfo) ff.Player.SendPackCmd(2506, f.FightOverInfo)
}) })
} }
}) })
return f return f, nil
} }
// 被击败的ID // 被击败的ID

View File

@@ -257,6 +257,10 @@ func (our *Input) GetAction(opp *Input) {
our.FightC.UseSkill(our.Player, int32(bestKillSkill.ID)) our.FightC.UseSkill(our.Player, int32(bestKillSkill.ID))
return return
} }
if len(allSkills) <= 0 {
our.FightC.UseSkill(our.Player, 0)
return
}
randomIdx := rand.Intn(len(allSkills)) randomIdx := rand.Intn(len(allSkills))
chosenSkill := skills[randomIdx] chosenSkill := skills[randomIdx]

View File

@@ -64,8 +64,8 @@ func (f *FightC) battleLoop() {
} }
} }
ff.Player.SendFightEndInfo(f.FightOverInfo) ff.Player.SendPackCmd(2506, f.FightOverInfo)
//待退出玩家战斗状态
}) })
close(f.actionChan) close(f.actionChan)
@@ -242,7 +242,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
f.GetInputByAction(a, false).Heal(f.GetInputByAction(a, false), a, decimal.NewFromInt(int64(addhp))) f.GetInputByAction(a, false).Heal(f.GetInputByAction(a, false), a, decimal.NewFromInt(int64(addhp)))
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendUsePetItemInfo(info.UsePetIteminfo{ ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
UserID: f.GetInputByAction(a, false).UserID, UserID: f.GetInputByAction(a, false).UserID,
ChangeHp: int32(addhp), ChangeHp: int32(addhp),
ItemID: uint32(item.ID), ItemID: uint32(item.ID),
@@ -252,7 +252,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
case gconv.Int(item.PP) != 0: case gconv.Int(item.PP) != 0:
f.GetInputByAction(a, false).HealPP(item.PP) f.GetInputByAction(a, false).HealPP(item.PP)
f.Broadcast(func(ff *input.Input) { f.Broadcast(func(ff *input.Input) {
ff.Player.SendUsePetItemInfo(info.UsePetIteminfo{ ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
UserID: f.GetInputByAction(a, false).UserID, UserID: f.GetInputByAction(a, false).UserID,
ItemID: uint32(item.ID), ItemID: uint32(item.ID),

View File

@@ -1,9 +1,7 @@
package pet package pet
import ( import (
"blazing/logic/service/common"
"blazing/logic/service/player" "blazing/logic/service/player"
"blazing/logic/service/space"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
@@ -39,16 +37,6 @@ type PetShowInboundInfo struct {
Flag uint32 `codec:"flag"` Flag uint32 `codec:"flag"`
} }
func (t *PetShowInboundInfo) Broadcast(mapid uint32, o PetShowOutboundInfo) {
space.GetSpace(mapid).User.Range(func(key uint32, v common.PlayerI) (stop bool) {
t.Head.Result = 0
v.SendPack(t.Head.Pack(&o))
return false
})
}
type PetShowOutboundInfo struct { type PetShowOutboundInfo struct {
UserID uint32 `codec:"UserID" description:"米米号"` UserID uint32 `codec:"UserID" description:"米米号"`
CatchTime uint32 `codec:"CatchTime" description:"精灵获得的时间"` CatchTime uint32 `codec:"CatchTime" description:"精灵获得的时间"`

View File

@@ -2,7 +2,6 @@ package player
import ( import (
"blazing/logic/service/fight/info" "blazing/logic/service/fight/info"
maps "blazing/logic/service/maps/info"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
) )
@@ -20,31 +19,8 @@ func (f *AI_player) SendPack(b []byte) error {
return nil return nil
} }
func (p *AI_player) SendWalkMapInfo(b maps.WalkOutInfo) {
} func (f *AI_player) SendPackCmd(_ uint32, _ any) {
func (p *AI_player) SendLeaveMapInfo(b maps.LeaveMapOutboundInfo) {
}
func (p *AI_player) SendEnterMapInfo(b maps.OutInfo) {
}
func (f *AI_player) SendReadyToFightInfo(gg info.FightStartOutboundInfo) {
//fmt.Println(gg)
}
func (f *AI_player) SendNoteReadyToFightInfo(fs info.NoteReadyToFightInfo) {
// fmt.Println(fs)
}
func (f *AI_player) SendFightEndInfo(_ info.FightOverInfo) {
//fmt.Println("战斗结束")
}
func (f *AI_player) SendUsePetItemInfo(_ info.UsePetIteminfo) {
//fmt.Println("战斗结束") //fmt.Println("战斗结束")
@@ -54,15 +30,7 @@ func (p *AI_player) GetPetInfo() []model.PetInfo {
return p.petinfo return p.petinfo
} }
func (p *AI_player) SendAttackValue(info.AttackValueS) {
}
func (p *AI_player) SendChangePet(info.ChangePetInfo) {
}
func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) { func (lw *AI_player) SendLoadPercent(info.LoadPercentOutboundInfo) {
} }
func (p *AI_player) Send_ARENA_GET_INFO(b info.S2C_ARENA_GET_INFO) {
}

View File

@@ -5,12 +5,6 @@ import (
maps "blazing/logic/service/maps/info" maps "blazing/logic/service/maps/info"
) )
func (p *Player) SendAttackValue(b info.AttackValueS) {
t1 := NewTomeeHeader(2505, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendLeaveMapInfo(b maps.LeaveMapOutboundInfo) { func (p *Player) SendLeaveMapInfo(b maps.LeaveMapOutboundInfo) {
t1 := NewTomeeHeader(2002, p.Info.UserID) t1 := NewTomeeHeader(2002, p.Info.UserID)
@@ -23,39 +17,10 @@ func (p *Player) SendEnterMapInfo(b maps.OutInfo) {
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样 p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
} }
func (p *Player) SendWalkMapInfo(b maps.WalkOutInfo) {
t1 := NewTomeeHeader(2101, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样 func (p *Player) SendPackCmd(cmd uint32, b any) {
}
func (p *Player) SendChangePet(b info.ChangePetInfo) {
t1 := NewTomeeHeader(2407, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendReadyToFightInfo(b info.FightStartOutboundInfo) {
t1 := NewTomeeHeader(2504, p.Info.UserID)
p.SendPack(t1.Pack(&b))
}
func (p *Player) Send_ARENA_GET_INFO(b info.S2C_ARENA_GET_INFO) {
t1 := NewTomeeHeader(2419, p.Info.UserID)
p.SendPack(t1.Pack(&b))
}
func (p *Player) SendNoteReadyToFightInfo(b info.NoteReadyToFightInfo) {
t1 := NewTomeeHeader(2503, p.Info.UserID)
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendFightEndInfo(b info.FightOverInfo) {
p.FightC = nil
//<-time.After(10000)
t1 := NewTomeeHeader(2506, p.Info.UserID)
p.SendPack(t1.Pack(&b))
p.SendPack(NewTomeeHeader(cmd, p.Info.UserID).Pack(&b))
} }
func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) { func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
@@ -63,9 +28,3 @@ func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
p.SendPack(t1.Pack(&b)) p.SendPack(t1.Pack(&b))
} }
func (f *Player) SendUsePetItemInfo(b info.UsePetIteminfo) {
t1 := NewTomeeHeader(2406, f.Info.UserID)
f.SendPack(t1.Pack(&b))
}

View File

@@ -10,6 +10,20 @@ import (
"golang.org/x/time/rate" "golang.org/x/time/rate"
) )
// 向其他人广播,不含自己
func (s *Space) Broadcast(c common.PlayerI, cmd uint32, data any) {
go s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
if k != c.GetInfo().UserID {
v.SendPackCmd(cmd, data)
}
return false
})
}
func (s *Space) LeaveMap(c common.PlayerI) { func (s *Space) LeaveMap(c common.PlayerI) {
if c == nil { if c == nil {
return return
@@ -19,14 +33,8 @@ func (s *Space) LeaveMap(c common.PlayerI) {
} }
s.UP_ARENA(c, 0) //退出擂台 s.UP_ARENA(c, 0) //退出擂台
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
if k != c.GetInfo().UserID { s.Broadcast(c, 2002, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
v.SendLeaveMapInfo(info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
}
return false
})
s.User.Delete(c.GetInfo().UserID) s.User.Delete(c.GetInfo().UserID)
s.UserInfo.Delete(c.GetInfo().UserID) s.UserInfo.Delete(c.GetInfo().UserID)
@@ -41,12 +49,9 @@ func (s *Space) EnterMap(c common.PlayerI) {
out := info.NewOutInfo() out := info.NewOutInfo()
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true}) copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
if k != c.GetInfo().UserID { s.Broadcast(c, 2001, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
v.SendEnterMapInfo(*out)
}
return false
})
s.User.Store(c.GetInfo().UserID, c) s.User.Store(c.GetInfo().UserID, c)
s.UserInfo.Store(c.GetInfo().UserID, *out) s.UserInfo.Store(c.GetInfo().UserID, *out)
if s.SuperValue != nil { if s.SuperValue != nil {
@@ -67,18 +72,14 @@ func (s *Space) GetInfo() []maps.OutInfo {
var limiter = rate.NewLimiter(rate.Limit(10), 5) var limiter = rate.NewLimiter(rate.Limit(10), 5)
func (s *Space) Walk(b maps.WalkOutInfo) { func (s *Space) Walk(c common.PlayerI, info info.WalkOutInfo) {
// cool.Limiter.Take() // cool.Limiter.Take()
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5) //r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
if !limiter.Allow() { if !limiter.Allow() {
return return
} }
s.User.Range(func(playerID uint32, player common.PlayerI) bool { go s.Broadcast(c, 2101, info)
player.SendWalkMapInfo(b)
return false
})
} }

View File

@@ -74,13 +74,8 @@ func (s *Space) UP_ARENA(c common.PlayerI, FLAG uint32) {
s.ARENA_Player = c //添加用户 s.ARENA_Player = c //添加用户
} }
s.Broadcast(c, 2419, s.ARENA)
s.User.Range(func(playerID uint32, p common.PlayerI) bool {
p.Send_ARENA_GET_INFO(s.ARENA)
return false
})
} }
// NewSyncMap 创建一个新的玩家同步map // NewSyncMap 创建一个新的玩家同步map