Exemplo n.º 1
0
        private static void AddRewardItemsToInventory(GameSession session, RecipeMetadata recipe)
        {
            // award items
            List <RecipeItem> result = recipe.GetResult();

            for (int i = 0; i < result.Count; i++)
            {
                Item rewardItem = new(result.ElementAt(i).Id)
                {
                    Rarity = result.ElementAt(i).Rarity,
                    Amount = result.ElementAt(i).Amount
                };
                InventoryController.Add(session, rewardItem, true);
            }

            // add mastery exp
            session.Player.Levels.GainMasteryExp(Enum.Parse <MasteryType>(recipe.MasteryType, true),
                                                 recipe.RewardMastery);

            // add player exp
            if (recipe.HasExpReward())
            {
                // TODO: add metadata for common exp tables to be able to look up exp amount for masteries etc.
            }
        }
Exemplo n.º 2
0
        private static bool RemoveRequiredItemsFromInventory(GameSession session, RecipeMetadata recipe)
        {
            List <Item>       playerInventoryItems = new(session.Player.Inventory.Items.Values);
            List <RecipeItem> ingredients          = recipe.GetIngredients();

            for (int i = 0; i < ingredients.Count; i++)
            {
                RecipeItem ingredient = ingredients.ElementAt(i);
                Item       item       = playerInventoryItems.FirstOrDefault(x => x.Id == ingredient.Id);
                if (item == null)
                {
                    continue;
                }

                // check if whole stack will be used, and remove the item
                // otherwise we want to just want to subtract the amount
                if (ingredient.Amount == item.Amount)
                {
                    InventoryController.Remove(session, item.Uid, out Item _);
                }
                else
                {
                    InventoryController.Update(session, item.Uid, item.Amount - ingredient.Amount);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        private void HandleCraftItem(GameSession session, PacketReader packet)
        {
            int recipeId = packet.ReadInt();

            // attempt to oad the recipe metadata
            RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(recipeId);

            if (recipe == null)
            {
                Logger.LogError($"Unknown recipe ID {recipeId} from user: {session.Player.Name}");
                return;
            }

            // does the play have enough mesos for this recipe?
            if (!session.Player.Wallet.Meso.Modify(-recipe.GetMesosRequired()))
            {
                // send notice to player saying they haven't got enough mesos
                session.SendNotice("You don't have enough mesos.");
                return;
            }

            // does the player have all the required ingredients for this recipe?
            if (!PlayerHasAllIngredients(session, recipe))
            {
                // send notice to player saying they haven't got enough materials
                session.SendNotice("You've run out of materials.");
                return;
            }

            // only add reward items once all required items & mesos have been removed from player
            if (RemoveRequiredItemsFromInventory(session, recipe))
            {
                AddRewardItemsToInventory(session, recipe);
            }
        }
Exemplo n.º 4
0
        public static List <RecipeItem> GetResult(this RecipeMetadata recipe)
        {
            List <RecipeItem> result      = new List <RecipeItem>();
            List <string>     rewardItems = new List <string>
            {
                recipe.RewardItem1,
                recipe.RewardItem2,
                recipe.RewardItem3,
                recipe.RewardItem4,
                recipe.RewardItem5
            };

            foreach (string rewardItem in rewardItems)
            {
                if (string.IsNullOrEmpty(rewardItem))
                {
                    continue;
                }

                List <int> split = new List <int>(Array.ConvertAll(rewardItem.Split(','), int.Parse));
                result.Add(new RecipeItem {
                    Id = split[0], Rarity = split[1], Amount = split[2]
                });
            }

            return(result);
        }
Exemplo n.º 5
0
    private static void AddRewardItemsToInventory(GameSession session, RecipeMetadata recipe)
    {
        // award items
        List <RecipeItem> resultItems = recipe.RewardItems;

        foreach (RecipeItem resultItem in resultItems)
        {
            Item rewardItem = new(resultItem.ItemId)
            {
                Rarity = resultItem.Rarity,
                Amount = resultItem.Amount
            };
            session.Player.Inventory.AddItem(session, rewardItem, true);
            session.Send(MasteryPacket.GetCraftedItem((MasteryType)recipe.MasteryType, rewardItem));
        }

        // add mastery exp
        session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, recipe.RewardMastery);

        // add player exp
        if (recipe.ExceptRewardExp)
        {
            // TODO: add metadata for common exp tables to be able to look up exp amount for masteries etc.
        }
    }
Exemplo n.º 6
0
        public static void HandleGathering(GameSession session, int recipeId, out int numDrop)
        {
            numDrop = 0;
            RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(recipeId);

            if (recipe == null)
            {
                return;
            }

            long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == (MasteryType)recipe.MasteryType).CurrentExp;

            if (currentMastery < recipe.RequireMastery)
            {
                return;
            }

            session.Player.IncrementGatheringCount(recipe.Id, 0);
            int numCount = session.Player.GatheringCount.FirstOrDefault(x => x.RecipeId == recipe.Id).CurrentCount;

            List <RecipeItem> items = recipe.RewardItems;
            int masteryDiffFactor   = numCount switch
            {
                int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0),
                int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1),
                int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2),
                _ => MasteryFactorMetadataStorage.GetFactor(3)
            };

            if (masteryDiffFactor == 0)
            {
                return;
            }

            foreach (RecipeItem item in items)
            {
                int prob = masteryDiffFactor / 100;
                if (RandomProvider.Get().Next(100) >= prob)
                {
                    continue;
                }

                session.FieldManager.AddItem(session, new Item(item.ItemId)
                {
                    Rarity = item.Rarity,
                    Amount = item.Amount
                });

                numDrop += item.Amount;
            }
            if (numDrop <= 0)
            {
                return;
            }

            session.Player.IncrementGatheringCount(recipe.Id, 1);
            session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, recipe.RewardMastery);
        }
    }
