refactor: 重构战斗结构体以支持双打模式
This commit is contained in:
@@ -75,7 +75,8 @@ func (f *FightC) battleLoop() {
|
||||
if ff.Player.GetInfo().PetList[j].CatchTime == ff.AllPet[i].Info.CatchTime {
|
||||
|
||||
if ff.UserID == f.WinnerId {
|
||||
if ff.CurPet[0].Info.CatchTime == ff.Player.GetInfo().PetList[j].CatchTime {
|
||||
currentPet := ff.CurrentPet()
|
||||
if currentPet != nil && currentPet.Info.CatchTime == ff.Player.GetInfo().PetList[j].CatchTime {
|
||||
f.Winpet = &ff.Player.GetInfo().PetList[j]
|
||||
}
|
||||
|
||||
@@ -100,9 +101,14 @@ func (f *FightC) battleLoop() {
|
||||
addpet.EffectInfo = nil //清空特性信息
|
||||
f.Our[0].Player.(*player.Player).Service.Pet.PetAdd(&addpet, 0)
|
||||
|
||||
oppPet := f.Opp[0].CurrentPet()
|
||||
petID := uint32(0)
|
||||
if oppPet != nil {
|
||||
petID = uint32(oppPet.ID)
|
||||
}
|
||||
f.Our[0].Player.SendPackCmd(2409, &info.CatchMonsterOutboundInfo{
|
||||
CatchTime: uint32(addpet.CatchTime),
|
||||
PetId: uint32(f.Opp[0].CurPet[0].ID),
|
||||
PetId: petID,
|
||||
})
|
||||
|
||||
defer f.Our[0].Player.(*player.Player).Service.Done.UpdatePet(addpet, 0, 1)
|
||||
@@ -323,11 +329,6 @@ func (f *FightC) handleTimeout(expectedSlots map[actionSlotKey]struct{}, actions
|
||||
|
||||
}
|
||||
|
||||
type roundActionPair struct {
|
||||
our action.BattleActionI
|
||||
opp action.BattleActionI
|
||||
}
|
||||
|
||||
func flattenActionMap(actions map[actionSlotKey]action.BattleActionI) []action.BattleActionI {
|
||||
flattened := make([]action.BattleActionI, 0, len(actions))
|
||||
for _, act := range actions {
|
||||
@@ -371,44 +372,38 @@ func (f *FightC) sortActions(actions []action.BattleActionI) {
|
||||
})
|
||||
}
|
||||
|
||||
func (f *FightC) buildRoundActionPairs(actions []action.BattleActionI) []roundActionPair {
|
||||
remaining := append([]action.BattleActionI(nil), actions...)
|
||||
f.sortActions(remaining)
|
||||
func sortActionsByActor(actions []action.BattleActionI) {
|
||||
sort.SliceStable(actions, func(i, j int) bool {
|
||||
a, b := actions[i], actions[j]
|
||||
if a == nil || b == nil {
|
||||
return a != nil
|
||||
}
|
||||
if a.GetActorIndex() != b.GetActorIndex() {
|
||||
return a.GetActorIndex() < b.GetActorIndex()
|
||||
}
|
||||
if a.GetTargetIndex() != b.GetTargetIndex() {
|
||||
return a.GetTargetIndex() < b.GetTargetIndex()
|
||||
}
|
||||
return a.GetPlayerID() < b.GetPlayerID()
|
||||
})
|
||||
}
|
||||
|
||||
used := make([]bool, len(remaining))
|
||||
pairs := make([]roundActionPair, 0, len(remaining))
|
||||
for i, act := range remaining {
|
||||
if used[i] || act == nil {
|
||||
func (f *FightC) splitRoundActions(actions []action.BattleActionI) ([]action.BattleActionI, []action.BattleActionI) {
|
||||
our := make([]action.BattleActionI, 0, len(actions))
|
||||
opp := make([]action.BattleActionI, 0, len(actions))
|
||||
for _, act := range actions {
|
||||
if act == nil {
|
||||
continue
|
||||
}
|
||||
used[i] = true
|
||||
|
||||
pair := roundActionPair{}
|
||||
if f.isOurPlayerID(act.GetPlayerID()) {
|
||||
pair.our = act
|
||||
our = append(our, act)
|
||||
} else {
|
||||
pair.opp = act
|
||||
opp = append(opp, act)
|
||||
}
|
||||
|
||||
for j := i + 1; j < len(remaining); j++ {
|
||||
candidate := remaining[j]
|
||||
if used[j] || candidate == nil {
|
||||
continue
|
||||
}
|
||||
if f.isOurPlayerID(candidate.GetPlayerID()) == f.isOurPlayerID(act.GetPlayerID()) {
|
||||
continue
|
||||
}
|
||||
used[j] = true
|
||||
if pair.our == nil {
|
||||
pair.our = candidate
|
||||
} else {
|
||||
pair.opp = candidate
|
||||
}
|
||||
break
|
||||
}
|
||||
pairs = append(pairs, pair)
|
||||
}
|
||||
return pairs
|
||||
sortActionsByActor(our)
|
||||
sortActionsByActor(opp)
|
||||
return our, opp
|
||||
}
|
||||
|
||||
// 根据动作类型执行一回合结算
|
||||
@@ -418,11 +413,24 @@ func (f *FightC) resolveRound(actions []action.BattleActionI) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, pair := range f.buildRoundActionPairs(actions) {
|
||||
ourActions, oppActions := f.splitRoundActions(actions)
|
||||
roundLen := len(ourActions)
|
||||
if len(oppActions) > roundLen {
|
||||
roundLen = len(oppActions)
|
||||
}
|
||||
for i := 0; i < roundLen; i++ {
|
||||
if f.closefight {
|
||||
return
|
||||
}
|
||||
f.resolveActionPair(pair.our, pair.opp)
|
||||
var ourAct action.BattleActionI
|
||||
var oppAct action.BattleActionI
|
||||
if i < len(ourActions) {
|
||||
ourAct = ourActions[i]
|
||||
}
|
||||
if i < len(oppActions) {
|
||||
oppAct = oppActions[i]
|
||||
}
|
||||
f.resolveActionPair(ourAct, oppAct)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user