public void Init(bool spawnDefenders, bool spawnAttackers, float defenderAdvantageFactor = 1f) { foreach (IEnumerable <MissionAgentSpawnLogic.SpawnPhase> phase in this._phases) { if (!phase.Any <MissionAgentSpawnLogic.SpawnPhase>()) { throw new Exception("There must be at least 1 phase (initial phase) on each side before Init was called."); } } int[] numArray1 = new int[2] { this._phases[0].Sum <MissionAgentSpawnLogic.SpawnPhase>((Func <MissionAgentSpawnLogic.SpawnPhase, int>)(p => p.TotalSpawnNumber)), this._phases[1].Sum <MissionAgentSpawnLogic.SpawnPhase>((Func <MissionAgentSpawnLogic.SpawnPhase, int>)(p => p.TotalSpawnNumber)) }; int num1 = ((IEnumerable <int>)numArray1).Sum(); float[] numArray2 = new float[2] { (float)numArray1[0] / (float)num1, (float)numArray1[1] / (float)num1 }; if ((double)numArray2[0] < 0.600000023841858) { numArray2[0] *= defenderAdvantageFactor; if ((double)numArray2[0] > 0.600000023841858) { numArray2[0] = 0.6f; } numArray2[1] = 1f - numArray2[0]; } BattleSideEnum side = (double)numArray2[0] < (double)numArray2[1] ? BattleSideEnum.Defender : BattleSideEnum.Attacker; BattleSideEnum oppositeSide = side.GetOppositeSide(); int[] numArray3 = new int[2]; numArray3[(int)side] = MBMath.Ceiling(numArray2[(int)side] * (float)this._battleSize); numArray3[(int)oppositeSide] = this._battleSize - numArray3[(int)side]; for (int index = 0; index < 2; ++index) { foreach (MissionAgentSpawnLogic.SpawnPhase spawnPhase in this._phases[index]) { if (spawnPhase.InitialSpawnNumber > numArray3[index]) { int num2 = numArray3[index]; int num3 = spawnPhase.InitialSpawnNumber - num2; spawnPhase.InitialSpawnNumber = num2; spawnPhase.RemainingSpawnNumber += num3; } } } Mission.Current.SetBattleAgentCount(Math.Min(this.DefenderActivePhase.InitialSpawnNumber, this.AttackerActivePhase.InitialSpawnNumber)); this._missionSides[0].SetSpawnTroops(spawnDefenders); this._missionSides[1].SetSpawnTroops(spawnAttackers); }
private void CheckIsEnemySideRetreatingOrOneSideDepleted() { if (!this._canCheckForEndConditionSiege) { this._canCheckForEndConditionSiege = this.Mission.GetMissionBehaviour <SiegeDeploymentHandler>() == null; } else { if (!this._canCheckForEndCondition) { return; } BattleSideEnum side = this.Mission.PlayerTeam.Side; this._isPlayerSideDepleted = this._missionAgentSpawnLogic.IsSideDepleted(side); this._isEnemySideDepleted = this._missionAgentSpawnLogic.IsSideDepleted(side.GetOppositeSide()); if (this._isEnemySideDepleted || this._isPlayerSideDepleted || this.Mission.GetMissionBehaviour <HideoutPhasedMissionController>() != null) { return; } bool flag = true; foreach (Team team in (ReadOnlyCollection <Team>) this.Mission.Teams) { if (team.IsEnemyOf(this.Mission.PlayerTeam)) { foreach (Agent activeAgent in team.ActiveAgents) { if (!activeAgent.IsRunningAway) { flag = false; break; } } } } if (!flag) { this._enemiesNotYetRetreatingTime = MissionTime.Now; } if ((double)this._enemiesNotYetRetreatingTime.ElapsedSeconds <= 3.0) { return; } this._isEnemySideRetreating = true; } }