Exemplo n.º 7
0
        public Dictionary <Guid, RecipeMetadata> GetIndexedRecipeMetadata()
        {
            if (indexedRecipeMetadata == null)
            {
                indexedRecipeMetadata = RecipeMetadata.ToDictionary(m => m.RecipeId);
            }

            return(indexedRecipeMetadata);
        }
Exemplo n.º 8
0
        public static long GetMesosRequired(this RecipeMetadata recipe)
        {
            if (string.IsNullOrEmpty(recipe.RequireMeso))
            {
                return(0);
            }

            return(long.Parse(recipe.RequireMeso));
        }
Exemplo n.º 9
0
        private void HandleCraftItem(GameSession session, PacketReader packet)
        {
            int recipeId = packet.ReadInt();

            // attempt to oad the recipe metadata
            RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(recipeId);

            if (recipe == null)
            {
                Logger.LogError($"Unknown recipe ID {recipeId} from user: {session.Player.Name}");
                return;
            }

            if (recipe.RequireMastery > 0)
            {
                if (session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == (MasteryType)recipe.MasteryType).CurrentExp < recipe.RequireMastery)
                {
                    session.Send(MasteryPacket.MasteryNotice((short)MasteryNotice.NotEnoughMastery));
                    return;
                }
            }

            if (recipe.RequireQuest.Count > 0)
            {
                foreach (int questId in recipe.RequireQuest)
                {
                    QuestStatus quest = session.Player.QuestList.FirstOrDefault(x => x.Basic.Id == questId);
                    if (quest == null || !quest.Completed)
                    {
                        session.Send(MasteryPacket.MasteryNotice((short)MasteryNotice.RequiredQuestIsNotCompleted));
                        return;
                    }
                }
            }

            // does the play have enough mesos for this recipe?
            if (!session.Player.Wallet.Meso.Modify(-recipe.RequireMeso))
            {
                session.Send(MasteryPacket.MasteryNotice((short)MasteryNotice.NotEnoughMesos));
                return;
            }

            // does the player have all the required ingredients for this recipe?
            if (!PlayerHasAllIngredients(session, recipe))
            {
                session.Send(MasteryPacket.MasteryNotice((short)MasteryNotice.NotEnoughItems));
                return;
            }

            // only add reward items once all required items & mesos have been removed from player
            if (RemoveRequiredItemsFromInventory(session, recipe))
            {
                AddRewardItemsToInventory(session, recipe);
            }
        }
Exemplo n.º 10
0
        private static bool PlayerHasEnoughMesos(GameSession session, RecipeMetadata recipe)
        {
            long mesoBalance = session.Player.Wallet.Meso.Amount;

            if (mesoBalance == 0)
            {
                return(false);
            }

            return(mesoBalance >= recipe.GetMesosRequired());
        }
