Example #1
0
    private void AddWinnerToQuestVariable(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault((Contender match) => match.Empire == questBehaviour.Initiator && match.ContenderState == ContenderState.Survived);

        if (contender != null)
        {
            this.WinnerArmyGUID = contender.GUID;
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.Output_WinnerVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.Output_WinnerVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            DepartmentOfDefense agency = questBehaviour.Initiator.GetAgency <DepartmentOfDefense>();
            Diagnostics.Assert(agency != null);
            Army army = agency.Armies.FirstOrDefault((Army match) => match.GUID == this.WinnerArmyGUID);
            if (army == null)
            {
                Diagnostics.LogError("Decorator_KillArmy: the army (GUID:'{0}') cannot be found in the empire (index:'{1}') armies", new object[]
                {
                    this.WinnerArmyGUID,
                    questBehaviour.Initiator.Index
                });
            }
            questVariable.Object = army;
        }
    }
Example #2
0
    private bool IsThereOneTargetEnemyDead(QuestBehaviour questBehaviour, EventEncounterStateChange e)
    {
        if (this.EnemyArmyGUIDs != null)
        {
            if (questBehaviour.Quest.QuestDefinition.Category != "GlobalQuest" && !this.IgnoreDisbandedArmies)
            {
                for (int i = 0; i < this.EnemyArmyGUIDs.Length; i++)
                {
                    IGameEntity gameEntity;
                    this.gameEntityRepositoryService.TryGetValue(this.EnemyArmyGUIDs[i], out gameEntity);
                    if (gameEntity != null)
                    {
                        break;
                    }
                    if (gameEntity == null && i == this.EnemyArmyGUIDs.Length - 1)
                    {
                        return(true);
                    }
                }
            }
            for (int j = 0; j < this.EnemyArmyGUIDs.Length; j++)
            {
                ulong enemyArmyGUID = this.EnemyArmyGUIDs[j];
                if (enemyArmyGUID == 0UL)
                {
                    Diagnostics.LogError("Enemy contender corresponding to quest variable (varname: '{0}') isn't valid in quest definition (name: '{1}')", new object[]
                    {
                        this.EnemyArmyGUIDs,
                        questBehaviour.Quest.QuestDefinition.Name
                    });
                }
                else
                {
                    Func <ContenderSnapShot, bool> < > 9__2;
                    Contender contender = e.EventArgs.Encounter.Contenders.FirstOrDefault(delegate(Contender match)
                    {
                        IEnumerable <ContenderSnapShot> contenderSnapShots = match.ContenderSnapShots;
                        Func <ContenderSnapShot, bool> predicate;
                        if ((predicate = < > 9__2) == null)
                        {
                            predicate = (< > 9__2 = ((ContenderSnapShot snapshot) => snapshot.ContenderGUID == enemyArmyGUID));
                        }
                        return(contenderSnapShots.Any(predicate));
                    });
                    if (contender != null && contender.Empire != e.Empire && contender.ContenderState == ContenderState.Defeated)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        IEnumerable <Contender> enemiesContenderFromEmpire = e.EventArgs.Encounter.GetEnemiesContenderFromEmpire(e.Empire as global::Empire);

        if (enemiesContenderFromEmpire == null)
        {
            return(false);
        }
        return(enemiesContenderFromEmpire.Any((Contender match) => match.ContenderState == ContenderState.Defeated));
    }
Example #3
0
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        int num = this.ComputeEleapsedTurn(questBehaviour);

        if (num == -1)
        {
            Diagnostics.LogError("QuestBehaviourTreeNode_Action_UpdateTimerLocalization, Timer '{0}' isn't started, you can't update it.", new object[]
            {
                this.TimerVarName
            });
            return(State.Success);
        }
        int num2 = this.TurnCountBeforeTimeOut;

        if (this.ScaleWithGameSpeed)
        {
            num2 = Mathf.CeilToInt((float)this.TurnCountBeforeTimeOut * questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier));
        }
        int num3 = num2 - num;

        if (!string.IsNullOrEmpty(this.TimerLocalizationKey) && num3 >= 0)
        {
            QuestInstruction_UpdateLocalizationVariable questInstruction = new QuestInstruction_UpdateLocalizationVariable(this.TimerLocalizationKey, num3.ToString());
            questBehaviour.Push(questInstruction);
        }
        return(State.Success);
    }
Example #4
0
    public override bool Initialize(QuestBehaviour questBehaviour)
    {
        City city;

        if (this.CityGUID == GameEntityGUID.Zero && !string.IsNullOrEmpty(this.CityVarName) && questBehaviour.TryGetQuestVariableValueByName <City>(this.CityVarName, out city))
        {
            if (city == null)
            {
                Diagnostics.LogError("City is null or empty, quest variable (varname: '{0}')", new object[]
                {
                    this.CityVarName
                });
                return(false);
            }
            this.CityGUID = city.GUID;
        }
        ulong num;

        if (this.ArmyGuid == 0UL && !string.IsNullOrEmpty(this.ArmyGuidVarName) && questBehaviour.TryGetQuestVariableValueByName <ulong>(this.ArmyGuidVarName, out num))
        {
            if (num == 0UL)
            {
                Diagnostics.LogError("QuestBehaviourTreeNode_ConditionCheck_IsArmyAtCity : Army guid is invalid");
                return(false);
            }
            this.ArmyGuid = new GameEntityGUID(num);
        }
        return(base.Initialize(questBehaviour));
    }
Example #5
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null)
        {
            Diagnostics.LogError("Failed to retrieve the game service.");
            return(false);
        }
        global::Game game = service.Game as global::Game;

        if (game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        this.gameEntityRepositoryService = game.Services.GetService <IGameEntityRepositoryService>();
        if (this.gameEntityRepositoryService == null)
        {
            Diagnostics.LogError("Failed to retrieve the game entity repository service.");
            return(false);
        }
        City value;

        if (this.StoredCity != 0UL && !string.IsNullOrEmpty(this.Output_CityVarName) && this.gameEntityRepositoryService.TryGetValue <City>(this.StoredCity, out value))
        {
            this.UpdateQuestVariable(questBehaviour, this.Output_CityVarName, value);
        }
        return(base.Initialize(questBehaviour));
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        if (this.Tags.IsNullOrEmpty)
        {
            Diagnostics.LogWarning("Marker was added without any tags in quest {0} : abort.", new object[]
            {
                questBehaviour.Quest.QuestDefinition.XmlSerializableName
            });
            return(State.Success);
        }
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null || !(service.Game is global::Game))
        {
            Diagnostics.LogError("Unable to retrieve the game service.");
            return(State.Running);
        }
        if (!this.TryResolveTarget(questBehaviour))
        {
            return(State.Running);
        }
        questBehaviour.Push(new QuestInstruction_UpdateQuestMarker
        {
            BoundTargetGUID         = this.TargetEntityGUID,
            MarkerGUID              = this.QuestMarkerGUID,
            Tags                    = this.Tags,
            Empire                  = questBehaviour.Initiator,
            RevealUnexploredLand    = this.RevealUnexploredLand,
            MarkerVisibleInFogOfWar = this.MarkerVisibleInFogOfWar,
            MarkerTypeName          = this.MarkerTypeName,
            IgnoreInteraction       = this.IgnoreInteraction
        });
        return(State.Success);
    }
