Exemplo n.º 1
0
        public void TestSolutionOpen()
        {
            RandomGeneratorExtensions.GetGetNewRandom = () => new RandomGenerator(4541247);

            // create problem.
            var problem = STSPHelper.CreateDirectedSTSP(0, 5, 10, 1, 40);

            // create the solver.
            var solver    = new RandomSolver();
            var objective = new STSPObjective();

            for (var i = 0; i < 100; i++)
            {
                // generate solution.
                STSPFitness fitness;

                var solution = solver.Solve(problem, objective, out fitness);

                // test contents.
                Assert.AreEqual(problem.First, solution.First);
                Assert.AreEqual(problem.Last, solution.Last);
                Assert.AreEqual(solution.Count, fitness.Customers);
                Assert.IsTrue(40 >= fitness.Weight);
            }
        }
Exemplo n.º 2
0
    private void InitializeCampingSkills(int bonusSkills = 0)
    {
        CurrentCampingSkills = new CampingSkill[HeroClass.CampingSkills.Count];

        var availableGeneralSkills = HeroClass.CampingSkills.FindAll(skill => skill.Classes.Count > 4);
        int generalSkillsRequired  = HeroClass.Generation.NumberOfSharedCampingSkills;

        foreach (var skill in availableGeneralSkills.OrderBy(x => RandomSolver.NextDouble())
                 .Take(Mathf.Min(generalSkillsRequired, availableGeneralSkills.Count)))
        {
            int skillIndex = HeroClass.CampingSkills.IndexOf(skill);
            CurrentCampingSkills[skillIndex] = skill;
        }
        var availableSpecificSkills = HeroClass.CampingSkills.FindAll(skill => skill.Classes.Count <= 4);
        int specificSkillsRequired  = HeroClass.Generation.NumberOfSpecificCampingSkills + bonusSkills;

        foreach (var skill in availableSpecificSkills.OrderBy(x => RandomSolver.NextDouble())
                 .Take(Mathf.Min(specificSkillsRequired, availableSpecificSkills.Count)))
        {
            int skillIndex = HeroClass.CampingSkills.IndexOf(skill);
            CurrentCampingSkills[skillIndex] = skill;
        }

        var availableGeneratedSkills = new List <CampingSkill>(CurrentCampingSkills);

        availableGeneratedSkills.RemoveAll(skill => skill == null);

        SelectedCampingSkills = availableGeneratedSkills.OrderBy(x => RandomSolver.NextDouble())
                                .Take(Mathf.Min(4, availableGeneratedSkills.Count)).ToList();
    }
Exemplo n.º 3
0
        public void TestSolutionClosed()
        {
            RandomGeneratorExtensions.GetGetNewRandom = () => new RandomGenerator(4541247);

            // create problem.
            var problem = TSPHelper.CreateTSP(0, 0, 5, 10);

            // create the solver.
            var solver = new RandomSolver();

            for (int i = 0; i < 100; i++)
            {
                // generate solution.
                float fitness;
                var   solution = solver.Solve(problem, new TSPObjective(), out fitness);

                // test contents.
                Assert.AreEqual(50, fitness);
                Assert.AreEqual(0, solution.First);
                Assert.AreEqual(0, solution.Last);
                var solutionList = new List <int>(solution);
                Assert.AreEqual(0, solutionList[0]);
                Assert.IsTrue(solutionList.Remove(0));
                Assert.IsTrue(solutionList.Remove(1));
                Assert.IsTrue(solutionList.Remove(2));
                Assert.IsTrue(solutionList.Remove(3));
                Assert.IsTrue(solutionList.Remove(4));
                Assert.AreEqual(0, solutionList.Count);
            }
        }