Exemplo n.º 11
0
        public IEnumerable <RecipeBinding> LoadRecipeGraph()
        {
            using (var session = GetStatelessSession())
            {
                RecipeMetadata metadata = null;
                var            recipes  = session.QueryOver <Models.Recipes>()
                                          .JoinAlias(r => r.RecipeMetadata, () => metadata)
                                          .Select(
                    p => p.RecipeId,
                    p => p.Rating,
                    p => metadata.DietGlutenFree,
                    p => metadata.DietNoAnimals,
                    p => metadata.DietNomeat,
                    p => metadata.DietNoPork,
                    p => metadata.DietNoRedMeat,
                    p => metadata.MealBreakfast,
                    p => metadata.MealDessert,
                    p => metadata.MealDinner,
                    p => metadata.MealLunch,
                    p => metadata.NutritionLowCalorie,
                    p => metadata.NutritionLowCarb,
                    p => metadata.NutritionLowFat,
                    p => metadata.NutritionLowSodium,
                    p => metadata.NutritionLowSugar,
                    p => metadata.SkillCommon,
                    p => metadata.SkillEasy,
                    p => metadata.SkillQuick)
                                          .List <Object[]>();

                return(recipes.Select(r => new RecipeBinding
                {
                    Id = (Guid)r[0],
                    Rating = Convert.ToByte(r[1]),
                    Tags = ((bool)r[2] ? 1 << 0 : 0) +
                           ((bool)r[3] ? 1 << 1 : 0) +
                           ((bool)r[4] ? 1 << 2 : 0) +
                           ((bool)r[5] ? 1 << 3 : 0) +
                           ((bool)r[6] ? 1 << 4 : 0) +
                           ((bool)r[7] ? 1 << 5 : 0) +
                           ((bool)r[8] ? 1 << 6 : 0) +
                           ((bool)r[9] ? 1 << 7 : 0) +
                           ((bool)r[10] ? 1 << 8 : 0) +
                           ((bool)r[11] ? 1 << 9 : 0) +
                           ((bool)r[12] ? 1 << 10 : 0) +
                           ((bool)r[13] ? 1 << 11 : 0) +
                           ((bool)r[14] ? 1 << 12 : 0) +
                           ((bool)r[15] ? 1 << 13 : 0) +
                           ((bool)r[16] ? 1 << 14 : 0) +
                           ((bool)r[17] ? 1 << 15 : 0) +
                           ((bool)r[18] ? 1 << 16 : 0)
                }).ToList());
            }
        }
Exemplo n.º 12
0
    private static bool PlayerHasAllIngredients(GameSession session, RecipeMetadata recipe)
    {
        List <RecipeItem> ingredients = recipe.RequiredItems;

        foreach (RecipeItem ingredient in ingredients)
        {
            Item item = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Id == ingredient.ItemId && x.Rarity == ingredient.Rarity);
            if (item == null || item.Amount < ingredient.Amount)
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 13
0
    private void UpdateCraftRecipeIcons(RectTransform recipePanel, ObjectMetadata item)
    {
        //ObjectMetadata objectData = metadataManager.GetObjectMetadataWithObjectId(item.objectId);
        RecipeMetadata selectedRecipe = MetadataLoader.Instance.GetRecipeMetadataById(item.recipeId);

        Image[] recipeIcons = recipePanel.GetComponentsInChildren <Image>();

        for (int i = 0; i < recipeIcons.Length; i++)
        {
            ResourceMetadata resource = metadataManager.GetResourceMetadataByType(selectedRecipe.resources[i]);
            if (resource != null)
            {
                recipeIcons[i].sprite = resource.icon;
            }
        }
    }
Exemplo n.º 14
0
        private static bool PlayerHasAllIngredients(GameSession session, RecipeMetadata recipe)
        {
            List <Item>       playerInventoryItems = new(session.Player.Inventory.Items.Values);
            List <RecipeItem> ingredients          = recipe.GetIngredients();

            for (int i = 0; i < ingredients.Count; i++)
            {
                RecipeItem ingredient = ingredients.ElementAt(i);
                Item       item       = playerInventoryItems.FirstOrDefault(x => x.Id == ingredient.Id);
                if (item != null)
                {
                    return(item.Amount >= ingredient.Amount);
                }
            }

            return(false);
        }
Exemplo n.º 15
0
        private static bool RemoveRequiredItemsFromInventory(GameSession session, RecipeMetadata recipe)
        {
            List <RecipeItem> ingredients = recipe.RequiredItems;

            foreach (RecipeItem ingredient in ingredients)
            {
                Item item = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Id == ingredient.ItemId && x.Rarity == ingredient.Rarity);
                if (item == null || item.Amount < ingredient.Amount)
                {
                    return(false);
                }

                InventoryController.Consume(session, item.Uid, ingredient.Amount);
            }

            return(true);
        }
Exemplo n.º 16
0
    public List <RecipeMetadata> GetRecipeMetadata()
    {
        if (recipeList != null)
        {
            return(recipeList);
        }
        recipeList = new List <RecipeMetadata>();

        SqliteCommand    cmd    = sqlHelper.CreateTextCommand("SELECT * FROM recipe_metadata");
        SqliteDataReader reader = sqlHelper.ExecuteCommand(cmd);

        while (reader.Read())
        {
            RecipeMetadata row = new RecipeMetadata(reader);
            recipeList.Add(row);
        }
        sqlHelper.CloseResultReader(reader);

        return(recipeList);
    }