Example #7
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        if (this.WinnerArmyGUID != GameEntityGUID.Zero && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_WinnerVarName))
        {
            QuestVariable questVariable = new QuestVariable(this.Output_WinnerVarName);
            questVariable.Object = this.WinnerArmyGUID;
            questBehaviour.QuestVariables.Add(questVariable);
        }
        this.SaveEnemyArmyGUIDs(questBehaviour);
        MajorEmpire majorEmpire;

        if (this.FocusedEmpireVarName != string.Empty && questBehaviour.TryGetQuestVariableValueByName <MajorEmpire>(this.FocusedEmpireVarName, out majorEmpire))
        {
            this.FocusedEmpireIndex = majorEmpire.Index;
        }
        if (this.UpdateVarName)
        {
            this.UpdateVars = true;
        }
        else
        {
            this.UpdateVars = false;
        }
        IGameService service = Services.GetService <IGameService>();

        this.gameEntityRepositoryService = service.Game.Services.GetService <IGameEntityRepositoryService>();
        return(base.Initialize(questBehaviour));
    }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null || !(service.Game is global::Game))
        {
            Diagnostics.LogError("Unable to retrieve the game service.");
            return(false);
        }
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();

        if (service2 == null)
        {
            Diagnostics.LogError("Unable to retrieve the game entity repository service.");
            return(false);
        }
        if (!this.TryResolveTarget(questBehaviour))
        {
            return(false);
        }
        if (this.QuestMarkerGUID == 0UL)
        {
            this.QuestMarkerGUID = service2.GenerateGUID();
        }
        QuestVariable questVariable = questBehaviour.GetQuestVariableByName(this.Output_QuestMarkerVarName);

        if (questVariable == null)
        {
            questVariable = new QuestVariable(this.Output_QuestMarkerVarName);
            questBehaviour.QuestVariables.Add(questVariable);
        }
        questVariable.Object = this.QuestMarkerGUID;
        return(base.Initialize(questBehaviour));
    }
 protected override State Execute(QuestBehaviour questBehaviour, EventEmpireWorldTerraformed e, params object[] parameters)
 {
     if (!e.Reversible && base.CheckAgainstQuestInitiatorFilter(questBehaviour, e.TerraformingEmpire as global::Empire, base.QuestInitiatorFilter) && e.TerraformedTiles.Length != 0)
     {
         IGameService service = Services.GetService <IGameService>();
         World        world   = (service.Game as global::Game).World;
         IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
         Diagnostics.Assert(service2 != null);
         for (int i = 0; i < e.TerraformedTiles.Length; i++)
         {
             QuestBehaviourTreeNode_Decorator_TerraformRegion.< > c__DisplayClass0_0 CS$ < > 8__locals1 = new QuestBehaviourTreeNode_Decorator_TerraformRegion.< > c__DisplayClass0_0();
             CS$ < > 8__locals1.region = service2.GetRegion(e.TerraformedTiles[i]);
             bool flag = true;
             int  k;
             int  j;
             for (j = 0; j < CS$ < > 8__locals1.region.WorldPositions.Length; j = k + 1)
             {
                 if (!service2.IsWaterTile(CS$ < > 8__locals1.region.WorldPositions[j]) && !service2.HasRidge(CS$ < > 8__locals1.region.WorldPositions[j]) && (!service2.ContainsTerrainTag(CS$ < > 8__locals1.region.WorldPositions[j], "TerrainTagVolcanic") || world.TemporaryTerraformations.Exists((World.TemporaryTerraformation tt) => tt.worldPosition == CS$ < > 8__locals1.region.WorldPositions[j])))
                 {
                     flag = false;
                     break;
                 }
                 k = j;
             }
             if (flag)
             {
                 this.RegionTerraformed = flag;
                 base.UpdateQuestVariable(questBehaviour, this.Output_RegionTerraformedVarName, this.RegionTerraformed);
                 return(State.Success);
             }
         }
     }
     return(State.Running);
 }
