Esempio n. 1
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);
        }
    }
Esempio n. 2
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);
        }
    }
    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);
    }
Esempio n. 4
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));
    }
    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);
        }
    }
    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);
    }
Esempio n. 7
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);
    }
Esempio n. 8
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);
    }
Esempio n. 9
0
    public Quirk RemoveNegativeQuirk()
    {
        var negativeQuirks = quirkData.FindAll(quirkInfo =>
                                               !quirkInfo.Quirk.IsPositive && !quirkInfo.Quirk.IsDisease && !quirkInfo.IsLocked);

        if (negativeQuirks.Count == 0)
        {
            negativeQuirks = quirkData.FindAll(quirkInfo => !quirkInfo.Quirk.IsPositive && !quirkInfo.Quirk.IsDisease);
        }

        if (negativeQuirks.Count > 0)
        {
            var removedQuirk = negativeQuirks[RandomSolver.Next(negativeQuirks.Count)];
            RevertQuirk(removedQuirk.Quirk);
            quirkData.Remove(removedQuirk);
            return(removedQuirk.Quirk);
        }
        return(null);
    }
    public bool SelectSkill(FormationUnit performer, MonsterBrainDecision decision)
    {
        if (IsRestricted(performer))
        {
            return(false);
        }

        var monster         = (Monster)performer.Character;
        var availableSkills = monster.Data.CombatSkills.FindAll(skill => IsValidSkill(performer, skill));

        if (availableSkills.Count > 0)
        {
            decision.Decision           = BrainDecisionType.Perform;
            decision.SelectedSkill      = availableSkills[RandomSolver.Next(availableSkills.Count)];
            decision.TargetInfo.Targets = BattleSolver.GetSkillAvailableTargets(performer, decision.SelectedSkill);
            decision.TargetInfo.Targets.RemoveAll(target => !IsValidTarget(target));
            decision.TargetInfo.Type = decision.SelectedSkill.TargetRanks.SkillTargetType;

            if (decision.TargetInfo.Targets.Count == 0)
            {
                return(false);
            }

            var availableTargetDesires = monster.Brain.TargetDesireSet.FindAll(IsValidTargetDesire);
            while (availableTargetDesires.Count > 0)
            {
                TargetSelectionDesire desire = RandomSolver.ChooseByRandom(availableTargetDesires);
                if (desire.SelectTarget(performer, decision))
                {
                    return(true);
                }

                availableTargetDesires.Remove(desire);
            }
            return(false);
        }
        return(false);
    }
    private void Start()
    {
        HeroPool  = new List <Hero>();
        HeroSeeds = new List <int>();

        foreach (var heroClass in DarkestDungeonManager.Data.HeroClasses.Values.ToList())
        {
            for (int i = 0; i < 4; i++)
            {
                string generatedName = LocalizationManager.GetString("hero_name_" + RandomSolver.Next(0, 556).ToString());
                int    heroSeed      = GetInstanceID() + System.DateTime.Now.Millisecond + (int)System.DateTime.Now.Ticks + i + HeroPool.Count;
                RandomSolver.SetRandomSeed(heroSeed);
                HeroSeeds.Add(heroSeed);
                HeroPool.Add(new Hero(heroClass.StringId, generatedName));
            }
        }

        var initialParty = new List <Hero>(HeroPool).OrderBy(x => RandomSolver.NextDouble()).Take(4).ToList();

        multiplayerPartyPanel.LoadInitialComposition(initialParty);

        launcherPanel.ProgressLabel.text = "Disconnected!";
        CampaignSelectionManager.Instanse.RoomSelector.RegionLabel.text = "Region: " + RegionToString(selectedRegion);
    }
Esempio n. 12
0
 private Quirk AddOrReplaceQuirk(Quirk addedQuirk, List <QuirkInfo> replacableQuirks)
 {
     if (replacableQuirks.Count < (addedQuirk.IsDisease ? 3 : 5))
     {
         quirkData.Add(new QuirkInfo(addedQuirk, false, 1, true));
         ApplyQuirk(addedQuirk);
     }
     else
     {
         var replacements = replacableQuirks.FindAll(quirkInfo => !quirkInfo.IsLocked);
         if (replacements.Count > 0)
         {
             int replaceIndex = RandomSolver.Next(replacements.Count);
             RevertQuirk(replacements[replaceIndex].Quirk);
             replacements[replaceIndex].ReplaceBy(addedQuirk);
             ApplyQuirk(addedQuirk);
         }
         else
         {
             return(null);
         }
     }
     return(addedQuirk);
 }
