Пример #1
0
    void IVictoryManagementService.CheckForAlerts(int turn)
    {
        if (turn < 0 || this.HasAlreadyWon)
        {
            return;
        }
        Diagnostics.Assert(this.InterpreterContext != null);
        Snapshot snapshot = null;
        IGameStatisticsManagementService service = Services.GetService <IGameStatisticsManagementService>();

        if (service != null && service.Snapshot != null)
        {
            string name = string.Format("Turn #{0}", turn);
            if (!service.Snapshot.TryGetSnapshot(name, out snapshot))
            {
                Diagnostics.LogWarning("Skipping check because snapshot is missing (turn: {0}).", new object[]
                {
                    turn
                });
                return;
            }
            if (snapshot != null)
            {
                foreach (KeyValuePair <string, float> keyValuePair in snapshot.KeyValuePairs)
                {
                    this.InterpreterContext.Register(keyValuePair.Key, keyValuePair.Value);
                }
            }
        }
        Diagnostics.Assert(base.Game != null);
        this.InterpreterContext.Register("Turn", base.Game.Turn);
        int num  = 0;
        int num2 = 0;
        int num3 = 0;
        int num4 = 0;
        int num5 = 0;

        for (int i = 0; i < base.Game.Empires.Length; i++)
        {
            MajorEmpire majorEmpire = base.Game.Empires[i] as MajorEmpire;
            if (majorEmpire == null)
            {
                break;
            }
            num++;
            num3++;
            if (majorEmpire.SimulationObject.Tags.Contains(Empire.TagEmpireEliminated))
            {
                num2++;
                num3--;
            }
            else
            {
                for (int j = 0; j < this.simulationPathNumberOfMainCities.Length; j++)
                {
                    num4 += (int)this.simulationPathNumberOfMainCities[j].CountValidatedObjects(majorEmpire);
                }
                DepartmentOfTheInterior agency = majorEmpire.GetAgency <DepartmentOfTheInterior>();
                if (agency != null)
                {
                    num5 += agency.Cities.Count;
                }
            }
        }
        this.InterpreterContext.Register("NumberOfMajorEmpires", num);
        this.InterpreterContext.Register("NumberOfMajorEmpiresEliminated", num2);
        this.InterpreterContext.Register("NumberOfMajorEmpiresLeft", num3);
        this.InterpreterContext.Register("NumberOfMainCitiesLeft", num4);
        this.InterpreterContext.Register("NumberOfCitiesLeft", num5);
        for (int k = 0; k < base.Game.Empires.Length; k++)
        {
            MajorEmpire majorEmpire2 = base.Game.Empires[k] as MajorEmpire;
            if (majorEmpire2 == null)
            {
                break;
            }
            if (snapshot != null)
            {
                Snapshot snapshot2 = snapshot.TakeSnapshot(majorEmpire2.Name);
                if (snapshot2 != null)
                {
                    foreach (KeyValuePair <string, float> keyValuePair2 in snapshot2.KeyValuePairs)
                    {
                        this.InterpreterContext.Register(keyValuePair2.Key, keyValuePair2.Value);
                    }
                }
            }
            try
            {
                int num6 = 0;
                for (int l = 0; l < this.simulationPathNumberOfMainCities.Length; l++)
                {
                    num6 += (int)this.simulationPathNumberOfMainCities[l].CountValidatedObjects(majorEmpire2);
                }
                this.InterpreterContext.Register("NumberOfMainCities", num6);
                this.InterpreterContext.Register("VictoryWonderProgress", this.GetWonderProgress(majorEmpire2));
                majorEmpire2.SimulationObject.AddChild(this.InterpreterContext.SimulationObject);
                foreach (VictoryCondition victoryCondition in this.VictoryConditionsFilteredThisGame)
                {
                    if (majorEmpire2.VictoryConditionStatuses != null)
                    {
                        MajorEmpire.VictoryConditionStatus victoryConditionStatus;
                        if (!majorEmpire2.VictoryConditionStatuses.TryGetValue(victoryCondition.Name, out victoryConditionStatus))
                        {
                            victoryConditionStatus = new MajorEmpire.VictoryConditionStatus();
                            majorEmpire2.VictoryConditionStatuses.Add(victoryCondition.Name, victoryConditionStatus);
                        }
                        if (victoryCondition.Alerts != null)
                        {
                            if (victoryConditionStatus.LastTurnWhenAlertWasTriggered == null || victoryConditionStatus.LastTurnWhenAlertWasTriggered.Length != victoryCondition.Alerts.Length)
                            {
                                victoryConditionStatus.LastTurnWhenAlertWasTriggered = new int[victoryCondition.Alerts.Length];
                            }
                            for (int m = 0; m < victoryCondition.Alerts.Length; m++)
                            {
                                VictoryCondition.Alert alert = victoryCondition.Alerts[m];
                                if (alert != null && (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] == 0 || (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] < 0 && alert.Repeat)))
                                {
                                    if (alert.Evaluate(this.InterpreterContext))
                                    {
                                        victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] = base.Game.Turn;
                                    }
                                    else if (victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] > 0)
                                    {
                                        victoryConditionStatus.LastTurnWhenAlertWasTriggered[m] = -victoryConditionStatus.LastTurnWhenAlertWasTriggered[m];
                                    }
                                }
                            }
                        }
                        if (victoryCondition.Progression != null)
                        {
                            if (victoryConditionStatus.Variables == null || victoryConditionStatus.Variables.Length != victoryCondition.Progression.Vars.Length)
                            {
                                victoryConditionStatus.Variables = new float[victoryCondition.Progression.Vars.Length];
                            }
                            for (int n = 0; n < victoryCondition.Progression.Vars.Length; n++)
                            {
                                victoryConditionStatus.Variables[n] = victoryCondition.Progression.Vars[n].Evaluate(this.InterpreterContext);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                majorEmpire2.SimulationObject.RemoveChild(this.InterpreterContext.SimulationObject);
            }
        }
        for (int num7 = 0; num7 < base.Game.Empires.Length; num7++)
        {
            MajorEmpire majorEmpire3 = base.Game.Empires[num7] as MajorEmpire;
            if (majorEmpire3 == null)
            {
                break;
            }
            foreach (VictoryCondition victoryCondition2 in this.VictoryConditionsFilteredThisGame)
            {
                MajorEmpire.VictoryConditionStatus victoryConditionStatus2;
                if (victoryCondition2.Alerts != null && majorEmpire3.VictoryConditionStatuses != null && majorEmpire3.VictoryConditionStatuses.TryGetValue(victoryCondition2.Name, out victoryConditionStatus2))
                {
                    for (int num8 = 0; num8 < victoryCondition2.Alerts.Length; num8++)
                    {
                        if (victoryConditionStatus2.LastTurnWhenAlertWasTriggered != null && num8 < victoryConditionStatus2.LastTurnWhenAlertWasTriggered.Length && victoryConditionStatus2.LastTurnWhenAlertWasTriggered[num8] >= base.Game.Turn && victoryCondition2.Alerts[num8] != null)
                        {
                            EventVictoryConditionAlert eventToNotify = new EventVictoryConditionAlert(majorEmpire3, victoryCondition2, victoryConditionStatus2, num8);
                            this.EventService.Notify(eventToNotify);
                        }
                    }
                }
            }
        }
    }
