/// <summary>
        /// Executes the strategy logic in charge of regenerating GP after the gather.
        /// </summary>
        /// <returns></returns>
        public async Task <GpRegenStrategyResult> RegenerateGp(GatheringPointObject node, IGatheringRotation gatherRotation, GatherStrategy gatherStrategy, CordialTime cordialTime, CordialType cordialType)
        {
            var rtn = new GpRegenStrategyResult()
            {
                StrategyState        = GpRegenStrategyResult.GpRegenStrategyResultState.OK,
                EffectiveCordialType = cordialType,
                OriginalCordialType  = cordialType,
            };

            var useCordial = cordialTime.HasFlag(CordialTime.AfterGather) &&
                             this.cordialStock.HasStock() &&
                             this.cordialStock.GetCordialCooldown() == TimeSpan.Zero;

            var currentGp = ExProfileBehavior.Me.CurrentGP;
            var maxGp     = ExProfileBehavior.Me.MaxGP;
            var missingGp = maxGp - currentGp;
            var cordial   = this.cordialStock.GetBestCordial(missingGp, cordialType);

            // Return OK if there is no cordial to use
            if (cordial == null)
            {
                rtn.UseState = InventoryItem.UseResult.OK;
                return(rtn);
            }

            // Use the cordial
            rtn.UseState = await cordial.Use(
                ExProfileBehavior.Me
                );

            // Log the result
            this.LogCordialResult(
                rtn.UseState ?? InventoryItem.UseResult.CantUse,
                cordial,
                currentGp
                );

            return(rtn);
        }
Exemple #2
0
        /// <summary>
        /// Executes the strategy logic in charge of regenerating GP before the gather.
        /// </summary>
        /// <returns></returns>
        public async Task <GpRegenStrategyResult> RegenerateGp(GatheringPointObject node, IGatheringRotation gatherRotation, GatherStrategy gatherStrategy, CordialTime cordialTime, CordialType cordialType)
        {
            var rtn = new GpRegenStrategyResult()
            {
                EffectiveCordialType = this.effectiveCordialType,
                OriginalCordialType  = this.requestedCordialType,
            };

            // Return OK immediately if there is no node
            if (node == null)
            {
                this.logger.GatheringNodeIsGone();

                rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.NodeGone;
                return(rtn);
            }

            // Configure the strategy and report to the log
            this.Configure(node, gatherRotation, gatherStrategy, cordialTime, cordialType);
            this.logger.LogReport(this);

            // Return not enough time if player has less than 3 seconds to gather
            if (this.EffectiveTimeTillGather.TotalSeconds < 3)
            {
                this.logger.GatheringNotEnoughTime();

                rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.NotEnoughTime;
                return(rtn);
            }

            if (this.gatherStrategy == GatherStrategy.GatherOrCollect)
            {
                // Return not enough GP if we cannot meet the target breakpoint for the rotation
                if (this.BreakpointGp > this.TargetGp)
                {
                    this.logger.RegeneratingNotEnoughGp();

                    rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.NotEnoughGp;
                    return(rtn);
                }
            }

            // Use the cordial if one was selected
            if (this.Cordial != null)
            {
                rtn.UseState = await this.Cordial.Use(
                    ExProfileBehavior.Me,
                    maxTimeout : this.EffectiveTimeTillGather,
                    dismount : true
                    );

                this.LogCordialResult(rtn.UseState.Value);

                // Recalculate player's ability to gather after cordial use failure
                if (rtn.UseState != InventoryItem.UseResult.OK)
                {
                    this.effectiveCordialType = CordialType.None;
                    this.CalculateTargetAndCordialSelection();

                    this.logger.LogReport(this);

                    // Return not enough GP if we cannot meet the target breakpoint for the rotation
                    if (this.BreakpointGp > this.TargetGp)
                    {
                        this.logger.RegeneratingNotEnoughGp();

                        rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.NotEnoughGp;
                        return(rtn);
                    }
                }
            }

            // Handle TouchAndGo overrides
            if (this.gatherStrategy == GatherStrategy.TouchAndGo)
            {
                // Do nothing if this is not ephemeral
                if (!node.IsEphemeral())
                {
                    this.logger.GatheringNodeSkippedNotEphemeral();

                    rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.OK;
                    return(rtn);
                }

                if (this.EffectiveTimeToRegenerate.TotalSeconds > MAX_TOUCHANDGO_WAIT)
                {
                    this.logger.RegeneratingSkippedExceedsEphemeralMaxWait(
                        this.EffectiveTimeToRegenerate.TotalSeconds,
                        MAX_TOUCHANDGO_WAIT
                        );

                    rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.OK;
                    return(rtn);
                }
            }

            // Return OK immediately if the rotation forcefully gathers the item
            if (gatherRotation.ShouldForceGather(node))
            {
                rtn.StrategyState = GpRegenStrategyResult.GpRegenStrategyResultState.OK;
                return(rtn);
            }

            // Execute wait logic
            rtn.StrategyState = await this.WaitForGpRegeneration();

            return(rtn);
        }