protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (!this.downloadableContentService.IsShared(DownloadableContent13.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
        if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!(army.Empire is MajorEmpire))
        {
            return(State.Failure);
        }
        MantaZone mantaZone = null;

        if (!string.IsNullOrEmpty(this.MantaZoneVarName) && aiBehaviorTree.Variables.ContainsKey(this.MantaZoneVarName))
        {
            mantaZone = (aiBehaviorTree.Variables[this.MantaZoneVarName] as MantaZone);
        }
        if (mantaZone == null)
        {
            return(State.Failure);
        }
        float num = 0f;
        IWorldPositionable worldPositionable = null;

        this.GoThrought <OrbSpawnInfo>(mantaZone.Orbs, army, new Func <OrbSpawnInfo, Army, float>(this.ComputeOrbCollectingScore), ref num, ref worldPositionable);
        this.GoThrought <PointOfInterest>(mantaZone.Ruins, army, new Func <PointOfInterest, Army, float>(this.ComputeRuinScore), ref num, ref worldPositionable);
        this.GoThrought <PointOfInterest>(mantaZone.Resources, army, new Func <PointOfInterest, Army, float>(this.ComputeResourceScore), ref num, ref worldPositionable);
        if (worldPositionable != null)
        {
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = worldPositionable;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, worldPositionable);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
Esempio n. 2
0
    protected virtual void Running()
    {
        AIData_Army aidata = this.aiDataRepository.GetAIData <AIData_Army>(this.AIDataArmyGUID);

        if (aidata == null || aidata.ArmyMission == null)
        {
            this.Completion = AICommanderMission.AICommanderMissionCompletion.Fail;
            return;
        }
        switch (aidata.ArmyMission.Completion)
        {
        case AIArmyMission.AIArmyMissionCompletion.Fail:
        {
            AIArmyMission.AIArmyMissionErrorCode errorCode = aidata.ArmyMission.ErrorCode;
            aidata.ArmyMission.Reset();
            TickableState tickableState = TickableState.NoTick;
            this.Completion = this.GetCompletionFor(errorCode, out tickableState);
            this.State      = tickableState;
            return;
        }

        case AIArmyMission.AIArmyMissionCompletion.Running:
            aidata.ArmyMission.Tick();
            return;

        case AIArmyMission.AIArmyMissionCompletion.Success:
        {
            aidata.ArmyMission.Reset();
            TickableState tickableState2 = TickableState.NoTick;
            this.Completion = this.GetCompletionWhenSuccess(aidata, out tickableState2);
            this.State      = tickableState2;
            return;
        }

        default:
            return;
        }
    }
Esempio n. 3
0
 protected override AICommanderMission.AICommanderMissionCompletion GetCompletionFor(AIArmyMission.AIArmyMissionErrorCode errorCode, out TickableState tickableState)
 {
     return(base.GetCompletionFor(errorCode, out tickableState));
 }
    protected override State Execute(AIBehaviorTree aiBehaviorTree, params object[] parameters)
    {
        if (!this.downloadableContentService.IsShared(DownloadableContent20.ReadOnlyName))
        {
            return(State.Failure);
        }
        Army army;

        AIArmyMission.AIArmyMissionErrorCode armyUnlessLocked = base.GetArmyUnlessLocked(aiBehaviorTree, "$Army", out army);
        if (armyUnlessLocked != AIArmyMission.AIArmyMissionErrorCode.None)
        {
            return(State.Failure);
        }
        if (!aiBehaviorTree.Variables.ContainsKey(this.TargetListVarName))
        {
            return(State.Failure);
        }
        if (!string.IsNullOrEmpty(this.OpportunityMaximumTurnName) && aiBehaviorTree.Variables.ContainsKey(this.OpportunityMaximumTurnName))
        {
            this.OpportunityMaximumTurn = (float)aiBehaviorTree.Variables[this.OpportunityMaximumTurnName];
        }
        List <IWorldPositionable> list = aiBehaviorTree.Variables[this.TargetListVarName] as List <IWorldPositionable>;

        if (list == null)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        if (list.Count == 0)
        {
            aiBehaviorTree.ErrorCode = 10;
            return(State.Failure);
        }
        AIEntity_Empire entity          = aiBehaviorTree.AICommander.AIPlayer.GetEntity <AIEntity_Empire>();
        float           num             = 0.1f;
        float           propertyValue   = army.GetPropertyValue(SimulationProperties.MaximumMovement);
        PointOfInterest pointOfInterest = null;

        for (int i = 0; i < list.Count; i++)
        {
            PointOfInterest pointOfInterest2 = list[i] as PointOfInterest;
            if (pointOfInterest2 != null)
            {
                if (pointOfInterest2.CreepingNodeImprovement != null)
                {
                    CreepingNode creepingNode = null;
                    IGameEntity  gameEntity   = null;
                    if (this.gameEntityRepositoryService.TryGetValue(pointOfInterest2.CreepingNodeGUID, out gameEntity))
                    {
                        creepingNode = (gameEntity as CreepingNode);
                    }
                    if (creepingNode != null)
                    {
                        if (DepartmentOfDefense.CanDismantleCreepingNode(army, creepingNode, false))
                        {
                            float num2 = 0.5f;
                            if (entity != null)
                            {
                                num2 = this.ComputeDestroyInterest(creepingNode, entity, army) * 0.5f;
                            }
                            if (num2 >= 0f)
                            {
                                float num3 = (float)this.worldPositionningService.GetDistance(army.WorldPosition, pointOfInterest2.WorldPosition);
                                float num4 = num3 / propertyValue;
                                if (num4 <= this.MaximumTurnDistance)
                                {
                                    float num5 = 0.5f - num4 / this.MaximumTurnDistance;
                                    num2 = AILayer.Boost(num2, num5 * 0.5f);
                                    float life    = creepingNode.Life;
                                    float maxLife = creepingNode.MaxLife;
                                    num2 = AILayer.Boost(num2, (1f - life / maxLife) * 0.2f);
                                    if (num2 > num)
                                    {
                                        num             = num2;
                                        pointOfInterest = pointOfInterest2;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (pointOfInterest != null)
        {
            if (this.OpportunityMaximumTurn > 0f)
            {
                int num6 = 0;
                int num7 = 0;
                if (aiBehaviorTree.Variables.ContainsKey(this.OpportunityMainTargetPosition))
                {
                    WorldPosition mainTargetPosition = (WorldPosition)aiBehaviorTree.Variables[this.OpportunityMainTargetPosition];
                    if (!AIBehaviorTreeNode_Decorator_EvaluateOpportunity.IsDetourWorthCheckingFast(this.worldPositionningService, army, pointOfInterest.WorldPosition, mainTargetPosition, out num7, out num6))
                    {
                        return(State.Failure);
                    }
                }
            }
            if (aiBehaviorTree.Variables.ContainsKey(this.Output_TargetVarName))
            {
                aiBehaviorTree.Variables[this.Output_TargetVarName] = pointOfInterest;
            }
            else
            {
                aiBehaviorTree.Variables.Add(this.Output_TargetVarName, pointOfInterest);
            }
            return(State.Success);
        }
        return(State.Failure);
    }
Esempio n. 5
0
 protected override AICommanderMission.AICommanderMissionCompletion GetCompletionFor(AIArmyMission.AIArmyMissionErrorCode errorCode, out TickableState tickableState)
 {
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.NoTargetSelected && base.AIDataArmyGUID.IsValid && !this.IsMissionCompleted() && !this.IsRegionColonized())
     {
         tickableState = TickableState.Optional;
         return(AICommanderMission.AICommanderMissionCompletion.Running);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.InvalidDestination && this.PositionIndex + 1 < this.ListOfPosition.Length)
     {
         int positionIndex = this.PositionIndex;
         this.PositionIndex = positionIndex + 1;
         tickableState      = TickableState.NoTick;
         return(AICommanderMission.AICommanderMissionCompletion.Running);
     }
     return(base.GetCompletionFor(errorCode, out tickableState));
 }
Esempio n. 6
0
 protected virtual AICommanderMission.AICommanderMissionCompletion GetCompletionFor(AIArmyMission.AIArmyMissionErrorCode errorCode, out TickableState tickableState)
 {
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.MoveInProgress)
     {
         tickableState = TickableState.NeedTick;
         return(AICommanderMission.AICommanderMissionCompletion.Running);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.NoTargetSelected)
     {
         tickableState = TickableState.Optional;
         return(AICommanderMission.AICommanderMissionCompletion.Success);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.DestinationNotReached || errorCode == AIArmyMission.AIArmyMissionErrorCode.NoMovementPoint || errorCode == AIArmyMission.AIArmyMissionErrorCode.NoSavingPosition || errorCode == AIArmyMission.AIArmyMissionErrorCode.AllActionPointSpent)
     {
         tickableState = TickableState.NoTick;
         return(AICommanderMission.AICommanderMissionCompletion.Running);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.TargetBesieging)
     {
         tickableState = TickableState.NoTick;
         return(AICommanderMission.AICommanderMissionCompletion.Initializing);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.PathNotFound || errorCode == AIArmyMission.AIArmyMissionErrorCode.TargetLocked)
     {
         tickableState = TickableState.Optional;
         return(AICommanderMission.AICommanderMissionCompletion.Running);
     }
     if (errorCode == AIArmyMission.AIArmyMissionErrorCode.OrderGoToFail || errorCode == AIArmyMission.AIArmyMissionErrorCode.AlreadyInPosition || errorCode == AIArmyMission.AIArmyMissionErrorCode.NoTargetInRange || errorCode == AIArmyMission.AIArmyMissionErrorCode.SearchFail || errorCode == AIArmyMission.AIArmyMissionErrorCode.InvalidDestination)
     {
         tickableState = TickableState.Optional;
         return(AICommanderMission.AICommanderMissionCompletion.Initializing);
     }
     tickableState = TickableState.NoTick;
     return(AICommanderMission.AICommanderMissionCompletion.Fail);
 }