Пример #2
0
	public override void ReadXml(XmlReader reader)
	{
		this.TurnWhenLastBegun = reader.GetAttribute<int>("TurnWhenLastBegun");
		int num = reader.ReadVersionAttribute();
		base.ReadXml(reader);
		if (reader.IsStartElement("VictoryConditionStatuses"))
		{
			int attribute = reader.GetAttribute<int>("Count");
			reader.ReadStartElement("VictoryConditionStatuses");
			this.VictoryConditionStatuses.Clear();
			for (int i = 0; i < attribute; i++)
			{
				string attribute2 = reader.GetAttribute("Name");
				MajorEmpire.VictoryConditionStatus victoryConditionStatus = new MajorEmpire.VictoryConditionStatus();
				reader.ReadStartElement("VictoryConditionStatus");
				int attribute3 = reader.GetAttribute<int>("Count");
				victoryConditionStatus.LastTurnWhenAlertWasTriggered = new int[attribute3];
				reader.ReadStartElement("Alerts");
				for (int j = 0; j < attribute3; j++)
				{
					victoryConditionStatus.LastTurnWhenAlertWasTriggered[j] = reader.ReadElementString<int>("LastTurnWhenAlertWasTriggered");
				}
				reader.ReadEndElement("Alerts");
				int attribute4 = reader.GetAttribute<int>("Count");
				victoryConditionStatus.Variables = new float[attribute4];
				reader.ReadStartElement("Variables");
				for (int k = 0; k < attribute4; k++)
				{
					victoryConditionStatus.Variables[k] = reader.ReadElementString<float>("Value");
				}
				reader.ReadEndElement("Variables");
				reader.ReadEndElement();
				this.VictoryConditionStatuses.Add(attribute2, victoryConditionStatus);
			}
			reader.ReadEndElement("VictoryConditionStatuses");
		}
		if (num >= 2 && reader.IsStartElement("ConvertedVillages"))
		{
			this.convertedVillages = new List<Village>();
			IGameService service = Services.GetService<IGameService>();
			Diagnostics.Assert(service != null);
			Diagnostics.Assert(service.Game != null);
			Diagnostics.Assert(service.Game is global::Game);
			int attribute5 = reader.GetAttribute<int>("Count");
			if (attribute5 > 0)
			{
				reader.ReadStartElement("ConvertedVillages");
				for (int l = 0; l < attribute5; l++)
				{
					ulong attribute6 = reader.GetAttribute<ulong>("GUID");
					Village village = new Village(attribute6)
					{
						Empire = this
					};
					reader.ReadElementSerializable<Village>(ref village);
					if (village != null)
					{
						this.convertedVillages.Add(village);
					}
				}
				reader.ReadEndElement("ConvertedVillages");
			}
			else
			{
				reader.Skip("ConvertedVillages");
			}
		}
		if (num >= 3)
		{
			if (reader.IsStartElement("TamedKaijus"))
			{
				this.tamedKaijus = new List<Kaiju>();
				IGameService service2 = Services.GetService<IGameService>();
				Diagnostics.Assert(service2 != null);
				Diagnostics.Assert(service2.Game != null);
				Diagnostics.Assert(service2.Game is global::Game);
				int attribute7 = reader.GetAttribute<int>("Count");
				if (attribute7 > 0)
				{
					reader.ReadStartElement("TamedKaijus");
					for (int m = 0; m < attribute7; m++)
					{
						Kaiju kaiju = new Kaiju();
						kaiju.MajorEmpire = this;
						kaiju.Empire = this;
						reader.ReadElementSerializable<Kaiju>(ref kaiju);
						if (kaiju != null)
						{
							this.tamedKaijus.Add(kaiju);
						}
					}
					reader.ReadEndElement("TamedKaijus");
				}
				else
				{
					reader.Skip("TamedKaijus");
				}
			}
			if (reader.IsStartElement("InfectedVillages"))
			{
				this.infectedVillages = new List<Village>();
				IGameService service3 = Services.GetService<IGameService>();
				Diagnostics.Assert(service3 != null);
				Diagnostics.Assert(service3.Game != null);
				Diagnostics.Assert(service3.Game is global::Game);
				int attribute8 = reader.GetAttribute<int>("Count");
				if (attribute8 > 0)
				{
					reader.ReadStartElement("InfectedVillages");
					for (int n = 0; n < attribute8; n++)
					{
						ulong attribute9 = reader.GetAttribute<ulong>("GUID");
						Village village2 = new Village(attribute9)
						{
							Empire = this
						};
						reader.ReadElementSerializable<Village>(ref village2);
						if (village2 != null)
						{
							this.InfectedVillages.Add(village2);
						}
					}
					reader.ReadEndElement("InfectedVillages");
				}
				else
				{
					reader.Skip("InfectedVillages");
				}
			}
		}
	}