Esempio n. 13
0
    public override bool ApplyQueued(FormationUnit performer, FormationUnit target, Effect effect)
    {
        if (target == null)
        {
            return(false);
        }

        if (target.Party.Units.Count < 2)
        {
            return(false);
        }

        if (IsPartyShuffle)
        {
            foreach (var unit in target.Party.Units)
            {
                float moveChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                                   (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

                moveChance -= unit.Character.GetSingleAttribute(AttributeType.Move).ModifiedValue;
                if (performer != null && performer.Character is Hero)
                {
                    moveChance += performer.Character.GetSingleAttribute(AttributeType.MoveChance).ModifiedValue;
                }

                moveChance = Mathf.Clamp(moveChance, 0, 0.95f);
                if (RandomSolver.CheckSuccess(moveChance))
                {
                    var shuffleTargets = unit.Party.Units.FindAll(shuffle => shuffle != unit);
                    var shuffleRoll    = shuffleTargets[RandomSolver.Next(shuffleTargets.Count)];

                    if (shuffleRoll.Rank < unit.Rank)
                    {
                        unit.Pull(unit.Rank - shuffleRoll.Rank);
                    }
                    else
                    {
                        unit.Push(shuffleRoll.Rank - unit.Rank);
                    }
                    return(true);
                }
            }
            return(true);
        }
        else
        {
            float moveChance = effect.IntegerParams[EffectIntParams.Chance].HasValue ?
                               (float)effect.IntegerParams[EffectIntParams.Chance].Value / 100 : 1;

            moveChance -= target.Character.GetSingleAttribute(AttributeType.Move).ModifiedValue;
            if (performer != null && performer.Character is Hero)
            {
                moveChance += performer.Character.GetSingleAttribute(AttributeType.MoveChance).ModifiedValue;
            }

            moveChance = Mathf.Clamp(moveChance, 0, 0.95f);
            if (RandomSolver.CheckSuccess(moveChance))
            {
                var shuffleTargets = target.Party.Units.FindAll(unit => unit != target);
                var shuffleRoll    = shuffleTargets[RandomSolver.Next(shuffleTargets.Count)];

                if (shuffleRoll.Rank < target.Rank)
                {
                    target.Pull(target.Rank - shuffleRoll.Rank);
                }
                else
                {
                    target.Push(shuffleRoll.Rank - target.Rank);
                }
                return(true);
            }
            RaidSceneManager.RaidEvents.ShowPopupMessage(target, PopupMessageType.MoveResist);
            return(false);
        }
    }
Esempio n. 14
0
    public override bool ApplyInstant(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);
            }
        }

        List <int>   summonPool = new List <int>();
        List <float> chancePool = new List <float>(SummonChances);

        for (int i = 0; i < SummonMonsters.Count; i++)
        {
            summonPool.Add(i);
        }

        for (int i = 0; i < SummonCount; i++)
        {
            if (summonPool.Count == 0)
            {
                break;
            }

            int rolledIndex = RandomSolver.ChooseRandomIndex(chancePool);
            int summonIndex = summonPool[rolledIndex];
            if (SummonLimits.Count > 0)
            {
                if (SummonLimits[summonIndex] <= performer.Party.Units.FindAll(unit =>
                                                                               unit.Character.Name == SummonMonsters[summonIndex]).Count)
                {
                    i--;
                    summonPool.RemoveAt(rolledIndex);
                    chancePool.RemoveAt(rolledIndex);
                    continue;
                }
            }
            if (performer.Formation.AvailableSummonSpace < DarkestDungeonManager.Data.Monsters[SummonMonsters[summonIndex]].Size)
            {
                i--;
                summonPool.RemoveAt(rolledIndex);
                chancePool.RemoveAt(rolledIndex);
                continue;
            }
            MonsterData summonData     = DarkestDungeonManager.Data.Monsters[SummonMonsters[summonIndex]];
            GameObject  summonObject   = Resources.Load("Prefabs/Monsters/" + summonData.TypeId) as GameObject;
            bool        rollInitiative = SummonRollInitiatives.Count > 0;
            if (SummonRanks.Count > 0)
            {
                RaidSceneManager.BattleGround.SummonUnit(summonData, summonObject, SummonRanks[summonIndex].
                                                         Ranks[RandomSolver.Next(SummonRanks[summonIndex].Ranks.Count)], rollInitiative, CanSpawnLoot);
            }
            else
            {
                RaidSceneManager.BattleGround.SummonUnit(summonData, summonObject, 1, rollInitiative, CanSpawnLoot);
            }
        }
        return(true);
    }
