Files
bl/logic/service/fight/playeraction.go

157 lines
3.7 KiB
Go
Raw Normal View History

package fight
import (
"blazing/common/data/xmlres"
"blazing/logic/service/common"
2025-09-28 08:13:42 +00:00
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"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 // 速度相同时,发起方优先
}
// 玩家逃跑/无响应/掉线
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),
Reason: info.FightOverInfo{
Reason: res,
},
}
if c.GetInfo().UserID == f.ownerID {
ret.Reason.WinnerId = f.Opp.Player.GetInfo().UserID
} else {
ret.Reason.WinnerId = f.Our.Player.GetInfo().UserID
}
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),
}
f.Switch = append(f.Switch, ret)
f.GetInputByPlayer(c, false).InitAttackValue() //切换精灵消除能力提升
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
2025-09-28 08:13:42 +00:00
t.OnOwnerSwitchOut(input.Ctx{})
return true
})
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
2025-09-28 08:13:42 +00:00
t.OnSwitchOut(input.Ctx{})
return true
})
f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id)
f.Broadcast(func(ff *input.Input) { //先给自身广播
if ff.Player.GetInfo().UserID == c.GetInfo().UserID {
ff.Player.SendChangePet(ret.Reason)
}
})
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
2025-09-28 08:13:42 +00:00
t.OnOwnerSwitchIn(input.Ctx{})
return true
})
f.GetInputByPlayer(c, true).Exec(func(t input.Effect) bool {
2025-09-28 08:13:42 +00:00
t.OnSwitchIn(input.Ctx{})
return true
})
f.actionChan <- ret
}
// 玩家使用技能
func (f *FightC) UseSkill(c common.PlayerI, id int32) {
2025-09-28 08:13:42 +00:00
ret := &action.SelectSkillAction{
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
}
2025-09-30 18:32:15 +08:00
//ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
2025-09-30 18:32:15 +08:00
for _, v := range f.GetInputByPlayer(c, false).CurrentPet.Skills {
if v != nil && v.ID == int(id) {
ret.SkillEntity = v
``` refactor(effectarg): 移动EffectArgs初始化逻辑 将EffectArgs的初始化从effectarg.go中的init函数移动到file.go的initfile函数中, 确保在使用前正确加载配置并初始化映射。 refactor(login): 更新Login方法中的Person调用 修改Login方法中对Person函数的调用,传递UserID参数以获取正确的用户信息。 refactor(user): 统一使用Person方法替代PersonOther 在UserSimInfo和UserMoreInfo方法中,将原先调用的PersonOther方法统一替换为 Person方法,保持代码一致性。 refactor(effect_damage): 简化属性获取和伤害计算逻辑 移除deepcopy相关逻辑,简化Effect0的OnSkill方法中的属性获取和伤害计算流程, 直接通过输入参数进行计算。 refactor(fightc): 优化玩家输入处理和战斗逻辑 更新GetInputByPlayer方法中的玩家判断逻辑,使用UserID比较代替对象比较; 在initplayer中添加InitAttackValue调用; 修复battleLoop中打印语句的格式问题; 调整技能攻击处理流程,增加SkillUseEnd回调调用。 refactor(attr): 改进属性获取方法和伤害计算逻辑 将GetProp方法重命名为Prop,并支持传入对方输入参数; 更新CalculatePower方法签名,使用Input类型代替BattlePetEntity; 在属性获取和伤害计算中正确处理双方属性影响。 refactor(playeraction): 简化技能使用逻辑 简化UseSkill方法中获取当前宠物信息的逻辑,去除冗余的条件判断; 在找到对应技能后添加break语句,提高执行效率。 refactor(reg): 更新Person方法实现 合并Person和PersonOther方法为统一的Person方法; 在数据库查询失败时添加错误处理,避免潜在的空指针异常。 ```
2025-09-24 12:40:13 +08:00
break
}
}
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}
}
// 战斗准备
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.Pool
func init() {
Fightpool, _ = ants.NewPool(math.MaxInt32)
//defer p.Release()
}