Exemplo n.º 17
0
        public IEnumerable <RecipeBinding> LoadRecipeGraph()
        {
            if (recipedata != null)
            {
                return(recipedata);
            }

            // Initialize Recipe Graph
            var metadata = store.GetIndexedRecipeMetadata();
            var graph    = (from r in store.Recipes
                            join m in metadata on r.RecipeId equals m.Key
                            select new RecipeBinding
            {
                Id = r.RecipeId,
                Rating = Convert.ToByte(r.Rating),
                Tags = RecipeMetadata.ToRecipeTags(m.Value)
            });

            return(recipedata = graph);
        }
Exemplo n.º 18
0
    private ObjectMetadata FindMatchingRecipeObject()
    {
        foreach (var obj in metadataManager.objectsDictionary)
        {
            ObjectMetadata data = obj.Value;
            if (!CraftingManager.Instance.IsCraftAvailable(data))
            {
                continue;
            }

            RecipeMetadata recipe = MetadataLoader.Instance.GetRecipeMetadataById(data.recipeId);

            if (recipe != null)
            {
                bool doesMatch = true;
                for (int i = 0; i < recipe.resources.Count; i++)
                {
                    if (i == resourceList.Count)
                    {
                        doesMatch = false;
                        break;
                    }

                    if (resourceList[i].resourceEnum != recipe.resources[i])
                    {
                        doesMatch = false;
                        break;
                    }
                }

                if (doesMatch)
                {
                    return(data);
                }
            }
        }

        return(null);
    }
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string uuid = packet.ReadMapleString();
            IFieldObject <InteractObject> interactObject = session.FieldManager.State.InteractObjects[uuid];

            if (interactObject == null)
            {
                return;
            }

            MapInteractObject mapObject = MapEntityStorage.GetInteractObject(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);
            int numDrop = 0;

            switch (interactObject.Value.Type)
            {
            case InteractObjectType.Binoculars:
                QuestHelper.UpdateExplorationQuest(session, mapObject.InteractId.ToString(), "interact_object_rep");
                break;

            case InteractObjectType.Gathering:
                RecipeMetadata recipe = RecipeMetadataStorage.GetRecipe(mapObject.RecipeId);

                session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, 0);
                long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == (MasteryType)recipe.MasteryType).CurrentExp;
                if (currentMastery < recipe.RequireMastery)
                {
                    return;
                }

                session.Player.IncrementGatheringCount(mapObject.RecipeId, 0);
                int numCount = session.Player.GatheringCount[mapObject.RecipeId].Current;

                List <RecipeItem> items = RecipeMetadataStorage.GetResult(recipe);
                int masteryDiffFactor   = numCount switch
                {
                    int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0),
                    int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1),
                    int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2),
                    _ => MasteryFactorMetadataStorage.GetFactor(3),
                };

                foreach (RecipeItem item in items)
                {
                    int prob = RarityChance[item.Rarity] * masteryDiffFactor / 10000;
                    if (RandomProvider.Get().Next(100) >= prob)
                    {
                        continue;
                    }
                    for (int i = 0; i < item.Amount; i++)
                    {
                        session.FieldManager.AddItem(session, new Item(item.Id));
                    }
                    numDrop += item.Amount;
                }
                if (numDrop > 0)
                {
                    session.Player.IncrementGatheringCount(mapObject.RecipeId, numDrop);
                    session.Player.Levels.GainMasteryExp((MasteryType)recipe.MasteryType, recipe.RewardMastery);
                }
                break;

            case InteractObjectType.AdBalloon:
                session.Send(PlayerHostPacket.AdBalloonWindow(interactObject));
                return;

            default:
                break;
            }
            session.Send(InteractObjectPacket.UseObject(mapObject, (short)(numDrop > 0 ? 0 : 1), numDrop));
            session.Send(InteractObjectPacket.Extra(mapObject));
        }
