예제 #1
0
        public override Loot GetRandom(int level)
        {
            var index       = RandHelper.GetRandomEnumValue <EquipmentKind>(new[] { EquipmentKind.God, EquipmentKind.Trophy, EquipmentKind.Unset });
            var lootCreator = lootCreators[index];

            return(lootCreator.GetRandom(level));
        }
예제 #2
0
        Interior?GenerateRandomSimpleInterior(bool addFinishingDecorations = false)
        {
            Interior?interior = null;

            if (Width - generationInfo.MinSimpleInteriorSize > 4 &&
                Height - generationInfo.MinSimpleInteriorSize > 4)
            {
                interior = RandHelper.GetRandomEnumValue <Interior>();
                GenerateInterior(interior.Value);
            }
            else
            {
                addFinishingDecorations = true;
            }
            if (addFinishingDecorations)
            {
                AddDecorations();
            }

            return(interior);
        }
예제 #3
0
파일: Gem.cs 프로젝트: tomaszkot/Roguelike
        public void SetRandomKindAndLevelSize(int gameLevel, bool setKind)
        {
            GameLevel = gameLevel;

            if (setKind)
            {
                GemKind = RandHelper.GetRandomEnumValue <GemKind>();
            }
            EnchanterSize = EnchanterSize.Small;
            var smaller = RandHelper.GetRandomDouble() < 0.5f;

            if (gameLevel >= 10)
            {
                EnchanterSize = EnchanterSize.Big;
            }
            else if (gameLevel >= 8)
            {
                EnchanterSize = smaller ? EnchanterSize.Medium : EnchanterSize.Big;
            }
            else if (gameLevel >= 6)
            {
                EnchanterSize = smaller ? EnchanterSize.Small : EnchanterSize.Medium;
            }
            else if (gameLevel >= 4)
            {
                smaller = false;
            }

            if (!smaller && gameLevel < 10)
            {
                Damaged = true;
            }

            if (RandHelper.GetRandomDouble() < 0.3f)
            {
                Damaged = true;
            }

            SetProps();
        }
예제 #4
0
 public Plant() : this(RandHelper.GetRandomEnumValue <PlantKind>(true))
 {
 }
예제 #5
0
 public Mushroom() : this(RandHelper.GetRandomEnumValue <MushroomKind>())
 {
 }
예제 #6
0
 public Food() : this(RandHelper.GetRandomEnumValue <FoodKind>(new[] { FoodKind.Unset, FoodKind.Mushroom }))//Mushroom has it's own c-tor
 {
 }
예제 #7
0
        Tuple <EntranceSide, Tile> GenerateEntranceAtRandomSide(EntranceSide[] skip = null)
        {
            EntranceSide side = RandHelper.GetRandomEnumValue <EntranceSide>(skip);

            return(GenerateEntranceAtSide(side));
        }
