修改广播逻辑
This commit is contained in:
@@ -18,7 +18,7 @@ type UserModel interface {
|
||||
type Model struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
// ErrorCode 错误码枚举类型
|
||||
// ErrorCode 错误码枚举类型 -1 就是不回包,0是默认包
|
||||
type ErrorCode int32
|
||||
|
||||
func (t ErrorCode) Code() string { return fmt.Sprintf("%d", t) }
|
||||
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/space"
|
||||
"blazing/logic/service/user"
|
||||
blservice "blazing/modules/blazing/service"
|
||||
"strings"
|
||||
@@ -29,11 +27,7 @@ func (h *Controller) ChangePlayerName(data *user.ChangePlayerNameInboundInfo, c
|
||||
Nickname: newnice,
|
||||
UserID: c.Info.UserID,
|
||||
}
|
||||
|
||||
space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
|
||||
player.SendPack(data.Head.Pack(&result))
|
||||
return false
|
||||
})
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/space"
|
||||
"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})
|
||||
}
|
||||
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
|
||||
|
||||
})
|
||||
return nil, -1
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
|
||||
return
|
||||
}
|
||||
func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &item.TalkCountOutboundInfo{}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user.
|
||||
result = user.NewOutInfo() //设置登录消息
|
||||
|
||||
result.PlayerInfo = *t.Info
|
||||
go space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
space.GetSpace(t.Info.MapID).EnterMap(t)
|
||||
|
||||
return result, 0
|
||||
|
||||
|
||||
@@ -121,11 +121,12 @@ func (h *Controller) PlayerShowPet(
|
||||
copier.Copy(&results, pi)
|
||||
results.Flag = data.Flag
|
||||
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(
|
||||
|
||||
@@ -3,9 +3,7 @@ package controller
|
||||
import (
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/cool"
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/space"
|
||||
"blazing/logic/service/user"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
@@ -36,38 +34,28 @@ 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) {
|
||||
result = &user.AimatOutboundInfo{
|
||||
|
||||
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, player common.PlayerI) bool {
|
||||
ret := &user.AimatOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Point: data.Point,
|
||||
ShootType: data.ShootType,
|
||||
UserId: c.Info.UserID,
|
||||
}
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
|
||||
ItemId: data.ItemId,
|
||||
Point: data.Point,
|
||||
ShootType: data.ShootType,
|
||||
UserId: c.Info.UserID,
|
||||
}
|
||||
data.Head.Result = 0
|
||||
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) {
|
||||
|
||||
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]),
|
||||
SenderNickname: c.Info.Nick,
|
||||
SenderId: c.Info.UserID,
|
||||
}
|
||||
result.Message = cool.Filter.Replace(result.Message, '*')
|
||||
data.Head.Result = 0
|
||||
v.SendPack(data.Head.Pack(result))
|
||||
return false
|
||||
})
|
||||
|
||||
return nil, -1
|
||||
Message: string([]byte(data.Message)[:data.MessageLen-1]),
|
||||
SenderNickname: c.Info.Nick,
|
||||
SenderId: c.Info.UserID,
|
||||
}
|
||||
result.Message = cool.Filter.Replace(result.Message, '*')
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
return
|
||||
}
|
||||
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.Texture = 0
|
||||
result = &user.ChangeColorOutboundInfo{
|
||||
UserId: c.Info.UserID,
|
||||
Color: data.Color,
|
||||
Coins: c.Info.Coins,
|
||||
Texture: c.Info.Texture,
|
||||
}
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
|
||||
defer space.GetSpace(c.Info.MapID).User.Range(func(playerID uint32, v common.PlayerI) bool {
|
||||
data.Head.Result = 0
|
||||
result = &user.ChangeColorOutboundInfo{
|
||||
UserId: c.Info.UserID,
|
||||
Color: data.Color,
|
||||
Coins: c.Info.Coins,
|
||||
Texture: c.Info.Texture,
|
||||
}
|
||||
v.SendPack(data.Head.Pack(result))
|
||||
return false
|
||||
})
|
||||
|
||||
return nil, -1
|
||||
return
|
||||
}
|
||||
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
|
||||
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.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{
|
||||
UserId: c.Info.UserID,
|
||||
Color: c.Info.Color,
|
||||
Coins: c.Info.Coins,
|
||||
Texture: c.Info.Texture,
|
||||
}
|
||||
v.SendPack(data.Head.Pack(result))
|
||||
return false
|
||||
})
|
||||
result = &user.ChangeDoodleOutboundInfo{
|
||||
UserId: c.Info.UserID,
|
||||
Color: c.Info.Color,
|
||||
Coins: c.Info.Coins,
|
||||
Texture: c.Info.Texture,
|
||||
}
|
||||
c.GetSpace().Broadcast(c, data.Head.CMD, result)
|
||||
|
||||
return nil, -1
|
||||
return
|
||||
}
|
||||
func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, c *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) {
|
||||
//c.Info.Coins -= 200
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
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,
|
||||
Point: data.Point,
|
||||
Path: data.Path,
|
||||
@@ -17,5 +17,5 @@ func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *info.
|
||||
})
|
||||
|
||||
c.Info.Pos = data.Point
|
||||
return nil, -1
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2,26 +2,18 @@ package common
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/info"
|
||||
maps "blazing/logic/service/maps/info"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
type PlayerI interface {
|
||||
GetPlayerCaptureContext() *info.PlayerCaptureContext
|
||||
Roll(int, int) (bool, float64, float64)
|
||||
SendPack(b []byte) error
|
||||
//SendPack(b []byte) error
|
||||
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
|
||||
SendAttackValue(info.AttackValueS)
|
||||
SendChangePet(info.ChangePetInfo)
|
||||
SendUsePetItemInfo(info.UsePetIteminfo)
|
||||
SendLoadPercent(info.LoadPercentOutboundInfo)
|
||||
|
||||
SetFightC(FightI)
|
||||
SendLeaveMapInfo(b maps.LeaveMapOutboundInfo)
|
||||
SendEnterMapInfo(b maps.OutInfo)
|
||||
SendWalkMapInfo(b maps.WalkOutInfo)
|
||||
|
||||
SendPackCmd(cmd uint32, b any)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||||
|
||||
f.Broadcast(func(ff *input.Input) { //先给自身广播
|
||||
if ff.Player.GetInfo().UserID == c.GetInfo().UserID {
|
||||
ff.Player.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)
|
||||
}
|
||||
|
||||
// 通知双方玩家准备完成,即将开始战斗
|
||||
f.Our.Player.SendReadyToFightInfo(startInfo)
|
||||
f.Opp.Player.SendReadyToFightInfo(startInfo)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
|
||||
// 通知双方玩家准备完成,即将开始战斗
|
||||
|
||||
ff.Player.SendPackCmd(2504, startInfo)
|
||||
})
|
||||
|
||||
// 标记战斗已启动(原注释逻辑)
|
||||
// f.running = true
|
||||
|
||||
@@ -332,12 +332,12 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
for _, v := range f.Switch {
|
||||
|
||||
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{}
|
||||
}
|
||||
|
||||
@@ -99,10 +99,11 @@ func (f *FightC) IsFirst(play common.PlayerI) bool {
|
||||
|
||||
// 加载进度
|
||||
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,
|
||||
Percent: uint32(percent),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
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.ownerID = p1.GetInfo().UserID
|
||||
f.callback = fn
|
||||
f.callback = fn //战斗结束的回调
|
||||
f.quit = make(chan struct{})
|
||||
f.over = make(chan struct{})
|
||||
f.StartTime = time.Now()
|
||||
seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息
|
||||
f.rand = rand.New(rand.NewSource(seed))
|
||||
f.Info = p1.Getfightinfo()
|
||||
|
||||
//这里应该挪到玩家初始化执行
|
||||
p1.(*player.Player).PVPinfo = nil //清空战斗消息
|
||||
|
||||
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) {
|
||||
|
||||
ff.Player.SendNoteReadyToFightInfo(f.ReadyInfo)
|
||||
ff.Player.SendPackCmd(2503, f.ReadyInfo)
|
||||
|
||||
})
|
||||
// 60秒后判断战斗是否开始
|
||||
|
||||
cool.Cron.AfterFunc(60*time.Second, func() {
|
||||
if !f.Our.Finished || !f.Opp.Finished { //如果有任一没有加载完成
|
||||
f.closefight = true //阻止继续添加action
|
||||
f.Reason = info.BattleOverReason.PlayerOVerTime
|
||||
switch {
|
||||
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) {
|
||||
//todo 将血量和技能pp传回enterturn
|
||||
|
||||
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
||||
ff.Player.SendPackCmd(2506, f.FightOverInfo)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return f
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// 被击败的ID
|
||||
|
||||
@@ -257,6 +257,10 @@ func (our *Input) GetAction(opp *Input) {
|
||||
our.FightC.UseSkill(our.Player, int32(bestKillSkill.ID))
|
||||
return
|
||||
}
|
||||
if len(allSkills) <= 0 {
|
||||
our.FightC.UseSkill(our.Player, 0)
|
||||
return
|
||||
}
|
||||
|
||||
randomIdx := rand.Intn(len(allSkills))
|
||||
chosenSkill := skills[randomIdx]
|
||||
|
||||
@@ -64,8 +64,8 @@ func (f *FightC) battleLoop() {
|
||||
}
|
||||
|
||||
}
|
||||
ff.Player.SendFightEndInfo(f.FightOverInfo)
|
||||
|
||||
ff.Player.SendPackCmd(2506, f.FightOverInfo)
|
||||
//待退出玩家战斗状态
|
||||
})
|
||||
|
||||
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.Broadcast(func(ff *input.Input) {
|
||||
ff.Player.SendUsePetItemInfo(info.UsePetIteminfo{
|
||||
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
|
||||
UserID: f.GetInputByAction(a, false).UserID,
|
||||
ChangeHp: int32(addhp),
|
||||
ItemID: uint32(item.ID),
|
||||
@@ -252,7 +252,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
||||
case gconv.Int(item.PP) != 0:
|
||||
f.GetInputByAction(a, false).HealPP(item.PP)
|
||||
f.Broadcast(func(ff *input.Input) {
|
||||
ff.Player.SendUsePetItemInfo(info.UsePetIteminfo{
|
||||
ff.Player.SendPackCmd(2406, info.UsePetIteminfo{
|
||||
UserID: f.GetInputByAction(a, false).UserID,
|
||||
|
||||
ItemID: uint32(item.ID),
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package pet
|
||||
|
||||
import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/space"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
@@ -39,16 +37,6 @@ type PetShowInboundInfo struct {
|
||||
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 {
|
||||
UserID uint32 `codec:"UserID" description:"米米号"`
|
||||
CatchTime uint32 `codec:"CatchTime" description:"精灵获得的时间"`
|
||||
|
||||
@@ -2,7 +2,6 @@ package player
|
||||
|
||||
import (
|
||||
"blazing/logic/service/fight/info"
|
||||
maps "blazing/logic/service/maps/info"
|
||||
"blazing/modules/blazing/model"
|
||||
)
|
||||
|
||||
@@ -20,31 +19,8 @@ func (f *AI_player) SendPack(b []byte) error {
|
||||
return nil
|
||||
|
||||
}
|
||||
func (p *AI_player) SendWalkMapInfo(b maps.WalkOutInfo) {
|
||||
|
||||
}
|
||||
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) {
|
||||
func (f *AI_player) SendPackCmd(_ uint32, _ any) {
|
||||
|
||||
//fmt.Println("战斗结束")
|
||||
|
||||
@@ -54,15 +30,7 @@ func (p *AI_player) GetPetInfo() []model.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 (p *AI_player) Send_ARENA_GET_INFO(b info.S2C_ARENA_GET_INFO) {
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,6 @@ import (
|
||||
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) {
|
||||
t1 := NewTomeeHeader(2002, p.Info.UserID)
|
||||
|
||||
@@ -23,39 +17,10 @@ func (p *Player) SendEnterMapInfo(b maps.OutInfo) {
|
||||
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) 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))
|
||||
func (p *Player) SendPackCmd(cmd uint32, b any) {
|
||||
|
||||
p.SendPack(NewTomeeHeader(cmd, p.Info.UserID).Pack(&b))
|
||||
}
|
||||
|
||||
func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
|
||||
@@ -63,9 +28,3 @@ func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {
|
||||
p.SendPack(t1.Pack(&b))
|
||||
|
||||
}
|
||||
func (f *Player) SendUsePetItemInfo(b info.UsePetIteminfo) {
|
||||
|
||||
t1 := NewTomeeHeader(2406, f.Info.UserID)
|
||||
f.SendPack(t1.Pack(&b))
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,20 @@ import (
|
||||
"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) {
|
||||
if c == nil {
|
||||
return
|
||||
@@ -19,14 +33,8 @@ func (s *Space) LeaveMap(c common.PlayerI) {
|
||||
}
|
||||
|
||||
s.UP_ARENA(c, 0) //退出擂台
|
||||
s.User.Range(func(k uint32, v common.PlayerI) (stop bool) {
|
||||
|
||||
if k != c.GetInfo().UserID {
|
||||
v.SendLeaveMapInfo(info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
|
||||
|
||||
}
|
||||
return false
|
||||
})
|
||||
s.Broadcast(c, 2002, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
|
||||
|
||||
s.User.Delete(c.GetInfo().UserID)
|
||||
s.UserInfo.Delete(c.GetInfo().UserID)
|
||||
@@ -41,12 +49,9 @@ func (s *Space) EnterMap(c common.PlayerI) {
|
||||
|
||||
out := info.NewOutInfo()
|
||||
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 {
|
||||
v.SendEnterMapInfo(*out)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
s.Broadcast(c, 2001, info.LeaveMapOutboundInfo{UserID: c.GetInfo().UserID})
|
||||
|
||||
s.User.Store(c.GetInfo().UserID, c)
|
||||
s.UserInfo.Store(c.GetInfo().UserID, *out)
|
||||
if s.SuperValue != nil {
|
||||
@@ -67,18 +72,14 @@ func (s *Space) GetInfo() []maps.OutInfo {
|
||||
|
||||
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()
|
||||
//r := cool.Limiter.Get("Broadcast"+gconv.String(mapid), rate.Limit(10), 5)
|
||||
if !limiter.Allow() {
|
||||
return
|
||||
}
|
||||
|
||||
s.User.Range(func(playerID uint32, player common.PlayerI) bool {
|
||||
player.SendWalkMapInfo(b)
|
||||
|
||||
return false
|
||||
})
|
||||
go s.Broadcast(c, 2101, info)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -74,13 +74,8 @@ func (s *Space) UP_ARENA(c common.PlayerI, FLAG uint32) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user