Esempio n. 15
0
    public static MonsterBrainDecision UseMonsterBrain(FormationUnit performer, string combatSkillOverride = null)
    {
        if (performer.Character.IsMonster)
        {
            var monster = performer.Character as Monster;

            if (string.IsNullOrEmpty(combatSkillOverride))
            {
                var skillDesires         = new List <SkillSelectionDesire>(monster.Brain.SkillDesireSet);
                var monsterBrainDecision = new MonsterBrainDecision(BrainDecisionType.Pass);

                while (skillDesires.Count != 0)
                {
                    SkillSelectionDesire desire = RandomSolver.ChooseByRandom(skillDesires);
                    if (desire != null && desire.SelectSkill(performer, monsterBrainDecision))
                    {
                        var cooldown = monster.Brain.SkillCooldowns.Find(cd => cd.SkillId == monsterBrainDecision.SelectedSkill.Id);
                        if (cooldown != null)
                        {
                            performer.CombatInfo.SkillCooldowns.Add(cooldown.Copy());
                        }
                        RaidSceneManager.BattleGround.LastSkillUsed = monsterBrainDecision.SelectedSkill.Id;
                        return(monsterBrainDecision);
                    }
                    else
                    {
                        skillDesires.Remove(desire);
                    }
                }
                return(new MonsterBrainDecision(BrainDecisionType.Pass));
            }
            else
            {
                var availableSkill = monster.Data.CombatSkills.Find(skill => skill.Id == combatSkillOverride);

                if (availableSkill != null && IsSkillUsable(performer, availableSkill))
                {
                    var monsterBrainDecision = new MonsterBrainDecision(BrainDecisionType.Pass);
                    monsterBrainDecision.Decision           = BrainDecisionType.Perform;
                    monsterBrainDecision.SelectedSkill      = availableSkill;
                    monsterBrainDecision.TargetInfo.Targets = GetSkillAvailableTargets(performer, monsterBrainDecision.SelectedSkill);
                    monsterBrainDecision.TargetInfo.Type    = monsterBrainDecision.SelectedSkill.TargetRanks.IsSelfTarget ?
                                                              SkillTargetType.Self : monsterBrainDecision.SelectedSkill.TargetRanks.IsSelfFormation ?
                                                              SkillTargetType.Party : SkillTargetType.Enemy;

                    var availableTargetDesires = new List <TargetSelectionDesire>(monster.Brain.TargetDesireSet);

                    while (availableTargetDesires.Count > 0)
                    {
                        TargetSelectionDesire desire = RandomSolver.ChooseByRandom(availableTargetDesires);
                        if (desire.SelectTarget(performer, monsterBrainDecision))
                        {
                            return(monsterBrainDecision);
                        }
                        else
                        {
                            availableTargetDesires.Remove(desire);
                        }
                    }
                    return(new MonsterBrainDecision(BrainDecisionType.Pass));
                }
                return(new MonsterBrainDecision(BrainDecisionType.Pass));
            }
        }
        else
        {
            var hero = performer.Character as Hero;

            var availableSkills = hero.Mode == null ? new List <CombatSkill>(hero.CurrentCombatSkills).FindAll(skill =>
                                                                                                               skill != null && IsSkillUsable(performer, skill)) : new List <CombatSkill>(hero.CurrentCombatSkills).FindAll(skill =>
                                                                                                                                                                                                                            skill.ValidModes.Contains(hero.CurrentMode.Id) && IsSkillUsable(performer, skill));

            if (availableSkills.Count != 0)
            {
                var monsterBrainDecision = new MonsterBrainDecision(BrainDecisionType.Pass);
                monsterBrainDecision.Decision           = BrainDecisionType.Perform;
                monsterBrainDecision.SelectedSkill      = availableSkills[RandomSolver.Next(availableSkills.Count)];
                monsterBrainDecision.TargetInfo.Targets = GetSkillAvailableTargets(performer, monsterBrainDecision.SelectedSkill);
                monsterBrainDecision.TargetInfo.Type    = monsterBrainDecision.SelectedSkill.TargetRanks.IsSelfTarget ?
                                                          SkillTargetType.Self : monsterBrainDecision.SelectedSkill.TargetRanks.IsSelfFormation ?
                                                          SkillTargetType.Party : SkillTargetType.Enemy;

                var availableTargets = new List <FormationUnit>(monsterBrainDecision.TargetInfo.Targets);
                if (availableTargets.Count > 0)
                {
                    monsterBrainDecision.TargetInfo.Targets.Clear();

                    if (monsterBrainDecision.SelectedSkill.TargetRanks.IsMultitarget)
                    {
                        monsterBrainDecision.TargetInfo.Targets.AddRange(availableTargets);
                        return(monsterBrainDecision);
                    }
                    else
                    {
                        int index = RandomSolver.Next(availableTargets.Count);
                        monsterBrainDecision.TargetInfo.Targets.Add(availableTargets[index]);
                        availableTargets.RemoveAt(index);
                        return(monsterBrainDecision);
                    }
                }
                return(new MonsterBrainDecision(BrainDecisionType.Pass));
            }
            return(new MonsterBrainDecision(BrainDecisionType.Pass));
        }
    }