예제 #8
0
        public override CraftingResult Craft(Recipe recipe, List <Loot> lootToConvert)
        {
            if (recipe == null)
            {
                return(ReturnCraftingError("Recipe not set"));
            }

            if (recipe.MagicDustRequired > 0)
            {
                var magicDust = lootToConvert.Where(i => i is MagicDust).Cast <MagicDust>().FirstOrDefault();
                if (magicDust == null || magicDust.Count != recipe.MagicDustRequired)
                {
                    return(ReturnCraftingError("Invalid amount of Magic Dust"));
                }
            }
            lootToConvert = lootToConvert.Where(i => !(i is MagicDust)).ToList();
            var eqs = lootToConvert.Where(i => i is Equipment).Cast <Equipment>().ToList();

            if (eqs.Any(i => i.Class == EquipmentClass.Unique))
            {
                return(ReturnCraftingError("Unique items can not crafted"));
            }

            if (lootToConvert.Any())
            {
                var sulfCount  = GetStackedCount <StackedLoot>(lootToConvert, "Sulfur");
                var hoochCount = GetStackedCount <Hooch>(lootToConvert);

                if (lootToConvert.Count == 2 && recipe.Kind == RecipeKind.Custom)
                {
                    return(HandleCustomRecipe(lootToConvert));
                }
                else if (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.UnEnchantEquipment)
                {
                    var eqsToUncraft = Filter <Equipment>(lootToConvert);
                    if (eqsToUncraft.Count != 1 || eqsToUncraft[0].Enchants.Count == 0)
                    {
                        return(ReturnCraftingError("One enchanted piece of equipment is required"));
                    }
                    var eq    = eqsToUncraft[0];
                    var enchs = eqsToUncraft[0].Enchants.Select(i => i.Enchanter).ToList();
                    enchs.ForEach(i => i.Count = 1);
                    foreach (var ench in eqsToUncraft[0].Enchants)
                    {
                        foreach (var stat in ench.StatKinds)
                        {
                            eq.RemoveMagicStat(stat, ench.StatValue);
                        }
                    }
                    eq.Enchants = new List <Enchant>();

                    var lootItems = new List <Loot>()
                    {
                        eqsToUncraft[0]
                    };
                    lootItems.AddRange(enchs);
                    return(ReturnCraftedLoot(lootItems));//deleteCraftedLoot:false
                }
                else if (recipe.Kind == RecipeKind.CraftSpecialPotion && lootToConvert.Count == 2)
                {
                    var healthPotion = lootToConvert.Where(i => i.IsPotion(PotionKind.Health));
                    var manaPotion   = lootToConvert.Where(i => i.IsPotion(PotionKind.Mana));
                    if (healthPotion != null || manaPotion != null)
                    {
                        var toad = lootToConvert.Where(i => i.IsToadstool());
                        if (toad != null)
                        {
                            Potion pot = null;
                            if (healthPotion != null)
                            {
                                pot = new SpecialPotion(SpecialPotionKind.Strength, SpecialPotionSize.Small);
                            }
                            else
                            {
                                pot = new SpecialPotion(SpecialPotionKind.Magic, SpecialPotionSize.Small);
                            }
                            return(ReturnCraftedLoot(pot));
                        }
                    }
                }
                else if (recipe.Kind == RecipeKind.RechargeMagicalWeapon)
                {
                    var equips      = lootToConvert.Where(i => i is Weapon wpn0 && wpn0.IsMagician).Cast <Weapon>().ToList();
                    var equipsCount = equips.Count();
                    if (equipsCount != 1)
                    {
                        return(ReturnCraftingError("One charge emitting weapon is needed by the Recipe"));
                    }

                    var wpn = equips[0];
                    //foreach (var wpn in equips)
                    {
                        (wpn.SpellSource as WeaponSpellSource).Restore();
                        wpn.UpdateMagicWeaponDesc();
                    }
                    return(ReturnCraftedLoot(wpn, false));
                }
                else if (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.AntidotePotion)
                {
                    var plants = GetStackedCount <Plant>(lootToConvert);
                    if (plants != 1 || Filter <Plant>(lootToConvert).Where(i => i.Kind == PlantKind.Thistle).Count() != 1)
                    {
                        return(ReturnCraftingError("One thistle is needed by the Recipe"));
                    }

                    var hoohCount = GetStackedCount <Hooch>(lootToConvert);
                    if (hoohCount != 1)
                    {
                        return(ReturnCraftingError("One hooch is needed by the Recipe"));
                    }

                    return(ReturnCraftedLoot(new Potion(PotionKind.Antidote), true));
                }
                else if (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.Pendant)
                {
                    var cords = GetStackedCount <Cord>(lootToConvert);
                    if (cords == 0)
                    {
                        return(ReturnCraftingError("Cord is needed by the Recipe"));
                    }

                    var amulet = Equipment.CreatePendant();
                    return(ReturnCraftedLoot(amulet));
                }
                else if (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.EnchantEquipment)
                {
                    var equips      = lootToConvert.Where(i => i is Equipment);
                    var equipsCount = equips.Count();
                    if (equipsCount == 0)
                    {
                        return(ReturnCraftingError("Equipment is needed by the Recipe"));
                    }
                    if (equipsCount > 1)
                    {
                        return(ReturnCraftingError("One equipment is needed by the Recipe"));
                    }
                    var enchanters = lootToConvert.Where(i => !(i is Equipment)).ToList();
                    if (enchanters.Any(i => !(i is Enchanter)))
                    {
                        return(ReturnCraftingError("Only enchanting items (gems, claws,...)are alowed by the Recipe"));
                    }
                    var eq = equips.ElementAt(0) as Equipment;
                    if (!eq.Enchantable)
                    {
                        return(ReturnCraftingError("Equipment is not " + Translations.Strings.Enchantable.ToLower()));
                    }
                    var freeSlots = eq.EnchantSlots - eq.Enchants.Count;
                    if (freeSlots < enchanters.Count())
                    {
                        return(ReturnCraftingError("Too many enchantables added"));
                    }
                    string err;
                    foreach (var ench in enchanters.Cast <Enchanter>())
                    {
                        if (!ench.ApplyTo(eq, out err))
                        {
                            return(ReturnCraftingError(InvalidIngredients));
                        }
                    }

                    return(ReturnCraftedLoot(eq, false));
                }
                else if ((recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.ExplosiveCocktail) &&
                         sulfCount > 0 && hoochCount > 0)
                {
                    if (sulfCount != hoochCount)
                    {
                        return(ReturnCraftingError("Number of ingradients must be the same (except for Magic Dust)"));
                    }
                    return(ReturnCraftedLoot(new ProjectileFightItem(FightItemKind.ExplosiveCocktail, null)));
                }

                var allGems = lootToConvert.All(i => i is Gem);
                if ((recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.ThreeGems) && allGems && lootToConvert.Count == 1 &&
                    GetStackedCount <Gem>(lootToConvert) == 3)
                {
                    return(HandleAllGems(lootToConvert));
                }

                var hpCount         = lootToConvert.Where(i => i.IsPotion(PotionKind.Health)).Count();
                var mpCount         = lootToConvert.Where(i => i.IsPotion(PotionKind.Mana)).Count();
                var toadstools      = lootToConvert.Where(i => i.IsToadstool()).ToList();
                var toadstoolsCount = GetStackedCount <StackedLoot>(toadstools);
                if ((recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.TransformPotion) &&
                    (lootToConvert.Count == 2 && toadstoolsCount == 1 && (hpCount == 1 || mpCount == 1)))
                {
                    //if ((lootToConvert[0] as Potion).Count == 1)//TODO allow many conv (use many M Dust)
                    var potion = lootToConvert.Where(i => i.IsPotion()).Single();
                    {
                        if (potion.AsPotion().Kind == PotionKind.Mana)
                        {
                            if (toadstools.Single().AsToadstool().MushroomKind == MushroomKind.RedToadstool)
                            {
                                return(ReturnCraftedLoot(new Potion(PotionKind.Health)));
                            }
                        }
                        else
                        {
                            if (toadstools.Single().AsToadstool().MushroomKind == MushroomKind.BlueToadstool)
                            {
                                return(ReturnCraftedLoot(new Potion(PotionKind.Mana)));
                            }
                        }
                    }
                }

                if (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.Toadstools2Potion)
                {
                    var allToadstool = lootToConvert.All(i => i.IsToadstool()) && GetToadstoolsCount(lootToConvert) == 1;
                    if (allToadstool)
                    {
                        //var toadstools = lootToConvert.Cast<Mushroom>().GroupBy(i => i.MushroomKind);
                        //if (toadstools[0] as Mushroom)//same kind?
                        {
                            var toadstool = lootToConvert[0].AsToadstool();
                            if (toadstool != null && toadstool.Count == 3)
                            {
                                Potion potion = null;
                                if (toadstool.MushroomKind == MushroomKind.BlueToadstool)
                                {
                                    potion = new Potion(PotionKind.Mana);
                                }
                                else
                                {
                                    potion = new Potion(PotionKind.Health);
                                }
                                return(ReturnCraftedLoot(potion));
                            }
                        }
                    }
                }
            }

            if (lootToConvert.Count == 1)
            {
                var srcEq = lootToConvert[0] as Equipment;
                if (srcEq != null && (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.OneEq))
                {
                    return(CraftOneEq(srcEq));
                }

                else if (lootToConvert[0] is Gem && (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.TransformGem))
                {
                    var srcGem   = lootToConvert[0] as Gem;
                    var destKind = RandHelper.GetRandomEnumValue <GemKind>(new GemKind[] { srcGem.GemKind });
                    var destGem  = new Gem(destKind);
                    destGem.EnchanterSize = srcGem.EnchanterSize;
                    destGem.SetProps();
                    return(ReturnCraftedLoot(destGem));
                }
            }
            else if (lootToConvert.Count == 2 && eqs.Count == 2 && (recipe.Kind == RecipeKind.Custom || recipe.Kind == RecipeKind.TwoEq))
            {
                return(CraftTwoEq(eqs));
            }
            else if (recipe.Kind == RecipeKind.Custom && eqs.Count == 1)
            {
                if (eqs[0].EquipmentKind == EquipmentKind.Weapon)
                {
                    var spsCount = GetStackedCount <SpecialPotion>(lootToConvert);
                    if (spsCount == lootToConvert.Count - 1 && spsCount <= 2)
                    {
                        return(ReturnStealingEq(eqs, Filter <SpecialPotion>(lootToConvert)));
                    }
                }
            }
            else if (recipe.Kind == RecipeKind.Custom && lootToConvert.Count == 2)
            {
                //turn one Toadstool kind into other (using Potion)
                var toadstoolsCount = GetToadstoolsCount(lootToConvert);
                var potions         = lootToConvert.Where(i => i.IsPotion()).ToList();
                if (toadstoolsCount == 1 && potions.Count == 1)
                {
                    var tk = GetToadstools(lootToConvert)[0].MushroomKind;
                    var pk = (potions[0].AsPotion()).Kind;

                    if (tk == MushroomKind.RedToadstool && pk == PotionKind.Mana)
                    {
                        return(ReturnCraftedLoot(new Mushroom(MushroomKind.BlueToadstool)));
                    }
                    else if (tk == MushroomKind.BlueToadstool && pk == PotionKind.Health)
                    {
                        return(ReturnCraftedLoot(new Mushroom(MushroomKind.RedToadstool)));
                    }
                }
            }


            return(ReturnCraftingError(InvalidIngredients));
        }