2026-04-06 00:58:23 +08:00
|
|
|
package input
|
|
|
|
|
|
2026-04-08 01:28:55 +08:00
|
|
|
import "github.com/gogf/gf/v2/util/grand"
|
|
|
|
|
|
2026-04-06 00:58:23 +08:00
|
|
|
// TeamSlots 返回当前输入所在阵营的全部有效战斗位视图。
|
|
|
|
|
func (our *Input) TeamSlots() []*Input {
|
|
|
|
|
if our == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if len(our.Team) == 0 {
|
|
|
|
|
return []*Input{our}
|
|
|
|
|
}
|
|
|
|
|
slots := make([]*Input, 0, len(our.Team))
|
|
|
|
|
for _, teammate := range our.Team {
|
|
|
|
|
if teammate == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
slots = append(slots, teammate)
|
|
|
|
|
}
|
|
|
|
|
return slots
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 01:28:55 +08:00
|
|
|
// TeamSlotIndex 返回当前输入在本阵营中的原始站位下标。
|
|
|
|
|
func (our *Input) TeamSlotIndex() int {
|
|
|
|
|
if our == nil || len(our.Team) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
for idx, teammate := range our.Team {
|
|
|
|
|
if teammate == our {
|
|
|
|
|
return idx
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 00:58:23 +08:00
|
|
|
// Teammates 返回队友列表,不包含自己。
|
|
|
|
|
func (our *Input) Teammates() []*Input {
|
|
|
|
|
if our == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
teammates := make([]*Input, 0, len(our.Team))
|
|
|
|
|
for _, teammate := range our.TeamSlots() {
|
|
|
|
|
if teammate == nil || teammate == our {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
teammates = append(teammates, teammate)
|
|
|
|
|
}
|
|
|
|
|
return teammates
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LivingTeammates 返回当前仍有存活出战精灵的队友列表。
|
|
|
|
|
func (our *Input) LivingTeammates() []*Input {
|
|
|
|
|
if our == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
teammates := make([]*Input, 0, len(our.Team))
|
|
|
|
|
for _, teammate := range our.Teammates() {
|
|
|
|
|
currentPet := teammate.CurrentPet()
|
|
|
|
|
if currentPet == nil || currentPet.Info.Hp == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
teammates = append(teammates, teammate)
|
|
|
|
|
}
|
|
|
|
|
return teammates
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HasLivingTeammate 用于快速判断当前战斗位是否还有存活队友。
|
|
|
|
|
func (our *Input) HasLivingTeammate() bool {
|
|
|
|
|
return len(our.LivingTeammates()) > 0
|
|
|
|
|
}
|
2026-04-08 01:28:55 +08:00
|
|
|
|
|
|
|
|
// OpponentSlotAt 返回指定敌方站位。
|
|
|
|
|
func (our *Input) OpponentSlotAt(index int) *Input {
|
|
|
|
|
if our == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if index >= 0 && index < len(our.OppTeam) {
|
|
|
|
|
return our.OppTeam[index]
|
|
|
|
|
}
|
|
|
|
|
if index == 0 {
|
|
|
|
|
return our.Opp
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RandomOpponentSlotIndex 返回一个可用的敌方站位下标,优先从存活站位中随机。
|
|
|
|
|
func (our *Input) RandomOpponentSlotIndex() int {
|
|
|
|
|
if our == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if len(our.OppTeam) == 0 {
|
|
|
|
|
if our.Opp != nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
living := make([]int, 0, len(our.OppTeam))
|
|
|
|
|
available := make([]int, 0, len(our.OppTeam))
|
|
|
|
|
for idx, opponent := range our.OppTeam {
|
|
|
|
|
if opponent == nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
available = append(available, idx)
|
|
|
|
|
current := opponent.CurrentPet()
|
|
|
|
|
if current != nil && current.Info.Hp > 0 {
|
|
|
|
|
living = append(living, idx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
candidates := living
|
|
|
|
|
if len(candidates) == 0 {
|
|
|
|
|
candidates = available
|
|
|
|
|
}
|
|
|
|
|
if len(candidates) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if len(candidates) == 1 {
|
|
|
|
|
return candidates[0]
|
|
|
|
|
}
|
|
|
|
|
return candidates[grand.Intn(len(candidates))]
|
|
|
|
|
}
|