2025-09-14 03:36:26 +08:00
|
|
|
|
package fight
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/common/data/xmlres"
|
|
|
|
|
|
"blazing/logic/service/common"
|
2025-09-28 08:13:42 +00:00
|
|
|
|
"blazing/logic/service/fight/action"
|
2025-09-14 03:36:26 +08:00
|
|
|
|
"blazing/logic/service/fight/info"
|
2025-09-24 20:17:44 +00:00
|
|
|
|
"blazing/logic/service/fight/input"
|
2025-09-14 03:36:26 +08:00
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
|
"math"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
|
|
|
|
|
"github.com/panjf2000/ants/v2"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
// Compare 比较两个1v1战斗动作的执行优先级(核心逻辑)
|
|
|
|
|
|
func (f *FightC) Compare(a, b action.BattleActionI) (action.BattleActionI, action.BattleActionI) {
|
|
|
|
|
|
// 动作本身的优先级比较
|
|
|
|
|
|
p1 := b.Priority() - a.Priority()
|
|
|
|
|
|
if p1 > 0 { // 对手优先级更高
|
|
|
|
|
|
return b, a
|
|
|
|
|
|
} else if p1 < 0 {
|
|
|
|
|
|
return a, b
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return a, b // 速度相同时,发起方优先
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-23 16:42:10 +00:00
|
|
|
|
// 玩家逃跑/无响应/掉线
|
|
|
|
|
|
func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
2025-09-28 08:13:42 +00:00
|
|
|
|
ret := &action.EscapeAction{
|
|
|
|
|
|
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
2025-09-14 03:36:26 +08:00
|
|
|
|
Reason: info.FightOverInfo{
|
|
|
|
|
|
|
|
|
|
|
|
Reason: uint32(info.BattleOverReason.PlayerEscape),
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2025-09-23 16:42:10 +00:00
|
|
|
|
if c.GetInfo().UserID == f.ownerID {
|
|
|
|
|
|
ret.Reason.WinnerId = f.Opp.Player.GetInfo().UserID
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
2025-09-23 16:42:10 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
ret.Reason.WinnerId = f.Our.Player.GetInfo().UserID
|
2025-09-14 03:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
f.actionChan <- ret
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 切换精灵 主动和被驱逐
|
|
|
|
|
|
func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
2025-09-28 08:13:42 +00:00
|
|
|
|
ret := &action.ActiveSwitchAction{
|
|
|
|
|
|
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
2025-09-14 03:36:26 +08:00
|
|
|
|
}
|
2025-09-19 06:58:42 +00:00
|
|
|
|
f.Switch = append(f.Switch, ret)
|
2025-09-24 20:17:44 +00:00
|
|
|
|
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
|
2025-09-23 13:24:40 +08:00
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
t.OnOwnerSwitchOut(input.Ctx{})
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
2025-09-24 20:17:44 +00:00
|
|
|
|
return true
|
|
|
|
|
|
})
|
|
|
|
|
|
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
t.OnSwitchOut(input.Ctx{})
|
2025-09-24 20:17:44 +00:00
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
})
|
|
|
|
|
|
f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id)
|
|
|
|
|
|
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
t.OnOwnerSwitchIn(input.Ctx{})
|
2025-09-24 20:17:44 +00:00
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
})
|
|
|
|
|
|
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
t.OnSwitchIn(input.Ctx{})
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
2025-09-24 20:17:44 +00:00
|
|
|
|
return true
|
|
|
|
|
|
})
|
2025-09-14 03:36:26 +08:00
|
|
|
|
f.actionChan <- ret
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 玩家使用技能
|
|
|
|
|
|
func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
ret := &action.SelectSkillAction{
|
2025-09-21 14:56:37 +00:00
|
|
|
|
PlayerID: c.GetInfo().UserID,
|
2025-09-14 03:36:26 +08:00
|
|
|
|
}
|
2025-09-30 18:32:15 +08:00
|
|
|
|
//ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
2025-09-30 18:32:15 +08:00
|
|
|
|
for _, v := range f.GetInputByPlayer(c, false).CurrentPet.Skills {
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
|
|
|
|
|
if v != nil && v.ID == int(id) {
|
|
|
|
|
|
ret.Skill = v
|
2025-09-24 12:40:13 +08:00
|
|
|
|
break
|
2025-09-14 03:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
f.actionChan <- ret
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 玩家使用技能
|
|
|
|
|
|
func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
|
|
|
|
|
|
2025-09-28 08:13:42 +00:00
|
|
|
|
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}
|
2025-09-14 03:36:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 战斗准备
|
|
|
|
|
|
func (f *FightC) ReadyFight(c common.PlayerI) {
|
|
|
|
|
|
rett := info.FightStartOutboundInfo{}
|
|
|
|
|
|
|
|
|
|
|
|
copier.Copy(&rett.Info1, &f.Info.OurPetList[0]) // 复制自己的信息
|
|
|
|
|
|
copier.Copy(&rett.Info2, &f.Info.OpponentPetList[0])
|
|
|
|
|
|
rett.Info1.UserID = f.Info.OurInfo.UserID //
|
|
|
|
|
|
rett.Info2.UserID = f.Info.OpponentInfo.UserID
|
|
|
|
|
|
|
|
|
|
|
|
rrsult := func() { //传回函数
|
|
|
|
|
|
|
|
|
|
|
|
f.Our.Player.SendReadyToFightInfo(rett)
|
|
|
|
|
|
f.Opp.Player.SendReadyToFightInfo(rett)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-25 14:51:11 +00:00
|
|
|
|
switch f.Info.Status {
|
2025-09-14 03:36:26 +08:00
|
|
|
|
case 1: // 1v1
|
|
|
|
|
|
|
|
|
|
|
|
f.GetInputByPlayer(c, false).Finished = true
|
|
|
|
|
|
if f.GetInputByPlayer(c, true).Finished {
|
|
|
|
|
|
rrsult()
|
|
|
|
|
|
}
|
2025-09-20 00:17:29 +08:00
|
|
|
|
case 2: // 6v6
|
2025-09-14 03:36:26 +08:00
|
|
|
|
|
2025-09-20 00:17:29 +08:00
|
|
|
|
f.GetInputByPlayer(c, false).Finished = true
|
|
|
|
|
|
if f.GetInputByPlayer(c, true).Finished {
|
|
|
|
|
|
rrsult()
|
|
|
|
|
|
}
|
2025-09-14 03:36:26 +08:00
|
|
|
|
case 3: // 野怪战斗
|
|
|
|
|
|
|
|
|
|
|
|
//判断捕捉率大于0
|
|
|
|
|
|
if gconv.Int(xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate) > 0 {
|
|
|
|
|
|
rett.Info2.Catchable = 1
|
|
|
|
|
|
t, _ := f.Opp.Player.(*player.AI_player)
|
|
|
|
|
|
t.CanCapture = true
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rrsult()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Fightpool *ants.Pool
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
Fightpool, _ = ants.NewPool(math.MaxInt32)
|
|
|
|
|
|
//defer p.Release()
|
|
|
|
|
|
}
|