Esempio n. 16
0
    public int NextRound(BattleGround battleground)
    {
        RoundStatus = RoundStatus.Start;
        OrderedUnits.Clear();

        if (RoundNumber == 0 || RoundNumber == 1)
        {
            battleground.HeroFormation.UpdateBuffRule(BuffRule.FirstRound);
            battleground.MonsterFormation.UpdateBuffRule(BuffRule.FirstRound);
        }

        foreach (var unit in battleground.HeroParty.Units)
        {
            unit.CombatInfo.UpdateNextRound();
            OrderedUnits.Add(unit);

            if (SceneManagerHelper.ActiveSceneName == "DungeonMultiplayer")
            {
                if (unit.Character.Class == "antiquarian")
                {
                    OrderedUnits.Add(unit);
                }
            }
        }

        foreach (var unit in battleground.MonsterParty.Units)
        {
            unit.CombatInfo.UpdateNextRound();
            if (unit.Character.IsMonster)
            {
                for (int i = 0; i < unit.Character.Initiative.NumberOfTurns; i++)
                {
                    OrderedUnits.Add(unit);
                }
            }
            else
            {
                OrderedUnits.Add(unit);
            }

            if (SceneManagerHelper.ActiveSceneName == "DungeonMultiplayer")
            {
                if (unit.Character.Class == "antiquarian")
                {
                    OrderedUnits.Add(unit);
                }
            }
        }

        if (RoundNumber == 0)
        {
            if (RaidSceneManager.BattleGround.SurpriseStatus == SurpriseStatus.HeroesSurprised)
            {
                OrderedUnits = new List <FormationUnit>(OrderedUnits.OrderByDescending(unit => unit.Character.IsMonster ?
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble() :
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble() - 100));
            }
            else if (RaidSceneManager.BattleGround.SurpriseStatus == SurpriseStatus.MonstersSurprised)
            {
                OrderedUnits = new List <FormationUnit>(OrderedUnits.OrderByDescending(unit => unit.Character.IsMonster ?
                                                                                       unit.Character.BattleModifiers != null && unit.Character.BattleModifiers.CanBeSurprised ?
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble() - 100 :
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble() :
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble()));
            }
            else
            {
                OrderedUnits = new List <FormationUnit>(OrderedUnits.OrderByDescending(unit =>
                                                                                       unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble()));
            }
        }
        else
        {
            OrderedUnits = new List <FormationUnit>(OrderedUnits.OrderByDescending(unit =>
                                                                                   unit.Character.Speed + RandomSolver.Next(0, 3) + RandomSolver.NextDouble()));
        }

        return(++RoundNumber);
    }
    public static void ExecuteNarration(string id, NarrationPlace place, params string[] tags)
    {
        if (!DarkestDungeonManager.Data.Narration.ContainsKey(id))
        {
            return;
        }

        NarrationEntry narrationEntry = DarkestDungeonManager.Data.Narration[id];

        if (!RandomSolver.CheckSuccess(narrationEntry.Chance))
        {
            return;
        }

        var possibleEvents = narrationEntry.AudioEvents.FindAll(audioEvent => audioEvent.IsPossible(place, tags));

        if (possibleEvents.Count == 0)
        {
            return;
        }

        float maxPriority = possibleEvents.Max(audio => audio.Priority);

        possibleEvents.RemoveAll(lowPriorityEvent => lowPriorityEvent.Priority < maxPriority);

        NarrationAudioEvent narrationEvent = id == "combat_start" ?
                                             possibleEvents[0] : possibleEvents[RandomSolver.Next(possibleEvents.Count)];

        if (narrationEvent.QueueOnlyOnEmpty && NarrationQueue.Count > 0)
        {
            return;
        }

        if (id == "town_visit_start")
        {
            for (int i = 0; i < 3; i++)
            {
                if (RandomSolver.CheckSuccess(narrationEvent.Chance))
                {
                    break;
                }
                else
                {
                    narrationEvent = possibleEvents[RandomSolver.Next(possibleEvents.Count)];
                }

                if (i == 2)
                {
                    return;
                }
            }
        }
        else if (!RandomSolver.CheckSuccess(narrationEvent.Chance))
        {
            return;
        }

        var narrationInstanse = RuntimeManager.CreateInstance("event:" + narrationEvent.AudioEvent);

        if (narrationInstanse != null)
        {
            NarrationQueue.Add(narrationInstanse);
        }

        switch (place)
        {
        case NarrationPlace.Campaign:
            if (narrationEvent.MaxCampaignOccurrences > 0)
            {
                if (!DarkestDungeonManager.Campaign.NarrationCampaignInfo.ContainsKey(narrationEvent.AudioEvent))
                {
                    DarkestDungeonManager.Campaign.NarrationCampaignInfo.Add(narrationEvent.AudioEvent, 0);
                }

                DarkestDungeonManager.Campaign.NarrationCampaignInfo[narrationEvent.AudioEvent]++;
            }
            break;

        case NarrationPlace.Raid:
            if (narrationEvent.MaxRaidOccurrences > 0)
            {
                if (!DarkestDungeonManager.Campaign.NarrationRaidInfo.ContainsKey(narrationEvent.AudioEvent))
                {
                    DarkestDungeonManager.Campaign.NarrationRaidInfo.Add(narrationEvent.AudioEvent, 0);
                }

                DarkestDungeonManager.Campaign.NarrationRaidInfo[narrationEvent.AudioEvent]++;
            }
            goto case NarrationPlace.Campaign;

        case NarrationPlace.Town:
            if (narrationEvent.MaxTownVisitOccurrences > 0)
            {
                if (!DarkestDungeonManager.Campaign.NarrationTownInfo.ContainsKey(narrationEvent.AudioEvent))
                {
                    DarkestDungeonManager.Campaign.NarrationTownInfo.Add(narrationEvent.AudioEvent, 0);
                }

                DarkestDungeonManager.Campaign.NarrationTownInfo[narrationEvent.AudioEvent]++;
            }
            goto case NarrationPlace.Campaign;
        }
    }