Exemplo n.º 20
0
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string            uuid           = packet.ReadMapleString();
            MapInteractObject interactObject = MapEntityStorage.GetInteractObject(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);
            int numDrop = 0;

            if (interactObject == null)
            {
                return;
            }
            if (interactObject.Type == InteractObjectType.Binoculars)
            {
                QuestHelper.UpdateExplorationQuest(session, interactObject.InteractId.ToString(), "interact_object_rep");
            }
            else if (interactObject.Type == InteractObjectType.Gathering)
            {
                RecipeMetadata    recipe         = RecipeMetadataStorage.GetRecipe(interactObject.RecipeId);
                long              requireMastery = int.Parse(recipe.RequireMastery);
                Enums.MasteryType type           = (Enums.MasteryType) int.Parse(recipe.MasteryType);

                session.Player.Levels.GainMasteryExp(type, 0);
                long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == type).CurrentExp;
                if (currentMastery < requireMastery)
                {
                    return;
                }

                session.Player.IncrementGatheringCount(interactObject.RecipeId, 0);
                int numCount = session.Player.GatheringCount[interactObject.RecipeId].Current;

                List <RecipeItem> items = RecipeMetadataStorage.GetResult(recipe);
                Random            rand  = new Random();
                int masteryDiffFactor   = numCount switch
                {
                    int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0),
                    int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1),
                    int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2),
                    _ => MasteryFactorMetadataStorage.GetFactor(3),
                };

                foreach (RecipeItem item in items)
                {
                    int prob = (int)(RarityChance[item.Rarity] * masteryDiffFactor) / 10000;
                    if (rand.Next(100) >= prob)
                    {
                        continue;
                    }
                    for (int i = 0; i < item.Amount; i++)
                    {
                        session.FieldManager.AddItem(session, new Item(item.Id));
                    }
                    numDrop += item.Amount;
                }
                if (numDrop > 0)
                {
                    session.Player.IncrementGatheringCount(interactObject.RecipeId, numDrop);
                    session.Player.Levels.GainMasteryExp(type, recipe.RewardMastery);
                }
            }
            session.Send(InteractObjectPacket.UseObject(interactObject, (short)(numDrop > 0 ? 0 : 1), numDrop));
            session.Send(InteractObjectPacket.Extra(interactObject));
        }
Exemplo n.º 21
0
 public static bool HasExpReward(this RecipeMetadata recipe)
 {
     return(!recipe.ExceptRewardExp);
 }
Exemplo n.º 22
0
        public RecipeResult CreateRecipe(AuthIdentity identity, Recipe recipe)
        {
            using (var session = this.GetSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    // Create Recipe
                    var recipes = new Recipes
                    {
                        Title = recipe.Title,
                        Description = recipe.Description,
                        CookTime = recipe.CookTime,
                        PrepTime = recipe.PreparationTime,
                        Credit = recipe.Credit,
                        CreditUrl = recipe.CreditUrl,
                        DateEntered = recipe.DateEntered,
                        ImageUrl = recipe.ImageUrl,
                        Rating = recipe.AvgRating,
                        ServingSize = recipe.ServingSize,
                        Steps = recipe.Method
                    };

                    session.Save(recipes);

                    // Create Ingredients
                    short displayOrder = 0;
                    recipe.Ingredients.ForEach(i =>
                    {
                        var dbIngredient = new RecipeIngredients
                        {
                            Recipe = recipes,
                            Ingredient = Ingredients.FromId(i.Ingredient.Id),
                            IngredientForm = i.Form != null ? IngredientForms.FromId(i.Form.FormId) : null,
                            Qty = i.Amount != null ? (float?)i.Amount.SizeHigh : null,
                            QtyLow = i.Amount != null ? (float?)i.Amount.SizeLow : null,
                            Unit = i.Amount != null ? i.Amount.Unit : Units.Unit,
                            Section = i.Section,
                            DisplayOrder = ++displayOrder
                        };

                        session.Save(dbIngredient);
                    });

                    // Create RecipeMetadata
                    var recipeMetadata = new RecipeMetadata
                    {
                        Recipe = recipes,
                        DietGlutenFree = recipe.Tags.HasTag(RecipeTag.GlutenFree),
                        DietNoAnimals = recipe.Tags.HasTag(RecipeTag.NoAnimals),
                        DietNomeat = recipe.Tags.HasTag(RecipeTag.NoMeat),
                        DietNoPork = recipe.Tags.HasTag(RecipeTag.NoPork),
                        DietNoRedMeat = recipe.Tags.HasTag(RecipeTag.NoRedMeat),
                        MealBreakfast = recipe.Tags.HasTag(RecipeTag.Breakfast),
                        MealDessert = recipe.Tags.HasTag(RecipeTag.Dessert),
                        MealDinner = recipe.Tags.HasTag(RecipeTag.Dinner),
                        MealLunch = recipe.Tags.HasTag(RecipeTag.Lunch),
                        NutritionLowCalorie = recipe.Tags.HasTag(RecipeTag.LowCalorie),
                        NutritionLowCarb = recipe.Tags.HasTag(RecipeTag.LowCarb),
                        NutritionLowFat = recipe.Tags.HasTag(RecipeTag.LowFat),
                        NutritionLowSodium = recipe.Tags.HasTag(RecipeTag.LowSodium),
                        NutritionLowSugar = recipe.Tags.HasTag(RecipeTag.LowSugar),
                        SkillCommon = recipe.Tags.HasTag(RecipeTag.CommonIngredients),
                        SkillEasy = recipe.Tags.HasTag(RecipeTag.EasyToMake),
                        SkillQuick = recipe.Tags.HasTag(RecipeTag.Quick)
                    };

                    session.Save(recipeMetadata);
                    transaction.Commit();

                    return new RecipeResult
                    {
                        RecipeCreated = true,
                        NewRecipeId = recipes.RecipeId
                    };
                }
            }
        }