Example #10
0
    protected override State Execute(QuestBehaviour questBehaviour, EventConstructionEnded e, params object[] parameters)
    {
        Diagnostics.Assert(e.ConstructibleElement != null);
        if (e.ConstructibleElement.Name != this.ConstructionName)
        {
            return(State.Running);
        }
        City city;

        if (!Services.GetService <IGameService>().Game.Services.GetService <IGameEntityRepositoryService>().TryGetValue <City>(e.Context, out city))
        {
            if (!(this.CityGUID == GameEntityGUID.Zero))
            {
                return(State.Running);
            }
            return(State.Success);
        }
        else
        {
            if (this.CityGUID != GameEntityGUID.Zero && this.CityGUID != city.GUID)
            {
                return(State.Running);
            }
            base.UpdateQuestVariable(questBehaviour, this.Output_CityVarName, city);
            if (!string.IsNullOrEmpty(this.Output_CityVarName))
            {
                this.CityGUID = city.GUID;
            }
            return(State.Success);
        }
    }
Example #11
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null)
        {
            Diagnostics.LogError("Failed to retrieve the game service.");
            return(false);
        }
        this.game = (service.Game as global::Game);
        if (this.game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        if (!string.IsNullOrEmpty(this.TimerLocalizationKey))
        {
            int num = this.ComputeEleapsedTurn(questBehaviour);
            if (num != -1)
            {
                int num2 = this.TurnCountBeforeTimeOut;
                if (this.ScaleWithGameSpeed)
                {
                    num2 = Mathf.CeilToInt((float)this.TurnCountBeforeTimeOut * questBehaviour.Initiator.GetPropertyValue(SimulationProperties.GameSpeedMultiplier));
                }
                int num3 = num2 - num;
                if (num3 >= 0)
                {
                    QuestInstruction_UpdateLocalizationVariable questInstruction = new QuestInstruction_UpdateLocalizationVariable(this.TimerLocalizationKey, num3.ToString());
                    questBehaviour.Push(questInstruction);
                }
            }
        }
        return(true);
    }
 protected override State Execute(QuestBehaviour questBehaviour, EventDistrictLevelUp e, params object[] parameters)
 {
     Diagnostics.Assert(e.District != null);
     if (e.OldLevel >= this.Level || e.NewLevel < this.Level)
     {
         return(State.Running);
     }
     if (e.City == null)
     {
         if (!(this.CityGUID == GameEntityGUID.Zero))
         {
             return(State.Running);
         }
         return(State.Success);
     }
     else
     {
         this.AddDistrictToQuestVariable(questBehaviour, e);
         if (this.CityGUID != GameEntityGUID.Zero && this.CityGUID != e.City.GUID)
         {
             return(State.Running);
         }
         base.UpdateQuestVariable(questBehaviour, this.Output_CityVarName, e.City);
         if (!string.IsNullOrEmpty(this.Output_CityVarName) && base.CheckConditions(questBehaviour, e, parameters) == State.Success)
         {
             this.CityGUID = e.City.GUID;
         }
         return(State.Success);
     }
 }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        IGameService service = Services.GetService <IGameService>();

        if (service == null || service.Game == null)
        {
            Diagnostics.LogError("Failed to retrieve the game service.");
            return(false);
        }
        this.Game = (service.Game as global::Game);
        if (this.Game == null)
        {
            Diagnostics.LogError("Failed to cast gameService.Game to Game.");
            return(false);
        }
        if (this.ArmyGUID == 0UL)
        {
            ulong armyGUID;
            if (!string.IsNullOrEmpty(this.ArmyGUIDVarName) && questBehaviour.TryGetQuestVariableValueByName <ulong>(this.ArmyGUIDVarName, out armyGUID))
            {
                this.ArmyGUID = armyGUID;
            }
        }
        else
        {
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.ArmyGUIDVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.ArmyGUIDVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = this.ArmyGUID;
        }
        return(base.Initialize(questBehaviour));
    }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        string text;

        if (!string.IsNullOrEmpty(this.ResourceNameVarName) && string.IsNullOrEmpty(this.ResourceName) && questBehaviour.TryGetQuestVariableValueByName <string>(this.ResourceNameVarName, out text))
        {
            if (string.IsNullOrEmpty(text))
            {
                Diagnostics.LogError("Resource name is null or empty, quest variable (varname: '{0}')", new object[]
                {
                    this.ResourceNameVarName
                });
            }
            this.ResourceName = text;
        }
        QuestRegisterVariable questRegisterVariable;

        if (!string.IsNullOrEmpty(this.WantedAmountVarName) && this.WantedAmount == -1 && questBehaviour.TryGetQuestVariableValueByName <QuestRegisterVariable>(this.WantedAmountVarName, out questRegisterVariable))
        {
            if (questRegisterVariable == null)
            {
                Diagnostics.LogError("QuestRegisterVariable is null, quest variable (varname: '{0}')", new object[]
                {
                    this.WantedAmountVarName
                });
            }
            this.WantedAmount = questRegisterVariable.Value;
        }
        this.TryInitializingTargets(questBehaviour, false);
        return(base.Initialize(questBehaviour));
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        global::Empire empire2 = this.Game.Empires.FirstOrDefault((global::Empire empire) => empire.Bits == questBehaviour.Quest.EmpireBits);

        if (empire2 == null)
        {
            Diagnostics.LogError("Failed to retrieve the (lesser) quest empire.");
            return(State.Running);
        }
        ulong num;

        if (questBehaviour.TryGetQuestVariableValueByName <ulong>(this.ArmyGUIDVarName, out num) && num != 0UL)
        {
            IGameEntityRepositoryService service = this.Game.Services.GetService <IGameEntityRepositoryService>();
            IGameEntity gameEntity = null;
            if (!service.TryGetValue(num, out gameEntity))
            {
                Diagnostics.LogWarning("Action failed getting the targeted Army");
                return(State.Success);
            }
            Army army = gameEntity as Army;
            if (army == null)
            {
                Diagnostics.LogError("Action failed getting the targeted Army");
                return(State.Success);
            }
            OrderDestroyArmy orderDestroyArmy = new OrderDestroyArmy(army.Empire.Index, num);
            Diagnostics.Log("Posting order: {0}.", new object[]
            {
                orderDestroyArmy.ToString()
            });
            empire2.PlayerControllers.Server.PostOrder(orderDestroyArmy);
        }
        return(State.Success);
    }
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        if (this.gameEntityRepositoryService == null)
        {
            IGameService service = Services.GetService <IGameService>();
            if (service == null || service.Game == null)
            {
                Diagnostics.LogError("Failed to retrieve the game service.");
                return(false);
            }
            global::Game game = service.Game as global::Game;
            if (game == null)
            {
                Diagnostics.LogError("Failed to cast gameService.Game to Game.");
                return(false);
            }
            this.gameEntityRepositoryService = game.Services.GetService <IGameEntityRepositoryService>();
            if (this.gameEntityRepositoryService == null)
            {
                Diagnostics.LogError("Failed to retrieve the game entity repository service.");
                return(false);
            }
        }
        IGarrison garrison;

        if (this.StoredDestination != 0UL && !string.IsNullOrEmpty(this.Output_DestinationGUID) && this.gameEntityRepositoryService.TryGetValue <IGarrison>(this.StoredDestination, out garrison))
        {
            base.UpdateQuestVariable(questBehaviour, this.Output_DestinationGUID, garrison.GUID);
        }
        return(base.Initialize(questBehaviour));
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        global::Empire empire2 = this.Game.Empires.FirstOrDefault((global::Empire empire) => empire.Bits == questBehaviour.Quest.EmpireBits);

        if (empire2 == null)
        {
            Diagnostics.LogError("Failed to retrieve the (lesser) quest empire.");
            return(State.Running);
        }
        IEnumerator gameEntities = this.Game.Services.GetService <IGameEntityRepositoryService>().GameEntities;

        while (gameEntities.MoveNext())
        {
            object obj  = gameEntities.Current;
            Army   army = (obj as IGameEntity) as Army;
            if (army != null && army.HasTag(this.ArmyTag))
            {
                OrderDestroyArmy orderDestroyArmy = new OrderDestroyArmy(army.Empire.Index, army.GUID);
                Diagnostics.Log("Posting order: {0}.", new object[]
                {
                    orderDestroyArmy.ToString()
                });
                empire2.PlayerControllers.Server.PostOrder(orderDestroyArmy);
            }
        }
        return(State.Success);
    }
    protected override State Execute(QuestBehaviour questBehaviour, params object[] parameters)
    {
        this.ComputeObjective(questBehaviour);
        if (!this.Objective.IsValid)
        {
            Diagnostics.LogWarning("[UpdateArmyObjective]  Execute: Invalid objective : {0}", new object[]
            {
                this.Objective.ToString()
            });
            this.PrintVariables(questBehaviour);
        }
        else
        {
            Diagnostics.Log("[UpdateArmyObjective] Execute: Valid objective : {0}", new object[]
            {
                this.Objective.ToString()
            });
        }
        this.ComputeArmyGUID(questBehaviour);
        if (this.ArmyGUID == GameEntityGUID.Zero)
        {
            Diagnostics.LogWarning("[UpdateArmyObjective] Execute: Invalid army GUID");
            Diagnostics.LogWarning("[UpdateArmyObjective] Execute: ArmyGUIDVarName={0}, GUID found: {1}", new object[]
            {
                this.ArmyGUIDVarName,
                this.ArmyGUID
            });
        }
        OrderUpdateArmyObjective order = new OrderUpdateArmyObjective(this.LesserEmpire.Index, this.ArmyGUID, this.Objective);

        this.LesserEmpire.PlayerControllers.Server.PostOrder(order);
        return(State.Success);
    }
    protected override State Execute(QuestBehaviour questBehaviour, EventTerraformDeviceEntityCreated e, params object[] parameters)
    {
        global::Game game = Services.GetService <IGameService>().Game as global::Game;

        if (this.DevicePositionVarName == string.Empty)
        {
            return(State.Success);
        }
        IEnumerable <WorldPosition> source;

        if (this.DevicePositionVarName != null && questBehaviour.TryGetQuestVariableValueByName <WorldPosition>(this.DevicePositionVarName, out source))
        {
            this.DevicePositions = source.ToArray <WorldPosition>();
        }
        if (this.DevicePositions != null && this.DevicePositions[0] == e.TerraformDevice.WorldPosition)
        {
            IQuestManagementService service = game.Services.GetService <IQuestManagementService>();
            if (service != null)
            {
                this.EntityGUID = e.TerraformDevice.GUID;
                QuestVariable questVariable = new QuestVariable(this.Output_EntityVarName, e.TerraformDevice);
                service.State.AddGlobalVariable(questBehaviour.Initiator.Index, questVariable);
            }
            return(State.Success);
        }
        return(State.Running);
    }
