private void OnOfferCB(GameObject obj)
    {
        if (this.DiplomaticContract == null)
        {
            Diagnostics.LogWarning("Diplomatic contract is null");
            return;
        }
        Diagnostics.Assert(this.DiplomaticContract.Terms != null);
        if (this.DiplomaticContract.Terms.Count == 0)
        {
            return;
        }
        OrderChangeDiplomaticContractState order = new OrderChangeDiplomaticContractState(this.DiplomaticContract, DiplomaticContractState.Proposed);

        base.PlayerController.PostOrder(order);
        this.DiplomaticContract = null;
        this.HandleCancelRequest();
    }
Esempio n. 2
0
    void IDiplomacyControl.OnServerBeginTurn()
    {
        this.firstBeginTurnDone = true;
        if (this.majorEmpires == null)
        {
            return;
        }
        while (this.visibilityControllerRefreshedArgs.Count > 0)
        {
            KeyValuePair <object, VisibilityRefreshedEventArgs> keyValuePair = this.visibilityControllerRefreshedArgs.Dequeue();
            this.OnVisibityRefreshed(keyValuePair.Key, keyValuePair.Value);
        }
        int turn = base.Game.Turn;

        for (int i = 0; i < this.majorEmpires.Length; i++)
        {
            MajorEmpire majorEmpire           = this.majorEmpires[i] as MajorEmpire;
            DepartmentOfForeignAffairs agency = majorEmpire.GetAgency <DepartmentOfForeignAffairs>();
            Diagnostics.Assert(agency != null);
            for (int j = i + 1; j < this.majorEmpires.Length; j++)
            {
                MajorEmpire        majorEmpire2       = this.majorEmpires[j] as MajorEmpire;
                DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(majorEmpire2);
                Diagnostics.Assert(diplomaticRelation != null && diplomaticRelation.State != null);
                if (majorEmpire.IsSpectator || majorEmpire.ELCPIsEliminated || majorEmpire2.IsSpectator || majorEmpire2.ELCPIsEliminated)
                {
                    if (diplomaticRelation.State.Name != DiplomaticRelationState.Names.Dead)
                    {
                        OrderChangeDiplomaticRelationState order = new OrderChangeDiplomaticRelationState(this.majorEmpires[i].Index, majorEmpire2.Index, DiplomaticRelationState.Names.Dead);
                        this.PlayerController.PostOrder(order);
                    }
                }
                else
                {
                    DiplomaticRelationState.Transition automaticTransition = diplomaticRelation.State.AutomaticTransition;
                    if (automaticTransition != null && automaticTransition.GetRemainingTurns(diplomaticRelation) <= 0)
                    {
                        OrderChangeDiplomaticRelationState order2 = new OrderChangeDiplomaticRelationState(i, j, automaticTransition.DestinationState);
                        this.PlayerController.PostOrder(order2);
                    }
                }
            }
        }
        bool[][] array = new bool[this.majorEmpires.Length][];
        for (int k = 0; k < this.majorEmpires.Length; k++)
        {
            array[k] = new bool[this.majorEmpires.Length];
        }
        Diagnostics.Assert(this.diplomaticContracts != null);
        for (int l = 0; l < this.diplomaticContracts.Count; l++)
        {
            DiplomaticContract diplomaticContract = this.diplomaticContracts[l];
            Diagnostics.Assert(diplomaticContract != null);
            if (diplomaticContract.EmpireWhichInitiated.Index >= array.Length || diplomaticContract.EmpireWhichReceives.Index >= array[diplomaticContract.EmpireWhichInitiated.Index].Length)
            {
                Diagnostics.Assert(false, "ELCP: Unexpected EmpireIndex {0}", new object[]
                {
                    diplomaticContract.ToString()
                });
            }
            else
            {
                if (diplomaticContract.State == DiplomaticContractState.Proposed && turn > diplomaticContract.TurnAtTheBeginningOfTheState)
                {
                    OrderChangeDiplomaticContractState order3 = new OrderChangeDiplomaticContractState(diplomaticContract, DiplomaticContractState.Refused);
                    this.PlayerController.PostOrder(order3);
                }
                if (diplomaticContract.State == DiplomaticContractState.Negotiation && turn > diplomaticContract.TurnAtTheBeginningOfTheState)
                {
                    if (diplomaticContract.EmpireWhichInitiated != diplomaticContract.EmpireWhichProposes || diplomaticContract.ContractRevisionNumber > 0 || array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index])
                    {
                        DiplomaticContractState            newState = DiplomaticContractState.Refused;
                        OrderChangeDiplomaticContractState order4   = new OrderChangeDiplomaticContractState(diplomaticContract, newState);
                        this.PlayerController.PostOrder(order4);
                    }
                    else
                    {
                        array[diplomaticContract.EmpireWhichInitiated.Index][diplomaticContract.EmpireWhichReceives.Index] = true;
                    }
                }
            }
        }
    }