Esempio n. 18
0
    public static void ExecuteSkill(FormationUnit performerUnit, FormationUnit targetUnit, CombatSkill skill, SkillArtInfo artInfo)
    {
        SkillResult.Skill   = skill;
        SkillResult.ArtInfo = artInfo;

        var target    = targetUnit.Character;
        var performer = performerUnit.Character;

        ApplyConditions(performerUnit, targetUnit, skill);

        if (skill.Move != null && !performerUnit.CombatInfo.IsImmobilized)
        {
            if (skill.Move.Pullforward > 0)
            {
                performerUnit.Pull(skill.Move.Pullforward, false);
            }
            else if (skill.Move.Pushback > 0)
            {
                performerUnit.Push(skill.Move.Pushback, false);
            }
        }

        if (skill.Category == SkillCategory.Heal || skill.Category == SkillCategory.Support)
        {
            #region Heal

            if (skill.Heal != null)
            {
                float initialHeal = RandomSolver.Next(skill.Heal.MinAmount, skill.Heal.MaxAmount + 1) *
                                    (1 + performer.GetSingleAttribute(AttributeType.HpHealPercent).ModifiedValue);

                if (skill.IsCritValid)
                {
                    float critChance = performer[AttributeType.CritChance].ModifiedValue + skill.CritMod / 100;
                    if (RandomSolver.CheckSuccess(critChance))
                    {
                        int critHeal = target.Heal(initialHeal * 1.5f, true);
                        targetUnit.OverlaySlot.UpdateOverlay();
                        SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, critHeal, SkillResultType.CritHeal));

                        ApplyEffects(performerUnit, targetUnit, skill);
                        if (targetUnit.Character.IsMonster == false)
                        {
                            DarkestDungeonManager.Data.Effects["crit_heal_stress_heal"].ApplyIndependent(targetUnit);
                        }
                        return;
                    }
                }

                int heal = target.Heal(initialHeal, true);
                targetUnit.OverlaySlot.UpdateOverlay();

                SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, heal, SkillResultType.Heal));
                ApplyEffects(performerUnit, targetUnit, skill);
            }
            else
            {
                SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, SkillResultType.Utility));
                ApplyEffects(performerUnit, targetUnit, skill);
            }

            #endregion
        }
        else
        {
            #region Damage

            float accuracy  = skill.Accuracy + performer.Accuracy;
            float hitChance = Mathf.Clamp(accuracy - target.Dodge, 0, 0.95f);
            float roll      = (float)RandomSolver.NextDouble();
            if (target.BattleModifiers != null && target.BattleModifiers.CanBeHit == false)
            {
                roll = float.MaxValue;
            }

            if (roll > hitChance)
            {
                if (!(skill.CanMiss == false || (target.BattleModifiers != null && target.BattleModifiers.CanBeMissed == false)))
                {
                    if (roll > Mathf.Min(accuracy, 0.95f))
                    {
                        SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, SkillResultType.Miss));
                    }
                    else
                    {
                        SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, SkillResultType.Dodge));
                    }

                    ApplyEffects(performerUnit, targetUnit, skill);
                    return;
                }
            }

            float initialDamage = performer is Hero?
                                  Mathf.Lerp(performer.MinDamage, performer.MaxDamage, (float)RandomSolver.NextDouble()) * (1 + skill.DamageMod) :
                                  Mathf.Lerp(skill.DamageMin, skill.DamageMax, (float)RandomSolver.NextDouble()) * performer.DamageMod;

            int damage = Mathf.CeilToInt(initialDamage * (1 - target.Protection));
            if (damage < 0)
            {
                damage = 0;
            }

            if (target.BattleModifiers != null && target.BattleModifiers.CanBeDamagedDirectly == false)
            {
                damage = 0;
            }

            if (skill.IsCritValid)
            {
                float critChance = performer.GetSingleAttribute(AttributeType.CritChance).ModifiedValue + skill.CritMod;
                if (RandomSolver.CheckSuccess(critChance))
                {
                    int critDamage = target.TakeDamage(damage * 1.5f);
                    targetUnit.OverlaySlot.UpdateOverlay();

                    if (target.HasZeroHealth)
                    {
                        SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, critDamage, true, SkillResultType.Crit));
                    }
                    else
                    {
                        SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, critDamage, SkillResultType.Crit));
                    }

                    ApplyEffects(performerUnit, targetUnit, skill);
                    if (targetUnit.Character.IsMonster == false)
                    {
                        DarkestDungeonManager.Data.Effects["Stress 2"].ApplyIndependent(targetUnit);
                    }
                    return;
                }
            }
            damage = target.TakeDamage(damage);
            targetUnit.OverlaySlot.UpdateOverlay();
            if (target.HasZeroHealth)
            {
                SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, damage, true, SkillResultType.Hit));
            }
            else
            {
                SkillResult.AddResultEntry(new SkillResultEntry(targetUnit, damage, SkillResultType.Hit));
            }

            ApplyEffects(performerUnit, targetUnit, skill);

            #endregion
        }
    }
 public bool CheckTrigger(Unit caster, Unit target, SpellInfo spellInformation, Spell spell)
 {
     isTriggered = RandomSolver.Next(0, 10000) < triggerChance * 100;
     return(isTriggered);
 }