Exemple #1
0
        private async Task <MethodResult> IncubateEggs()
        {
            MethodResult <EggIncubator> incubatorResponse = GetIncubator();

            if (!incubatorResponse.Success)
            {
                return(new MethodResult());
            }

            PokemonData egg = Eggs.FirstOrDefault(x => String.IsNullOrEmpty(x.EggIncubatorId));

            if (egg == null)
            {
                return(new MethodResult
                {
                    Message = "No egg to incubate",
                    Success = true
                });
            }

            try
            {
                UseItemEggIncubatorResponse response = await _client.Inventory.UseItemEggIncubator(incubatorResponse.Data.Id, egg.Id);

                if (response.Result != UseItemEggIncubatorResponse.Types.Result.Success)
                {
                    LogCaller(new LoggerEventArgs(String.Format("Failed to incubate egg. Response: {0}", response.Result), LoggerTypes.Warning));

                    return(new MethodResult());
                }

                LogCaller(new LoggerEventArgs(String.Format("Incubating egg in {0}. Pokmeon Id: {1}", response.EggIncubator.ItemId.ToString().Replace("ItemIncubator", ""), response.EggIncubator.PokemonId), LoggerTypes.Incubate));

                return(new MethodResult
                {
                    Message = "Success",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("Incubate egg request failed", LoggerTypes.Exception, ex));

                return(new MethodResult
                {
                    Message = "Incubate egg request failed"
                });
            }
        }
        private async Task <MethodResult> IncubateEggs()
        {
            if (!UserSettings.IncubateEggs)
            {
                LogCaller(new LoggerEventArgs("Incubating disabled", LoggerTypes.Info));

                return(new MethodResult
                {
                    Message = "Incubate eggs disabled",
                    Success = true
                });
            }

            MethodResult <EggIncubator> incubatorResponse = GetIncubator();

            if (!incubatorResponse.Success)
            {
                return(new MethodResult
                {
                    Message = incubatorResponse.Message,
                    Success = true
                });
            }

            PokemonData egg = Eggs.FirstOrDefault(x => String.IsNullOrEmpty(x.EggIncubatorId));

            if (egg == null)
            {
                return(new MethodResult
                {
                    Message = "No egg to incubate",
                    Success = true
                });
            }

            try
            {
                var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
                {
                    RequestType    = RequestType.UseItemEggIncubator,
                    RequestMessage = new UseItemEggIncubatorMessage
                    {
                        ItemId    = incubatorResponse.Data.Id,
                        PokemonId = egg.Id
                    }.ToByteString()
                });

                UseItemEggIncubatorResponse useItemEggIncubatorResponse = null;

                useItemEggIncubatorResponse = UseItemEggIncubatorResponse.Parser.ParseFrom(response);
                LogCaller(new LoggerEventArgs(String.Format("Incubating egg in {0}. Pokmeon Id: {1}", useItemEggIncubatorResponse.EggIncubator.ItemId.ToString().Replace("ItemIncubator", ""), useItemEggIncubatorResponse.EggIncubator.PokemonId), LoggerTypes.Incubate));

                return(new MethodResult
                {
                    Message = "Success",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("UseItemEggIncubatorResponse parsing failed because response was empty", LoggerTypes.Exception, ex));

                return(new MethodResult());
            }
        }
 /// <summary>
 /// Provides a safe way to invoke the <see cref="UseItemEggIncubatorReceived" /> event.
 /// </summary>
 /// <param name="value"></param>
 public void RaiseUseItemEggIncubatorReceived(UseItemEggIncubatorResponse value) => UseItemEggIncubatorReceived?.Invoke(this, value);
Exemple #4
0
        private static async Task <List <IncubatorUsage> > HatchNewEgg(ISession session)
        {
            _logger.Debug("Hatching new egg?");

            PlayerStats playerStats = await session.Inventory.GetPlayerStats(refreshCache : true);

            //if (playerStats == null) return null; // can this ever be null?

            List <EggIncubator> incubators =
                (await session.Inventory.GetEggIncubators()).Where(incubator => incubator.UsesRemaining > 0 || incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited).ToList();

            _logger.Debug("Incubators :: Count {0}, Total Remaining Usages {1}", incubators.Count, incubators.Sum(incubator => incubator.UsesRemaining));

            List <PokemonData> unusedEggs =
                (await session.Inventory.GetEggs()).Where(egg => string.IsNullOrEmpty(egg.EggIncubatorId))
                .OrderBy(egg => egg.EggKmWalkedTarget - egg.EggKmWalkedStart)
                .ToList();

            List <IncubatorUsage> newRememberedIncubators = new List <IncubatorUsage>();

            foreach (EggIncubator incubator in incubators)
            {
                if (incubator.PokemonId == 0)
                {
                    // Unlimited incubators prefer short eggs, limited incubators prefer long eggs
                    // Special case: If only one incubator is available at all, it will prefer long eggs
                    PokemonData egg = incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && incubators.Count > 1
                        ? unusedEggs.FirstOrDefault()
                        : unusedEggs.LastOrDefault();

                    if (egg == null)
                    {
                        continue;
                    }

                    // Skip (save) limited incubators depending on user choice in config
                    if (!session.LogicSettings.UseLimitedEggIncubators &&
                        incubator.ItemId != ItemId.ItemIncubatorBasicUnlimited)
                    {
                        continue;
                    }

                    UseItemEggIncubatorResponse response = await session.Client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id);

                    unusedEggs.Remove(egg);

                    newRememberedIncubators.Add(new IncubatorUsage {
                        IncubatorId = incubator.Id, PokemonId = egg.Id
                    });

                    session.EventDispatcher.Send(new EggIncubatorStatusEvent
                    {
                        IncubatorId = incubator.Id,
                        WasAddedNow = true,
                        PokemonId   = egg.Id,
                        KmToWalk    = egg.EggKmWalkedTarget,
                        KmRemaining = response.EggIncubator.TargetKmWalked - playerStats.KmWalked
                    });
                }
                else
                {
                    newRememberedIncubators.Add(new IncubatorUsage
                    {
                        IncubatorId = incubator.Id,
                        PokemonId   = incubator.PokemonId
                    });

                    session.EventDispatcher.Send(new EggIncubatorStatusEvent
                    {
                        IncubatorId = incubator.Id,
                        PokemonId   = incubator.PokemonId,
                        KmToWalk    = incubator.TargetKmWalked - incubator.StartKmWalked,
                        KmRemaining = incubator.TargetKmWalked - playerStats.KmWalked
                    });
                }
            }

            return(newRememberedIncubators);
        }