Beispiel #1
0
	private IEnumerator GameServerState_Turn_Begin_Interact(string context, string pass)
	{
		IGameService gameService = Services.GetService<IGameService>();
		Diagnostics.Assert(gameService != null);
		Diagnostics.Assert(gameService.Game != null);
		global::Game game = gameService.Game as global::Game;
		if (game != null && game.Turn > this.TurnWhenLastBegun)
		{
			this.TurnWhenLastBegun = game.Turn;
			OrderInteractWith order = new OrderInteractWith(base.Index, GameEntityGUID.Zero, "BeginTurn");
			order.WorldPosition = WorldPosition.Invalid;
			order.Tags.AddTag("BeginTurn");
			if (global::GameManager.Preferences.QuestVerboseMode)
			{
				Diagnostics.Log("[Quest] Trying to trigger quests with event BeginTurn for empire {0}", new object[]
				{
					order.EmpireIndex
				});
			}
			IPlayerControllerRepositoryControl playerControllerRepositoryService = gameService.Game.Services.GetService<IPlayerControllerRepositoryService>() as IPlayerControllerRepositoryControl;
			playerControllerRepositoryService.GetPlayerControllerById("server").PostOrder(order);
		}
		yield return null;
		yield break;
	}
Beispiel #2
0
    public Amplitude.Unity.Game.Orders.Order Search(BaseNavyArmy army)
    {
        PointOfInterest pointOfInterest = this.worldPositionService.GetPointOfInterest(army.Garrison.WorldPosition);

        if (pointOfInterest != null && this.CouldSearch(army, pointOfInterest))
        {
            OrderInteractWith orderInteractWith = new OrderInteractWith(army.Garrison.Empire.Index, army.Garrison.GUID, FleetAction_Dive.ReadOnlyName);
            orderInteractWith.WorldPosition = army.Garrison.WorldPosition;
            orderInteractWith.Tags.AddTag("NavalInteract");
            orderInteractWith.TargetGUID     = pointOfInterest.GUID;
            orderInteractWith.ArmyActionName = FleetAction_Dive.ReadOnlyName;
            return(orderInteractWith);
        }
        return(null);
    }
    public override void Execute(Army army, global::PlayerController playerController, out Ticket ticket, EventHandler <TicketRaisedEventArgs> ticketRaisedEventHandler, params object[] parameters)
    {
        ticket = null;
        PointOfInterest pointOfInterest = null;

        if (parameters != null && parameters.Length != 0 && parameters[0] is PointOfInterest)
        {
            pointOfInterest = (parameters[0] as PointOfInterest);
        }
        ArmyAction.FailureFlags.Clear();
        if (pointOfInterest != null)
        {
            OrderInteractWith orderInteractWith = new OrderInteractWith(army.Empire.Index, army.GUID, this.Name);
            orderInteractWith.WorldPosition = army.WorldPosition;
            orderInteractWith.Tags.AddTag("Interact");
            orderInteractWith.TargetGUID     = pointOfInterest.GUID;
            orderInteractWith.ArmyActionName = this.Name;
            orderInteractWith.NumberOfActionPointsToSpend = base.GetCostInActionPoints();
            Diagnostics.Assert(playerController != null);
            playerController.PostOrder(orderInteractWith, out ticket, ticketRaisedEventHandler);
        }
    }
 protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
 {
     if (this.currentTicket != null)
     {
         if (!this.currentTicket.Raised)
         {
             return(State.Running);
         }
         bool flag = this.currentTicket.PostOrderResponse == PostOrderResponse.PreprocessHasFailed || this.currentTicket.PostOrderResponse == PostOrderResponse.AuthenticationHasFailed;
         this.currentTicket = null;
         if (flag)
         {
             aiBehaviorTree.ErrorCode = 1;
             return(State.Failure);
         }
         if (this.fastTravel)
         {
             Army army;
             if (this.CurrentPathCollection != null && base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) == AIArmyMission.AIArmyMissionErrorCode.None)
             {
                 PointOfInterest         pointOfInterest = this.worldPositionningService.GetPointOfInterest(this.CurrentPathCollection.ExitNode.WorldPosition);
                 IGameService            service         = Services.GetService <IGameService>();
                 IQuestManagementService service2        = service.Game.Services.GetService <IQuestManagementService>();
                 IQuestRepositoryService service3        = service.Game.Services.GetService <IQuestRepositoryService>();
                 if (pointOfInterest != null && ELCPUtilities.CanSearch(army.Empire, pointOfInterest, service2, service3) && this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest.WorldPosition) < 2 && this.pathfindingService.IsTransitionPassable(army.WorldPosition, pointOfInterest.WorldPosition, army, OrderAttack.AttackFlags, null))
                 {
                     OrderInteractWith orderInteractWith = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionSearch");
                     orderInteractWith.WorldPosition = army.WorldPosition;
                     orderInteractWith.Tags.AddTag("Interact");
                     orderInteractWith.TargetGUID = pointOfInterest.GUID;
                     army.Empire.PlayerControllers.AI.PostOrder(orderInteractWith);
                 }
             }
             this.fastTravel            = false;
             this.CurrentPathCollection = null;
         }
         return(State.Success);
     }
     else
     {
         Army army2;
         if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army2) != AIArmyMission.AIArmyMissionErrorCode.None)
         {
             return(State.Failure);
         }
         if (!aiBehaviorTree.Variables.ContainsKey(this.DestinationVarName))
         {
             aiBehaviorTree.LogError("{0} not set", new object[]
             {
                 this.DestinationVarName
             });
             return(State.Failure);
         }
         if (this.AllowFastTravel && !(army2 is KaijuArmy) && aiBehaviorTree.AICommander.Empire is MajorEmpire && aiBehaviorTree.AICommander.Empire.SimulationObject.Tags.Contains(FactionTrait.FactionTraitMimics1))
         {
             float propertyValue  = army2.GetPropertyValue(SimulationProperties.MaximumNumberOfActionPoints);
             float propertyValue2 = army2.GetPropertyValue(SimulationProperties.ActionPointsSpent);
             if (propertyValue > propertyValue2)
             {
                 return(this.MykaraExecute(aiBehaviorTree, army2));
             }
             if (this.CurrentPathCollection != null)
             {
                 this.CurrentPathCollection = null;
                 this.WorldPath             = null;
             }
         }
         if (army2.GetPropertyValue(SimulationProperties.Movement) < 0.001f)
         {
             aiBehaviorTree.ErrorCode = 24;
             return(State.Failure);
         }
         WorldPosition worldPosition = (WorldPosition)aiBehaviorTree.Variables[this.DestinationVarName];
         aiBehaviorTree.LastPathfindTargetPosition = worldPosition;
         if (!worldPosition.IsValid)
         {
             aiBehaviorTree.ErrorCode = 3;
             return(State.Failure);
         }
         if (this.WorldPath != null && this.WorldPath.Destination == worldPosition)
         {
             return(State.Success);
         }
         this.currentFlags = PathfindingFlags.IgnoreFogOfWar;
         if (!aiBehaviorTree.AICommander.MayUseFrozenTiles())
         {
             this.currentFlags |= PathfindingFlags.IgnoreFrozenWaters;
         }
         this.WorldPath = new WorldPath();
         if (army2.WorldPosition == worldPosition)
         {
             aiBehaviorTree.ErrorCode = 4;
             return(State.Failure);
         }
         int  distance = this.worldPositionningService.GetDistance(army2.WorldPosition, worldPosition);
         bool flag2    = this.pathfindingService.IsTransitionPassable(army2.WorldPosition, worldPosition, army2, (PathfindingFlags)0, null);
         if (distance == 1 && flag2 && !this.pathfindingService.IsTileStopable(worldPosition, army2, (PathfindingFlags)0, null))
         {
             aiBehaviorTree.ErrorCode = 4;
             return(State.Failure);
         }
         PathfindingContext pathfindingContext = army2.GenerateContext();
         pathfindingContext.Greedy = true;
         PathfindingResult pathfindingResult = this.pathfindingService.FindPath(pathfindingContext, army2.WorldPosition, worldPosition, PathfindingManager.RequestMode.Default, null, this.currentFlags, null);
         if (pathfindingResult == null && this.IgnoreArmies)
         {
             this.currentFlags |= PathfindingFlags.IgnoreArmies;
             pathfindingResult  = this.pathfindingService.FindPath(pathfindingContext, army2.WorldPosition, worldPosition, PathfindingManager.RequestMode.Default, null, this.currentFlags, null);
         }
         if (pathfindingResult == null)
         {
             aiBehaviorTree.ErrorCode = 3;
             if (ELCPUtilities.ELCPVerboseMode)
             {
                 Diagnostics.Log("ELCP {0}/{1} didnt find pathfindingResult to {2} with flags {3}", new object[]
                 {
                     army2.Empire,
                     army2.LocalizedName,
                     worldPosition,
                     this.currentFlags
                 });
             }
             return(State.Failure);
         }
         this.WorldPath.Build(pathfindingResult, army2.GetPropertyValue(SimulationProperties.MovementRatio), this.numberOfTurnForWorldPath, false);
         this.WorldPath = this.ComputeSafePathOpportunity(army2, worldPosition, this.WorldPath);
         if (!this.WorldPath.IsValid)
         {
             aiBehaviorTree.ErrorCode = 3;
             if (ELCPUtilities.ELCPVerboseMode)
             {
                 Diagnostics.Log("ELCP {0}/{1} worldpath invalid {2} with flags {3}", new object[]
                 {
                     army2.Empire,
                     army2.LocalizedName,
                     worldPosition,
                     this.currentFlags
                 });
             }
             return(State.Failure);
         }
         if (aiBehaviorTree.Variables.ContainsKey(this.Output_PathVarName))
         {
             aiBehaviorTree.Variables[this.Output_PathVarName] = this.WorldPath;
         }
         else
         {
             aiBehaviorTree.Variables.Add(this.Output_PathVarName, this.WorldPath);
         }
         return(State.Success);
     }
 }
