refactor: 重构战斗结构体以支持双打模式

This commit is contained in:
xinian
2026-04-04 22:13:42 +08:00
committed by cnb
parent 7916f90992
commit 39e1d4c42f
16 changed files with 543 additions and 246 deletions

View File

@@ -162,6 +162,23 @@ func (f *FightC) linkOppInputs() {
}
}
func (f *FightC) linkTeamViews() {
for _, fighter := range f.Our {
if fighter == nil {
continue
}
fighter.Team = f.Our
fighter.OppTeam = f.Opp
}
for _, fighter := range f.Opp {
if fighter == nil {
continue
}
fighter.Team = f.Opp
fighter.OppTeam = f.Our
}
}
func (f *FightC) getSideInputs(userID uint32, isOpposite bool) []*input.Input {
isOur := f.isOurPlayerID(userID)
if isOpposite {
@@ -177,36 +194,48 @@ func (f *FightC) getSideInputs(userID uint32, isOpposite bool) []*input.Input {
}
func (f *FightC) findInputByUserID(userID uint32) (*input.Input, bool) {
isOur := f.isOurPlayerID(userID)
if isOur {
if in := f.selectInput(f.Our, 0); in != nil {
for _, in := range f.Our {
if in != nil && in.ControlledBy(userID) {
return in, true
}
return nil, true
}
if in := f.selectInput(f.Opp, 0); in != nil {
return in, false
for _, in := range f.Opp {
if in != nil && in.ControlledBy(userID) {
return in, false
}
}
return nil, false
}
func (f *FightC) getInputByUserID(userID uint32, index int, isOpposite bool) *input.Input {
return f.selectInput(f.getSideInputs(userID, isOpposite), index)
selected := f.selectInput(f.getSideInputs(userID, isOpposite), index)
if selected == nil {
return nil
}
// 操作自身站位时,必须由该站位控制者发起。
if !isOpposite && !selected.ControlledBy(userID) {
return nil
}
return selected
}
func (f *FightC) getInputByController(userID uint32, isOpposite bool) *input.Input {
sideInputs := f.getSideInputs(userID, isOpposite)
for _, in := range sideInputs {
if in != nil && in.ControlledBy(userID) {
return in
}
}
return f.selectInput(sideInputs, 0)
}
func (f *FightC) expectedActionSlots() map[actionSlotKey]struct{} {
slots := make(map[actionSlotKey]struct{}, len(f.Our)+len(f.Opp))
for actorIndex, fighter := range f.Our {
if fighter == nil || fighter.Player == nil {
continue
}
slots[newActionSlotKey(fighter.Player.GetInfo().UserID, actorIndex)] = struct{}{}
for _, slot := range f.SideSlots(SideOur) {
slots[newActionSlotKey(slot.ControllerUserID, slot.SlotIndex)] = struct{}{}
}
for actorIndex, fighter := range f.Opp {
if fighter == nil || fighter.Player == nil {
continue
}
slots[newActionSlotKey(fighter.Player.GetInfo().UserID, actorIndex)] = struct{}{}
for _, slot := range f.SideSlots(SideOpp) {
slots[newActionSlotKey(slot.ControllerUserID, slot.SlotIndex)] = struct{}{}
}
return slots
}
@@ -234,7 +263,7 @@ func (f *FightC) GetInputByPlayer(c common.PlayerI, isOpposite bool) *input.Inpu
}
return f.primaryOur()
}
return f.getInputByUserID(c.GetInfo().UserID, 0, isOpposite)
return f.getInputByController(c.GetInfo().UserID, isOpposite)
}
func (f *FightC) GetInputByAction(c action.BattleActionI, isOpposite bool) *input.Input {
@@ -266,6 +295,14 @@ func (f *FightC) GetCurrPETAt(c common.PlayerI, actorIndex int) *info.BattlePetE
}
return in.PrimaryCurPet()
}
func (f *FightC) GetCurrPETByAction(c action.BattleActionI, isOpposite bool) *info.BattlePetEntity {
in := f.GetInputByAction(c, isOpposite)
if in == nil {
return nil
}
return in.CurrentPet()
}
func (f *FightC) GetOpp(c common.PlayerI) *input.Input {
return f.GetInputByPlayer(c, true)
}