Example #20
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        Diagnostics.Log("UpdateVariable.Initialize");
        global::Game game = Services.GetService <IGameService>().Game as global::Game;

        if (game == null)
        {
            Diagnostics.LogError("Cannot retrieve game service, Action_uptateVariable");
        }
        if (this.EmpireIndex != -1)
        {
            QuestVariable questVariable = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.EmpireVarName);
            if (questVariable == null)
            {
                questVariable = new QuestVariable(this.EmpireVarName);
                questBehaviour.QuestVariables.Add(questVariable);
            }
            questVariable.Object = game.Empires[this.EmpireIndex];
        }
        MajorEmpire majorEmpire;

        if (this.EmpireIndex == -1 && this.EmpireVarName != string.Empty && questBehaviour.TryGetQuestVariableValueByName <MajorEmpire>(this.EmpireVarName, out majorEmpire))
        {
            this.EmpireIndex = majorEmpire.Index;
        }
        return(true);
    }
 protected void AddDistrictToQuestVariable(QuestBehaviour questBehaviour, EventDistrictLevelUp e)
 {
     if (e.District != null)
     {
         base.UpdateQuestVariable(questBehaviour, this.Output_DistrictSimObjectVarName, e.District);
         this.DistrictGUID = e.District.GUID;
     }
 }
