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)); }
protected override void Create() { Func <string, Loot> createPotion = (string tag) => { var kind = PotionKind.Unset; var specialKind = SpecialPotionKind.Unset; if (tag == "health_potion") { kind = PotionKind.Health; } else if (tag == "mana_potion") { kind = PotionKind.Mana; } else if (tag == "antidote_potion") { kind = PotionKind.Antidote; } else if (tag == "magic_potion") { kind = PotionKind.Special; specialKind = SpecialPotionKind.Magic; } else if (tag == "strength_potion") { kind = PotionKind.Special; specialKind = SpecialPotionKind.Strength; } else { Debug.Assert(false); } Potion loot = null; if (specialKind != SpecialPotionKind.Unset) { loot = new SpecialPotion(specialKind, SpecialPotionSize.Small); } else { loot = new Potion(kind); } return(loot); }; var names = new[] { "antidote_potion", "health_potion", "mana_potion", "magic_potion", "strength_potion" }; foreach (var name in names) { factory[name] = createPotion; } InitRepices(); factory["magic_dust"] = (string tag) => { return(new MagicDust()); }; factory["hooch"] = (string tag) => { return(new Hooch()); }; factory["hour_glass"] = (string tag) => { //new GenericLoot("Pick", "Tool for mining", "pick"); return(new GenericLoot("Hourglass", "Hourglass - quite useless tool", "hour_glass")); }; factory["gold_chest_key"] = (string tag) => { var key = new Key(); key.Kind = KeyKind.Chest; return(key); }; factory["cord"] = (string tag) => { return(new Cord()); }; factory["pendant"] = (string tag) => { var jew = new Jewellery() { EquipmentKind = EquipmentKind.Amulet }; jew.SetIsPendant(true); return(jew); }; factory["goblet"] = (string tag) => { return(new Goblet() { }); }; factory["pick"] = (string tag) => { return(new GenericLoot("Pick", "Tool for mining", "pick")); }; factory["skull"] = (string tag) => { return(new GenericLoot("Skull of a giant", "Ancient skull of a gaint, worth a couple of coins", "skull")); }; factory["coin"] = (string tag) => { return(new Gold()); }; //PoisonCocktail and others var fis = GetEnumValues <FightItemKind>(); foreach (var fik in fis) { factory[fik.ToString()] = (string tag) => { var fi = CreateFightItem(fik); return(fi); }; factoryFightItem[fik.ToString()] = (string tag) => { var fi = CreateFightItem(fik); return(fi); }; } var tinyTrophies = HunterTrophy.TinyTrophiesTags; foreach (var tt in tinyTrophies) { var kind = HunterTrophyKind.Unset; if (tt.EndsWith("claw")) { kind = HunterTrophyKind.Claw; } else if (tt.EndsWith("fang")) { kind = HunterTrophyKind.Fang; } else if (tt.EndsWith("tusk")) { kind = HunterTrophyKind.Tusk; } EnchanterSize enchanterSize = EnchanterSize.Small; if (tt.StartsWith("big")) { enchanterSize = EnchanterSize.Big; } else if (tt.StartsWith("medium")) { enchanterSize = EnchanterSize.Medium; } factory[tt] = (string tag) => { return(new HunterTrophy(kind) { EnchanterSize = enchanterSize, tag1 = tag }); }; } //gems var gemTagTypes = new[] { "diamond", "emerald", "ruby", "amber" }; var gemTagSizes = new[] { "big", "medium", "small" }; List <string> gemTags = new List <string>(); foreach (var gt in gemTagTypes) { foreach (var gs in gemTagSizes) { gemTags.Add(gt + "_" + gs); } } foreach (var gemTag in gemTags) { EnchanterSize enchanterSize = EnchanterSize.Small; if (gemTag.EndsWith("big")) { enchanterSize = EnchanterSize.Big; } else if (gemTag.EndsWith("medium")) { enchanterSize = EnchanterSize.Medium; } GemKind gemKind = GemKind.Diamond; if (gemTag.StartsWith("emerald")) { gemKind = GemKind.Emerald; } else if (gemTag.StartsWith("ruby")) { gemKind = GemKind.Ruby; } else if (gemTag.StartsWith("amber")) { gemKind = GemKind.Amber; } factory[gemTag] = (string tag) => { return(new Gem(gemKind) { EnchanterSize = enchanterSize }); }; } }