Exemplo n.º 1
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.º 2
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.º 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;
            }

            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.º 4
0
 public void IncrementGatheringCount(int recipeID, int amount)
 {
     if (!GatheringCount.ContainsKey(recipeID))
     {
         int maxLimit = (int)(RecipeMetadataStorage.GetRecipe(recipeID).NormalPropLimitCount * 1.4);
         GatheringCount[recipeID] = new PlayerStat(maxLimit, 0, 0);
     }
     if ((GatheringCount[recipeID].Current + amount) <= GatheringCount[recipeID].Max)
     {
         PlayerStat stat = GatheringCount[recipeID];
         stat.Current            += amount;
         GatheringCount[recipeID] = stat;
     }
 }
Exemplo n.º 5
0
        public void IncrementGatheringCount(int recipeID, int amount)
        {
            GatheringCount gatheringCount = GatheringCount.FirstOrDefault(x => x.RecipeId == recipeID);

            if (gatheringCount is null)
            {
                int maxLimit = (int)(RecipeMetadataStorage.GetRecipe(recipeID).NormalPropLimitCount * 1.4);
                gatheringCount = new GatheringCount(recipeID, 0, maxLimit);
                GatheringCount.Add(gatheringCount);
            }

            if (gatheringCount.CurrentCount + amount <= gatheringCount.MaxCount)
            {
                gatheringCount.CurrentCount += amount;
            }
        }
        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));
        }
        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));
        }
        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));
        }