public async Task InitializeAsync(string search = "")
        {
            try
            {
                UserDialogs.Instance.Loading("Estamos carregando os filmes, aguarde um instante..", null, null, true, MaskType.Gradient);

                var guid      = Guid.NewGuid().ToString();
                var publickey = GetHash(guid + AppSettings.PrivateKey + AppSettings.PublicKey);
                var endpoint  = $"characters?apikey={AppSettings.PublicKey}&hash={publickey}&ts={guid}&limit=10&offset=1";
                var response  = await dataService.GetAsync <Character>(endpoint, "character", 100);

                var list = (List <Models.Result>)response.Result;
                if (list.Count > 0 && list != null)
                {
                    Heroes.AddRange(list);
                    foreach (var item in list)
                    {
                        heroes.Add(item);
                    }
                }
                else
                {
                    Heroes = new ObservableRangeCollection <Result>(heroes.OrderBy(p => p.Name));
                    Heroes.AddRange(Heroes);
                    Message = "NENHUM PERSONAGEM FOI CARREGADO";
                }
                UserDialogs.Instance.ShowLoading("Finalizando..", MaskType.Gradient);
                UserDialogs.Instance.HideLoading();
            }
            catch (Exception exception)
            {
                UserDialogs.Instance.ShowLoading("Finalizando..", MaskType.Gradient);
                UserDialogs.Instance.HideLoading();
                var properties = new Dictionary <string, string> {
                    { "CharacterViewModel.cs", "InitializeAsync" }
                };
                //Crashes.TrackError(exception, properties);

                Heroes = new ObservableRangeCollection <Result>();
                Heroes.AddRange(Heroes);
            }
        }
Exemple #2
0
    public void RestockHeroes(List <int> rosterIds, Estate estate)
    {
        var heroClasses = DarkestDungeonManager.Data.HeroClasses.Keys.ToList();

        Heroes.AddRange(EventHeroes);
        EventHeroes.Clear();
        GraveIndexes.Clear();
        #region Clear unrecruited heroes
        if (Heroes != null && Heroes.Count > 0)
        {
            for (int i = 0; i < Heroes.Count; i++)
            {
                if (rosterIds.Contains(Heroes[i].RosterId))
                {
                    Debug.LogError("Same id returned while restocking heroes.");
                }
                else
                {
                    rosterIds.Add(Heroes[i].RosterId);
                }

                estate.HeroPurchases.Remove(Heroes[i].RosterId);
            }
        }
        #endregion
        #region Create new recruits
        Heroes = new List <Hero>();
        if (DarkestDungeonManager.RaidManager.Quest != null && DarkestDungeonManager.RaidManager.Quest.Goal.Id == "tutorial_final_room")
        {
            for (int i = 0; i < firstHeroClasses.Length; i++)
            {
                int id      = rosterIds[Random.Range(0, rosterIds.Count)];
                var newHero = new Hero(id, firstHeroClasses[i],
                                       LocalizationManager.GetString("hero_name_" + Random.Range(0, 556).ToString()));
                Heroes.Add(newHero);
                rosterIds.Remove(id);
                GeneratePurchaseInfo(newHero, estate);
            }
        }
        else
        {
            for (int i = 0; i < RecruitSlots; i++)
            {
                RecruitUpgrade experienceUpgrade = null;

                if (CurrentRecruitMaxLevel > 0)
                {
                    for (int j = 0; j <= RecruitExperienceUpgrades.Count - 1; j++)
                    {
                        if (RecruitExperienceUpgrades[j].Level <= CurrentRecruitMaxLevel &&
                            RandomSolver.CheckSuccess(RecruitExperienceUpgrades[j].Chance))
                        {
                            experienceUpgrade = RecruitExperienceUpgrades[j];
                            break;
                        }
                    }
                }
                int    id        = rosterIds[Random.Range(0, rosterIds.Count)];
                string heroClass = heroClasses[Random.Range(0, DarkestDungeonManager.Data.HeroClasses.Count)];
                string heroName  = LocalizationManager.GetString("hero_name_" + Random.Range(0, 556).ToString());
                var    newHero   = experienceUpgrade == null ?
                                   new Hero(id, heroClass, heroName) :
                                   new Hero(id, heroClass, heroName, experienceUpgrade);
                Heroes.Add(newHero);
                rosterIds.Remove(id);
                GeneratePurchaseInfo(newHero, estate);
            }
        }
        #endregion
        #region Add recruits for minimum of one party
        int abominations = DarkestDungeonManager.Campaign.Heroes.FindAll(hero =>
                                                                         hero.Class == "abomination").Count + Heroes.FindAll(hero => hero.Class == "abomination").Count;
        int additionalHeroes = 4 - DarkestDungeonManager.Campaign.Heroes.Count - Heroes.Count + abominations;
        if (abominations > 3)
        {
            return;
        }
        for (int i = 0; i < additionalHeroes; i++)
        {
            RecruitUpgrade experienceUpgrade = null;

            if (CurrentRecruitMaxLevel > 0)
            {
                for (int j = 0; j <= RecruitExperienceUpgrades.Count - 1; j++)
                {
                    if (RecruitExperienceUpgrades[j].Level <= CurrentRecruitMaxLevel &&
                        RandomSolver.CheckSuccess(RecruitExperienceUpgrades[j].Chance))
                    {
                        experienceUpgrade = RecruitExperienceUpgrades[j];
                        break;
                    }
                }
            }
            int    id        = rosterIds[Random.Range(0, rosterIds.Count)];
            string heroClass = "abomination";
            while (heroClass == "abomination")
            {
                heroClass = heroClasses[Random.Range(0, DarkestDungeonManager.Data.HeroClasses.Count)];
            }

            string heroName = LocalizationManager.GetString("hero_name_" + Random.Range(0, 556).ToString());
            var    newHero  = experienceUpgrade == null ?
                              new Hero(id, heroClass, heroName) :
                              new Hero(id, heroClass, heroName, experienceUpgrade);
            Heroes.Add(newHero);
            rosterIds.Remove(id);
            GeneratePurchaseInfo(newHero, estate);
        }
        #endregion
    }