refactor: 重构战斗系统支持多单位多动作

This commit is contained in:
xinian
2026-04-04 05:44:02 +08:00
committed by cnb
parent b62b4af628
commit 28d92c1e18
23 changed files with 1652 additions and 311 deletions

View File

@@ -16,6 +16,9 @@ import (
// processSkillAttack 处理技能攻击逻辑
func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info.SkillEntity) {
if attacker == nil || defender == nil || skill == nil {
return
}
skill.AttackTimeC(attacker.Prop[5]) //计算命中
defender.Exec(func(effect input.Effect) bool { //计算闪避,然后修改对方命中),同时相当于计算属性无效这种
@@ -33,8 +36,8 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info
var originalProps [2][6]int8
var originalPetInfo [2]model.PetInfo
//复制属性
originalProps[0], originalProps[1] = f.Our[0].Prop, f.Opp[0].Prop //先复制能力提升
originalPetInfo[0], originalPetInfo[1] = f.Our[0].CurPet[0].Info, f.Opp[0].CurPet[0].Info //先复制宠物信息
originalProps[0], originalProps[1] = attacker.Prop, defender.Prop
originalPetInfo[0], originalPetInfo[1] = attacker.CurPet[0].Info, defender.CurPet[0].Info
attacker.Exec(func(effect input.Effect) bool {
//计算变威力
effect.Ctx().SkillEntity = skill
@@ -55,8 +58,8 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info
}
//还原属性
f.Our[0].Prop, f.Opp[0].Prop = originalProps[0], originalProps[1]
f.Our[0].CurPet[0].Info, f.Opp[0].CurPet[0].Info = originalPetInfo[0], originalPetInfo[1]
attacker.Prop, defender.Prop = originalProps[0], originalProps[1]
attacker.CurPet[0].Info, defender.CurPet[0].Info = originalPetInfo[0], originalPetInfo[1]
if attacker.IsCritical == 1 { //命中了才有暴击
//暴击破防
@@ -149,15 +152,13 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
})
})
if firstAttack != nil { //如果首技能是空的,说明都空过了
firstAttacker, _ := f.getSkillParticipants(firstAttack)
if firstAttacker != nil {
firstAttacker.Parseskill(firstAttack)
}
secondAttacker, _ := f.getSkillParticipants(secondAttack)
if secondAttacker != nil {
secondAttacker.Parseskill(secondAttack)
for _, skillAction := range []*action.SelectSkillAction{firstAttack, secondAttack} {
attackerInput, _ := f.getSkillParticipants(skillAction)
if attackerInput == nil {
continue
}
f.setActionAttackValue(skillAction)
attackerInput.Parseskill(skillAction)
}
f.Broadcast(func(fighter *input.Input) {
fighter.Exec(func(effect input.Effect) bool { //回合开始前
@@ -212,17 +213,26 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
for i := 0; i < 2; i++ {
var originalSkill *info.SkillEntity //原始技能
var currentSkill *info.SkillEntity //当前技能
var currentAction *action.SelectSkillAction
if i == 0 {
attacker, defender = f.First, f.Second
currentAction = firstAttack
attacker, defender = f.getSkillParticipants(firstAttack)
originalSkill = f.copySkill(firstAttack)
//先手阶段,先修复后手效果
f.Second.RecoverEffect()
} else {
attacker, defender = f.Second, f.First
currentAction = secondAttack
attacker, defender = f.getSkillParticipants(secondAttack)
originalSkill = f.copySkill(secondAttack)
//取消后手历史效果
f.Second.ReactvieEffect()
}
if attacker == nil {
attacker = f.First
}
if defender == nil {
defender = f.Second
}
currentSkill = originalSkill
defender.Exec(func(effect input.Effect) bool { //这个是能否使用技能
@@ -234,7 +244,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
return effect.ActionStart(firstAttack, secondAttack)
})
canUse := canUseSkill && action.CanUse(currentSkill) && attacker.CurPet[0].Info.Hp > 0
canUse := canUseSkill && action.CanUse(currentSkill) && attacker != nil && attacker.CurPet[0].Info.Hp > 0
if !canUse {
@@ -250,6 +260,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
//先手权不一定出手
} else {
f.setActionAttackValue(currentAction)
for _, effect := range attacker.EffectCache {
effect.IsFirst(true)
@@ -345,7 +356,7 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction)
}
}
})
f.Switch = make(map[uint32]*action.ActiveSwitchAction)
f.Switch = make(map[actionSlotKey]*action.ActiveSwitchAction)
if f.closefight && f.Info.Mode == info.BattleMode.PET_MELEE {
// f.Broadcast(func(fighter *input.Input) {
// if fighter.UserID != f.WinnerId {