Example #22
0
    protected override bool Initialize(QuestBehaviour questBehaviour)
    {
        if (string.IsNullOrEmpty(this.ConstructionName))
        {
            if (string.IsNullOrEmpty(this.ConstructionNameVarName))
            {
                Diagnostics.LogError("Missing attribute 'ConstructionNameVarName'");
                return(false);
            }
            string text;
            if (!questBehaviour.TryGetQuestVariableValueByName <string>(this.ConstructionNameVarName, out text))
            {
                Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[]
                {
                    this.ConstructionNameVarName
                });
                return(false);
            }
            if (string.IsNullOrEmpty(text))
            {
                Diagnostics.LogError("Construction name is null or empty (varname: '{0}')", new object[]
                {
                    this.ConstructionNameVarName
                });
                return(false);
            }
            this.ConstructionName = text;
        }
        if (this.CityGUID != GameEntityGUID.Zero && !string.IsNullOrEmpty(this.Output_CityVarName) && !questBehaviour.QuestVariables.Exists((QuestVariable match) => match.Name == this.Output_CityVarName))
        {
            IGameService service = Services.GetService <IGameService>();
            if (service == null)
            {
                Diagnostics.LogError("Unable to retrieve the game service.");
                return(false);
            }
            IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
            if (service2 == null)
            {
                Diagnostics.LogError("Unable to retrieve the game entity repository service.");
                return(false);
            }
            City @object;
            if (service2.TryGetValue <City>(this.CityGUID, out @object))
            {
                QuestVariable questVariable = new QuestVariable(this.Output_CityVarName);
                questVariable.Object = @object;
                questBehaviour.QuestVariables.Add(questVariable);
            }
        }
        City city = null;

        if (this.CityGUID == GameEntityGUID.Zero && !string.IsNullOrEmpty(this.TargetCityVarName) && questBehaviour.TryGetQuestVariableValueByName <City>(this.TargetCityVarName, out city))
        {
            this.CityGUID = city.GUID;
        }
        return(base.Initialize(questBehaviour));
    }
    private bool TryResolveTarget(QuestBehaviour questBehaviour)
    {
        if (this.TargetEntityGUID != 0UL)
        {
            return(true);
        }
        QuestVariable questVariableByName = questBehaviour.GetQuestVariableByName(this.TargetEntityVarName);

        if (questVariableByName == null)
        {
            Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        if (questVariableByName.Object == null)
        {
            Diagnostics.LogError("Quest variable object is null (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        try
        {
            IGameEntity gameEntity;
            if (questVariableByName.Object is IEnumerable <object> )
            {
                gameEntity = ((questVariableByName.Object as IEnumerable <object>).ElementAt(0) as IGameEntity);
            }
            else
            {
                gameEntity = (questVariableByName.Object as IGameEntity);
            }
            if (gameEntity == null)
            {
                Diagnostics.LogWarning("Quest variable object is not a game entity (varname: '{0}')", new object[]
                {
                    this.TargetEntityVarName
                });
            }
            else
            {
                this.TargetEntityGUID = gameEntity.GUID;
            }
        }
        catch
        {
            Diagnostics.LogError("Quest variable object is not a game entity (varname: '{0}')", new object[]
            {
                this.TargetEntityVarName
            });
            return(false);
        }
        return(true);
    }
Example #24
0
 public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
 {
     if (this.RegionIndex != -1)
     {
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         global::Game game = service.Game as global::Game;
         if (game == null)
         {
             return(State.Failure);
         }
         IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
         global::Empire            empire;
         if (gameEvent != null)
         {
             empire = (gameEvent.Empire as global::Empire);
         }
         else
         {
             empire = questBehaviour.Initiator;
         }
         DepartmentOfForeignAffairs agency = empire.GetAgency <DepartmentOfForeignAffairs>();
         Diagnostics.Assert(agency != null);
         for (int i = 0; i < game.Empires.Length; i++)
         {
             if (i != empire.Index && (this.IgnoredEmpiresIndex == null || !this.IgnoredEmpiresIndex.Contains(i)))
             {
                 global::Empire empire2 = game.Empires[i];
                 bool           flag;
                 if (empire2 is MajorEmpire)
                 {
                     DiplomaticRelation diplomaticRelation = agency.GetDiplomaticRelation(empire2);
                     Diagnostics.Assert(diplomaticRelation != null);
                     Diagnostics.Assert(diplomaticRelation.State != null);
                     flag = (diplomaticRelation.State.Name == DiplomaticRelationState.Names.ColdWar || diplomaticRelation.State.Name == DiplomaticRelationState.Names.War || diplomaticRelation.State.Name == DiplomaticRelationState.Names.Unknown);
                 }
                 else
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     DepartmentOfDefense agency2 = empire2.GetAgency <DepartmentOfDefense>();
                     for (int j = 0; j < agency2.Armies.Count; j++)
                     {
                         if ((this.IncludeNaval || !agency2.Armies[j].IsNaval) && (int)service2.GetRegionIndex(agency2.Armies[j].WorldPosition) == this.RegionIndex)
                         {
                             return(State.Success);
                         }
                     }
                 }
             }
         }
     }
     return(State.Failure);
 }
 protected override bool Initialize(QuestBehaviour questBehaviour)
 {
     if (string.IsNullOrEmpty(this.Output_NumberOfTilesVarName))
     {
         Diagnostics.LogError("Failed to specify tile counter variable name");
     }
     this.NumberOfTiles = (int)questBehaviour.Initiator.GetPropertyValue(SimulationProperties.TilesTerraformed);
     base.UpdateQuestVariable(questBehaviour, this.Output_NumberOfTilesVarName, this.NumberOfTiles);
     return(base.Initialize(questBehaviour));
 }
 protected override bool Initialize(QuestBehaviour questBehaviour)
 {
     if (string.IsNullOrEmpty(this.Output_RegionTerraformedVarName))
     {
         Diagnostics.LogError("Failed to specify tile counter variable name");
     }
     this.RegionTerraformed = false;
     base.UpdateQuestVariable(questBehaviour, this.Output_RegionTerraformedVarName, this.RegionTerraformed);
     return(base.Initialize(questBehaviour));
 }
Example #27
0
 public bool Initialize(QuestBehaviour questBehaviour)
 {
     if (string.IsNullOrEmpty(base.XmlSerializableTarget))
     {
         Diagnostics.LogError("QuestBehaviourPrerequisites: some prerequisite have a null or empty target.");
         return(false);
     }
     this.targetSimulationObjectWrapper = this.GetTargetSimulationObjectWrapper(questBehaviour);
     return(true);
 }
Example #28
0
    public override State Execute(BehaviourTree behaviourTree, params object[] parameters)
    {
        QuestBehaviour questBehaviour = behaviourTree as QuestBehaviour;

        if (questBehaviour != null)
        {
            if (parameters == null)
            {
                return(State.Running);
            }
            if (parameters.Length == 0)
            {
                return(State.Running);
            }
            T t = parameters[0] as T;
            if (t != null)
            {
                GameEvent gameEvent = t as GameEvent;
                if (gameEvent != null && !this.CheckAgainstQuestInitiatorFilter(questBehaviour, gameEvent, this.QuestInitiatorFilter))
                {
                    return(State.Running);
                }
                if (this.questRepositoryService == null || this.questManagementService == null)
                {
                    IGameService service = Services.GetService <IGameService>();
                    Diagnostics.Assert(service != null && service.Game != null);
                    this.questManagementService = service.Game.Services.GetService <IQuestManagementService>();
                    Diagnostics.Assert(this.questManagementService != null);
                    this.questRepositoryService = service.Game.Services.GetService <IQuestRepositoryService>();
                    Diagnostics.Assert(this.questRepositoryService != null);
                }
                State state = this.Execute(questBehaviour, t, new object[0]);
                if (state == State.Success)
                {
                    state = this.CheckConditions(questBehaviour, gameEvent, parameters);
                    if (state == State.Success)
                    {
                        this.IncrementProgression(questBehaviour, t as GameEvent);
                        if (!string.IsNullOrEmpty(this.PrerequisiteVerifiedMessage) && gameEvent.Empire.Index == questBehaviour.Initiator.Index)
                        {
                            QuestInstruction_ShowMessagePanel questInstruction = new QuestInstruction_ShowMessagePanel(this.PrerequisiteVerifiedMessage);
                            questBehaviour.Push(questInstruction);
                        }
                    }
                    else if (!string.IsNullOrEmpty(this.PrerequisiteNotVerifiedMessage) && gameEvent.Empire.Index == questBehaviour.Initiator.Index)
                    {
                        QuestInstruction_ShowMessagePanel questInstruction2 = new QuestInstruction_ShowMessagePanel(this.PrerequisiteNotVerifiedMessage);
                        questBehaviour.Push(questInstruction2);
                    }
                }
                return(state);
            }
        }
        return(State.Running);
    }
 protected void AddPositionToForbiddenSpawnPosition(QuestBehaviour questBehaviour, WorldPosition position)
 {
     if (!string.IsNullOrEmpty(this.ForbiddenSpawnLocationVarName))
     {
         List <WorldPosition> list = questBehaviour.QuestVariables.FirstOrDefault((QuestVariable match) => match.Name == this.ForbiddenSpawnLocationVarName).Object as List <WorldPosition>;
         if (!list.Contains(position))
         {
             list.Add(position);
         }
     }
 }
Example #30
0
 public override State CheckCondition(QuestBehaviour questBehaviour, GameEvent gameEvent, params object[] parameters)
 {
     this.Initialize(questBehaviour);
     if (this.RegionIndex != -1)
     {
         IGameService service = Services.GetService <IGameService>();
         Diagnostics.Assert(service != null);
         if (service.Game as global::Game == null)
         {
             return(State.Failure);
         }
         IWorldPositionningService service2 = service.Game.Services.GetService <IWorldPositionningService>();
         global::Empire            empire;
         if (gameEvent != null)
         {
             empire = (gameEvent.Empire as global::Empire);
         }
         else
         {
             empire = questBehaviour.Initiator;
         }
         DepartmentOfDefense agency = empire.GetAgency <DepartmentOfDefense>();
         if (this.CheckAllArmies)
         {
             for (int i = 0; i < agency.Armies.Count; i++)
             {
                 if ((int)service2.GetRegionIndex(agency.Armies[i].WorldPosition) == this.RegionIndex)
                 {
                     return(State.Success);
                 }
             }
         }
         else
         {
             Army army = agency.GetArmy(this.ArmyGuid);
             if (army == null)
             {
                 return(State.Failure);
             }
             Region region = service2.GetRegion(army.WorldPosition);
             if (region == null)
             {
                 return(State.Failure);
             }
             if (this.RegionIndex == region.Index)
             {
                 return(State.Success);
             }
         }
     }
     return(State.Failure);
 }