Files
bl/logic/service/fight/playeraction.go
昔念 79213c67d6 ```
fix(socket): 修复TCP连接处理中逻辑取反错误

修复了`handleTcp`函数中对`s.discorse`的判断条件错误,导致CORS配置未正确应用的问题。

feat(player): 增加地图切换标记支持

在`Player`结构体中新增`Changemap`字段,用于标识玩家是否切换过地图,并在相关业务逻辑中进行设置和判断。

feat(pet): 重构精灵生成与经验处理逻辑

将`GenPetInfo`方法从model包迁移至player包,增加个体值、性格、特性等随机生成逻辑,优化技能学习处理方式。

refactor(service): 优化定时任务与连接管理

使用`cool.Cron`替代原生ticker实现刷怪定时任务,优化连接获取方式,确保并发安全。

refactor(model): 移除冗余代码并优化结构

从`pet.go`中移除已迁移至`player`包的函数定义,精简模型结构,提升模块清晰度。

refactor(config): 更新部门及字典名称配置

将`base_sys_department.json`和
2025-10-13 18:51:41 +08:00

160 lines
3.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package fight
import (
"blazing/common/data/xmlres"
"blazing/logic/service/common"
"blazing/logic/service/fight/action"
"blazing/logic/service/fight/info"
"blazing/logic/service/fight/input"
"blazing/logic/service/player"
"fmt"
"math"
"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) {
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) {
ret := &action.ActiveSwitchAction{
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
}
f.Switch = append(f.Switch, ret)
f.GetInputByPlayer(c, false).Exec(func(t input.Effect) bool {
t.OnOwnerSwitchOut(input.Ctx{})
return true
})
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.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 {
t.OnOwnerSwitchIn(input.Ctx{})
return true
})
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) {
ret := &action.SelectSkillAction{
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
}
//ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
ret.ID = uint32(id)
for _, v := range f.GetInputByPlayer(c, false).CurrentPet.Skills {
if v != nil && v.ID == int(id) {
ret.Skill = v
break
}
}
f.actionChan <- ret
}
// 玩家使用技能
func (f *FightC) Capture(c common.PlayerI, id uint32) {
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: // 野怪战斗
//判断捕捉率大于0
fmt.Println("CatchRate", xmlres.PetMAP[int(f.Info.OpponentPetList[0].ID)].CatchRate)
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()
}