Пример #1
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)]);
    }
Пример #2
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));
    }
Пример #3
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;
            }
        }
    }
Пример #4
0
 static void DistributeQuestTypes(QuestGenerationInfo questInfo, QuestDatabase questData)
 {
     foreach (var dungeonInfo in questInfo.dungeonQuests)
     {
         foreach (var quest in dungeonInfo.Quests)
         {
             if (quest.IsPlotQuest)
             {
                 continue;
             }
             GeneratedQuestType questType = RandomSolver.ChooseByRandom(dungeonInfo.GeneratedTypes);
             quest.Type   = questType.Type;
             quest.Length = questType.Length;
         }
     }
 }
Пример #5
0
    static void LoadHallEnviroment(Dungeon dungeon, DungeonEnviromentData envData, int mashIndex)
    {
        foreach (var hall in dungeon.Hallways.Values)
        {
            foreach (var sector in hall.Halls)
            {
                sector.TextureId = Random.Range(1, envData.HallVariations + 1).ToString();
                switch (sector.Type)
                {
                case AreaType.Battle:
                    var monsterBattleSet = RandomSolver.ChooseByRandom <DungeonBattleEncounter>(
                        envData.BattleMashes.Find(mash => mash.MashId == mashIndex).RoomEncounters).MonsterSet;
                    sector.BattleEncounter = new BattleEncounter(monsterBattleSet);
                    break;

                case AreaType.Curio:
                    if (sector.Prop == null)
                    {
                        string curioName = RandomSolver.ChooseByRandom <DungeonPropsEncounter>(envData.HallCurios).PropName;
                        sector.Prop = DarkestDungeonManager.Data.Curios[curioName];
                    }
                    break;

                case AreaType.Hunger:
                    break;

                case AreaType.Obstacle:
                    string obstacleName = RandomSolver.ChooseByRandom <DungeonPropsEncounter>(envData.Obstacles).PropName;
                    sector.Prop = DarkestDungeonManager.Data.Obstacles[obstacleName];
                    break;

                case AreaType.Trap:
                    string trapName = RandomSolver.ChooseByRandom <DungeonPropsEncounter>(envData.Traps).PropName;
                    sector.Prop = DarkestDungeonManager.Data.Traps[trapName];
                    break;

                case AreaType.Empty:
                case AreaType.Door:
                    break;

                default:
                    Debug.LogError("Unexpected hall sector type: " + sector.Type.ToString());
                    break;
                }
            }
        }
    }
    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);
    }
