diff --git a/common/rpc/rpc.go b/common/rpc/rpc.go index 36626e806..b951f038e 100644 --- a/common/rpc/rpc.go +++ b/common/rpc/rpc.go @@ -29,8 +29,8 @@ type ServerHandler struct{} // 实现踢人 func (h *ServerHandler) Kick(ctx context.Context, userid uint32) error { - - cool.Loger.Info(context.TODO(),"服务器收到踢人" ) + + cool.Loger.Info(context.TODO(), "服务器收到踢人") useid1, err := share.ShareManager.GetUserOnline(userid) if err != nil { @@ -48,13 +48,14 @@ func (h *ServerHandler) Kick(ctx context.Context, userid uint32) error { // 注册logic服务器 func (h *ServerHandler) RegisterLogic(ctx context.Context, id, port uint16) error { + cool.Loger.Debug(context.Background(), "注册logic服务器", id, port) //TODO 待修复滚动更新可能导致的玩家可以同时在旧服务器和新服务器同时在线的bug revClient, ok := jsonrpc.ExtractReverseClient[ClientHandler](ctx) if !ok { return fmt.Errorf("no reverse client") } - blservice.NewLoginServiceService().GetServerID(id) - aa, ok := clientmap[port] + t, _ := blservice.NewLoginServiceService().GetServerID(id) + aa, ok := clientmap[t] if ok { //如果已经存在且这个端口已经被存过 aa.QuitSelf(0) } diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 2df93f6bf..d56ba6b7e 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -24,7 +24,7 @@ func (s *Server) Boot() error { // gnet.WithReuseAddr(true), gnet.WithSocketRecvBuffer(s.bufferSize)) if err != nil { - return err + panic(err) } // err := gnet.Run(s, s.network+"://"+s.addr, gnet.WithMulticore(s.multicore)) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index 0d0909daa..12663f1d2 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -184,7 +184,10 @@ func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Playe // 加载进度 func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) { + if c.FightC != nil { + + c.FightC.LoadPercent(c, int32(data.Percent)) + } - c.FightC.LoadPercent(c, int32(data.Percent)) return nil, -1 } diff --git a/logic/controller/item.go b/logic/controller/item.go index 9c8bee585..505a72a13 100644 --- a/logic/controller/item.go +++ b/logic/controller/item.go @@ -126,9 +126,17 @@ func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) ( // 2. 生成 1-10 的随机数:rand.Intn(10) → 0-9,+1 后范围变为 1-10 randomNum := rand.Intn(10) + 1 c.Service.Talk(func(t map[uint32]uint32) bool { + if t == nil { + t = make(map[uint32]uint32) + + } _, ok := t[data.ID] - if ok { - t[data.ID] += 1 + if !ok { + t[data.ID] = 0 + } + + t[data.ID] += 1 + if t[data.ID] < uint32(te.CollectCnt) { result.OutList = append(result.OutList, item.CateInfo{ID: uint32(talkcacche[te.Name]), Count: uint32(randomNum)}) c.ItemAdd(model.SingleItemInfo{ItemId: uint32(talkcacche[te.Name]), ItemCnt: uint32(randomNum)}) } diff --git a/logic/controller/pet.go b/logic/controller/pet.go index 140a750d6..1e5d93110 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -166,7 +166,7 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player) }) if ok { - c.AddPetExp(onpet, data.Exp, false) + c.AddPetExp(onpet, data.Exp) } return &pet.PetSetExpOutboundInfo{ diff --git a/logic/logic1 b/logic/logic1 deleted file mode 100644 index d454c1310..000000000 Binary files a/logic/logic1 and /dev/null differ diff --git a/logic/service/fight/effect/effect_4_5.go b/logic/service/fight/effect/effect_4_5.go index 1663dfdd3..9ddfabe93 100644 --- a/logic/service/fight/effect/effect_4_5.go +++ b/logic/service/fight/effect/effect_4_5.go @@ -44,7 +44,7 @@ func (e *EffectStat) OnSkill(ctx input.Ctx) bool { if !e.Hit() { return true } - t, _, _ := e.Input.Player.Roll(e.EffectNode.SideEffectArgs[1], 100) + t, _, _ := e.Input.Player.Roll(e.SideEffectArgs[1], 100) if !t { //没触发 return true } @@ -53,10 +53,10 @@ func (e *EffectStat) OnSkill(ctx input.Ctx) bool { ptype = info.AbilityOpType.SUB } if !e.Etype { //自身 - e.Input.SetProp(e.Input, int8(e.EffectNode.SideEffectArgs[0]), int8(e.EffectNode.SideEffectArgs[2]), ptype) + e.Input.SetProp(e.Input, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]), ptype) } else { //对方 - ctx.SetProp(e.Input, int8(e.EffectNode.SideEffectArgs[0]), int8(e.EffectNode.SideEffectArgs[2]), ptype) + ctx.SetProp(e.Input, int8(e.SideEffectArgs[0]), int8(e.SideEffectArgs[2]), ptype) } return true } diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 682a1dcb0..bbc715de5 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -166,8 +166,6 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) bool { func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.PlayerI) *FightC { f := &FightC{} f.ownerID = p1.GetInfo().UserID - f.Info.Status = status //房主 - f.Info.Mode = mode f.StartTime = time.Now() seed := f.StartTime.UnixNano() ^ int64(p1.GetInfo().UserID) ^ int64(p2.GetInfo().UserID) // ^ int64(f.Round) // 用异或运算混合多维度信息 @@ -176,6 +174,8 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla Status: status, } + f.Info.Status = status //房主 + f.Info.Mode = mode ok := f.initplayer(p1, false) if !ok { return nil @@ -710,11 +710,12 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { for i := 0; i < 20; i++ { //堆叠状态剩余回合 t := f.First.GetEffect(input.EffectType.Status, i) - if t[0].ID() != 0 { //状态都是叠层类的 + + if len(t) > 0 && t[0].ID() != 0 { //状态都是叠层类的 ret.FAttack.Status[i] = int8(t[0].Duration()) } t = f.Second.GetEffect(input.EffectType.Status, i) - if t[0].ID() != 0 { + if len(t) > 0 && t[0].ID() != 0 { ret.SAttack.Status[i] = int8(t[0].Duration()) } diff --git a/logic/service/fight/input/node.go b/logic/service/fight/input/node.go index 64bfc3331..ca1e8e59b 100644 --- a/logic/service/fight/input/node.go +++ b/logic/service/fight/input/node.go @@ -112,8 +112,9 @@ func (c *Input) AddEffect(e Effect) { e.Stack(v.Stack() + e.Stack()) //获取到当前叠层数然后叠加 //v.Duration(e.Duration()) //回合数覆盖 } - c.Effects = append(c.Effects, e) + } + c.Effects = append(c.Effects, e) return } @@ -131,13 +132,13 @@ func (c *Input) Exec(fn func(Effect) bool) bool { result := true for _, value := range c.Effects { if value.Alive() { - result1 := fn(value) - if !result1 { + + if !fn(value) { //存在false,但是仍然要向下执行 result = false //如果是false,说明存在阻止向下执行的effect,比如免疫能力提升效果 } } - return true + } return result diff --git a/logic/service/fight/node/PetSwitch.go b/logic/service/fight/node/PetSwitch.go index 461fd9303..3cf464de1 100644 --- a/logic/service/fight/node/PetSwitch.go +++ b/logic/service/fight/node/PetSwitch.go @@ -1,6 +1,9 @@ package node -import "blazing/logic/service/fight/input" +import ( + "blazing/logic/service/fight/info" + "blazing/logic/service/fight/input" +) // 切精灵返回false,重写change方法来实现切换效果 // 精灵切换相关触发 @@ -14,6 +17,7 @@ func (e *EffectNode) OnSwitchOut(ctx input.Ctx) bool { if e.GetInput().UserID == ctx.Player.GetInfo().UserID { //清除对方的我方施加uff e.NotALive() } + return true } @@ -21,11 +25,8 @@ func (e *EffectNode) OnOwnerSwitchIn(ctx input.Ctx) bool { return true } -//自身下场,清除掉技能效果 +// 自身下场,清除掉技能效果 func (e *EffectNode) OnOwnerSwitchOut(ctx input.Ctx) bool { - e.Input.AttackValue = nil - //自身下场清除掉自身的回合效果 - //this.GetBattle().Effects[this.GetInput().UserID].RemoveEffect(this) - e.NotALive() + e.Input.AttackValue = info.NewAttackValue(e.Input.UserID) return true } diff --git a/logic/service/fight/playeraction.go b/logic/service/fight/playeraction.go index bf1da594e..96f839cc9 100644 --- a/logic/service/fight/playeraction.go +++ b/logic/service/fight/playeraction.go @@ -51,7 +51,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) { BaseAction: action.NewBaseAction(c.GetInfo().UserID), } f.Switch = append(f.Switch, ret) - + f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升 f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool { t.OnOwnerSwitchOut(input.Ctx{}) diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index 2c2fcbfb1..534db64b7 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -12,9 +12,12 @@ import ( "fmt" "reflect" + "github.com/gobwas/ws" + "github.com/gobwas/ws/wsutil" "github.com/gogf/gf/v2/os/glog" "github.com/lunixbochs/struc" "github.com/panjf2000/gnet/v2" + "github.com/panjf2000/gnet/v2/pkg/logging" ) // TomeeHeader 结构体字段定义 @@ -177,7 +180,7 @@ func (h *ClientData) Recv(data TomeeHeader) { return } - t := h.Conn.Context().(*ClientData).Player + t := h.Conn.Context().(*ClientData) if ok && aa != 0 { //这里实现回复错误包 @@ -245,3 +248,30 @@ func (h *ClientData) OnEvent(v []byte) { h.Recv(header) } +func (p *ClientData) SendPack(b []byte) error { + // if _, ok := p.MainConn.Context().(*ClientData); !ok { + // return fmt.Errorf("链接错误,取消发包") + + // } + + p.Conn.Context().(*ClientData).Mu.Lock() + defer p.Conn.Context().(*ClientData).Mu.Unlock() + + if p.Conn.Context().(*ClientData).Wsmsg.Upgraded { + // This is the echo server + err := wsutil.WriteServerMessage(p.Conn, ws.OpBinary, b) + if err != nil { + logging.Infof("conn[%v] [err=%v]", p.Conn.RemoteAddr().String(), err.Error()) + return err + } + } else { + + _, err := p.Conn.Write(b) + if err != nil { + glog.Debug(context.Background(), err) + + } + } + + return nil +} diff --git a/logic/service/player/pet.go b/logic/service/player/pet.go index 728da526f..c2b81ea6a 100644 --- a/logic/service/player/pet.go +++ b/logic/service/player/pet.go @@ -13,7 +13,7 @@ import ( // 主函数实现 // 添加经验 // 禁止发包 -func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32, bro bool) { +func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) { addExp = utils.Min(addExp, p.Info.ExpPool) originalLevel := petinfo.Level Exp := petinfo.Exp + addExp @@ -38,19 +38,6 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32, bro bool) { petinfo.CalculatePetPane() petinfo.Cure() } - if bro { - return - } - t1 := NewTomeeHeader(2508, p.Info.UserID) - rrr := &info.PetUpdateOutboundInfo{} - - var petinfwo info.UpdatePropInfo - - copier.Copy(&petinfwo, petinfo) - rrr.Data = append(rrr.Data, petinfwo) - p.SendPack(t1.Pack(rrr)) //准备包由各自发,因为协议不一样 - // 发送经验更新消息 - //player.SendMessage(generatePetUpdateInfo(petEntity, originalExp+addExp-exp, addition)) // 处理技能学习 canLearnSkillList := LastFourElements(petinfo.GetLevelRangeCanLearningSkills(originalLevel, petinfo.Level)) //获取最后四个技能,如果不足,那就取全部技能 @@ -70,7 +57,18 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32, bro bool) { } petinfo.SkillList = petinfo.SkillList[:4] //归正到4 - //todo 待实现 + + t1 := NewTomeeHeader(2508, p.Info.UserID) + rrr := &info.PetUpdateOutboundInfo{} + + var petinfwo info.UpdatePropInfo + + copier.Copy(&petinfwo, petinfo) + rrr.Data = append(rrr.Data, petinfwo) + p.SendPack(t1.Pack(rrr)) //准备包由各自发,因为协议不一样 + // 发送经验更新消息 + //player.SendMessage(generatePetUpdateInfo(petEntity, originalExp+addExp-exp, addition)) + // // 发送技能更新消息 // updateSkillInfo := UpdateSkillInfo{ // PetCatchTime: petEntity.captureTime, diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 31a55d14a..d7e5458eb 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -6,7 +6,6 @@ import ( "blazing/common/socket/errorcode" "blazing/common/utils" "blazing/cool" - "fmt" "math/rand" "strings" @@ -21,12 +20,8 @@ import ( "time" "github.com/antlabs/timer" - "github.com/gobwas/ws" - "github.com/gobwas/ws/wsutil" "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/glog" "github.com/gogf/gf/v2/util/gconv" - "github.com/panjf2000/gnet/pkg/logging" "github.com/panjf2000/gnet/v2" ) @@ -109,6 +104,10 @@ func (p *Player) SpawnMonsters() { p.SendPack(tt.Pack(&p.OgreInfo)) +} +func (p *Player) SendPack(b []byte) error { + return p.MainConn.Context().(*ClientData).SendPack(b) + } // 2. 从 string 类型 slice 随机选一个元素 @@ -282,33 +281,6 @@ func (player1 *Player) Kick() { <-player1.MainConn.Context().(*ClientData).CloseChan } } -func (p *Player) SendPack(b []byte) error { - if _, ok := p.MainConn.Context().(*ClientData); !ok { - return fmt.Errorf("链接错误,取消发包") - - } - - p.MainConn.Context().(*ClientData).Mu.Lock() - defer p.MainConn.Context().(*ClientData).Mu.Unlock() - - if p.MainConn.Context().(*ClientData).Wsmsg.Upgraded { - // This is the echo server - err := wsutil.WriteServerMessage(p.MainConn, ws.OpBinary, b) - if err != nil { - logging.Infof("conn[%v] [err=%v]", p.MainConn.RemoteAddr().String(), err.Error()) - return err - } - } else { - - err := p.MainConn.AsyncWrite(b, nil) - if err != nil { - glog.Debug(context.Background(), err) - - } - } - - return nil -} func (p *Player) Cheak(b error) { if b != nil { diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index a59176ddd..24ed3db38 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -3,7 +3,7 @@ server: address: ":8080" #前台服务器地址 port: 53388 #后台服务器端口 rpc: 56409 #rpc服务端口 - game: [27777] + game: [27777, 27778] openapiPath: "/api.json" swaggerPath: "/swagger" clientMaxBodySize: diff --git a/public/config/talk.xml b/public/config/talk.xml index c2c12a03f..377d924d3 100644 --- a/public/config/talk.xml +++ b/public/config/talk.xml @@ -36,4 +36,5 @@ + \ No newline at end of file