public DefenseFront( TacticPerimeterDefense.EnemyCluster matchedEnemyCluster, Formation meleeFormation) { this.MatchedEnemyCluster = matchedEnemyCluster; this.MeleeFormation = meleeFormation; this.RangedFormation = (Formation)null; }
private void DetermineEnemyClusters() { List <Formation> list1 = this.team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(et => et.Team.Formations)).ToList <Formation>(); List <Formation> formationList = new List <Formation>(); foreach (Formation formation in list1) { Formation enemyFormation = formation; if ((double)enemyFormation.QuerySystem.FormationPower < (double)Math.Min(this.team.QuerySystem.TeamPower, this.team.QuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(et => et.TeamPower))) / 4.0) { if (!this._enemyClusters.Any <TacticPerimeterDefense.EnemyCluster>((Func <TacticPerimeterDefense.EnemyCluster, bool>)(ec => ec.enemyFormations.Contains(enemyFormation)))) { formationList.Add(enemyFormation); } } else { TacticPerimeterDefense.EnemyCluster enemyCluster1 = this._enemyClusters.FirstOrDefault <TacticPerimeterDefense.EnemyCluster>((Func <TacticPerimeterDefense.EnemyCluster, bool>)(ec => ec.enemyFormations.Any <Formation>((Func <Formation, bool>)(ef => ef == enemyFormation)))); if (enemyCluster1 != null) { if ((double)(this._defendPosition.AsVec2 - enemyCluster1.AggregatePosition).DotProduct(this._defendPosition.AsVec2 - enemyFormation.QuerySystem.AveragePosition) < 0.70710678118) { enemyCluster1.RemoveFromCluster(enemyFormation); } else { continue; } } List <TacticPerimeterDefense.EnemyCluster> list2 = this._enemyClusters.Where <TacticPerimeterDefense.EnemyCluster>((Func <TacticPerimeterDefense.EnemyCluster, bool>)(c => (double)(this._defendPosition.AsVec2 - c.AggregatePosition).DotProduct(this._defendPosition.AsVec2 - enemyFormation.QuerySystem.MedianPosition.AsVec2) >= 0.70710678118)).ToList <TacticPerimeterDefense.EnemyCluster>(); if (list2.Any <TacticPerimeterDefense.EnemyCluster>()) { list2.MaxBy <TacticPerimeterDefense.EnemyCluster, float>((Func <TacticPerimeterDefense.EnemyCluster, float>)(ec => (this._defendPosition.AsVec2 - ec.AggregatePosition).DotProduct(this._defendPosition.AsVec2 - enemyFormation.QuerySystem.MedianPosition.AsVec2))).AddToCluster(enemyFormation); } else { TacticPerimeterDefense.EnemyCluster enemyCluster2 = new TacticPerimeterDefense.EnemyCluster(); enemyCluster2.AddToCluster(enemyFormation); this._enemyClusters.Add(enemyCluster2); } } } if (!this._enemyClusters.Any <TacticPerimeterDefense.EnemyCluster>()) { return; } foreach (Formation formation in formationList) { Formation skippedFormation = formation; this._enemyClusters.MaxBy <TacticPerimeterDefense.EnemyCluster, float>((Func <TacticPerimeterDefense.EnemyCluster, float>)(ec => (this._defendPosition.AsVec2 - ec.AggregatePosition).DotProduct(this._defendPosition.AsVec2 - skippedFormation.QuerySystem.MedianPosition.AsVec2))).AddToCluster(skippedFormation); } }