diff --git a/common/rpc/client.go b/common/rpc/client.go index c3e8f5f4..447694a4 100644 --- a/common/rpc/client.go +++ b/common/rpc/client.go @@ -7,6 +7,7 @@ import ( "context" "github.com/butoften/array" + "github.com/samber/lo" ) func GetServerInfoList() []ServerInfo { @@ -45,9 +46,13 @@ func GetServerInfoList() []ServerInfo { } } + array.Sort(&ret1, func(a ServerInfo, b ServerInfo) bool { return a.OnlineID < b.OnlineID }) + ret1 = lo.UniqBy(ret1, func(s ServerInfo) int { + return int(s.Port) + }) //fmt.Printf("升序 Sort: %v\n", ret1) return ret1 diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 581877cb..29014a4d 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -2,7 +2,6 @@ package socket import ( "context" - "fmt" "log" "net" "os" @@ -58,7 +57,7 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) { // 防护逻辑:临时封禁异常 IP(可扩展为 IP 黑名单) // go s.tempBlockIP(remoteIP, 5*time.Minute) } - fmt.Println(err, c.RemoteAddr().String(), "断开连接") + //fmt.Println(err, c.RemoteAddr().String(), "断开连接") atomic.AddInt64(&s.connected, -1) //logging.Infof("conn[%v] disconnected", c.RemoteAddr().String()) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index c50aa6ce..72e1c00b 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -40,7 +40,7 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *pla -1, 0, //野怪没特性 0, - 2) + 50) moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName moinfo.PetList = append(moinfo.PetList, *mo) } else { @@ -104,9 +104,6 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn int(refpet.Shiny), int(refpet.Lv)) - if c.FightC != nil { - return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight - } moinfo := &model.PlayerInfo{} moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName moinfo.PetList = append(moinfo.PetList, *mo) diff --git a/logic/controller/pet.go b/logic/controller/pet.go index bb24e6ac..a65caefa 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -74,7 +74,7 @@ func (h *Controller) PetRelease( if v.CatchTime == uint32(data.CatchTime) { c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { t.Data = v - t.InBag = 0 + //t.InBag = 0 }) @@ -88,9 +88,18 @@ func (h *Controller) PetRelease( case 1: //todo 背包 c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { - t.InBag = 1 - c.Info.PetList = append(c.Info.PetList, t.Data) - result.PetInfo = t.Data + + _, _, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool { + return item.CatchTime == uint32(data.CatchTime) + + }) + + //如果背包没找到,再放入背包 + if !ok && t.CatchTime != 0 { + //t.InBag = 1 + c.Info.PetList = append(c.Info.PetList, t.Data) + result.PetInfo = t.Data + } }) diff --git a/logic/controller/walk.go b/logic/controller/walk.go index f2eff74b..32b71ec3 100644 --- a/logic/controller/walk.go +++ b/logic/controller/walk.go @@ -14,11 +14,11 @@ func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *maps. } result.UserID = data.Head.UserID - c.Info.Pos = data.Point + //glog.Debug(context.Background(), err1) if !c.Info.Pos.BothLessThan50(data.Point) { //距离超过50才广播 data.Broadcast(c.Info.MapID, *result) //走路的广播 } - + c.Info.Pos = data.Point return nil, -1 } diff --git a/logic/service/fight/action.go b/logic/service/fight/action.go index 71e09bec..2df20396 100644 --- a/logic/service/fight/action.go +++ b/logic/service/fight/action.go @@ -55,38 +55,40 @@ func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) { // 切换精灵 主动和被驱逐 func (f *FightC) ChangePet(c common.PlayerI, id uint32) { + if f.closefight { cool.Loger.Debug(context.Background(), " 战斗chan已关闭") return } + selfinput := f.GetInputByPlayer(c, false) + + oldpet := selfinput.CurrentPet ret := &action.ActiveSwitchAction{ BaseAction: action.NewBaseAction(c.GetInfo().UserID), } + selfinput.CurrentPet, ret.Reason = selfinput.GetPet(id) + f.Switch = append(f.Switch, ret) f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升 + //这时候精灵已经切换过了,可以直接给新精灵加效果 - f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool { + f.Broadcast(func(ff *input.Input) { - t.OnSwitchOut() + ff.Exec(func(t input.Effect) bool { - return true + t.Switch(selfinput, oldpet, selfinput.CurrentPet) + + return true + }) }) - f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id) - f.GetInputByPlayer(c, false).CancelAll(f.GetInputByPlayer(c, false)) //清除效果类 - f.GetInputByPlayer(c, true).CancelAll(f.GetInputByPlayer(c, false)) //清除自身对对方施加的效果类 - f.Broadcast(func(ff *input.Input) { //先给自身广播 + + f.Broadcast(func(ff *input.Input) { //先给自身广播 if ff.Player.GetInfo().UserID == c.GetInfo().UserID { ff.Player.SendChangePet(ret.Reason) } }) - f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool { - - t.OnSwitchIn() - - return true - }) f.actionChan <- ret } @@ -144,9 +146,23 @@ func (f *FightC) ReadyFight(c common.PlayerI) { rett.Info2.UserID = f.Info.OpponentInfo.UserID rrsult := func() { //传回函数 + i := Fightpool.Free() + if i <= 0 { + Fightpool.Tune(Fightpool.Cap() + 1) + + cool.Loger.Error(context.Background(), "Fightpool is full") + + } + rr := Fightpool.Submit(f.battleLoop) + if rr != nil { + panic(rr) + } f.Our.Player.SendReadyToFightInfo(rett) f.Opp.Player.SendReadyToFightInfo(rett) + //f.runing = true + //然后开始战斗循环 + } switch f.Info.Status { @@ -174,6 +190,6 @@ func (f *FightC) ReadyFight(c common.PlayerI) { var Fightpool *ants.MultiPool func init() { - Fightpool, _ = ants.NewMultiPool(1, 1, ants.LeastTasks) + Fightpool, _ = ants.NewMultiPool(10, 100, ants.LeastTasks) //defer p.Release() } diff --git a/logic/service/fight/effect/effect_43.go b/logic/service/fight/effect/effect_43.go index 13e3c0e9..743c8a94 100644 --- a/logic/service/fight/effect/effect_43.go +++ b/logic/service/fight/effect/effect_43.go @@ -27,8 +27,9 @@ func (e *Effect43) OnSkill() bool { if !e.Hit() { return true } - - e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, decimal.NewFromInt(int64(e.Ctx().Our.MaxHp)).Div(decimal.NewFromInt(int64(e.SideEffectArgs[0])))) + tt := decimal.NewFromInt(int64(e.Ctx().Our.CurrentPet.Info.MaxHp)).Div(decimal.NewFromInt(int64(e.SideEffectArgs[0]))) + //fmt.Println("恢复自身最大体量的1/n", tt.IntPart()) + e.Ctx().Our.Heal(e.Ctx().Our, &action.SelectSkillAction{}, tt) return true } diff --git a/logic/service/fight/effect/effect_62.go b/logic/service/fight/effect/effect_62.go index b8daafa7..92b9a960 100644 --- a/logic/service/fight/effect/effect_62.go +++ b/logic/service/fight/effect/effect_62.go @@ -4,6 +4,7 @@ import ( "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" "blazing/logic/service/fight/node" + "fmt" "github.com/shopspring/decimal" ) @@ -29,6 +30,7 @@ type Effect62_sub struct { // 这个实际上在对方回合执行的 func (e *Effect62_sub) OnSkill() bool { + fmt.Println("镇魂歌剩余回合", e.Duration()) //defer e.Alive(false) if e.Duration() == 0 { //说明对方没有切换精灵 //直接扣除所有血量OnSkill diff --git a/logic/service/fight/effect/effect_7.go b/logic/service/fight/effect/effect_7.go index 44364db6..3c05d580 100644 --- a/logic/service/fight/effect/effect_7.go +++ b/logic/service/fight/effect/effect_7.go @@ -39,7 +39,8 @@ func (e *Effect7) Damage_Floor() bool { if e.Ctx().DamageZone.Type == info.DamageType.Red { if e.Ctx().Our.CurrentPet.Info.Hp <= e.Ctx().Opp.CurrentPet.Info.Hp { - e.Ctx().DamageZone.Damage = decimal.NewFromInt(int64(e.Ctx().Our.CurrentPet.Info.Hp - e.Ctx().Opp.CurrentPet.Info.Hp)) + e.Ctx().DamageZone.Damage = decimal.NewFromInt(int64(e.Ctx().Opp.CurrentPet.Info.Hp - e.Ctx().Our.CurrentPet.Info.Hp)) + } } diff --git a/logic/service/fight/effect/effect_status.go b/logic/service/fight/effect/effect_status.go index 202fd548..a3a263bc 100644 --- a/logic/service/fight/effect/effect_status.go +++ b/logic/service/fight/effect/effect_status.go @@ -9,9 +9,27 @@ import ( "github.com/shopspring/decimal" ) +type BaseSataus struct { + node.EffectNode +} + +// /重写切换事件 +func (e *BaseSataus) Switch(in *input.Input, outpet, inpet *info.BattlePetEntity) bool { + + //状态如果是我方切换,那么就消除掉状态效果 + if e.Input == e.Ctx().Our { + //下场,执行消回合效果 + // e.ctx.Our.CancelAll() + ///我放下场 + e.Alive(false) + } + + return true +} + // 施加一个基类effect type EffectStatus struct { - node.EffectNode + BaseSataus Status info.EnumBattleStatus } @@ -27,6 +45,7 @@ func (e *StatusNotSkill) Skill_Hit_Pre() bool { } type StatusSleep struct { //睡眠不能出手 ,这个挂载到对面来实现对方攻击后解除睡眠效果 + BaseSataus StatusNotSkill can bool } diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 11f4a767..ff5d1431 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -246,7 +246,13 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { //根本没释放技能,这些效果全部失效 for _, e := range attacker.EffectCache { - e.Alive() + e.Alive(false) + + } + + //这时候将被覆盖的效果全部装回来enterturn + for _, e := range attacker.Effect_Lost { + e.Alive(true) } } diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index 6c9c3a77..9be344ec 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -6,7 +6,6 @@ import ( "blazing/logic/service/fight/action" "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" - "context" "math/rand" "sort" "sync" @@ -16,13 +15,13 @@ import ( ) type FightC struct { - Info info.NoteReadyToFightInfo - IsReady bool - ownerID uint32 // 战斗发起者ID - Our *input.Input //始终等于房主ID - Opp *input.Input //对手ID - Switch []*action.ActiveSwitchAction - + Info info.NoteReadyToFightInfo + IsReady bool + ownerID uint32 // 战斗发起者ID + Our *input.Input //始终等于房主ID + Opp *input.Input //对手ID + Switch []*action.ActiveSwitchAction + runing bool rand *rand.Rand StartTime time.Time actionChan chan action.BattleActionI // 所有操作统一从这里进入 @@ -33,6 +32,7 @@ type FightC struct { Second *input.Input closefight bool overl sync.Once + waittime int info.FightOverInfo } @@ -134,6 +134,12 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) bool { default: } if opp { + switch f.Info.Status { + case info.BattleStatus.FIGHT_WITH_PLAYER: + + default: + temp.Finished = true //PVE 默认boss数据直接加载完成 + } f.Opp = temp //这里是对方的 copier.Copy(&f.Info.OpponentInfo, f.Opp.Player.GetInfo()) @@ -197,20 +203,31 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla } f.Our.SetOPP(f.Opp) f.Opp.SetOPP(f.Our) - i := Fightpool.Free() - if i <= 0 { - Fightpool.Tune(Fightpool.Cap() + 1) - cool.Loger.Error(context.Background(), "Fightpool is full") - } - rr := Fightpool.Submit(f.battleLoop) - if rr != nil { - panic(rr) - } f.Broadcast(func(ff *input.Input) { ff.Player.SendNoteReadyToFightInfo(f.Info) + }) + // 60秒后判断战斗是否开始 + + cool.Cron.AfterFunc(60*time.Second, func() { + if !f.Our.Finished || !f.Opp.Finished { //如果有任一没有加载完成 + f.Reason = info.BattleOverReason.PlayerOVerTime + switch { + case !f.Opp.Finished: //邀请方没加载完成 先判断邀请方,如果都没加载完成,就算做房主胜利 + f.WinnerId = f.Our.Player.GetInfo().UserID + case !f.Our.Finished: //被邀请方没加载完成 + f.WinnerId = f.Opp.Player.GetInfo().UserID + } + f.Broadcast(func(ff *input.Input) { + //todo 将血量和技能pp传回enterturn + + ff.Player.SendFightEndInfo(f.FightOverInfo) + + }) + } + }) return f diff --git a/logic/service/fight/input/effect.go b/logic/service/fight/input/effect.go index 51041bc0..873c0b1d 100644 --- a/logic/service/fight/input/effect.go +++ b/logic/service/fight/input/effect.go @@ -125,7 +125,8 @@ func equalInts(a, b []int) bool { return true } -func (our *Input) AddEffect(e Effect) { +// 返回被替换eddect +func (our *Input) AddEffect(e Effect) Effect { e.Alive(true) //添加后默认激活 //todo 免疫 //TODO 先激活 @@ -133,7 +134,7 @@ func (our *Input) AddEffect(e Effect) { // 如果已有同 ID 的效果,尝试叠加 for _, v := range our.Effects { if v == e { - return //完全相同,跳过执行 + return nil //完全相同,跳过执行 } //如果效果相同,id相同,参数相同,就是同一个,确认是否可以叠加,正常来说本身就可以共存 //衰弱本身参数也是相同的,区别只是传入的回合数不一样和层数不一样 @@ -142,9 +143,10 @@ func (our *Input) AddEffect(e Effect) { v.Alive() && //如果之前的效果还存活 equalInts(v.GetArgs(), e.GetArgs()) { //如果层数可以叠加或者是无限层数 - if v.MaxStack() == 0 { + if v.MaxStack() == 0 { //说明进行了替换 v.Alive(false) //不允许叠层,取消效果 e.Duration(utils.Max(e.Duration(), v.Duration())) + return v //这里把V替换掉了 } else { ///e.Alive(false) //取消之前效果 if v.Stack() <= v.MaxStack() { //如果小于最大叠层,状态可以叠层 @@ -155,7 +157,7 @@ func (our *Input) AddEffect(e Effect) { } v.Duration(utils.Max(e.Duration(), v.Duration())) - return + return nil // c.Effects = append(c.Effects, e) //return } @@ -166,7 +168,7 @@ func (our *Input) AddEffect(e Effect) { //无限叠加,比如能力提升类buff // 如果没有同 ID 的效果,直接添加 our.Effects = append(our.Effects, e) - + return nil } // ForEachEffectBool 遍历所有 Effect,执行“无参数、返回 bool”的方法 @@ -202,19 +204,22 @@ func (our *Input) CancelTurn() { } -// 消除全部 -func (our *Input) CancelAll(in *Input) { - if in == our { //消除自身 - our.Effects = make([]Effect, 0) - return - } +// // 消除全部 断回合效果,但是我放下场的时候应该断掉所有的回合类效果 +// func (our *Input) CancelAll() { +// our.Effects = make([]Effect, 0) - for _, value := range our.Effects { - if value.GetInput() == in { //false是自身,true是对方,反转后为真就是自己的 - //slice = append(slice[:i], slice[i+1:]...) - value.Alive(false) - } +// for _, value := range our.Effects { - } +// value.Alive(false) -} +// } + +// //取消到在对方的我方对对方的效果 +// for _, value := range our.Opp.Effects { +// if value.GetInput() == our { //false是自身,true是对方,反转后为真就是自己的 +// //slice = append(slice[:i], slice[i+1:]...) +// value.Alive(false) +// } +// } + +// } diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index f0965bca..0d9bc751 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -97,6 +97,10 @@ func (our *Input) DelPP(value int) { // 这个方法是对对方造成伤害 // 伤害落实 // 血量扣减节点比如触发回神,反弹也在这里实现 func (our *Input) Damage(in *Input, sub *info.DamageZone) { + if sub.Type == info.DamageType.Red { //每回合计算伤害的时候重置伤害 + our.Opp.DamageZone.Damage = sub.Damage + + } // 对方对我方造成,需要吃到对方的加成 var ok bool if our != in { @@ -169,15 +173,15 @@ func (our *Input) Damage(in *Input, sub *info.DamageZone) { } if sub.Type == info.DamageType.Red { //红才会产生造成伤害 - our.Opp.DamageZone.Damage = sub.Damage // 叠加总伤害 + our.Opp.DamageZone.Damage = sub.Damage // 叠加总伤害 这里相当于记录红伤 our.Opp.AttackValue.LostHp = uint32(our.Opp.DamageZone.Damage.IntPart()) //红伤落实 } - if uint32(our.Opp.DamageZone.Damage.IntPart()) > our.CurrentPet.Info.Hp { + if uint32(sub.Damage.IntPart()) > our.CurrentPet.Info.Hp { our.CurrentPet.Info.Hp = 0 } else { - our.CurrentPet.Info.Hp = our.CurrentPet.Info.Hp - uint32(our.Opp.DamageZone.Damage.IntPart()) + our.CurrentPet.Info.Hp = our.CurrentPet.Info.Hp - uint32(sub.Damage.IntPart()) } //todo 待实现死亡effet diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index ddf299a2..210c65ab 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -23,6 +23,7 @@ type Input struct { // info.BattleActionI Effects []Effect //effects 实际上全局就是effect无限回合 //effects容器 技能的 EffectCache []Effect //这里是命中前执行的容器,也就是命中前执行的所有逻辑相关,理论上一个effect被激活,就应该同时将其他的effect取消激活 + Effect_Lost []Effect //NewEffects []Effect DamageZone struct { @@ -94,7 +95,7 @@ func (our *Input) ResetAttackValue() { our.AttackValue.IsCritical = 0 our.AttackValue.GainHp = 0 our.AttackValue.LostHp = 0 - + our.DamageZone.Damage = decimal.NewFromInt(0) } // 这个每回合都会调用 @@ -160,7 +161,8 @@ func (our *Input) Initeffectcache() { // 解析并 施加effect func (our *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) { our.EffectCache = make([]Effect, 0) //先把上一回合数据清空,但是应该把本身延续类效果集成过来 - our.Initeffectcache() //这里说明是延续的效果,每次复制出来一个新的就好了 + our.Effect_Lost = make([]Effect, 0) + our.Initeffectcache() //这里说明是延续的效果,每次复制出来一个新的就好了 //i.NewEffects = make([]Effect, 0) //这里说明是新增的效果 temparg := skill.SideEffectArgS @@ -180,7 +182,11 @@ func (our *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) { // defender.AddEffect(t) // } else { //t.SetArgs(i, temparg[:args]...) //设置入参 - our.AddEffect(t) + loste := our.AddEffect(t) + if loste != nil { + our.Effect_Lost = append(our.Effect_Lost, loste) + } + // } //这里是临时缓存buff,后面确认命中后修改HIT状态 // t.Alive() //先让效果保持存活 diff --git a/logic/service/fight/input/interface.go b/logic/service/fight/input/interface.go index 656b19a3..430d58e1 100644 --- a/logic/service/fight/input/interface.go +++ b/logic/service/fight/input/interface.go @@ -32,7 +32,10 @@ type Effect interface { Skill_Use_ex() bool //技能PP减少节点 Skill_Useed() bool //技能PP减少节点 //OnDefeat(opp *Input) bool // 精灵被击败时触发 - OnSwitch(in *Input,) bool // 精灵出战 / 上场时触发 + + // 首发其实就是切换的精灵为nil + + Switch(in *Input, outpet, inpet *info.BattlePetEntity) bool // 精灵出战 / 上场时触发 //OnSwitchOut() bool // 精灵下场时触发 // OnOwnerSwitchIn() bool // 所属玩家精灵出战时触发 // OnOwnerSwitchOut() bool // 所属玩家精灵下场时触发 diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index 4ffaad62..08248b8a 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -52,7 +52,7 @@ func (f *FightC) battleLoop() { // 收集玩家动作(含超时判定) func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.BattleActionI { actions := make(map[uint32]action.BattleActionI) - timeout := time.After(60 * time.Second) + timeout := time.After(60*time.Second + time.Duration(f.waittime)) for len(actions) < 2 { select { @@ -113,11 +113,11 @@ func (f *FightC) handleTimeout(ourID, oppID uint32, actions map[uint32]action.Ba continue } fmt.Printf("玩家%d 超时\n", pid) - player := f.GetInputByPlayer(f.getPlayerByID(pid), true).Player - if !f.GetInputByPlayer(f.getPlayerByID(pid), false).Finished { - fmt.Printf("玩家%d 加载超时\n", pid) - f.UseSkill(player, 0) //卡加载,给对方也一个action - } + // player := f.GetInputByPlayer(f.getPlayerByID(pid), true).Player + // if !f.GetInputByPlayer(f.getPlayerByID(pid), false).Finished { + // fmt.Printf("玩家%d 加载超时\n", pid) + // f.UseSkill(player, 0) //卡加载,给对方也一个action + // } f.Reason = info.BattleOverReason.PlayerOVerTime f.closefight = true @@ -236,12 +236,15 @@ func (f *FightC) handleSkillActions(a1, a2 action.BattleActionI) { switch { case s1 == nil || s1.SkillEntity == nil: + f.waittime = s2.CD f.enterturn(s2, nil) fmt.Println("1 空过 2玩家执行技能:", s2.PlayerID, s2.Info.ID) case s2 == nil || s2.SkillEntity == nil: + f.waittime = s1.CD f.enterturn(s1, nil) fmt.Println("2 空过 玩家执行技能:", s1.PlayerID, s1.Info.ID) default: + f.waittime = s1.CD + s2.CD f.enterturn(s1, s2) fmt.Println("玩家执行技能:", s1.PlayerID, s1.Info.ID, s2.PlayerID, s2.Info.ID) } diff --git a/logic/service/fight/node/PetSwitch.go b/logic/service/fight/node/PetSwitch.go index 9ea7da34..59c5636f 100644 --- a/logic/service/fight/node/PetSwitch.go +++ b/logic/service/fight/node/PetSwitch.go @@ -1,24 +1,22 @@ package node +import ( + "blazing/logic/service/fight/info" + "blazing/logic/service/fight/input" +) + // 切精灵返回false,重写change方法来实现切换效果 // 精灵切换相关触发 -func (e *EffectNode) OnSwitchIn() bool { - //panic("not implemented") // TODO: Implement - return true -} +func (e *EffectNode) Switch(in *input.Input, outpet, inpet *info.BattlePetEntity) bool { -func (e *EffectNode) OnSwitchOut() bool { + //说明是我放切精灵 + if e.Input == in { + //下场,执行消回合效果 + // e.ctx.Our.CancelAll() + ///我放下场 + e.Alive(false) + } return true } - -func (e *EffectNode) OnOwnerSwitchIn() bool { - return true -} - -// 自身下场,清除掉技能效果 -func (e *EffectNode) OnOwnerSwitchOut() bool { - // e.Input.AttackValue = info.NewAttackValue(e.Input.UserID) - return true -} diff --git a/logic/service/maps/walk.go b/logic/service/maps/walk.go index fab1012b..4fa0c41b 100644 --- a/logic/service/maps/walk.go +++ b/logic/service/maps/walk.go @@ -22,7 +22,7 @@ type WalkInInfo struct { Path string } -var limiter = rate.NewLimiter(rate.Limit(10), 1) +var limiter = rate.NewLimiter(rate.Limit(10), 5) func (t *WalkInInfo) Broadcast(mapid uint32, o WalkOutInfo) { // cool.Limiter.Take() diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index 9e11ba06..a41babde 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -5,7 +5,6 @@ import ( "blazing/common/utils/bytearray" "blazing/cool" "sync" - "time" "context" @@ -221,9 +220,9 @@ func NewClientData(c gnet.Conn) *ClientData { Wsmsg: &WsCodec{}, } cd.LF = lockfree.NewLockfree[[]byte]( - 8, + 16, cd, - lockfree.NewSleepBlockStrategy(time.Millisecond), + &lockfree.SchedBlockStrategy{}, ) // 启动Lockfree if err := cd.LF.Start(); err != nil { diff --git a/logic/service/player/player.go b/logic/service/player/player.go index ef8989de..0755b108 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -82,6 +82,7 @@ func (p *Player) GetAction() { func (p *Player) CanFight() bool { if p.FightC != nil { return false + } for _, v := range p.Info.PetList { if v.Hp > 0 { // 只要找到一个血量大于0的宠物,就可以战斗 @@ -319,6 +320,7 @@ func (p *Player) Save() { } if p.FightC != nil { + //ov := make(chan struct{}) go func() { diff --git a/login/internal/cmd/cmd.go b/login/internal/cmd/cmd.go index 593de99f..0cd46cf4 100644 --- a/login/internal/cmd/cmd.go +++ b/login/internal/cmd/cmd.go @@ -52,7 +52,7 @@ func beforeServeHook(r *ghttp.Request) { r.Response.CORSDefault() } -var limiter = rate.NewLimiter(rate.Limit(10), 1) +var limiter = rate.NewLimiter(rate.Limit(10), 5) // Limiter is a middleware that implements rate limiting for all HTTP requests. // It returns HTTP 429 (Too Many Requests) when the rate limit is exceeded. diff --git a/modules/blazing/model/pet.go b/modules/blazing/model/pet.go index 69a1a280..d0920102 100644 --- a/modules/blazing/model/pet.go +++ b/modules/blazing/model/pet.go @@ -16,7 +16,7 @@ const TableNamePet = "pet" type Pet struct { *cool.Model PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"` - InBag int `gorm:"not null;comment:'是否在背包中'" json:"in_bag"` //"0为放入仓库,1为放入背包 + Free int `gorm:"not null;default:0;comment:'是否放生'" json:"free"` //"0为放入仓库,1为放入背包 CatchTime uint32 `gorm:"not null;unique;comment:'捕捉时间'" json:"catch_time"` //唯一键 // Owner uint32 `struc:"skip"` //仅作为存储 // FreedTime uint32 `struc:"skip"` //放生时间 diff --git a/modules/blazing/service/pet.go b/modules/blazing/service/pet.go index 4592267b..5f24357c 100644 --- a/modules/blazing/service/pet.go +++ b/modules/blazing/service/pet.go @@ -9,10 +9,10 @@ import ( "github.com/gogf/gf/v2/util/gconv" ) -// 获取精灵信息 0是仓库,1是背包,2是放生 +// 获取精灵信息 0是仓库,1是放生 func (s *UserService) PetInfo(flag int) []model.PetEX { var tt []model.PetEX - err := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("in_bag", flag).Scan(&tt) + err := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("free", flag).Scan(&tt) if err != nil { return []model.PetEX{} } @@ -31,6 +31,9 @@ func (s *UserService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) { m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime) var tt model.PetEX m.Scan(&tt) + if tt.CatchTime == 0 { + return + } tt.Data.CatchTime = tt.CatchTime t(&tt) m.Update(tt) @@ -39,6 +42,7 @@ func (s *UserService) PetInfo_One(cachetime uint32) model.PetEX { m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime) var tt model.PetEX + m.Scan(&tt) tt.Data.CatchTime = tt.CatchTime return tt @@ -51,7 +55,7 @@ func (s *UserService) PetAdd(y model.PetInfo) { player.PlayerID = s.userid player.Data = y player.CatchTime = y.CatchTime - player.InBag = 0 + //player.InBag = 0 _, err := m1.Insert(player) if err != nil { @@ -67,7 +71,7 @@ func (s *PetService) ModifyBefore(ctx context.Context, method string, param map[ admin := cool.GetAdmin(ctx) userId := admin.UserId - if 0 != gconv.Uint(param["in_bag"]) { + if gconv.Uint(param["free"]) != 0 { err = fmt.Errorf("修改失败") } if userId != gconv.Uint(param["player_id"]) { @@ -95,7 +99,7 @@ func NewPetService() *PetService { ) return [][]interface{}{ {"player_id", userId, true}, - {"in_bag", 0, true}, + {"free", 0, true}, } }, },