private void ValidateAccountMessagesByResource(StaticString resourceName) { int[] array = this.accountIndexByResource[resourceName]; for (int i = 0; i < array.Length; i++) { this.accounts[array[i]].WantedAmount = 0f; this.accounts[array[i]].WantedAmountPriority = 0f; this.accounts[array[i]].PromisedAmount = 0f; } this.GatherMessages(array); if (this.workingMessages.Count == 0) { return; } int[] bestEvaluationIndex = new int[this.workingMessages.Count]; int[] array2 = new int[this.workingMessages.Count]; float availableResourceStock = this.aiLayerEconomy.GetAvailableResourceStock(resourceName); float num = availableResourceStock; for (int j = 0; j < array.Length; j++) { this.accounts[array[j]].EstimatedBalance = availableResourceStock; } for (int k = 0; k < this.workingMessages.Count; k++) { EvaluableMessage evaluableMessage = this.workingMessages[k]; array2[k] = k; bestEvaluationIndex[k] = -1; float num2 = 0f; for (int l = 0; l < evaluableMessage.BuyEvaluations.Count; l++) { BuyEvaluation buyEvaluation = evaluableMessage.BuyEvaluations[l]; if (evaluableMessage.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtaining || buyEvaluation == null || evaluableMessage.ChosenProductionEvaluation == null || !(buyEvaluation.CityGuid != evaluableMessage.ChosenProductionEvaluation.CityGuid)) { buyEvaluation.ComputeFinalBuyoutScore(evaluableMessage.Interest, num); if (num2 < buyEvaluation.BuyoutFinalScore) { bestEvaluationIndex[k] = l; num2 = buyEvaluation.BuyoutFinalScore; } } } } Array.Sort <int>(array2, delegate(int left, int right) { if (bestEvaluationIndex[left] == -1) { return(1); } if (bestEvaluationIndex[right] == -1) { return(-1); } return(-1 * this.workingMessages[left].BuyEvaluations[bestEvaluationIndex[left]].BuyoutFinalScore.CompareTo(this.workingMessages[right].BuyEvaluations[bestEvaluationIndex[right]].BuyoutFinalScore)); }); for (int m = 0; m < this.workingMessages.Count; m++) { EvaluableMessage evaluableMessage2 = this.workingMessages[m]; if (evaluableMessage2.ChosenBuyEvaluation != null) { if (num < evaluableMessage2.ChosenBuyEvaluation.DustCost) { evaluableMessage2.RevokeChosenBuyEvaluation(); } else { num -= evaluableMessage2.ChosenBuyEvaluation.DustCost; this.accounts[this.EnsureAccount(evaluableMessage2.AccountTag)].PromisedAmount += evaluableMessage2.ChosenBuyEvaluation.DustCost; } } } int num3 = 0; while (num3 < array2.Length && num > 0f) { int num4 = array2[num3]; EvaluableMessage evaluableMessage3 = this.workingMessages[num4]; int num5 = bestEvaluationIndex[num4]; if (num5 >= 0 && num5 < evaluableMessage3.BuyEvaluations.Count) { BuyEvaluation buyEvaluation2 = evaluableMessage3.BuyEvaluations[num5]; Account account = this.accounts[this.EnsureAccount(evaluableMessage3.AccountTag)]; if (num < buyEvaluation2.DustCost) { if (num3 == 0) { account.WantedAmount = buyEvaluation2.DustCost; account.WantedAmountPriority = buyEvaluation2.BuyoutFinalScore; } num -= account.GetAvailableAmount() * this.percentRetainWhenNotEnough; } else if (buyEvaluation2.BuyoutFinalScore > 0f) { evaluableMessage3.ValidateBuyEvaluation(buyEvaluation2); account.PromisedAmount += buyEvaluation2.DustCost; num -= buyEvaluation2.DustCost; } } num3++; } }
private void ValidateAccountMessages(Account account) { account.WantedAmount = 0f; this.workingMessages.Clear(); float num = account.GetAvailableAmount(); if (num <= 0f) { return; } Func <EvaluableMessage, bool> filter = (EvaluableMessage match) => match.AccountTag == account.AccountTag && (match.EvaluationState == EvaluableMessage.EvaluableMessageState.Pending || match.EvaluationState == EvaluableMessage.EvaluableMessageState.Obtaining); this.workingMessages.AddRange(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage>(BlackboardLayerID.City, filter)); this.workingMessages.AddRange(base.AIEntity.AIPlayer.Blackboard.GetMessages <EvaluableMessage>(BlackboardLayerID.Empire, filter)); if (this.workingMessages.Count == 0) { return; } int[] bestEvaluationIndex = new int[this.workingMessages.Count]; int[] array = new int[this.workingMessages.Count]; for (int i = 0; i < this.workingMessages.Count; i++) { EvaluableMessage evaluableMessage = this.workingMessages[i]; array[i] = i; bestEvaluationIndex[i] = -1; float num2 = 0f; for (int j = 0; j < evaluableMessage.BuyEvaluations.Count; j++) { BuyEvaluation buyEvaluation = evaluableMessage.BuyEvaluations[j]; if (evaluableMessage.EvaluationState != EvaluableMessage.EvaluableMessageState.Obtaining || buyEvaluation == null || evaluableMessage.ChosenProductionEvaluation == null || !(buyEvaluation.CityGuid != evaluableMessage.ChosenProductionEvaluation.CityGuid)) { buyEvaluation.ComputeFinalBuyoutScore(evaluableMessage.Interest, account.GetAvailableAmount()); if (num2 < buyEvaluation.BuyoutFinalScore) { bestEvaluationIndex[i] = j; num2 = buyEvaluation.BuyoutFinalScore; } } } } Array.Sort <int>(array, delegate(int left, int right) { if (bestEvaluationIndex[left] == -1) { return(1); } if (bestEvaluationIndex[right] == -1) { return(-1); } return(-1 * this.workingMessages[left].BuyEvaluations[bestEvaluationIndex[left]].BuyoutFinalScore.CompareTo(this.workingMessages[right].BuyEvaluations[bestEvaluationIndex[right]].BuyoutFinalScore)); }); int num3 = 3; for (int k = 0; k < array.Length; k++) { int num4 = array[k]; EvaluableMessage evaluableMessage2 = this.workingMessages[num4]; int num5 = bestEvaluationIndex[num4]; if (num5 >= 0 && num5 < evaluableMessage2.BuyEvaluations.Count) { BuyEvaluation buyEvaluation2 = evaluableMessage2.BuyEvaluations[num5]; if (num < buyEvaluation2.DustCost) { if (k == 0) { account.WantedAmount = buyEvaluation2.DustCost; } if (--num3 < 0) { break; } num -= account.GetAvailableAmount() * this.percentRetainWhenNotEnough; if (num <= 0f) { return; } } else if (buyEvaluation2.BuyoutFinalScore > 0f) { if (evaluableMessage2.ChosenBuyEvaluation != null) { account.PromisedAmount -= evaluableMessage2.ChosenBuyEvaluation.DustCost; } evaluableMessage2.ValidateBuyEvaluation(buyEvaluation2); account.PromisedAmount += buyEvaluation2.DustCost; num -= buyEvaluation2.DustCost; } } } }