Exemplo n.º 23
0
        private static void HandleUse(GameSession session, PacketReader packet)
        {
            string           uuid  = packet.ReadMapleString();
            MapInteractActor actor = MapEntityStorage.GetInteractActors(session.Player.MapId).FirstOrDefault(x => x.Uuid == uuid);
            int numDrop            = 0;

            if (actor == null)
            {
                return;
            }
            if (actor.Type == InteractActorType.Binoculars)
            {
                List <QuestStatus> questList = session.Player.QuestList;
                foreach (QuestStatus item in questList.Where(x => x.Basic.QuestID >= 72000000 && x.Condition != null))
                {
                    QuestCondition condition = item.Condition.FirstOrDefault(x => x.Code != "" && int.Parse(x.Code) == actor.InteractId);
                    if (condition == null)
                    {
                        continue;
                    }

                    item.Completed         = true;
                    item.CompleteTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    session.Send(QuestPacket.CompleteExplorationGoal(item.Basic.QuestID));
                    session.Send(QuestPacket.CompleteQuest(item.Basic.QuestID));
                    break;
                }
            }
            else if (actor.Type == InteractActorType.Gathering)
            {
                RecipeMetadata    recipe         = RecipeMetadataStorage.GetRecipe(actor.RecipeId);
                long              requireMastery = int.Parse(recipe.RequireMastery);
                Enums.MasteryType type           = (Enums.MasteryType) int.Parse(recipe.MasteryType);

                session.Player.Levels.GainMasteryExp(type, 0);
                long currentMastery = session.Player.Levels.MasteryExp.FirstOrDefault(x => x.Type == type).CurrentExp;
                if (currentMastery < requireMastery)
                {
                    return;
                }

                session.Player.IncrementGatheringCount(actor.RecipeId, 0);
                int numCount = session.Player.GatheringCount[actor.RecipeId].Current;

                List <RecipeItem> items = RecipeMetadataStorage.GetResult(recipe);
                Random            rand  = new Random();
                int masteryDiffFactor   = numCount switch
                {
                    int n when n < recipe.HighPropLimitCount => MasteryFactorMetadataStorage.GetFactor(0),
                    int n when n < recipe.NormalPropLimitCount => MasteryFactorMetadataStorage.GetFactor(1),
                    int n when n < (int)(recipe.NormalPropLimitCount * 1.3) => MasteryFactorMetadataStorage.GetFactor(2),
                    _ => MasteryFactorMetadataStorage.GetFactor(3),
                };

                foreach (RecipeItem item in items)
                {
                    int prob = (int)(RarityChance[item.Rarity] * masteryDiffFactor) / 10000;
                    if (rand.Next(100) >= prob)
                    {
                        continue;
                    }
                    for (int i = 0; i < item.Amount; i++)
                    {
                        session.FieldManager.AddItem(session, new Item(item.Id));
                    }
                    numDrop += item.Amount;
                }
                if (numDrop > 0)
                {
                    session.Player.IncrementGatheringCount(actor.RecipeId, numDrop);
                    session.Player.Levels.GainMasteryExp(type, recipe.RewardMastery);
                }
            }
            session.Send(InteractActorPacket.UseObject(actor, numDrop > 0 ? 0 : 1, numDrop));
            session.Send(InteractActorPacket.Extra(actor));
        }
