public void UpdateDistractionSquad(IEnumerable <UnitCommander> otherUnits) { if (!Enabled) { return; } if (DistractionSquad.Count() > 0) { var deadUnits = DistractionSquad.Count(d => !otherUnits.Any(u => d.UnitCalculation.Unit.Tag == u.UnitCalculation.Unit.Tag)); if (deadUnits > 0) { DistractionSquad.RemoveAll(d => !otherUnits.Any(u => d.UnitCalculation.Unit.Tag == u.UnitCalculation.Unit.Tag)); DistractionSquadState = DistractionSquadState.Regrouping; } } foreach (var commander in otherUnits.Where(c => !DistractionSquad.Any(d => d.UnitCalculation.Unit.Tag == c.UnitCalculation.Unit.Tag))) { var unitType = commander.UnitCalculation.Unit.UnitType; foreach (var desiredUnitClaim in DistractionSquadClaim) { if ((uint)desiredUnitClaim.UnitType == unitType && !commander.UnitCalculation.Unit.IsHallucination && DistractionSquad.Count(u => u.UnitCalculation.Unit.UnitType == (uint)desiredUnitClaim.UnitType) < desiredUnitClaim.Count) { DistractionSquad.Add(commander); } } } }
void UpdateState() { if (!Enabled) { DistractionSquadState = DistractionSquadState.NotDistracting; return; } if (DistractionSquadState == DistractionSquadState.NotDistracting) { if (DistractionSquad.Count() >= DistractionSquadClaim.Sum(c => c.Count)) { DistractionSquadState = DistractionSquadState.Regrouping; } } if (DistractionSquadState == DistractionSquadState.Regrouping) { if (DistractionSquad.Count() >= DistractionSquadClaim.Sum(c => c.Count)) { if (RegroupPoint != null && DistractionSquad.Any(u => Vector2.DistanceSquared(new Vector2(RegroupPoint.X, RegroupPoint.Y), u.UnitCalculation.Position) < 100)) { if (DistractionSquad.All(u => DistractionSquad.Count(d => u.UnitCalculation.NearbyAllies.Any(a => a.Unit.Tag == d.UnitCalculation.Unit.Tag)) >= DistractionSquad.Count() - 1)) // they're all next to each other grouped up, // warp prism does mining so this doesn't work { DistractionSquadState = DistractionSquadState.Enroute; } } } } if (DistractionSquadState == DistractionSquadState.Enroute) { if (DistractionTarget != null && DistractionSquad.Any(d => Vector2.DistanceSquared(d.UnitCalculation.Position, new Vector2(DistractionTarget.X, DistractionTarget.Y)) < 100)) // any are near target { DistractionSquadState = DistractionSquadState.Distracting; } } if (DistractionSquadState == DistractionSquadState.Distracting) { if (DistractionSquad.Count() < DistractionSquadClaim.Sum(c => c.Count)) // lost a unit, go back and regroup { DistractionSquadState = DistractionSquadState.Regrouping; } } }