public override bool Process() { if (TargetUnit == null) { return(false); } // look for 3-7 enemies nearby int maxTargets = Spell.GetIndirectPower(); List <MapUnit> targets = new List <MapUnit>(); int range = Mathf.CeilToInt(Spell.GetDistance()); int fromX = Spell.User.X - range; int fromY = Spell.User.Y - range; int toX = Spell.User.X + Spell.User.Width + range; int toY = Spell.User.Y + Spell.User.Height + range; for (int y = fromY; y <= toY; y++) { if (y < 0 || y >= MapLogic.Instance.Height) { continue; } for (int x = fromX; x <= toX; x++) { if (x < 0 || x >= MapLogic.Instance.Width) { continue; } if (targets.Count >= maxTargets - 1) { break; } MapNode node = MapLogic.Instance.Nodes[x, y]; foreach (MapObject objnode in node.Objects) { if (objnode is MapUnit) { MapUnit unit = (MapUnit)objnode; if ((Spell.User.Player.Diplomacy[unit.Player.ID] & DiplomacyFlags.Enemy) != 0) // in war with this unit, then add to list { if (!targets.Contains(unit)) { targets.Add(unit); } } } } } } // randomize units System.Random rng = new System.Random(); targets = targets.Where(a => a != TargetUnit).OrderBy(a => rng.Next()).Take(maxTargets - 1).ToList(); targets.Insert(0, TargetUnit); for (int i = 0; i < targets.Count; i++) { SpawnProjectile(targets[i], Spell.GetDamage(), i + 1, 1f / targets.Count); } return(false); }