func (a *Interact) findTargets(ent *game.Entity, g *game.Game) []*game.Entity { var targets []*game.Entity for _, e := range g.Ents { x, y := e.Pos() dx, dy := e.Dims() if e == ent { continue } if e.ObjectEnt == nil { continue } if e.Sprite().State() != "ready" { continue } if distBetweenEnts(e, ent) > a.Range { continue } if !ent.HasLos(x, y, dx, dy) { continue } // Make sure it's still active: active := false active = true if !active { continue } targets = append(targets, e) } return targets }
func (a *AoeAttack) AiBestTarget(ent *game.Entity, extra_dist int, spec AiAoeTarget) (x, y int, targets []*game.Entity) { ex, ey := ent.Pos() max := 0 best_dist := 10000 var bx, by int var radius int if a.Range > 0 { radius += a.Range } if extra_dist > 0 { radius += extra_dist } for x := ex - radius; x <= ex+radius; x++ { for y := ey - radius; y <= ey+radius; y++ { if !ent.HasLos(x, y, 1, 1) { continue } targets = a.getTargetsAt(ent.Game(), x, y) ok := true count := 0 for i := range targets { if targets[i].Side() != ent.Side() { count++ } else if ent.Side() == game.SideHaunt && spec == AiAoeHitMinionsOk { if targets[i].HauntEnt == nil || targets[i].HauntEnt.Level != game.LevelMinion { ok = false } } else if spec != AiAoeHitAlliesOk { ok = false } } dx := x - ex if dx < 0 { dx = -dx } dy := y - ey if dy < 0 { dy = -dy } dist := dx if dy > dx { dist = dy } if ok && (count > max || count == max && dist < best_dist) { max = count best_dist = dist bx, by = x, y } } } return bx, by, a.getTargetsAt(ent.Game(), bx, by) }
func (a *AoeAttack) AiAttackPosition(ent *game.Entity, x, y int) game.ActionExec { if !ent.HasLos(x, y, 1, 1) { base.Log().Printf("Don't have los") return nil } if a.Ap > ent.Stats.ApCur() { base.Log().Printf("Don't have the ap") return nil } var exec aoeExec exec.SetBasicData(ent, a) exec.X, exec.Y = x, y return &exec }
func (a *Interact) AiInteractWithObject(ent, object *game.Entity) game.ActionExec { if ent.Stats.ApCur() < a.Ap { return nil } if distBetweenEnts(ent, object) > a.Range { return nil } x, y := object.Pos() dx, dy := object.Dims() if !ent.HasLos(x, y, dx, dy) { return nil } var exec interactExec exec.SetBasicData(ent, a) exec.Target = object.Id return &exec }
func (a *BasicAttack) validTarget(source, target *game.Entity) bool { if source.Stats == nil || target.Stats == nil { return false } if distBetweenEnts(source, target) > a.Range { return false } x2, y2 := target.Pos() dx, dy := target.Dims() if !source.HasLos(x2, y2, dx, dy) { return false } if target.Stats.HpCur() <= 0 { return false } if source.Side() == target.Side() && !a.Target_allies { return false } if source.Side() != target.Side() && !a.Target_enemies { return false } return true }