Пример #7
0
    public void ProvideActivity()
    {
        foreach (var activitySlot in ActivitySlots)
        {
            switch (activitySlot.Status)
            {
            case ActivitySlotStatus.Caretaken:
            case ActivitySlotStatus.Crierd:
                activitySlot.Status = ActivitySlotStatus.Available;
                activitySlot.Hero   = null;
                break;

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

            case ActivitySlotStatus.Paid:
                activitySlot.Hero.GetPairedAttribute(AttributeType.Stress).DecreaseValue(StressHealAmount);
                if (RandomSolver.CheckSuccess(SideEffectChance))
                {
                    var effect = RandomSolver.ChooseByRandom <TownEffect>(SideEffects);
                    switch (effect.Type)
                    {
                    case TownEffectType.GoMissing:
                        var missingEffect = effect as MissingTownEffect;
                        var duration      = RandomSolver.ChooseByRandom <MissingDuration>(missingEffect.Durations);

                        LogActivity(ActivityEffectType.Missing, activitySlot.Hero, "None");

                        activitySlot.Hero.Status          = HeroStatus.Missing;
                        activitySlot.Hero.MissingDuration = duration.Duration;
                        activitySlot.Status = ActivitySlotStatus.Available;
                        activitySlot.Hero   = null;
                        break;

                    case TownEffectType.ActivityLock:
                        activitySlot.Status = ActivitySlotStatus.Blocked;
                        LogActivity(ActivityEffectType.Lock, activitySlot.Hero, "None");
                        break;

                    case TownEffectType.AddQuirk:
                        var addQuirkEffect = effect as AddQuirkTownEffect;
                        var activityQuirk  = RandomSolver.ChooseByRandom <TownActivityQuirk>(addQuirkEffect.QuirkSet);
                        if (activityQuirk != null)
                        {
                            var quirk = DarkestDungeonManager.Data.Quirks[activityQuirk.QuirkName];
                            if (activitySlot.Hero.AddQuirk(quirk))
                            {
                                LogActivity(ActivityEffectType.AddQuirk, activitySlot.Hero, quirk.Id);
                            }
                        }
                        activitySlot.Hero.Status = HeroStatus.Available;
                        activitySlot.Status      = ActivitySlotStatus.Available;
                        activitySlot.Hero        = null;
                        break;

                    case TownEffectType.AddTrinket:
                        if (activitySlot.Hero.LeftTrinket != null || activitySlot.Hero.RightTrinket != null)
                        {
                            var trinket = DarkestDungeonManager.Campaign.Estate.NomadWagon.GenerateTrinket();
                            DarkestDungeonManager.Campaign.RealmInventory.AddTrinket(trinket);
                            LogActivity(ActivityEffectType.AddTrinket, activitySlot.Hero, trinket.Id);
                        }
                        activitySlot.Hero.Status = HeroStatus.Available;
                        activitySlot.Status      = ActivitySlotStatus.Available;
                        activitySlot.Hero        = null;
                        break;

                    case TownEffectType.RemoveTrinket:
                        if (activitySlot.Hero.LeftTrinket != null && activitySlot.Hero.RightTrinket != null)
                        {
                            if (Random.value > 0.5f)
                            {
                                LogActivity(ActivityEffectType.RemoveTrinket,
                                            activitySlot.Hero, activitySlot.Hero.LeftTrinket.Id);
                                activitySlot.Hero.Unequip(TrinketSlot.Left);
                            }
                            else
                            {
                                LogActivity(ActivityEffectType.RemoveTrinket,
                                            activitySlot.Hero, activitySlot.Hero.RightTrinket.Id);
                                activitySlot.Hero.Unequip(TrinketSlot.Right);
                            }
                        }
                        else if (activitySlot.Hero.LeftTrinket != null)
                        {
                            LogActivity(ActivityEffectType.RemoveTrinket,
                                        activitySlot.Hero, activitySlot.Hero.LeftTrinket.Id);
                            activitySlot.Hero.Unequip(TrinketSlot.Left);
                        }
                        else if (activitySlot.Hero.RightTrinket != null)
                        {
                            LogActivity(ActivityEffectType.RemoveTrinket,
                                        activitySlot.Hero, activitySlot.Hero.RightTrinket.Id);
                            activitySlot.Hero.Unequip(TrinketSlot.Right);
                        }
                        activitySlot.Hero.Status = HeroStatus.Available;
                        activitySlot.Status      = ActivitySlotStatus.Available;
                        activitySlot.Hero        = null;
                        break;

                    case TownEffectType.ApplyBuff:
                        var addBuffTownEffect = effect as AddBuffTownEffect;
                        var activityBuff      = RandomSolver.ChooseByRandom <TownActivityBuff>(addBuffTownEffect.BuffSets);
                        if (activityBuff != null)
                        {
                            foreach (var buffName in activityBuff.BuffNames)
                            {
                                var buff = DarkestDungeonManager.Data.Buffs[buffName];
                                if (!activitySlot.Hero.ContainsBuff(buff, BuffSourceType.Estate))
                                {
                                    activitySlot.Hero.AddBuff(new BuffInfo(buff, BuffDurationType.Raid, BuffSourceType.Estate));
                                }
                            }
                            LogActivity(ActivityEffectType.AddBuff, activitySlot.Hero, activityBuff.BuffNames[0]);
                        }
                        activitySlot.Hero.Status = HeroStatus.Available;
                        activitySlot.Status      = ActivitySlotStatus.Available;
                        activitySlot.Hero        = null;
                        break;

                    case TownEffectType.ChangeCurrency:
                        var changeCurrencyEffect = effect as CurrencyTownEffect;
                        var change = RandomSolver.ChooseByRandom <TownActivityCurrency>(changeCurrencyEffect.Changes);
                        if (change != null)
                        {
                            if (change.Amount > 0)
                            {
                                LogActivity(ActivityEffectType.CurrencyGained,
                                            activitySlot.Hero, change.Amount.ToString());
                                DarkestDungeonManager.Campaign.Estate.AddGold(change.Amount);
                            }
                            else
                            {
                                LogActivity(ActivityEffectType.CurrencyLost,
                                            activitySlot.Hero, Mathf.Abs(change.Amount).ToString());
                                DarkestDungeonManager.Campaign.Estate.RemoveGold(-change.Amount);
                            }
                        }
                        activitySlot.Hero.Status = HeroStatus.Available;
                        activitySlot.Status      = ActivitySlotStatus.Available;
                        activitySlot.Hero        = null;
                        break;
                    }
                }
                else
                {
                    LogActivity(ActivityEffectType.Nothing, activitySlot.Hero, "None");
                    activitySlot.Hero.Status = HeroStatus.Available;
                    activitySlot.Status      = ActivitySlotStatus.Available;
                    activitySlot.Hero        = null;
                }
                break;

            default:
                break;
            }
        }
    }
Пример #8
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));
        }
    }