Beispiel #5
0
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        Army army2;

        base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army2);
        IGameService service = Services.GetService <IGameService>();

        Diagnostics.Assert(service != null);
        IGameEntityRepositoryService service2 = service.Game.Services.GetService <IGameEntityRepositoryService>();
        State result;

        if (this.orderTicket != null)
        {
            if (!this.orderTicket.Raised)
            {
                result = State.Running;
            }
            else
            {
                OrderInteractWith orderInteractWith = this.orderTicket.Order as OrderInteractWith;
                IGameEntity       gameEntity        = null;
                if (this.orderTicket.PostOrderResponse != PostOrderResponse.Processed)
                {
                    if (service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity))
                    {
                        PointOfInterest pointOfInterest;
                        if (gameEntity is Village)
                        {
                            pointOfInterest = (gameEntity as Village).PointOfInterest;
                        }
                        else
                        {
                            pointOfInterest = (gameEntity as PointOfInterest);
                        }
                        if (pointOfInterest != null)
                        {
                            IQuestRepositoryService service3 = service.Game.Services.GetService <IQuestRepositoryService>();
                            foreach (QuestMarker questMarker in service.Game.Services.GetService <IQuestManagementService>().GetMarkersByBoundTargetGUID(pointOfInterest.GUID))
                            {
                                Quest quest;
                                if (service3.TryGetValue(questMarker.QuestGUID, out quest) && quest.QuestDefinition.Name == "GlobalQuestCoop#0004" && quest.EmpireBits == army2.Empire.Bits && questMarker.IsVisibleFor(army2.Empire))
                                {
                                    this.orderTicket = null;
                                    QuestBehaviour questBehaviour = service3.GetQuestBehaviour(quest.Name, army2.Empire.Index);
                                    if (questBehaviour != null)
                                    {
                                        if (quest.QuestDefinition.Variables.First((QuestVariableDefinition p) => p.VarName == "$NameOfStrategicResourceToGather1") != null)
                                        {
                                            QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount questBehaviourTreeNode_ConditionCheck_HasResourceAmount;
                                            if (!ELCPUtilities.TryGetFirstNodeOfType <QuestBehaviourTreeNode_ConditionCheck_HasResourceAmount>(questBehaviour.Root as BehaviourTreeNodeController, out questBehaviourTreeNode_ConditionCheck_HasResourceAmount))
                                            {
                                                break;
                                            }
                                            string resourceName            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.ResourceName;
                                            int    wantedAmount            = questBehaviourTreeNode_ConditionCheck_HasResourceAmount.WantedAmount;
                                            DepartmentOfTheTreasury agency = army2.Empire.GetAgency <DepartmentOfTheTreasury>();
                                            if (agency == null)
                                            {
                                                break;
                                            }
                                            float num;
                                            if (agency != null && agency.TryGetResourceStockValue(army2.Empire.SimulationObject, resourceName, out num, false) && num >= (float)wantedAmount)
                                            {
                                                return(State.Running);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            if ((pointOfInterest.Interaction.Bits & aiBehaviorTree.AICommander.Empire.Bits) != aiBehaviorTree.AICommander.Empire.Bits)
                            {
                                pointOfInterest.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                            }
                        }
                    }
                    aiBehaviorTree.ErrorCode = 30;
                    this.orderTicket         = null;
                    result = State.Failure;
                }
                else
                {
                    if (this.orderTicket.PostOrderResponse == PostOrderResponse.Processed && service2.TryGetValue(orderInteractWith.TargetGUID, out gameEntity) && gameEntity is PointOfInterest && orderInteractWith.Tags.Contains("Talk") && orderInteractWith.QuestRewards == null)
                    {
                        PointOfInterest pointOfInterest2 = gameEntity as PointOfInterest;
                        Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin parley order without quest reward: {1} ", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire.ToString(),
                            pointOfInterest2.WorldPosition
                        });
                        if (pointOfInterest2 != null)
                        {
                            pointOfInterest2.Interaction.Bits |= 1 << orderInteractWith.EmpireIndex;
                        }
                    }
                    this.orderTicket = null;
                    result           = State.Success;
                }
            }
        }
        else
        {
            Army army;
            if (base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army) > AIArmyMission.AIArmyMissionErrorCode.None)
            {
                result = State.Failure;
            }
            else
            {
                if (!aiBehaviorTree.Variables.ContainsKey(this.TargetVarName))
                {
                    aiBehaviorTree.LogError("${0} not set", new object[]
                    {
                        this.TargetVarName
                    });
                    return(State.Failure);
                }
                IGameEntity gameEntity2 = aiBehaviorTree.Variables[this.TargetVarName] as IGameEntity;
                if (!(gameEntity2 is IWorldPositionable) || (!(gameEntity2 is PointOfInterest) && !(gameEntity2 is Village)))
                {
                    aiBehaviorTree.ErrorCode = 10;
                    return(State.Failure);
                }
                if (gameEntity2 is Village)
                {
                    Village village = gameEntity2 as Village;
                    Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin village {2} {3}", new object[]
                    {
                        aiBehaviorTree.AICommander.Empire,
                        army.LocalizedName,
                        village.WorldPosition,
                        this.QuestVillage
                    });
                    PointOfInterest pointOfInterest3 = village.PointOfInterest;
                    if (pointOfInterest3 == null)
                    {
                        return(State.Failure);
                    }
                    if (!this.QuestVillage)
                    {
                        if (village.HasBeenConverted || village.HasBeenPacified || village.IsInEncounter || village.PointOfInterest.PointOfInterestImprovement == null)
                        {
                            return(State.Failure);
                        }
                        if (!aiBehaviorTree.AICommander.Empire.GetAgency <DepartmentOfScience>().CanParley())
                        {
                            return(State.Failure);
                        }
                        if (pointOfInterest3.SimulationObject.Tags.Contains(Village.DissentedVillage))
                        {
                            return(State.Failure);
                        }
                        if ((pointOfInterest3.Interaction.Bits & army.Empire.Bits) != 0)
                        {
                            Diagnostics.Log("fail");
                            return(State.Failure);
                        }
                        QuestMarker questMarker2;
                        if (service.Game.Services.GetService <IQuestManagementService>().TryGetMarkerByGUID(pointOfInterest3.GUID, out questMarker2))
                        {
                            Diagnostics.Log("ELCP: Empire {0} AIBehaviorTreeNode_Action_SearchInRuin Questmarker active", new object[]
                            {
                                aiBehaviorTree.AICommander.Empire.ToString()
                            });
                            return(State.Failure);
                        }
                    }
                }
                Diagnostics.Assert(AIScheduler.Services != null);
                if (service.Game.Services.GetService <IWorldPositionningService>().GetDistance(army.WorldPosition, (gameEntity2 as IWorldPositionable).WorldPosition) != 1)
                {
                    aiBehaviorTree.ErrorCode = 12;
                    result = State.Failure;
                }
                else
                {
                    IEncounterRepositoryService service4 = service.Game.Services.GetService <IEncounterRepositoryService>();
                    if (service4 != null)
                    {
                        IEnumerable <Encounter> enumerable = service4;
                        if (enumerable != null && enumerable.Any((Encounter encounter) => encounter.IsGarrisonInEncounter(army.GUID, false)))
                        {
                            return(State.Running);
                        }
                    }
                    if (gameEntity2 is Village)
                    {
                        Diagnostics.Log("ELCP {0} {1} AIBehaviorTreeNode_Action_SearchInRuin2 village", new object[]
                        {
                            aiBehaviorTree.AICommander.Empire,
                            army.LocalizedName
                        });
                        PointOfInterest   pointOfInterest4   = (gameEntity2 as Village).PointOfInterest;
                        OrderInteractWith orderInteractWith2 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionParley");
                        orderInteractWith2.WorldPosition = army.WorldPosition;
                        orderInteractWith2.Tags.AddTag("Talk");
                        orderInteractWith2.TargetGUID     = pointOfInterest4.GUID;
                        orderInteractWith2.ArmyActionName = "ArmyActionParley";
                        orderInteractWith2.NumberOfActionPointsToSpend = 0f;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith2, out this.orderTicket, null);
                    }
                    else
                    {
                        if (Amplitude.Unity.Framework.Application.Preferences.EnableModdingTools)
                        {
                            Diagnostics.Log("~~~~~ ELCP: {0}/{1} ArmyActionSearch at {2}, {3} {4} ~~~~~", new object[]
                            {
                                army.LocalizedName,
                                army.Empire,
                                (gameEntity2 as PointOfInterest).WorldPosition,
                                ((gameEntity2 as PointOfInterest).Interaction.Bits & army.Empire.Bits) == army.Empire.Bits,
                                (gameEntity2 as PointOfInterest).UntappedDustDeposits
                            });
                        }
                        OrderInteractWith orderInteractWith3 = new OrderInteractWith(army.Empire.Index, army.GUID, "ArmyActionSearch");
                        orderInteractWith3.WorldPosition = army.WorldPosition;
                        orderInteractWith3.Tags.AddTag("Interact");
                        orderInteractWith3.TargetGUID = gameEntity2.GUID;
                        aiBehaviorTree.AICommander.Empire.PlayerControllers.AI.PostOrder(orderInteractWith3, out this.orderTicket, null);
                    }
                    result = State.Running;
                }
            }
        }
        return(result);
    }