Exemplo n.º 4
0
    private void InitializeQuirks(RecruitUpgrade expUpgrade = null)
    {
        int positiveQuirkNumber = RandomSolver.Next(HeroClass.Generation.NumberOfPositiveQuirksMin,
                                                    HeroClass.Generation.NumberOfPositiveQuirksMax + 1);

        int negativeQuirkNumber = RandomSolver.Next(HeroClass.Generation.NumberOfNegativeQuirksMin,
                                                    HeroClass.Generation.NumberOfNegativeQuirksMax + 1);

        if (expUpgrade != null)
        {
            positiveQuirkNumber += expUpgrade.ExtraPositiveQuirks;
            negativeQuirkNumber += expUpgrade.ExtraNegativeQuirks;
        }

        for (int i = 0; i < positiveQuirkNumber; i++)
        {
            var availableQuirks = DarkestDungeonManager.Data.Quirks.Values.ToList().FindAll(newQuirk => newQuirk.IsPositive &&
                                                                                            quirkData.TrueForAll(quirkInfo => !quirkInfo.Quirk.IncompatibleQuirks.Contains(newQuirk.Id)) &&
                                                                                            quirkData.Find(quirkInfo => quirkInfo.Quirk == newQuirk) == null);
            var availableQuirk = availableQuirks[RandomSolver.Next(availableQuirks.Count)];
            quirkData.Add(new QuirkInfo(availableQuirk, false, 1, false));
            ApplyQuirk(availableQuirk);
        }

        for (int i = 0; i < negativeQuirkNumber; i++)
        {
            var availableQuirks = DarkestDungeonManager.Data.Quirks.Values.ToList().FindAll(newQuirk => !newQuirk.IsPositive &&
                                                                                            !newQuirk.IsDisease && quirkData.TrueForAll(quirkInfo => !quirkInfo.Quirk.IncompatibleQuirks.Contains(newQuirk.Id)) &&
                                                                                            quirkData.Find(quirkInfo => quirkInfo.Quirk == newQuirk) == null);
            var availableQuirk = availableQuirks[RandomSolver.Next(availableQuirks.Count)];
            quirkData.Add(new QuirkInfo(availableQuirk, false, 1, false));
            ApplyQuirk(availableQuirk);
        }
    }
Exemplo n.º 5
0
    private void InitializeCombatSkills(int bonusSkills = 0)
    {
        var availableSkills = new List <CombatSkill>(HeroClass.CombatSkills);
        int skillsRequired  = Mathf.Clamp(HeroClass.Generation.NumberOfRandomCombatSkills + bonusSkills, 0, HeroClass.CombatSkills.Count);

        CurrentCombatSkills = new CombatSkill[HeroClass.CombatSkills.Count];
        foreach (var guaranteedSkill in availableSkills.FindAll(skill => skill.IsGenerationGuaranteed))
        {
            CurrentCombatSkills[HeroClass.CombatSkills.IndexOf(guaranteedSkill)] = guaranteedSkill;
            availableSkills.Remove(guaranteedSkill);
            skillsRequired--;
        }

        for (int i = skillsRequired; i > 0; i--)
        {
            int generatedIndex = RandomSolver.Next(availableSkills.Count);
            CurrentCombatSkills[HeroClass.CombatSkills.IndexOf(availableSkills[generatedIndex])] = availableSkills[generatedIndex];
            availableSkills.RemoveAt(generatedIndex);
        }

        SelectedCombatSkills = new List <CombatSkill>();
        var selectionList = new List <CombatSkill>(CurrentCombatSkills);

        selectionList.RemoveAll(skill => skill == null);
        int selectedSkills = Mathf.Clamp(HeroClass.NumberOfSelectedCombatSkills, 0, selectionList.Count);

        for (int i = 0; i < selectedSkills; i++)
        {
            int selectedItem = RandomSolver.Next(selectionList.Count);
            SelectedCombatSkills.Add(selectionList[selectedItem]);
            selectionList.RemoveAt(selectedItem);
        }
    }
