Example #1
0
        public bool CompleteQuest(HeroInstance[] heros)
        {
            //Check if the hero completed it or not
            int successRate = GetTotalSuccessRate(heros);

            int totalHeroes   = 0;
            int successHeroes = 0;

            for (int i = 0; i < heros.Length; i++)
            {
                HeroInstance hero = heros[i];
                if (hero == null)
                {
                    continue;
                }
                totalHeroes++;

                bool giveRewards = true;
                int  failChance  = UnityEngine.Random.Range(0, 101);
                if (failChance > successRate)
                {
                    failChance = UnityEngine.Random.Range(0, 101);
                    if (failChance < 100 - successRate + 20)
                    {
                        HeroManager.SetHeroToState(hero, HeroStates.DEAD);
                        giveRewards = false;
                    }
                    else
                    {
                        HeroManager.SetHeroToState(hero, HeroStates.WOUNDED);
                        hero.WoundedDays = ((100 - successRate) / 10) + 4;
                        successHeroes++;
                    }
                }
                else
                {
                    successHeroes++;
                }

                if (giveRewards)
                {
                    if (ItemRewards[i] != null)
                    {
                        ItemRewards[i].ApplyReward(hero);
                    }
                    if (AdditionalReward != null && i == 0)
                    {
                        AdditionalReward.ApplyReward(hero);
                    }

                    hero.Experience += ExperiencePoints;
                    QuestSourceFaction faction = HeroManager.GetHeroFaction(hero);
                    ReputationManager.GetReputationTracker(faction).ModifyReputation(ExperiencePoints * 0.1f);
                }

                HeroManager.SetHeroToState(hero, HeroStates.IDLE);
            }

            if (successHeroes == 0)
            {
                RefundQuestRewards(true, true);
                return(false);
            }
            else
            {
                if (HandlerItemReward != null)
                {
                    InventoryManager.OwnedItems.Add(HandlerItemReward.Item);
                }
                InventoryManager.Gold  += Mathf.RoundToInt(HandlerAverageExpectedGoldReward * UnityEngine.Random.Range(HANDLER_GOLD_VARIANCE_MIN, HANDLER_GOLD_VARIANCE_MAX));
                InventoryManager.Stars += DifficultyLevel;
                return(true);
            }
        }