refactor: 统一战斗报文发送逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -69,6 +69,20 @@ func (our *Input) HasLivingTeammate() bool {
|
||||
return len(our.LivingTeammates()) > 0
|
||||
}
|
||||
|
||||
// TeamSlotAt 返回指定己方站位。
|
||||
func (our *Input) TeamSlotAt(index int) *Input {
|
||||
if our == nil {
|
||||
return nil
|
||||
}
|
||||
if index >= 0 && index < len(our.Team) {
|
||||
return our.Team[index]
|
||||
}
|
||||
if index == 0 {
|
||||
return our
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OpponentSlotAt 返回指定敌方站位。
|
||||
func (our *Input) OpponentSlotAt(index int) *Input {
|
||||
if our == nil {
|
||||
@@ -83,6 +97,50 @@ func (our *Input) OpponentSlotAt(index int) *Input {
|
||||
return nil
|
||||
}
|
||||
|
||||
func nextLivingSlotIndex(slots []*Input, start int) int {
|
||||
if len(slots) == 0 {
|
||||
return -1
|
||||
}
|
||||
if start < 0 {
|
||||
start = 0
|
||||
}
|
||||
if start >= len(slots) {
|
||||
start = 0
|
||||
}
|
||||
|
||||
availableIndex := -1
|
||||
for offset := 0; offset < len(slots); offset++ {
|
||||
idx := (start + offset) % len(slots)
|
||||
slot := slots[idx]
|
||||
if slot == nil {
|
||||
continue
|
||||
}
|
||||
if availableIndex < 0 {
|
||||
availableIndex = idx
|
||||
}
|
||||
current := slot.CurrentPet()
|
||||
if current != nil && current.Info.Hp > 0 {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
return availableIndex
|
||||
}
|
||||
|
||||
// OpponentSlotAtOrNextLiving 返回指定敌方站位;若该目标已死亡,则顺延到下一只存活精灵。
|
||||
func (our *Input) OpponentSlotAtOrNextLiving(index int) (*Input, int) {
|
||||
if our == nil {
|
||||
return nil, -1
|
||||
}
|
||||
if len(our.OppTeam) == 0 {
|
||||
return our.OpponentSlotAt(index), index
|
||||
}
|
||||
resolvedIndex := nextLivingSlotIndex(our.OppTeam, index)
|
||||
if resolvedIndex < 0 {
|
||||
return nil, -1
|
||||
}
|
||||
return our.OppTeam[resolvedIndex], resolvedIndex
|
||||
}
|
||||
|
||||
// RandomOpponentSlotIndex 返回一个可用的敌方站位下标,优先从存活站位中随机。
|
||||
func (our *Input) RandomOpponentSlotIndex() int {
|
||||
if our == nil {
|
||||
|
||||
Reference in New Issue
Block a user