164 lines
4.2 KiB
Go
164 lines
4.2 KiB
Go
package fight
|
||
|
||
import (
|
||
"blazing/common/data/xmlres"
|
||
"blazing/cool"
|
||
"blazing/logic/service/common"
|
||
"blazing/logic/service/fight/action"
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/fight/input"
|
||
"blazing/logic/service/player"
|
||
"context"
|
||
|
||
"github.com/gogf/gf/v2/util/gconv"
|
||
"github.com/jinzhu/copier"
|
||
"github.com/panjf2000/ants/v2"
|
||
)
|
||
|
||
// 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 // 速度相同时,发起方优先
|
||
}
|
||
|
||
// 玩家逃跑/无响应/掉线
|
||
func (f *FightC) Over(c common.PlayerI, res info.EnumBattleOverReason) {
|
||
if f.closefight {
|
||
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||
return
|
||
}
|
||
ret := &action.EscapeAction{
|
||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||
Reason: res,
|
||
}
|
||
|
||
f.actionChan <- ret
|
||
}
|
||
|
||
// 切换精灵 主动和被驱逐
|
||
func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
|
||
if f.closefight {
|
||
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||
return
|
||
}
|
||
ret := &action.ActiveSwitchAction{
|
||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||
}
|
||
f.Switch = append(f.Switch, ret)
|
||
f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升
|
||
|
||
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
|
||
|
||
t.OnSwitchOut(input.Ctx{})
|
||
|
||
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) { //先给自身广播
|
||
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(input.Ctx{})
|
||
|
||
return true
|
||
})
|
||
f.actionChan <- ret
|
||
}
|
||
|
||
// 玩家使用技能
|
||
func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
||
if f.closefight {
|
||
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||
return
|
||
}
|
||
ret := &action.SelectSkillAction{
|
||
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
|
||
}
|
||
|
||
for _, v := range f.GetInputByPlayer(c, false).CurrentPet.Skills {
|
||
|
||
if v != nil && v.ID == int(id) {
|
||
ret.SkillEntity = v
|
||
break
|
||
}
|
||
|
||
}
|
||
f.actionChan <- ret
|
||
}
|
||
|
||
// 玩家使用技能
|
||
func (f *FightC) Capture(c common.PlayerI, id uint32) {
|
||
if f.closefight {
|
||
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||
return
|
||
}
|
||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: id}
|
||
}
|
||
|
||
func (f *FightC) UseItem(c common.PlayerI, cacthid, itemid uint32) {
|
||
if f.closefight {
|
||
cool.Loger.Debug(context.Background(), " 战斗chan已关闭")
|
||
return
|
||
}
|
||
f.actionChan <- &action.UseItemAction{BaseAction: action.NewBaseAction(c.GetInfo().UserID), ItemID: itemid, CacthTime: cacthid}
|
||
}
|
||
|
||
// 战斗准备
|
||
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)
|
||
}
|
||
|
||
switch f.Info.Status {
|
||
case info.BattleStatus.FIGHT_WITH_PLAYER: //pvp
|
||
|
||
f.GetInputByPlayer(c, false).Finished = true
|
||
if f.GetInputByPlayer(c, true).Finished {
|
||
rrsult()
|
||
}
|
||
case info.BattleStatus.FIGHT_WITH_BOSS: // 6v6
|
||
rrsult()
|
||
case info.BattleStatus.FIGHT_WITH_NPC: // 野怪战斗
|
||
|
||
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.MultiPool
|
||
|
||
func init() {
|
||
Fightpool, _ = ants.NewMultiPool(1, 1, ants.LeastTasks)
|
||
//defer p.Release()
|
||
}
|