Exemplo n.º 6
0
    public override bool ApplyInstant(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        if (!performer.Character.IsMonster)
        {
            return(false);
        }

        if (((Monster)performer.Character).Data.ControllerCaptor == null)
        {
            return(false);
        }

        float debuffChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                             (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

        debuffChance -= target.Character.GetSingleAttribute(AttributeType.Debuff).ModifiedValue;
        debuffChance  = performer == target ? 1 : Mathf.Clamp(debuffChance, 0, 0.95f);

        if (RandomSolver.CheckSuccess(debuffChance))
        {
            RaidSceneManager.BattleGround.ControlUnit(target, performer, Duration);
            return(true);
        }
        return(false);
    }
Exemplo n.º 7
0
    public Hero(int heroIndex, PhotonPlayer player)
        : base(DarkestDungeonManager.Data.HeroClasses[(string)player.CustomProperties["HC" + heroIndex]])
    {
        RandomSolver.SetRandomSeed((int)player.CustomProperties["HS" + heroIndex]);

        InitializeHeroInfo(0, (string)player.CustomProperties["HN" + heroIndex],
                           (string)player.CustomProperties["HC" + heroIndex], 0, 30);

        InitializeEquipment(1, 1);
        InitializeQuirks();

        CurrentCombatSkills = new CombatSkill[HeroClass.CombatSkills.Count];
        for (int i = 0; i < CurrentCombatSkills.Length; i++)
        {
            CurrentCombatSkills[i] = HeroClass.CombatSkills[i];
        }

        var playerSkillFlags = (PlayerSkillFlags)player.CustomProperties["HF" + heroIndex];

        SelectedCombatSkills = new List <CombatSkill>();
        for (int i = 0; i < CurrentCombatSkills.Length; i++)
        {
            if ((playerSkillFlags & (PlayerSkillFlags)Mathf.Pow(2, i + 1)) != PlayerSkillFlags.Empty)
            {
                SelectedCombatSkills.Add(CurrentCombatSkills[i]);
            }
        }

        CurrentCampingSkills  = new CampingSkill[HeroClass.CampingSkills.Count];
        SelectedCampingSkills = new List <CampingSkill>();
    }
Exemplo n.º 8
0
    public override bool ApplyInstant(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        float poisonChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                             (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

        poisonChance -= target.Character.GetSingleAttribute(AttributeType.Poison).ModifiedValue;
        if (performer != null && performer.Character is Hero)
        {
            poisonChance += performer.Character.GetSingleAttribute(AttributeType.PoisonChance).ModifiedValue;
        }

        poisonChance = Mathf.Clamp(poisonChance, 0, 0.95f);
        if (RandomSolver.CheckSuccess(poisonChance))
        {
            var poisonStatus = (PoisonStatusEffect)target.Character.GetStatusEffect(StatusType.Poison);
            var newDot       = new DamageOverTimeInstanse
            {
                TickDamage  = DotPoison,
                TicksAmount = effect.IntegerParams[EffectIntParams.Duration] ?? 3
            };
            newDot.TicksLeft = newDot.TicksAmount;
            poisonStatus.AddInstanse(newDot);
            return(true);
        }
        return(false);
    }
Exemplo n.º 9
0
    public override bool ApplyInstant(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null || target.Character is Hero == false)
        {
            return(false);
        }

        float diseaseTriggerChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                                     (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

        if (!RandomSolver.CheckSuccess(diseaseTriggerChance))
        {
            return(false);
        }

        float diseaseChance = 1 - target.Character.GetSingleAttribute(AttributeType.Disease).ModifiedValue;

        if (RandomSolver.CheckSuccess(diseaseChance))
        {
            var hero = (Hero)target.Character;
            if (IsRandom == false && Disease != null)
            {
                if (hero.AddQuirk(Disease))
                {
                    return(true);
                }
            }
            else
            {
                hero.AddRandomDisease();
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 10
0
    public override bool ApplyInstant(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        var stunStatus = (StunStatusEffect)target.Character.GetStatusEffect(StatusType.Stun);

        if (stunStatus.IsApplied)
        {
            return(true);
        }

        float stunChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                           (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

        stunChance -= target.Character.GetSingleAttribute(AttributeType.Stun).ModifiedValue;
        if (performer != null && performer.Character is Hero)
        {
            stunChance += performer.Character.GetSingleAttribute(AttributeType.StunChance).ModifiedValue;
        }

        stunChance = Mathf.Clamp(stunChance, 0, 0.95f);
        if (RandomSolver.CheckSuccess(stunChance))
        {
            stunStatus.StunApplied = true;
            target.SetHalo("stunned");
            target.Character[StatusType.Guard].ResetStatus();
            return(true);
        }
        return(false);
    }
Exemplo n.º 11
0
        private void SolveMultiple100()
        {
            KnapsackInput input;

            for (int i = 0; i < 100; i++)
            {
                input = new KnapsackInput();
                input.GenerateRandomItems();
                var stopwatch     = new Stopwatch();
                var solverBaB     = new BranchAndBoundSolver(input.Items, input.Capacity);
                var solverRand    = new RandomSolver(input.Items, input.Capacity);
                var solverGreedy  = new GreedySolver(input.Items, input.Capacity);
                var solverDynamic = new DynamicProgrammingSolver(input.Items, input.Capacity);
                stopwatch.Start();
                solverBaB.Solve();
                stopwatch.Stop();
                timeResultsBaB.Add(new DataPoint(i, stopwatch.Elapsed.TotalMilliseconds));
                stopwatch.Restart();
                solverRand.Solve();
                stopwatch.Stop();
                timeResultsRand.Add(new DataPoint(i, stopwatch.Elapsed.TotalMilliseconds));
                stopwatch.Restart();
                solverGreedy.Solve();
                stopwatch.Stop();
                timeResultsGreedy.Add(new DataPoint(i, stopwatch.Elapsed.TotalMilliseconds));
                stopwatch.Restart();
                solverDynamic.Solve();
                stopwatch.Stop();
                timeResultsDynamic.Add(new DataPoint(i, stopwatch.Elapsed.TotalMilliseconds));
            }
            timeAverageGreedy  = Math.Round((timeResultsGreedy.Sum(x => x.Y) / 100), 4);
            timeAverageRand    = Math.Round((timeResultsRand.Sum(x => x.Y) / 100), 4);
            timeAverageBaB     = Math.Round((timeResultsBaB.Sum(x => x.Y) / 100), 4);
            timeAverageDynamic = Math.Round((timeResultsDynamic.Sum(x => x.Y) / 100), 4);
        }
Exemplo n.º 12
0
    protected virtual bool ChooseTargets(List <FormationUnit> availableTargets, MonsterBrainDecision decision)
    {
        if (availableTargets.Count > 0)
        {
            decision.TargetInfo.Targets.Clear();

            if (decision.SelectedSkill.TargetRanks.IsMultitarget)
            {
                decision.TargetInfo.Targets.AddRange(availableTargets);
                return(true);
            }
            else
            {
                int index = Random.Range(0, availableTargets.Count);
                decision.TargetInfo.Targets.Add(availableTargets[index]);
                availableTargets.RemoveAt(index);

                if (decision.SelectedSkill.ExtraTargetsChance > 0 && availableTargets.Count > 0 &&
                    RandomSolver.CheckSuccess(decision.SelectedSkill.ExtraTargetsChance))
                {
                    int sideTargetIndex = Random.Range(0, availableTargets.Count);
                    decision.TargetInfo.Targets.Add(availableTargets[sideTargetIndex]);
                    return(true);
                }
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 13
0
        private static void ChooseRandomMove(string tronFilePath)
        {
            ISolver     solver      = new RandomSolver();
            Coordinator coordinator = new Coordinator(solver);

            coordinator.IsInDebugMode = false;
            coordinator.Run(tronFilePath);
        }
Exemplo n.º 14
0
    public Trinket GenerateTrinket()
    {
        var trinketList = DarkestDungeonManager.Data.Items["trinket"].Values.Cast <Trinket>().ToList();
        var rarity      = RandomSolver.ChooseByRandom(RarityTable).RarityId;
        var rarityList  = trinketList.FindAll(item => item.RarityId == rarity);

        return(rarityList[UnityEngine.Random.Range(0, rarityList.Count)]);
    }
Exemplo n.º 15
0
    public override bool ApplyQueued(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        if (target.Character is Hero == false)
        {
            return(false);
        }

        if (effect.IntegerParams[EffectIntParams.Chance].HasValue)
        {
            if (!RandomSolver.CheckSuccess((float)effect.IntegerParams[EffectIntParams.Chance].Value / 100))
            {
                return(false);
            }
        }

        float initialDamage = StressAmount;

        if (performer != null)
        {
            initialDamage *= (1 + performer.Character.GetSingleAttribute(AttributeType.StressDmgPercent).ModifiedValue);
        }

        int damage = Mathf.RoundToInt(initialDamage * (1 +
                                                       target.Character.GetSingleAttribute(AttributeType.StressDmgReceivedPercent).ModifiedValue));

        if (damage < 1)
        {
            damage = 1;
        }

        target.Character.Stress.IncreaseValue(damage);
        if (target.Character.IsOverstressed)
        {
            if (target.Character.IsVirtued)
            {
                target.Character.Stress.CurrentValue = Mathf.Clamp(target.Character.Stress.CurrentValue, 0, 100);
            }
            else if (!target.Character.IsAfflicted && target.Character.IsOverstressed)
            {
                RaidSceneManager.Instanse.AddResolveCheck(target);
            }

            if (Mathf.Approximately(target.Character.Stress.CurrentValue, 200))
            {
                RaidSceneManager.Instanse.AddHeartAttackCheck(target);
            }
        }

        target.OverlaySlot.UpdateOverlay();
        RaidSceneManager.RaidEvents.ShowPopupMessage(target, PopupMessageType.Stress, damage.ToString());
        target.SetHalo("afflicted");
        return(true);
    }
    public void ProvideActivity()
    {
        foreach (var treatmentSlot in TreatmentSlots)
        {
            switch (treatmentSlot.Status)
            {
            case ActivitySlotStatus.Caretaken:
                treatmentSlot.Status = ActivitySlotStatus.Available;
                treatmentSlot.Hero   = null;
                break;

            case ActivitySlotStatus.Blocked:
            case ActivitySlotStatus.Checkout:
                treatmentSlot.Hero.Status = HeroStatus.Available;
                treatmentSlot.Status      = ActivitySlotStatus.Available;
                treatmentSlot.Hero        = null;
                break;

            case ActivitySlotStatus.Paid:
                if (treatmentSlot.TargetDiseaseQuirk != null)
                {
                    if (RandomSolver.CheckSuccess(CureAllChance))
                    {
                        var cured = treatmentSlot.Hero.RemoveDiseases();
                        if (cured.Count == 0)
                        {
                            Debug.LogError("Sanitarium treament diseases not found.");
                        }
                        else
                        {
                            LogActivity(ActivityType.RemoveAllDiseases,
                                        treatmentSlot.Hero, cured.Select(info => info.Quirk.Id).ToArray());
                        }
                    }
                    else
                    {
                        if (treatmentSlot.Hero.RemoveQuirk(treatmentSlot.TargetDiseaseQuirk) == null)
                        {
                            Debug.LogError("Sanitarium treament disease not found.");
                        }
                        else
                        {
                            LogActivity(ActivityType.RemoveDisease,
                                        treatmentSlot.Hero, new string[] { treatmentSlot.TargetDiseaseQuirk });
                        }
                    }
                }
                treatmentSlot.Hero.Status = HeroStatus.Available;
                treatmentSlot.Status      = ActivitySlotStatus.Available;
                treatmentSlot.Hero        = null;
                break;

            default:
                break;
            }
        }
    }
Exemplo n.º 17
0
    public static List <ItemDefinition> GenerateLoot(List <LootDefinition> battleLoot, RaidInfo raid)
    {
        List <ItemDefinition> lootItems = new List <ItemDefinition>();

        for (int i = 0; i < battleLoot.Count; i++)
        {
            for (int j = 0; j < battleLoot[i].Count; j++)
            {
                LootEntry entry = GetLootEntry(battleLoot[i].Code, raid);
                switch (entry.Type)
                {
                case LootType.Item:
                    LootEntryItem  itemEntry = entry as LootEntryItem;
                    ItemDefinition data      = new ItemDefinition();
                    data.Type   = itemEntry.ItemType;
                    data.Id     = itemEntry.ItemId;
                    data.Amount = itemEntry.ItemAmount;
                    lootItems.Add(data);
                    break;

                case LootType.Journal:
                    LootEntryJournal journalEntry = entry as LootEntryJournal;
                    ItemDefinition   dataJournal  = new ItemDefinition();
                    dataJournal.Type = "journal_page";
                    if (journalEntry.SpecificId.HasValue)
                    {
                        dataJournal.Id = journalEntry.SpecificId.Value.ToString();
                    }
                    else
                    {
                        dataJournal.Id = RandomSolver.Next(journalEntry.MinIndex, journalEntry.MaxIndex + 1).ToString();
                    }
                    dataJournal.Amount = 1;
                    lootItems.Add(dataJournal);
                    break;

                case LootType.Trinket:
                    LootEntryTrinket trinketEntry = entry as LootEntryTrinket;
                    var trinketList = DarkestDungeonManager.Data.Items["trinket"].Values.ToList().
                                      FindAll(trinket => ((Trinket)trinket).RarityId == trinketEntry.Rarity);

                    Trinket        trinketItem = (Trinket)trinketList[RandomSolver.Next(trinketList.Count)];
                    ItemDefinition trinketDef  = new ItemDefinition();
                    trinketDef.Type   = trinketItem.Type;
                    trinketDef.Id     = trinketItem.Id;
                    trinketDef.Amount = trinketDef.Amount;
                    lootItems.Add(trinketDef);
                    break;

                case LootType.Nothing:
                    break;
                }
            }
        }
        return(lootItems);
    }
Exemplo n.º 18
0
    private static LootEntry GetLootEntry(string tableId, RaidInfo raid)
    {
        LootTable lootTable = LootDatabase.LootTables[tableId.ToUpper()].
                              Find(table => ((table.Difficulty == raid.Quest.Difficulty) || (table.Difficulty == 0)) &&
                                   ((table.Dungeon == raid.Dungeon.Name) || (table.Dungeon == "")));

        LootEntry lootEntry = RandomSolver.ChooseBySingleRandom(lootTable.Entries);

        return(lootEntry.Type != LootType.Table ? lootEntry : GetLootEntry(((LootEntryTable)lootEntry).TableId, raid));
    }
Exemplo n.º 19
0
        public void TestOpen()
        {
            var problem     = TSPHelper.CreateDirectedTSP(0, 10, 100, 5);
            var random      = new RandomSolver();
            var randomRoute = random.Solve(problem, new Optimization.TSP.Directed.TSPObjective());

            var   op = new DirectionLocalSearch();
            float delta;
            var   optimized = op.Apply(problem, new Optimization.TSP.Directed.TSPObjective(), randomRoute, out delta);
        }
    public override bool ApplyQueued(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        if (effect.IntegerParams[EffectIntParams.Chance].HasValue)
        {
            if (!RandomSolver.CheckSuccess((float)effect.IntegerParams[EffectIntParams.Chance].Value / 100))
            {
                return(false);
            }
        }

        float initialHeal = HealAmount;

        if (performer != null)
        {
            initialHeal *= (1 + performer.Character.GetSingleAttribute(AttributeType.HpHealPercent).ModifiedValue);
        }

        if (performer != null && RandomSolver.CheckSuccess(performer.Character.Crit))
        {
            int critHeal = target.Character.Heal(initialHeal * 1.5f, true);
            RaidSceneManager.RaidEvents.ShowPopupMessage(target, PopupMessageType.CritHeal, critHeal.ToString());
            if (target.Character is Hero)
            {
                FMODUnity.RuntimeManager.PlayOneShot("event:/general/status/heal_ally_crit");
            }
            else
            {
                FMODUnity.RuntimeManager.PlayOneShot("event:/general/status/heal_enemy_crit");
            }

            target.OverlaySlot.UpdateOverlay();
            return(true);
        }
        else
        {
            int heal = target.Character.Heal(initialHeal, true);
            RaidSceneManager.RaidEvents.ShowPopupMessage(target, PopupMessageType.Heal, heal.ToString());
            if (target.Character is Hero)
            {
                FMODUnity.RuntimeManager.PlayOneShot("event:/general/status/heal_ally");
            }
            else
            {
                FMODUnity.RuntimeManager.PlayOneShot("event:/general/status/heal_enemy");
            }

            target.OverlaySlot.UpdateOverlay();
            return(true);
        }
    }
Exemplo n.º 21
0
    public Quirk AddRandomDisease()
    {
        var replacableQuirks = quirkData.FindAll(quirkInfo => quirkInfo.Quirk.IsDisease);
        var availableQuirks  = DarkestDungeonManager.Data.Quirks.Values.ToList().FindAll(newQuirk => newQuirk.IsDisease &&
                                                                                         quirkData.TrueForAll(quirkInfo => !quirkInfo.Quirk.IncompatibleQuirks.Contains(newQuirk.Id)) &&
                                                                                         quirkData.All(quirkInfo => quirkInfo.Quirk != newQuirk));

        var addedQuirk = availableQuirks[RandomSolver.Next(availableQuirks.Count)];

        return(AddOrReplaceQuirk(addedQuirk, replacableQuirks));
    }
Exemplo n.º 22
0
    public void RestockBonus(List <int> rosterIds, Estate estate, string bonusClass, int bonusAmount)
    {
        EventHeroes.Clear();
        GraveIndexes.Clear();

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

                estate.HeroPurchases.Remove(EventHeroes[i].RosterId);
            }
        }
        #endregion

        #region Create bonus recruits
        for (int i = 0; i < bonusAmount; 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 = DarkestDungeonManager.Data.HeroClasses[bonusClass].StringId;
            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);
            EventHeroes.Add(newHero);
            rosterIds.Remove(id);
            GeneratePurchaseInfo(newHero, estate);
        }
        #endregion
    }
    public void Apply(Unit caster, Unit target, Spell spell, ArenaManager world)
    {
        int amount = 0;

        amount += RandomSolver.Next(minValue, maxValue);

        if (amount < 1)
        {
            amount = 1;
        }

        int initialDamage = amount;

        caster.Character.parameters.Copy(world.SpellInfo.parameters);
        for (int i = 0; i < Modifiers.Count; i++)
        {
            Modifiers[i].ModifySpell(caster, target, world.SpellInfo, spell, world);
        }

        initialDamage = (int)(initialDamage * world.SpellInfo.parameters[ParameterType.DamageDealing].FinalValue);

        bool isCrit = RandomSolver.CheckSuccess(world.SpellInfo.parameters[ParameterType.CritChance].FinalValue);

        if (isCrit)
        {
            initialDamage = (int)(initialDamage * caster.Character.parameters[ParameterType.CritDamageMultiplier].FinalValue);
        }

        amount = initialDamage;
        Buff absorbBuff;

        for (int i = target.character.AbsorbEffects.Count - 1; i >= 0; i--)
        {
            amount = target.character.AbsorbEffects[i](target, world, amount, out absorbBuff);
            if (amount != 0)
            {
                target.character.Buffs.Remove(absorbBuff);
            }
            else
            {
                return;
            }
        }

        target.Character.health.Decrease((ushort)amount);

        if (caster.id == world.PlayerUnit.id)
        {
            GameObject damageEvent = MonoBehaviour.Instantiate(Resources.Load("Prefabs/UI/DamageEvent")) as GameObject;
            damageEvent.GetComponent <UnitDamageUIEvent>().Initialize(initialDamage, target, isCrit, ArenaManager.PlayerInterface);
        }
    }
Exemplo n.º 24
0
    public void Apply(Unit caster, Unit target, Spell spell, ArenaManager world)
    {
        int amount = modifier;

        amount += RandomSolver.Next(minValue, maxValue);

        if (amount < 1)
        {
            amount = 1;
        }

        target.Character.health.Increase((ushort)amount);
    }
Exemplo n.º 25
0
    public void RestockTrinkets()
    {
        Trinkets.Clear();
        var trinketList = DarkestDungeonManager.Data.Items["trinket"].Values.Cast <Trinket>().ToList();

        for (int i = 0; i < TrinketSlots; i++)
        {
            var rarity     = RandomSolver.ChooseByRandom(RarityTable).RarityId;
            var rarityList = trinketList.FindAll(item => item.RarityId == rarity);
            Trinkets.Add(rarityList[UnityEngine.Random.Range(0, rarityList.Count)]);
        }
        Trinkets.Sort((x, y) => y.PurchasePrice.CompareTo(x.PurchasePrice));
    }
Exemplo n.º 26
0
    public Quirk RemovePositiveQuirk()
    {
        var positiveQuirks = quirkData.FindAll(quirkInfo => quirkInfo.Quirk.IsPositive && !quirkInfo.IsLocked);

        if (positiveQuirks.Count > 0)
        {
            var removedQuirk = positiveQuirks[RandomSolver.Next(positiveQuirks.Count)];
            RevertQuirk(removedQuirk.Quirk);
            quirkData.Remove(removedQuirk);
            return(removedQuirk.Quirk);
        }
        return(null);
    }
Exemplo n.º 27
0
    public Quirk RemoveDiseaseQuirk()
    {
        var diseases = quirkData.FindAll(quirkInfo => quirkInfo.Quirk.IsDisease);

        if (diseases.Count > 0)
        {
            var removedDisease = diseases[RandomSolver.Next(diseases.Count)];
            RevertQuirk(removedDisease.Quirk);
            quirkData.Remove(removedDisease);
            return(removedDisease.Quirk);
        }
        return(null);
    }
Exemplo n.º 28
0
    private static void LoadRoomEnviroment(Dungeon dungeon, DungeonEnviromentData envData, int mashIndex)
    {
        foreach (var room in dungeon.Rooms.Values)
        {
            room.TextureId = envData.RoomVariations[Random.Range(0, envData.RoomVariations.Count)];
            switch (room.Type)
            {
            case AreaType.Battle:
                var monsterBattleSet = RandomSolver.ChooseByRandom(envData.BattleMashes.
                                                                   Find(mash => mash.MashId == mashIndex).RoomEncounters).MonsterSet;

                room.BattleEncounter = new BattleEncounter(monsterBattleSet);
                break;

            case AreaType.BattleCurio:
                if (room.Prop == null)
                {
                    string curioName = RandomSolver.ChooseByRandom(envData.RoomTresures).PropName;
                    room.Prop = DarkestDungeonManager.Data.Curios[curioName];
                    var monsterCurioSet = RandomSolver.ChooseByRandom(envData.BattleMashes.
                                                                      Find(mash => mash.MashId == mashIndex).RoomEncounters).MonsterSet;

                    room.BattleEncounter = new BattleEncounter(monsterCurioSet);
                }
                break;

            case AreaType.BattleTresure:
                if (room.Prop == null)
                {
                    string tresureName = RandomSolver.ChooseByRandom(envData.RoomTresures).PropName;
                    room.Prop = DarkestDungeonManager.Data.Curios[tresureName];
                }
                var monsterTreasureSet = RandomSolver.ChooseByRandom(envData.BattleMashes.Find(mash =>
                                                                                               mash.MashId == mashIndex).RoomEncounters).MonsterSet;

                room.BattleEncounter = new BattleEncounter(monsterTreasureSet);
                break;

            case AreaType.Empty:
            case AreaType.Entrance:
            case AreaType.Curio:
            case AreaType.Boss:
                break;

            default:
                Assert.IsTrue(false, "Unexpected room type: " + room.Type);
                break;
            }
        }
    }
    protected override bool ChooseTargets(List <FormationUnit> availableTargets, MonsterBrainDecision decision)
    {
        if (availableTargets.Count > 0)
        {
            decision.TargetInfo.Targets.Clear();

            if (decision.SelectedSkill.TargetRanks.IsMultitarget)
            {
                decision.TargetInfo.Targets.AddRange(availableTargets);
                return(true);
            }
            else
            {
                float         lowestRes       = float.MaxValue;
                FormationUnit lowestResTarget = null;
                foreach (var target in availableTargets)
                {
                    if (target.Character[ResistanceType].ModifiedValue < lowestRes)
                    {
                        lowestRes       = target.Character[ResistanceType].ModifiedValue;
                        lowestResTarget = target;
                    }
                }
                decision.TargetInfo.Targets.Add(lowestResTarget);
                availableTargets.Remove(lowestResTarget);

                if (decision.SelectedSkill.ExtraTargetsChance > 0 && availableTargets.Count > 0 &&
                    RandomSolver.CheckSuccess(decision.SelectedSkill.ExtraTargetsChance))
                {
                    lowestRes       = 500f;
                    lowestResTarget = null;
                    foreach (var target in availableTargets)
                    {
                        if (target.Character[ResistanceType].ModifiedValue < lowestRes)
                        {
                            lowestRes       = target.Character[ResistanceType].ModifiedValue;
                            lowestResTarget = target;
                        }
                    }
                    if (lowestResTarget != null)
                    {
                        decision.TargetInfo.Targets.Add(lowestResTarget);
                    }
                    return(true);
                }
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 30
0
        public ISolution Solve()
        {
            AvailableResourceSolver availableResourceSolver = new AvailableResourceSolver(_problem);

            availableResourceSolver.FindAvailableResources();

            RandomSolver solver = new RandomSolver(_problem);

            var solution = solver.Solve();



            return(null);
        }