Exemplo n.º 24
0
        public SearchResults Search(AuthIdentity identity, RecipeQuery query)
        {
            using (var session = this.adapter.GetSession())
            {
                Recipes recipe = null;

                var q = session.QueryOver <Recipes>(() => recipe)
                        .Where(p => !p.Hidden);

                // Add keyword search
                if (!string.IsNullOrWhiteSpace(query.Keywords))
                {
                    q = q.Where(
                        Restrictions.Or(
                            Restrictions.InsensitiveLike("Title", string.Format("%{0}%", query.Keywords.Trim())),
                            Restrictions.InsensitiveLike("Description", string.Format("%{0}%", query.Keywords.Trim()))));
                }

                if (query.Time.MaxPrep.HasValue)
                {
                    q = q.Where(p => p.PrepTime <= query.Time.MaxPrep.Value);
                }

                if (query.Time.MaxCook.HasValue)
                {
                    q = q.Where(p => p.CookTime <= query.Time.MaxCook.Value);
                }

                if (query.Rating > 0)
                {
                    q = q.Where(p => p.Rating >= (int)query.Rating);
                }

                // Add ingredients to include
                if (query.Include != null && query.Include.Length > 0)
                {
                    // Create a sub-query for ingredients to include
                    q = q.WithSubquery
                        .WhereExists(QueryOver.Of <RecipeIngredients>()
                                     .Where(item => item.Recipe.RecipeId == recipe.RecipeId)
                                     .Where(Restrictions.InG("Ingredient", query.Include.Select(Models.Ingredients.FromId).ToArray()))
                                     .Select(i => i.RecipeIngredientId).Take(1));
                }

                // Add ingredients to exclude
                if (query.Exclude != null && query.Exclude.Length > 0)
                {
                    // Create a sub-query for ingredients to exclude
                    q = q.WithSubquery
                        .WhereNotExists(QueryOver.Of <RecipeIngredients>()
                                        .Where(item => item.Recipe.RecipeId == recipe.RecipeId)
                                        .Where(Restrictions.InG("Ingredient", query.Exclude.Select(Models.Ingredients.FromId).ToArray()))
                                        .Select(i => i.RecipeIngredientId).Take(1));
                }

                if (query.Photos == PhotoFilter.Photo || query.Photos == PhotoFilter.HighRes)
                {
                    q = q.Where(Restrictions.IsNotNull("ImageUrl"));
                }

                // Need to search in metadata
                if (query.Diet || query.Nutrition || query.Skill || query.Taste || (query.Meal != MealFilter.All) || (query.Photos == PhotoFilter.HighRes))
                {
                    RecipeMetadata metadata = null;
                    q = q.JoinAlias(r => r.RecipeMetadata, () => metadata);

                    // Meal
                    if (query.Meal != MealFilter.All)
                    {
                        if (query.Meal == MealFilter.Breakfast)
                        {
                            q = q.Where(() => metadata.MealBreakfast);
                        }

                        if (query.Meal == MealFilter.Dessert)
                        {
                            q = q.Where(() => metadata.MealDessert);
                        }

                        if (query.Meal == MealFilter.Dinner)
                        {
                            q = q.Where(() => metadata.MealDinner);
                        }

                        if (query.Meal == MealFilter.Lunch)
                        {
                            q = q.Where(() => metadata.MealLunch);
                        }
                    }

                    // High-res photos
                    if (query.Photos == PhotoFilter.HighRes)
                    {
                        q = q.Where(() => metadata.PhotoRes >= 1024 * 768);
                    }

                    // Diet
                    if (query.Diet.GlutenFree)
                    {
                        q = q.Where(() => metadata.DietGlutenFree);
                    }

                    if (query.Diet.NoAnimals)
                    {
                        q = q.Where(() => metadata.DietNoAnimals);
                    }

                    if (query.Diet.NoMeat)
                    {
                        q = q.Where(() => metadata.DietNomeat);
                    }

                    if (query.Diet.NoPork)
                    {
                        q = q.Where(() => metadata.DietNoPork);
                    }

                    if (query.Diet.NoRedMeat)
                    {
                        q = q.Where(() => metadata.DietNoRedMeat);
                    }

                    // Nutrition
                    if (query.Nutrition.LowCalorie)
                    {
                        q = q.Where(() => metadata.NutritionLowCalorie);
                    }

                    if (query.Nutrition.LowCarb)
                    {
                        q = q.Where(() => metadata.NutritionLowCarb);
                    }

                    if (query.Nutrition.LowFat)
                    {
                        q = q.Where(() => metadata.NutritionLowFat);
                    }

                    if (query.Nutrition.LowSodium)
                    {
                        q = q.Where(() => metadata.NutritionLowSodium);
                    }

                    if (query.Nutrition.LowSugar)
                    {
                        q = q.Where(() => metadata.NutritionLowSugar);
                    }

                    // Skill
                    if (query.Skill.Common)
                    {
                        q = q.Where(() => metadata.SkillCommon).OrderBy(() => metadata.Commonality).Desc();
                    }

                    if (query.Skill.Easy)
                    {
                        q = q.Where(() => metadata.SkillEasy);
                    }

                    if (query.Skill.Quick)
                    {
                        q = q.Where(() => metadata.SkillQuick);
                    }

                    // Taste
                    if (query.Taste.MildToSpicy != SpicinessLevel.Medium)
                    {
                        q = query.Taste.MildToSpicy < SpicinessLevel.Medium
                           ? q.Where(() => metadata.TasteMildToSpicy <= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Asc()
                           : q.Where(() => metadata.TasteMildToSpicy >= query.Taste.Spiciness).OrderBy(() => metadata.TasteMildToSpicy).Desc();
                    }

                    if (query.Taste.SavoryToSweet != SweetnessLevel.Medium)
                    {
                        q = query.Taste.SavoryToSweet < SweetnessLevel.Medium
                           ? q.Where(() => metadata.TasteSavoryToSweet <= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Asc()
                           : q.Where(() => metadata.TasteSavoryToSweet >= query.Taste.Sweetness).OrderBy(() => metadata.TasteSavoryToSweet).Desc();
                    }
                }

                IQueryOverOrderBuilder <Recipes, Recipes> orderBy;
                switch (query.Sort)
                {
                case SortOrder.Title:
                    orderBy = q.OrderBy(p => p.Title);
                    break;

                case SortOrder.PrepTime:
                    orderBy = q.OrderBy(p => p.PrepTime);
                    break;

                case SortOrder.CookTime:
                    orderBy = q.OrderBy(p => p.CookTime);
                    break;

                case SortOrder.Image:
                    orderBy = q.OrderBy(p => p.ImageUrl);
                    break;

                default:
                    orderBy = q.OrderBy(p => p.Rating);
                    break;
                }

                var results = (query.Direction == SortDirection.Descending ? orderBy.Desc() : orderBy.Asc())
                              .Skip(query.Offset)
                              .List();

                return(new SearchResults
                {
                    Briefs = results.Select(r => r.AsRecipeBrief()).ToArray(),
                    TotalCount = results.Count
                });
            }
        }
Exemplo n.º 25
0
        public RecipeResult CreateRecipe(AuthIdentity identity, Recipe recipe)
        {
            using (var session = GetSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    // Create Recipe
                    var dbRecipe = new Models.Recipes
                    {
                        Title       = recipe.Title,
                        Description = recipe.Description,
                        CookTime    = recipe.CookTime,
                        PrepTime    = recipe.PrepTime,
                        Credit      = recipe.Credit,
                        CreditUrl   = recipe.CreditUrl,
                        DateEntered = recipe.DateEntered,
                        ImageUrl    = recipe.ImageUrl,
                        Rating      = recipe.AvgRating,
                        ServingSize = recipe.ServingSize,
                        Steps       = recipe.Method
                    };

                    session.Save(dbRecipe);

                    // Create Ingredients
                    short displayOrder = 0;
                    recipe.Ingredients.ForEach(i =>
                    {
                        var dbIngredient = new RecipeIngredients
                        {
                            Recipe         = dbRecipe,
                            Ingredient     = Models.Ingredients.FromId(i.Ingredient.Id),
                            IngredientForm = (i.Form != null ? IngredientForms.FromId(i.Form.FormId) : null),
                            Qty            = (i.Amount != null ? (float?)i.Amount.SizeHigh : null),
                            QtyLow         = (i.Amount != null ? (float?)i.Amount.SizeLow : null),
                            Unit           = (i.Amount != null ? i.Amount.Unit : Units.Unit),
                            Section        = i.Section,
                            DisplayOrder   = ++displayOrder
                        };

                        session.Save(dbIngredient);
                    });

                    // Create RecipeMetadata
                    var dbMetadata = new RecipeMetadata
                    {
                        Recipe              = dbRecipe,
                        DietGlutenFree      = recipe.Tags.HasTag(RecipeTag.GlutenFree),
                        DietNoAnimals       = recipe.Tags.HasTag(RecipeTag.NoAnimals),
                        DietNomeat          = recipe.Tags.HasTag(RecipeTag.NoMeat),
                        DietNoPork          = recipe.Tags.HasTag(RecipeTag.NoPork),
                        DietNoRedMeat       = recipe.Tags.HasTag(RecipeTag.NoRedMeat),
                        MealBreakfast       = recipe.Tags.HasTag(RecipeTag.Breakfast),
                        MealDessert         = recipe.Tags.HasTag(RecipeTag.Dessert),
                        MealDinner          = recipe.Tags.HasTag(RecipeTag.Dinner),
                        MealLunch           = recipe.Tags.HasTag(RecipeTag.Lunch),
                        NutritionLowCalorie = recipe.Tags.HasTag(RecipeTag.LowCalorie),
                        NutritionLowCarb    = recipe.Tags.HasTag(RecipeTag.LowCarb),
                        NutritionLowFat     = recipe.Tags.HasTag(RecipeTag.LowFat),
                        NutritionLowSodium  = recipe.Tags.HasTag(RecipeTag.LowSodium),
                        NutritionLowSugar   = recipe.Tags.HasTag(RecipeTag.LowSugar),
                        SkillCommon         = recipe.Tags.HasTag(RecipeTag.Common),
                        SkillEasy           = recipe.Tags.HasTag(RecipeTag.Easy),
                        SkillQuick          = recipe.Tags.HasTag(RecipeTag.Quick)
                    };

                    session.Save(dbMetadata);
                    transaction.Commit();

                    return(new RecipeResult
                    {
                        RecipeCreated = true,
                        NewRecipeId = dbRecipe.RecipeId
                    });
                }
            }
        }