diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 3e50794e3..75e0bdce5 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -6,10 +6,7 @@ import ( "sync/atomic" "time" - "blazing/common/data/share" - - "blazing/logic/service" - "blazing/logic/service/maps" + "blazing/logic/service/player" "github.com/gogf/gf/v2/os/glog" "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) { atomic.AddInt64(&s.connected, -1) //logging.Infof("conn[%v] disconnected", c.RemoteAddr().String()) - v, ok := c.Context().(*service.ClientData) + v, ok := c.Context().(*player.ClientData) if !ok { return } if v.Player != nil { - glog.Debug(context.Background(), v.Player.Info.UserID, "断开连接") - maps.LeaveMap(v.Player) - - v.Player.IsLogin = false - service.Mainplayer.Delete(v.Player.Info.UserID) - share.ShareManager.DeleteUserOnline(v.Player.Info.UserID) //设置用户登录服务器 - v.Player.Save() //保存玩家数据 + 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) { if conn.Context() == nil { - conn.SetContext(service.NewClientData()) //注入data + conn.SetContext(player.NewClientData()) //注入data } atomic.AddInt64(&s.connected, 1) @@ -91,7 +82,7 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) { return gnet.Close } - ws := c.Context().(*service.ClientData).Wsmsg + ws := c.Context().(*player.ClientData).Wsmsg if ws.Tcp { //升级失败时候防止缓冲区溢出 s.handleTcp(c) return gnet.None @@ -175,7 +166,7 @@ const CROSS_DOMAIN = " 0 { rett.Info2.Catchable = 1 - t, _ := f.Opp.Player.(*AI_player) + t, _ := f.Opp.Player.(*player.AI_player) t.CanCapture = true } @@ -203,54 +180,135 @@ func init() { Fightpool, _ = ants.NewPool(math.MaxInt32) //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.OwnerID = p1.ID() - f.Info = i //房主 + f.ownerID = p1.ID() + f.Info.FightId = i //房主 seed := f.StartTime.UnixNano() ^ int64(p1.ID()) ^ int64(p2.ID()) // ^ int64(f.Round) // 用异或运算混合多维度信息 f.rand = rand.New(rand.NewSource(seed)) + f.Info = info.NoteReadyToFightInfo{ - f.Our = &Input{ - CurrentPet: info.CreateBattlePetEntity(&p1.GetPetInfo()[0], f.rand), - Player: p1, + FightId: i, } - for k, v := range p1.GetPetInfo() { - if i.MAXPET == 0 || k < int(i.MAXPET) { //todo 待测试 - f.Our.AllPet = append(f.Our.AllPet, info.CreateBattlePetEntity(&v, f.rand)) - } + f.initplayer(p1, false) - } + 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() { rr := Fightpool.Submit(f.battleLoop) if rr != nil { 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() // 起战斗循环 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) @@ -261,7 +319,7 @@ func (f *FightC) Broadcast(t func(ff *Input)) { // 战斗回合循环 func (f *FightC) battleLoop() { 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) //战斗开始前操作 @@ -272,7 +330,7 @@ func (f *FightC) battleLoop() { if f.actionChan == nil { //回合数超过250,战斗平局结束f.Round > 250 || break } - actions := make(map[uint32]info.BattleActionI) // 每个玩家一条记录 + actions := make(map[uint32]BattleActionI) // 每个玩家一条记录 timeout := time.After(60 * time.Second) for len(actions) < 2 { @@ -287,9 +345,9 @@ func (f *FightC) battleLoop() { continue } - if a, isExpelled := action.(*info.ActiveSwitchAction); isExpelled { + if a, isExpelled := action.(*ActiveSwitchAction); isExpelled { //fmt.Println("对方死亡切换") - f.Broadcast(func(ff *Input) { + f.Broadcast(func(ff *input.Input) { ff.Player.SendChangePet(a.Reason) }) @@ -322,10 +380,10 @@ func (f *FightC) battleLoop() { fmt.Println("回合操作超时") 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 { - 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()] p2Action := actions[f.Opp.Player.ID()] fmt.Println("开始结算回合") - var BattleActionI [2]info.BattleActionI - BattleActionI[0], BattleActionI[1] = info.Compare(p1Action, p2Action) + var BattleActionI [2]BattleActionI + BattleActionI[0], BattleActionI[1] = Compare(p1Action, p2Action) 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) //广播逃跑原因 }) break - case *info.PlayerOfflineAction: //单方掉线 + case *PlayerOfflineAction: //单方掉线 - f.Broadcast(func(ff *Input) { + f.Broadcast(func(ff *input.Input) { ff.Player.SendFightEndInfo(faction.Reason) //广播逃跑原因 }) break - case *info.ActiveSwitchAction: //切换上场的 + case *ActiveSwitchAction: //切换上场的 f.enterturn(BattleActionI[1], nil) //切换,相当于后手直接出手 - case *info.UseItemAction: //使用道具 + case *UseItemAction: //使用道具 fmt.Println(faction.ItemID) switch { case faction.ItemID >= 30001 && faction.ItemID <= 300010: //胶囊 - f.Broadcast(func(ff *Input) { + f.Broadcast(func(ff *input.Input) { //todo 将血量和技能pp传回enterturn - tt, ok := ff.Player.(*Player) - mo, ism := f.Opp.Player.(*AI_player) + tt, ok := ff.Player.(*player.Player) + mo, ism := f.Opp.Player.(*player.AI_player) if ok { //如果获取玩家 @@ -381,7 +439,7 @@ func (f *FightC) battleLoop() { ff.Player.SendFightEndInfo(info.FightOverInfo{ - WinnerId: f.OwnerID, + WinnerId: f.ownerID, }) }) @@ -395,7 +453,7 @@ func (f *FightC) battleLoop() { fmt.Println("ItemID 不在指定范围内") } - case *info.SelectSkillAction: //选择技能 + case *SelectSkillAction: //选择技能 //回合前操作,比如挂载buff 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 -func (f *FightC) parseskill(id *info.SelectSkillAction) { +func (f *FightC) parseskill(id *SelectSkillAction) { temparg := id.Skill.SideEffectArgS for _, v := range id.Skill.SideEffectS { - t, ok := info.NodeM[v] + t, ok := node.NodeM[v] if ok { //获取成功 @@ -461,43 +478,33 @@ func (f *FightC) parseskill(id *info.SelectSkillAction) { t.SetArgs(temparg[:args]) //设置入参 //如果不是是房主方,说明施加的对象是反的,比如本来是false,实际上是给邀请方施加的 //所以这里要对target取反 - if id.GetPlayerID() != f.OwnerID { + if id.GetPlayerID() != f.ownerID { t.SetOwner(!t.GetOwner()) } temparg = temparg[args:] - f.EffectS.AddEffect(deepcopy.Copy(t).(info.Effect)) + f.EffectS.AddEffect(deepcopy.Copy(t).(node.Effect)) } } } -// 创建BPET实例的辅助函数 -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) { +func (f *FightC) initAttackers(fattack, sattack BattleActionI) { // 伤害值 // 根据攻击方归属设置当前战斗的主/次攻击方属性 - var first, second *Input // 定义临时变量存储主/次攻击方 - if fattack.GetPlayerID() == f.OwnerID { - first, second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方 + + if fattack.GetPlayerID() == f.ownerID { + f.First, f.Second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方 } else { - first, second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方 + f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方 } // 统一赋值,减少重复代码 - f.First = f.newBPET(first) - f.Second = f.newBPET(second) + f.First.InitAttackValue() + f.Second.InitAttackValue() 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 // 记录技能信息 attacker.AttackValue.SkillID = uint32(skill.Skill.ID) //获取技能ID 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 !t.GetOwner() { //先获取对方的 - return t.AttackTime() + return t.AttackTime(attacker, defender) } return true }) if attacker.AttackValue.AttackTime == 1 { //如果命中 - spower := skill.Skill.CalculatePower(defender.BattlePetEntity) + spower := skill.Skill.CalculatePower(defender.CurrentPet) attacker.Damage = spower CritRate := utils.Max(skill.Skill.CritRate, 1) 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) //初始化先后手 - var attacker, defender *BPET + var attacker, defender *input.Input for i := 0; i < 2; i++ { + var attackeraction BattleActionI if i == 0 { // attacker, defender = f.First, f.Second - attacker.BattleActionI, defender.BattleActionI = fattack, sattack + attackeraction = fattack + //attacker.BattleActionI, defender.BattleActionI = fattack, sattack } else { attacker, defender = f.Second, f.First + attackeraction = sattack } - skill, ok := attacker.BattleActionI.(*info.SelectSkillAction) + skill, ok := attackeraction.(*SelectSkillAction) if !ok { //还有系统选择放弃出手的 continue @@ -597,15 +607,15 @@ func (f *FightC) enterturn(fattack, sattack info.BattleActionI) { ) skill.Skill.Info.PP-- //减少PP if defender.CurrentPet.Info.Hp == 0 { - defender.CanChange = true //被打死就可以切精灵了 - if attacker.IsWin(defender.CurrentPet.Info.CatchTime) { //然后检查是否战斗结束 + defender.CanChange = true //被打死就可以切精灵了 + if f.IsWin(attacker, defender.CurrentPet.Info.CatchTime) { //然后检查是否战斗结束 var WinnerId uint32 if i == 0 { WinnerId = f.First.Player.ID() } else { WinnerId = f.Second.Player.ID() } - defer f.Broadcast(func(ff *Input) { + defer f.Broadcast(func(ff *input.Input) { //todo 将血量和技能pp传回enterturn 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{ FAttack: *f.First.AttackValue, SAttack: *f.Second.AttackValue, diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index 5e7a3b039..1d1ec3eb1 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -114,6 +114,7 @@ type BattlePetEntity struct { Status StatusDict //精灵的状态 //能力提升属性 Prop PropDict + NotAlive bool `struc:"skip"` DamageZone map[EnumCategory]map[EnumsZoneType]map[EnumsZoneType][]float64 // 三维map 伤害类型-》增还是减-》加还是乘-》值 } diff --git a/logic/service/fight/info/info.go b/logic/service/fight/info/info.go index ab755bfec..2a688a095 100644 --- a/logic/service/fight/info/info.go +++ b/logic/service/fight/info/info.go @@ -195,8 +195,7 @@ func (t *NoteReadyToFightInfo) onBothFinished() { // ReadyFightPetInfo 准备战斗的精灵信息结构体,ReadyFightPetInfo类 type ReadyFightPetInfo struct { // 精灵ID,@UInt long - ID uint32 `fieldDesc:"精灵ID" ` - NotAlive bool `struc:"skip"` + ID uint32 `fieldDesc:"精灵ID" ` // 精灵等级,@UInt long Level uint32 `fieldDesc:"精灵等级" ` diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go new file mode 100644 index 000000000..00e0e3e89 --- /dev/null +++ b/logic/service/fight/input/input.go @@ -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 + +} diff --git a/logic/service/fight/battle/node/Battle.go b/logic/service/fight/node/Battle.go similarity index 100% rename from logic/service/fight/battle/node/Battle.go rename to logic/service/fight/node/Battle.go diff --git a/logic/service/fight/battle/node/Heal.go b/logic/service/fight/node/Heal.go similarity index 100% rename from logic/service/fight/battle/node/Heal.go rename to logic/service/fight/node/Heal.go diff --git a/logic/service/fight/battle/node/PetSwitch.go b/logic/service/fight/node/PetSwitch.go similarity index 100% rename from logic/service/fight/battle/node/PetSwitch.go rename to logic/service/fight/node/PetSwitch.go diff --git a/logic/service/fight/battle/node/Sort.go b/logic/service/fight/node/Sort.go similarity index 100% rename from logic/service/fight/battle/node/Sort.go rename to logic/service/fight/node/Sort.go diff --git a/logic/service/fight/battle/node/Stack.go b/logic/service/fight/node/Stack.go similarity index 100% rename from logic/service/fight/battle/node/Stack.go rename to logic/service/fight/node/Stack.go diff --git a/logic/service/fight/battle/node/Turn.go b/logic/service/fight/node/Turn.go similarity index 100% rename from logic/service/fight/battle/node/Turn.go rename to logic/service/fight/node/Turn.go diff --git a/logic/service/fight/battle/node/attack.go b/logic/service/fight/node/attack.go similarity index 100% rename from logic/service/fight/battle/node/attack.go rename to logic/service/fight/node/attack.go diff --git a/logic/service/fight/battle/node/node.go b/logic/service/fight/node/node.go similarity index 94% rename from logic/service/fight/battle/node/node.go rename to logic/service/fight/node/node.go index 258136970..7f10a469a 100644 --- a/logic/service/fight/battle/node/node.go +++ b/logic/service/fight/node/node.go @@ -1,6 +1,7 @@ package node import ( + "blazing/logic/service/fight/input" "context" ) @@ -67,7 +68,7 @@ func (this *EffectNode) GetArgSize() int { return this.ArgSize } -func (this *EffectNode) AttackTime() bool { +func (this *EffectNode) AttackTime(*input.Input, *input.Input) bool { return true diff --git a/logic/service/fight/info/nodemanger.go b/logic/service/fight/node/nodemanger.go similarity index 93% rename from logic/service/fight/info/nodemanger.go rename to logic/service/fight/node/nodemanger.go index 7c4f7733f..13ff74c30 100644 --- a/logic/service/fight/info/nodemanger.go +++ b/logic/service/fight/node/nodemanger.go @@ -1,6 +1,7 @@ -package info +package node import ( + "blazing/logic/service/fight/input" "reflect" ) @@ -19,10 +20,10 @@ type Effect interface { OnDamage() bool // 造成伤害时触发 SetArgs(param []int) //设置参数 - Shield() bool // 护盾值变化时触发 - PostDamage() bool // 伤害结算后触发(血量扣除后) - AttackTime() bool //闪避率计算,,实际上是修改命中的判断 - OnCritPostDamage() bool // 暴击伤害结算后触发 + Shield() bool // 护盾值变化时触发 + PostDamage() bool // 伤害结算后触发(血量扣除后) + AttackTime(*input.Input, *input.Input) bool //闪避率计算,,实际上是修改命中的判断 + OnCritPostDamage() bool // 暴击伤害结算后触发 OnHit() bool // 技能命中时触发 OnMiss() bool // 技能未命中时触发 diff --git a/logic/service/friend/friend.go b/logic/service/friend/friend.go index 0c13c702e..4247b8c60 100644 --- a/logic/service/friend/friend.go +++ b/logic/service/friend/friend.go @@ -1,10 +1,10 @@ package friend -import "blazing/logic/service" +import "blazing/logic/service/player" //基地查看好友列表 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"` UserIds []uint32 `json:"userIds" ` diff --git a/logic/service/item/item.go b/logic/service/item/item.go index be2a9a749..0427ae24f 100644 --- a/logic/service/item/item.go +++ b/logic/service/item/item.go @@ -1,13 +1,13 @@ package item import ( - "blazing/logic/service" + "blazing/logic/service/player" "blazing/modules/blazing/model" ) // 实现了入站消息接口(Go中通过方法集隐式实现) type ItemListInboundInfo struct { - Head service.TomeeHeader `cmd:"2605" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"2605" struc:"[0]pad"` // 查询物品id的开始,对应Java的@UInt long Param1 uint32 `fieldDesc:"查询物品id的开始" messageType:"Item_List"` // 查询物品id的结尾,对应Java的@UInt long @@ -25,7 +25,7 @@ type ItemListOutboundInfo struct { // SingleItemInfo 单个物品信息结构体,对应Java的SingleItemInfo类 type GoldOnlineRemainInboundInfo struct { - Head service.TomeeHeader `cmd:"1106" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"1106" struc:"[0]pad"` } // GoldOnlineRemainOutboundInfo 对应Java的GoldOnlineRemainOutboundInfo diff --git a/logic/service/login/LoginSidInfo.go b/logic/service/login/LoginSidInfo.go index 4640c5235..be5fd83b3 100644 --- a/logic/service/login/LoginSidInfo.go +++ b/logic/service/login/LoginSidInfo.go @@ -2,7 +2,7 @@ package login import ( "blazing/common/data/share" - "blazing/logic/service" + "blazing/logic/service/player" "blazing/modules/blazing/model" "context" @@ -13,7 +13,7 @@ import ( // LoginSidInfo 登录携带的凭证结构体 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字节 diff --git a/logic/service/login/create_player.go b/logic/service/login/create_player.go index 0d1278127..74123d264 100644 --- a/logic/service/login/create_player.go +++ b/logic/service/login/create_player.go @@ -1,9 +1,9 @@ package login -import "blazing/logic/service" +import "blazing/logic/service/player" type CreatePlayerInboundInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 - Head service.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"108" struc:"[0]pad"` //玩家登录 // 玩家昵称,@ArraySerialize注解 Nickname string `struc:"[16]byte"` // 固定长度16字节 @@ -17,7 +17,7 @@ type CreatePlayerOutInfo struct { } type ChangePlayerNameInboundInfo struct { - Head service.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"2061" struc:"[0]pad"` //玩家登录 // 玩家昵称,@ArraySerialize注解 Nickname string `struc:"[16]byte"` // 固定长度16字节 diff --git a/logic/service/maphot/maphot.go b/logic/service/maphot/maphot.go index 4dba49005..c0af48882 100644 --- a/logic/service/maphot/maphot.go +++ b/logic/service/maphot/maphot.go @@ -1,12 +1,12 @@ package maphot import ( - "blazing/logic/service" + "blazing/logic/service/player" "blazing/logic/service/space" ) type InInfo struct { - Head service.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"1004" struc:"[0]pad"` //玩家登录 } // OutInfo 表示地图热度的出站消息 diff --git a/logic/service/maps/mapin.go b/logic/service/maps/mapin.go index e4ef42a4e..63ba10fa5 100644 --- a/logic/service/maps/mapin.go +++ b/logic/service/maps/mapin.go @@ -2,7 +2,9 @@ package maps import ( "blazing/common/data/xmlres" - "blazing/logic/service" + + "blazing/logic/service/common" + "blazing/logic/service/player" "blazing/logic/service/space" "blazing/modules/blazing/model" @@ -15,7 +17,7 @@ import ( ) type InInfo struct { - Head service.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图 + Head player.TomeeHeader `cmd:"2001" struc:"[0]pad"` //切换地图 // 地图类型 MapType uint32 @@ -29,7 +31,7 @@ type InInfo struct { 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 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 { //用户离线 @@ -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 { 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)] if ok && mapss.Monsters != nil { for i, m := range mapss.Monsters.Monsters { //这里是9个 id := strings.Split(m.ID, " ") lv := strings.Split(m.Lv, " ") - ttt := service.OgrePetInfo{ + ttt := player.OgrePetInfo{ Id: gconv.Uint32(RandomStringFromSlice(id)), } 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++ { t2.Data[t.monsters[i]] = t1.Data[t.monsters[i]] diff --git a/logic/service/maps/maplist.go b/logic/service/maps/maplist.go index 3a88db6f1..848298f06 100644 --- a/logic/service/maps/maplist.go +++ b/logic/service/maps/maplist.go @@ -1,9 +1,9 @@ package maps -import "blazing/logic/service" +import "blazing/logic/service/player" type ListMapPlayerInboundInfo struct { - Head service.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图 + Head player.TomeeHeader `cmd:"2003" struc:"[0]pad"` //切换地图 } type ListMapPlayerOutboundInfo struct { diff --git a/logic/service/maps/mapout.go b/logic/service/maps/mapout.go index 93dc6139f..91d6b2359 100644 --- a/logic/service/maps/mapout.go +++ b/logic/service/maps/mapout.go @@ -1,37 +1,21 @@ package maps import ( - "blazing/logic/service" + "blazing/logic/service/common" + "blazing/logic/service/player" "blazing/logic/service/space" ) -type LeaveMapOutboundInfo struct { - // 米米号 - UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"` -} - 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 player.SendPack(t.Head.Pack(&o)) 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()) -} diff --git a/logic/service/space/walk.go b/logic/service/maps/walk.go similarity index 71% rename from logic/service/space/walk.go rename to logic/service/maps/walk.go index ec069cf6a..c4688dc43 100644 --- a/logic/service/space/walk.go +++ b/logic/service/maps/walk.go @@ -1,12 +1,15 @@ -package space +package maps import ( - "blazing/logic/service" + "blazing/logic/service/common" + "blazing/logic/service/player" + "blazing/logic/service/space" + "blazing/modules/blazing/model" ) -type InInfo struct { - Head service.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包 +type WalkInInfo struct { + Head player.TomeeHeader `cmd:"2101" struc:"[0]pad"` //走路包 // Flag: 0为走,1为飞行模式,@UInt long Flag uint32 @@ -17,12 +20,12 @@ type InInfo struct { Reverse2 string `struc:"[2]byte"` } -func (t *InInfo) Broadcast(mapid uint32, o OutInfo) { +func (t *WalkInInfo) Broadcast(mapid uint32, o WalkOutInfo) { //tt := planetmap //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 tt := t.Head.Pack(&o) player.SendPack(tt) @@ -32,7 +35,7 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) { } // PeopleWalkOutboundInfo PeopleWalkOutboundInfo类,实现OutboundMessage接口 -type OutInfo struct { +type WalkOutInfo struct { // Flag: 0为走,1为飞行模式 Flag uint32 `fieldDesc:"0为走,1为飞行模式" codec:"uint"` diff --git a/logic/service/nono/nono.go b/logic/service/nono/nono.go index 6f70878f7..af5cce921 100644 --- a/logic/service/nono/nono.go +++ b/logic/service/nono/nono.go @@ -1,6 +1,6 @@ package nono -import "blazing/logic/service" +import "blazing/logic/service/player" // NonoOutboundInfo 用于表示Nono相关的出站信息 type NonoOutboundInfo struct { @@ -55,7 +55,7 @@ type NonoOutboundInfo struct { type NonoInboundInfo struct { // 消息头部,命令ID对应MessageCommandIDRegistry.Nono_Info - Head service.TomeeHeader `cmd:"9003" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"9003" struc:"[0]pad"` // 米米号,对应Java的@UInt long类型 UserID uint32 `fieldDescription:"米米号" struc:"uint32" uint:"true"` diff --git a/logic/service/pet/list.go b/logic/service/pet/list.go index f19e3bf2b..2e8d30a04 100644 --- a/logic/service/pet/list.go +++ b/logic/service/pet/list.go @@ -1,9 +1,9 @@ package pet -import "blazing/logic/service" +import "blazing/logic/service/player" type GetPetListInboundEmpty struct { - Head service.TomeeHeader `cmd:"2303" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"2303" struc:"[0]pad"` } type GetPetListOutboundInfo struct { ShortInfoListLen uint32 `struc:"int32,sizeof=ShortInfoList"` diff --git a/logic/service/pet/pet.go b/logic/service/pet/pet.go index 96566a5b3..266c5f548 100644 --- a/logic/service/pet/pet.go +++ b/logic/service/pet/pet.go @@ -1,13 +1,14 @@ package pet import ( - "blazing/logic/service" + "blazing/logic/service/common" + "blazing/logic/service/player" "blazing/logic/service/space" "blazing/modules/blazing/model" ) type InInfo struct { - Head service.TomeeHeader `cmd:"2301" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"2301" struc:"[0]pad"` CatchTime uint32 } @@ -26,13 +27,13 @@ type PetReleaseOutboundInfo struct { // 放入背包或者加入仓库 type PetReleaseInboundInfo struct { - Head service.TomeeHeader `cmd:"2304" struc:"[0]pad"` - CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"` - Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"` + Head player.TomeeHeader `cmd:"2304" struc:"[0]pad"` + CatchTime uint32 `json:"catch_time" fieldDescription:"精灵生成时间" autoCodec:"true" uint:"true"` + Flag uint32 `json:"flag" fieldDescription:"0为放入仓库,1为放入背包" autoCodec:"true" uint:"true"` } type PetShowInboundInfo struct { - Head service.TomeeHeader `cmd:"2305" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"2305" struc:"[0]pad"` CatchTime uint32 `codec:"catchTime" inboundMessageType:"Pet_Show"` Flag uint32 `codec:"flag"` @@ -40,7 +41,7 @@ type PetShowInboundInfo struct { 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 player.SendPack(t.Head.Pack(&o)) @@ -59,8 +60,8 @@ type PetShowOutboundInfo struct { Reserved1 [3]uint32 } type PetOneCureInboundInfo struct { - Head service.TomeeHeader `cmd:"2310" struc:"[0]pad"` - CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"` + Head player.TomeeHeader `cmd:"2310" struc:"[0]pad"` + CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"` } // PetOneCureOutboundInfo 宠物单个治疗出站消息 type PetOneCureOutboundInfo struct { CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true"` @@ -69,8 +70,8 @@ type PetOneCureOutboundInfo struct { // PetDefaultInboundInfo 对应Java的PetDefaultInboundInfo类 // 实现了InboundMessage接口 type PetDefaultInboundInfo struct { - Head service.TomeeHeader `cmd:"2308" struc:"[0]pad"` - CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true" autoCodec:"true" inboundMessageType:"Pet_Default"` + Head player.TomeeHeader `cmd:"2308" struc:"[0]pad"` + CatchTime uint32 `json:"catchTime" fieldDescription:"精灵捕捉时间" uint:"true" autoCodec:"true" inboundMessageType:"Pet_Default"` } // PetDefaultOutboundInfo 对应Java的PetDefaultOutboundInfo类 diff --git a/logic/service/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go similarity index 99% rename from logic/service/SocketHandler_Tomee.go rename to logic/service/player/SocketHandler_Tomee.go index de1d8a98c..a1ba6ffe0 100644 --- a/logic/service/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -1,4 +1,4 @@ -package service +package player import ( "blazing/common/utils/bytearray" diff --git a/logic/service/ai.go b/logic/service/player/ai.go similarity index 71% rename from logic/service/ai.go rename to logic/service/player/ai.go index 46d3fc5c8..8be244c61 100644 --- a/logic/service/ai.go +++ b/logic/service/player/ai.go @@ -1,25 +1,30 @@ -package service +package player import ( + "blazing/common/data/xmlres" + "blazing/logic/service/common" "blazing/logic/service/fight/info" "blazing/modules/blazing/model" "fmt" ) type AI_player struct { - FightC *FightC //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool + FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool petinfo []model.PetInfo //精灵信息 + info model.PlayerInfo 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.petinfo = make([]model.PetInfo, 0) ret.petinfo = append(ret.petinfo, m) + ret.info = i + ret.info.Nick = xmlres.PetMAP[int(m.ID)].DefName return ret } -func (f *AI_player) SetFightC(ff *FightC) { +func (f *AI_player) SetFightC(ff common.FightI) { f.FightC = ff } @@ -56,13 +61,18 @@ func (f *AI_player) SendFightEndInfo(_ info.FightOverInfo) { } 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() { p.FightC = nil return } +func (p *AI_player) GetInfo() model.PlayerInfo { + + return p.info +} func (p *AI_player) GetPetInfo() []model.PetInfo { diff --git a/logic/service/player.go b/logic/service/player/player.go similarity index 89% rename from logic/service/player.go rename to logic/service/player/player.go index cb0efc9ba..27d572f64 100644 --- a/logic/service/player.go +++ b/logic/service/player/player.go @@ -1,9 +1,13 @@ -package service +package player import ( + "blazing/common/data/share" "blazing/common/utils" + "blazing/logic/service/common" "blazing/logic/service/fight/info" + "blazing/logic/service/space" + "blazing/modules/blazing/model" blservice "blazing/modules/blazing/service" "context" @@ -14,6 +18,7 @@ import ( "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/panjf2000/gnet/pkg/logging" "github.com/tnnmigga/enum" ) @@ -95,7 +100,7 @@ type Player struct { Playerinvite uint32 //当前邀请的玩家ID Onlinetime uint32 //当前登录时间 OgreInfo *OgreInfo - FightC *FightC //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool + FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool Service *blservice.UserService //FightInfo info.NoteReadyToFightInfo } @@ -198,7 +203,7 @@ func (p *Player) SendFightEndInfo(b info.FightOverInfo) { t1 := NewTomeeHeader(2506, p.Info.UserID) p.SendPack(t1.Pack(&b)) - p.FightC = nil + p.SetFightC(nil) } 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 } +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 保存玩家数据 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 { p.FightC.Escape(p) //玩家逃跑 diff --git a/logic/service/player/server.go b/logic/service/player/server.go new file mode 100644 index 000000000..73ee2b482 --- /dev/null +++ b/logic/service/player/server.go @@ -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 +} diff --git a/logic/service/wscodec.go b/logic/service/player/wscodec.go similarity index 99% rename from logic/service/wscodec.go rename to logic/service/player/wscodec.go index 5c984b543..fc5439a58 100644 --- a/logic/service/wscodec.go +++ b/logic/service/player/wscodec.go @@ -1,4 +1,4 @@ -package service +package player import ( "bytes" diff --git a/logic/service/room/FitmentShowInfo.go b/logic/service/room/FitmentShowInfo.go index 35b8366fb..0b5ee0082 100644 --- a/logic/service/room/FitmentShowInfo.go +++ b/logic/service/room/FitmentShowInfo.go @@ -1,8 +1,6 @@ package room -import ( - "blazing/logic/service" -) +import "blazing/logic/service/player" // FitmentShowInfo 表示家具展示信息 type FitmentShowInfo struct { @@ -20,7 +18,7 @@ type FitmentShowInfo struct { // FitmentUseringInboundInfo FitmentUseringInboundInfo类,实现InboundMessage接口 type FitmentUseringInboundInfo struct { - Head service.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"10006" struc:"[0]pad"` //玩家登录 // 需要获取基地信息的目标玩家账号ID TargetUserID uint32 `json:"targetUserId"` } @@ -47,12 +45,12 @@ type PetRoomListOutboundInfo struct { } type PetRoomListInboundInfo struct { - Head service.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"2324" struc:"[0]pad"` //玩家登录 // 需要获取基地信息的目标玩家账号ID TargetUserID uint32 `json:"targetUserId"` } type FitmentAllInboundEmpty struct { - Head service.TomeeHeader `cmd:"10007" struc:"[0]pad"` + Head player.TomeeHeader `cmd:"10007" struc:"[0]pad"` } type FitmentAllOutboundInfo struct { FitmentsLen uint32 `json:"fitmentsLen" struc:"sizeof=Fitments"` diff --git a/logic/service/space/space.go b/logic/service/space/space.go index 6c212d76d..32e61e91d 100644 --- a/logic/service/space/space.go +++ b/logic/service/space/space.go @@ -3,7 +3,8 @@ package space import ( "blazing/common/data/xmlres" "blazing/common/utils" - "blazing/logic/service" + + "blazing/logic/service/common" "blazing/modules/blazing/model" "sync" @@ -11,25 +12,25 @@ import ( // Space 针对Player的并发安全map,键为uint32类型 type Space struct { - mu sync.RWMutex // 读写锁,读多写少场景更高效 - data map[uint32]service.PlayerI // 存储玩家数据的map,键为玩家ID - CanRefresh bool //是否能够刷怪 - ID uint32 // 地图ID - Name string //地图名称 - DefaultPos model.Pos //默认位置DefaultPos - Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 + mu sync.RWMutex // 读写锁,读多写少场景更高效 + data map[uint32]common.PlayerI // 存储玩家数据的map,键为玩家ID + CanRefresh bool //是否能够刷怪 + ID uint32 // 地图ID + Name string //地图名称 + DefaultPos model.Pos //默认位置DefaultPos + Positions map[uint32]model.Pos //从上一个地图跳转后默认位置 } // NewSyncMap 创建一个新的玩家同步map func NewSpace() *Space { return &Space{ - data: make(map[uint32]service.PlayerI), + data: make(map[uint32]common.PlayerI), } } // Get 根据玩家ID获取玩家实例 // 读操作使用RLock,允许多个goroutine同时读取 -func (m *Space) Get(playerID uint32) (service.PlayerI, bool) { +func (m *Space) Get(playerID uint32) (common.PlayerI, bool) { m.mu.RLock() defer m.mu.RUnlock() val, exists := m.data[playerID] @@ -38,7 +39,7 @@ func (m *Space) Get(playerID uint32) (service.PlayerI, bool) { // Set 存储玩家实例(按ID) // 写操作使用Lock,独占锁保证数据一致性 -func (m *Space) Set(playerID uint32, player service.PlayerI) *Space { +func (m *Space) Set(playerID uint32, player common.PlayerI) *Space { m.mu.Lock() defer m.mu.Unlock() m.data[playerID] = player @@ -64,7 +65,7 @@ func (m *Space) Len() int { // Range 遍历所有玩家并执行回调函数 // 读操作使用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() defer m.mu.RUnlock() for id, player := range m.data { @@ -113,3 +114,7 @@ func GetSpace(id uint32) *Space { } var planetmap = &utils.SyncMap[uint32, *Space]{} //玩家数据 +type LeaveMapOutboundInfo struct { + // 米米号 + UserID uint32 `struc:"uint32" fieldDesc:"米米号" json:"user_id"` +} diff --git a/logic/service/systemtime/System.go b/logic/service/systemtime/System.go index 175743f11..a77a5033c 100644 --- a/logic/service/systemtime/System.go +++ b/logic/service/systemtime/System.go @@ -1,13 +1,13 @@ package systemtime import ( - "blazing/logic/service" + "blazing/logic/service/player" "time" ) // LoginSidInfo 登录携带的凭证结构体 type InInfo struct { //这里直接使用组合来实现将传入的原始头部数据和结构体参数序列化 - Head service.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录 + Head player.TomeeHeader `cmd:"1002" struc:"[0]pad"` //玩家登录 } diff --git a/logic/service/task/AcceptTask.go b/logic/service/task/AcceptTask.go index b0164a0aa..699c569d9 100644 --- a/logic/service/task/AcceptTask.go +++ b/logic/service/task/AcceptTask.go @@ -1,12 +1,12 @@ package task -import "blazing/logic/service" +import "blazing/logic/service/player" // AcceptTaskInboundInfo 对应Java的AcceptTaskInboundInfo类 // 用于接收任务的入站信息 type AcceptTaskInboundInfo struct { - Head service.TomeeHeader `cmd:"2201|2231" struc:"[0]pad"` - TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long + Head player.TomeeHeader `cmd:"2201|2231" struc:"[0]pad"` + TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long } type AcceptTaskOutboundInfo struct { diff --git a/logic/service/task/AddTask.go b/logic/service/task/AddTask.go index 311f2315f..b59fa4cfe 100644 --- a/logic/service/task/AddTask.go +++ b/logic/service/task/AddTask.go @@ -1,13 +1,13 @@ package task -import "blazing/logic/service" +import "blazing/logic/service/player" // AddTaskBufInboundInfo 对应Java的AddTaskBufInboundInfo类 // 用于接收添加任务缓冲区的入站信息 type AddTaskBufInboundInfo struct { - Head service.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"` - TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long - TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息,对应Java的@ArraySerialize注解 + Head player.TomeeHeader `cmd:"2204|2235" struc:"[0]pad"` + TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long + TaskList []uint32 `struc:"[20]byte"` // 任务步骤信息,对应Java的@ArraySerialize注解 } type AddTaskBufOutboundInfo struct { // 该结构体没有字段,对应Java中的空类 diff --git a/logic/service/task/CompleteTask.go b/logic/service/task/CompleteTask.go index c851826e3..63c697212 100644 --- a/logic/service/task/CompleteTask.go +++ b/logic/service/task/CompleteTask.go @@ -1,11 +1,11 @@ package task -import "blazing/logic/service" +import "blazing/logic/service/player" type CompleteTaskInboundInfo struct { - Head service.TomeeHeader `cmd:"2202|2233" struc:"[0]pad"` - TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long - OutState uint32 `json:"outState" 分支"` // 当前状态,1表示完成任务,对应Java的@UInt long + Head player.TomeeHeader `cmd:"2202|2233" struc:"[0]pad"` + TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long + OutState uint32 `json:"outState" 分支"` // 当前状态,1表示完成任务,对应Java的@UInt long } type CompleteTaskOutboundInfo struct { TaskId uint32 `json:"taskId" description:"任务ID"` // 任务ID,对应Java的@UInt long diff --git a/logic/service/task/Delete_Task.go b/logic/service/task/Delete_Task.go index 973c64c39..9d3198358 100644 --- a/logic/service/task/Delete_Task.go +++ b/logic/service/task/Delete_Task.go @@ -1,11 +1,11 @@ package task -import "blazing/logic/service" +import "blazing/logic/service/player" // DeleteTaskInboundInfo 对应Java的DeleteTaskInboundInfo类 type DeleteTaskInboundInfo struct { - Head service.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"` - TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64对应Java的@UInt long + Head player.TomeeHeader `cmd:"2205|2232" struc:"[0]pad"` + TaskId uint32 `json:"taskId" description:"任务ID"` // 使用uint64对应Java的@UInt long } type DeleteTaskOutboundInfo struct { TaskId uint32 `json:"taskId" description:"任务ID"` // 对应@UInt long和@FieldDescription diff --git a/logic/service/task/GetTask.go b/logic/service/task/GetTask.go index 267c520a9..c20627942 100644 --- a/logic/service/task/GetTask.go +++ b/logic/service/task/GetTask.go @@ -1,7 +1,7 @@ package task import ( - "blazing/logic/service" + "blazing/logic/service/player" "encoding/binary" "errors" @@ -9,7 +9,7 @@ import ( ) 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 } diff --git a/modules/blazing/model/TeamInfo.go b/modules/blazing/model/TeamInfo.go index d12548b01..3dfb54f92 100644 --- a/modules/blazing/model/TeamInfo.go +++ b/modules/blazing/model/TeamInfo.go @@ -2,7 +2,7 @@ package model // TeamInfo 战队信息结构 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 Priv uint32 `struc:"uint32" default:"1"` // 默认值1 SuperCore uint32 `struc:"uint32" default:"1"` // 默认值1