void IDiplomaticTermManagement.ApplyEffects() { Diagnostics.Assert(base.Definition is DiplomaticTermResourceExchangeDefinition); Diagnostics.Assert(base.EmpireWhichProvides != null && base.EmpireWhichReceives != null); Diagnostics.Assert(base.EmpireWhichProvides.Index != base.EmpireWhichReceives.Index); DepartmentOfTheTreasury agency = base.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>(); DepartmentOfTheTreasury agency2 = base.EmpireWhichReceives.GetAgency <DepartmentOfTheTreasury>(); Diagnostics.Assert(agency != null && agency2 != null); if (this.BufferedAmount > 0f && this.BufferedAmount >= this.Amount) { this.BufferedAmount = 0f; } else if (!agency.TryTransferResources(base.EmpireWhichProvides, this.ResourceName, -this.Amount)) { Diagnostics.LogError("DiplomaticTermResourceExchange.ApplyEffect failed, can't debit the empire which provides the term (resource: {0} amount: {1})", new object[] { this.ResourceName, -this.Amount }); return; } if (!agency2.TryTransferResources(base.EmpireWhichReceives, this.ResourceName, this.Amount)) { Diagnostics.LogError("DiplomaticTermResourceExchange.ApplyEffect failed, can't credt the empire which receive the term (resource: {0} amount: {1})", new object[] { this.ResourceName, this.Amount }); return; } }
public void ExecuteTransferResource(BoosterEffect effect) { if (effect.Transfer == null) { return; } for (int i = 0; i < effect.Transfer.Length; i++) { BoosterEffect.TransferResource transferResource = effect.Transfer[i]; if (string.IsNullOrEmpty(transferResource.ResourceName)) { Diagnostics.LogWarning("Booster '{0}': Transfer number {1} resource name is null or empty.", new object[] { this.BoosterDefinition.Name, i }); } else { DepartmentOfTheTreasury agency = this.empire.GetAgency <DepartmentOfTheTreasury>(); if (agency != null) { agency.TryTransferResources(this.Context, transferResource.ResourceName, (float)transferResource.Amount); } } } }
void IDiplomaticContractManagement.SetDiplomaticState(DiplomaticContractState destinationState) { DiplomaticContractState state = this.State; IGameService service = Services.GetService <IGameService>(); Diagnostics.Assert(service != null); global::Game game = service.Game as global::Game; Diagnostics.Assert(game != null); this.TurnAtTheBeginningOfTheState = game.Turn; if (destinationState == DiplomaticContractState.Proposed && this.EmpireWhichProposes.IsControlledByAI && !this.EmpireWhichReceives.IsControlledByAI) { for (int i = this.terms.Count - 1; i >= 0; i--) { DiplomaticTermResourceExchange diplomaticTermResourceExchange = this.terms[i] as DiplomaticTermResourceExchange; if (diplomaticTermResourceExchange != null && diplomaticTermResourceExchange.EmpireWhichProvides.Index == this.EmpireWhichProposes.Index) { DepartmentOfTheTreasury agency = diplomaticTermResourceExchange.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>(); if (agency.TryTransferResources(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, -diplomaticTermResourceExchange.Amount)) { float num; agency.TryGetResourceStockValue(diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.ResourceName, out num, false); Diagnostics.Log("ELCP {0} with {1} Buffering Resource {2} {3}, providerstock2: {4}", new object[] { diplomaticTermResourceExchange.EmpireWhichProvides, diplomaticTermResourceExchange.EmpireWhichReceives, diplomaticTermResourceExchange.ResourceName, diplomaticTermResourceExchange.Amount, num }); diplomaticTermResourceExchange.BufferedAmount = diplomaticTermResourceExchange.Amount; } } } } if (destinationState == DiplomaticContractState.Negotiation || destinationState == DiplomaticContractState.Refused || destinationState == DiplomaticContractState.Ignored) { for (int j = this.terms.Count - 1; j >= 0; j--) { DiplomaticTermResourceExchange diplomaticTermResourceExchange2 = this.terms[j] as DiplomaticTermResourceExchange; if (diplomaticTermResourceExchange2 != null && diplomaticTermResourceExchange2.BufferedAmount > 0f) { DepartmentOfTheTreasury agency2 = diplomaticTermResourceExchange2.EmpireWhichProvides.GetAgency <DepartmentOfTheTreasury>(); agency2.TryTransferResources(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, diplomaticTermResourceExchange2.BufferedAmount); float num2; agency2.TryGetResourceStockValue(diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.ResourceName, out num2, false); Diagnostics.Log("ELCP {0} with {1} UnBuffering Resource {2} {3} {4}, providerstock2: {5}", new object[] { diplomaticTermResourceExchange2.EmpireWhichProvides, diplomaticTermResourceExchange2.EmpireWhichReceives, diplomaticTermResourceExchange2.ResourceName, diplomaticTermResourceExchange2.BufferedAmount, diplomaticTermResourceExchange2.Amount, num2 }); diplomaticTermResourceExchange2.BufferedAmount = 0f; } } } if (state == DiplomaticContractState.Proposed && destinationState == DiplomaticContractState.Negotiation) { global::Empire empireWhichProposes = this.EmpireWhichProposes; this.EmpireWhichProposes = this.EmpireWhichReceives; this.EmpireWhichReceives = empireWhichProposes; float empireWhichProposesEmpirePointInvestment = this.EmpireWhichProposesEmpirePointInvestment; this.EmpireWhichProposesEmpirePointInvestment = this.EmpireWhichReceivesEmpirePointInvestment; this.EmpireWhichReceivesEmpirePointInvestment = empireWhichProposesEmpirePointInvestment; for (int k = this.terms.Count - 1; k >= 0; k--) { DiplomaticTerm diplomaticTerm = this.terms[k]; Diagnostics.Assert(diplomaticTerm != null); if (!diplomaticTerm.CanApply(this, new string[0])) { this.terms.RemoveAt(k); } } int contractRevisionNumber = this.ContractRevisionNumber; this.ContractRevisionNumber = contractRevisionNumber + 1; } if (destinationState == DiplomaticContractState.Signed) { this.ApplyTerms(); } Diagnostics.Log("Contract {0} pass from state {1} to state {2}.", new object[] { this.GUID, this.State, destinationState }); this.State = destinationState; this.OnDiplomaticContractChange(); }