private void ExecuteHandler(ClientSession session)
        {
            ClientSession client =
                ServerManager.Instance.Sessions.FirstOrDefault(s =>
                                                               s.Character?.Miniland == session.Character.MapInstance);
            MinilandObject mlobj =
                client?.Character.MinilandObjects.Find(s => s.ItemInstance.ItemVNum == MinigameVNum);

            if (mlobj != null)
            {
                const bool full = false;
                byte       game = (byte)(mlobj.ItemInstance.Item.EquipmentSlot);
                switch (Type)
                {
                //play
                case 1:
                    if (mlobj.ItemInstance.DurabilityPoint <= 0)
                    {
                        session.SendPacket(UserInterfaceHelper.GenerateMsg(
                                               Language.Instance.GetMessageFromKey("NOT_ENOUGH_DURABILITY_POINT"), 0));
                        return;
                    }

                    if (session.Character.MinilandPoint <= 0)
                    {
                        session.SendPacket(
                            $"qna #mg^1^7^3125^1^1 {Language.Instance.GetMessageFromKey("NOT_ENOUGH_MINILAND_POINT")}");
                    }

                    session.Character.MapInstance.Broadcast(
                        UserInterfaceHelper.GenerateGuri(2, 1, session.Character.CharacterId));
                    session.Character.CurrentMinigame = (short)(game == 0 ? 5102 :
                                                                game == 1 ? 5103 :
                                                                game == 2 ? 5105 :
                                                                game == 3 ? 5104 :
                                                                game == 4 ? 5113 : 5112);
                    session.Character.MinigameLog = new MinigameLogDTO
                    {
                        CharacterId = session.Character.CharacterId,
                        StartTime   = DateTime.UtcNow.Ticks,
                        Minigame    = game
                    };
                    session.SendPacket($"mlo_st {game}");
                    break;

                //stop
                case 2:
                    session.Character.CurrentMinigame = 0;
                    session.Character.MapInstance.Broadcast(
                        UserInterfaceHelper.GenerateGuri(6, 1, session.Character.CharacterId));
                    break;

                case 3:
                    session.Character.CurrentMinigame = 0;
                    session.Character.MapInstance.Broadcast(
                        UserInterfaceHelper.GenerateGuri(6, 1, session.Character.CharacterId));
                    if (Point.HasValue && session.Character.MinigameLog != null)
                    {
                        session.Character.MinigameLog.EndTime = DateTime.UtcNow.Ticks;
                        session.Character.MinigameLog.Score   = Point.Value;

                        int level = -1;
                        for (short i = 0; i < SharedMinilandMethods.GetMinilandMaxPoint(game).Length; i++)
                        {
                            if (Point.Value > SharedMinilandMethods.GetMinilandMaxPoint(game)[i])
                            {
                                level = i;
                            }
                            else
                            {
                                break;
                            }
                        }

                        session.SendPacket(level != -1
                                ? $"mlo_lv {level}"
                                : $"mg 3 {game} {MinigameVNum} 0 0");
                    }

                    break;

                // select gift
                case 4:
                    if (session.Character.MinilandPoint >= 100 &&
                        session.Character.MinigameLog != null &&
                        Point.HasValue && Point.Value > 0 &&
                        SharedMinilandMethods.GetMinilandMaxPoint(game)[Point.Value - 1] < session.Character.MinigameLog.Score)
                    {
                        MinigameLogDTO dto = session.Character.MinigameLog;
                        DAOFactory.MinigameLogDAO.InsertOrUpdate(ref dto);
                        session.Character.MinigameLog = null;
                        Gift obj = SharedMinilandMethods.GetMinilandGift(MinigameVNum, Point.Value);
                        if (obj != null)
                        {
                            session.SendPacket($"mlo_rw {obj.VNum} {obj.Amount}");
                            session.SendPacket(session.Character.GenerateMinilandPoint());
                            List <ItemInstance> inv =
                                session.Character.Inventory.AddNewToInventory(obj.VNum, obj.Amount);
                            session.Character.MinilandPoint -= 100;
                            if (inv.Count == 0)
                            {
                                session.Character.SendGift(session.Character.CharacterId, obj.VNum, obj.Amount,
                                                           0, 0, false);
                            }

                            if (client != session)
                            {
                                switch (Point.Value)
                                {
                                case 0:
                                    mlobj.Level1BoxAmount++;
                                    break;

                                case 1:
                                    mlobj.Level2BoxAmount++;
                                    break;

                                case 2:
                                    mlobj.Level3BoxAmount++;
                                    break;

                                case 3:
                                    mlobj.Level4BoxAmount++;
                                    break;

                                case 4:
                                    mlobj.Level5BoxAmount++;
                                    break;
                                }
                            }
                        }
                    }

                    break;

                case 5:
                    session.SendPacket(session.Character.GenerateMloMg(mlobj, MinigameVNum));
                    break;

                //refill
                case 6:
                    if (!Point.HasValue || Point.Value < 0)
                    {
                        return;
                    }

                    if (session.Character.Gold > Point)
                    {
                        session.Character.Gold -= Point.Value;
                        session.SendPacket(session.Character.GenerateGold());
                        mlobj.ItemInstance.DurabilityPoint += Point.Value / 100;
                        session.SendPacket(UserInterfaceHelper.GenerateInfo(
                                               string.Format(Language.Instance.GetMessageFromKey("REFILL_MINIGAME"),
                                                             Point.Value / 100)));
                        session.SendPacket(session.Character.GenerateMloMg(mlobj, MinigameVNum));
                    }

                    break;

                //gift
                case 7:
                    session.SendPacket(
                        $"mlo_pmg {MinigameVNum} {session.Character.MinilandPoint} {(mlobj.ItemInstance.DurabilityPoint < 1000 ? 1 : 0)} {(full ? 1 : 0)} {(mlobj.Level1BoxAmount > 0 ? $"392 {mlobj.Level1BoxAmount}" : "0 0")} {(mlobj.Level2BoxAmount > 0 ? $"393 {mlobj.Level2BoxAmount}" : "0 0")} {(mlobj.Level3BoxAmount > 0 ? $"394 {mlobj.Level3BoxAmount}" : "0 0")} {(mlobj.Level4BoxAmount > 0 ? $"395 {mlobj.Level4BoxAmount}" : "0 0")} {(mlobj.Level5BoxAmount > 0 ? $"396 {mlobj.Level5BoxAmount}" : "0 0")} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
                    break;

                //get gift
                case 8:
                    if (!Point.HasValue)
                    {
                        return;
                    }
                    int amount = 0;
                    switch (Point.Value)
                    {
                    case 0:
                        amount = mlobj.Level1BoxAmount;
                        break;

                    case 1:
                        amount = mlobj.Level2BoxAmount;
                        break;

                    case 2:
                        amount = mlobj.Level3BoxAmount;
                        break;

                    case 3:
                        amount = mlobj.Level4BoxAmount;
                        break;

                    case 4:
                        amount = mlobj.Level5BoxAmount;
                        break;
                    }

                    List <Gift> gifts = new List <Gift>();
                    for (int i = 0; i < amount; i++)
                    {
                        Gift gift = SharedMinilandMethods.GetMinilandGift(MinigameVNum, Point.Value);
                        if (gift != null)
                        {
                            if (gifts.Any(o => o.VNum == gift.VNum))
                            {
                                gifts.First(o => o.Amount == gift.Amount).Amount += gift.Amount;
                            }
                            else
                            {
                                gifts.Add(gift);
                            }
                        }
                    }

                    string str = string.Empty;
                    for (int i = 0; i < 9; i++)
                    {
                        if (gifts.Count > i)
                        {
                            short itemVNum          = gifts[i].VNum;
                            byte  itemAmount        = gifts[i].Amount;
                            List <ItemInstance> inv =
                                session.Character.Inventory.AddNewToInventory(itemVNum, itemAmount);
                            if (inv.Count > 0)
                            {
                                session.SendPacket(session.Character.GenerateSay(
                                                       $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {ServerManager.GetItem(itemVNum).Name} x {itemAmount}",
                                                       12));
                            }
                            else
                            {
                                session.Character.SendGift(session.Character.CharacterId, itemVNum, itemAmount, 0,
                                                           0, false);
                            }

                            str += $" {itemVNum} {itemAmount}";
                        }
                        else
                        {
                            str += " 0 0";
                        }
                    }

                    session.SendPacket(
                        $"mlo_pmg {MinigameVNum} {session.Character.MinilandPoint} {(mlobj.ItemInstance.DurabilityPoint < 1000 ? 1 : 0)} {(full ? 1 : 0)} {(mlobj.Level1BoxAmount > 0 ? $"392 {mlobj.Level1BoxAmount}" : "0 0")} {(mlobj.Level2BoxAmount > 0 ? $"393 {mlobj.Level2BoxAmount}" : "0 0")} {(mlobj.Level3BoxAmount > 0 ? $"394 {mlobj.Level3BoxAmount}" : "0 0")} {(mlobj.Level4BoxAmount > 0 ? $"395 {mlobj.Level4BoxAmount}" : "0 0")} {(mlobj.Level5BoxAmount > 0 ? $"396 {mlobj.Level5BoxAmount}" : "0 0")}{str}");
                    break;

                //coupon
                case 9:
                    List <ItemInstance> items = session.Character.Inventory
                                                .Where(s => s.ItemVNum == 1269 || s.ItemVNum == 1271).OrderBy(s => s.Slot).ToList();
                    if (items.Count > 0)
                    {
                        short itemVNum = items[0].ItemVNum;
                        session.Character.Inventory.RemoveItemAmount(itemVNum);
                        int point = itemVNum == 1269 ? 300 : 500;
                        mlobj.ItemInstance.DurabilityPoint += point;
                        session.SendPacket(UserInterfaceHelper.GenerateInfo(
                                               string.Format(Language.Instance.GetMessageFromKey("REFILL_MINIGAME"), point)));
                        session.SendPacket(session.Character.GenerateMloMg(mlobj, MinigameVNum));
                    }

                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void ExecuteHandler(ClientSession session)
        {
            ClientSession client =
                ServerManager.Instance.Sessions.FirstOrDefault(s =>
                                                               s.Character?.Miniland == session.Character.MapInstance);
            ItemInstance minilandObjectItem =
                client?.Character.Inventory.LoadBySlotAndType <ItemInstance>(Slot, InventoryType.Miniland);

            if (minilandObjectItem != null)
            {
                MinilandObject minilandObject =
                    client.Character.MinilandObjects.Find(s => s.ItemInstanceId == minilandObjectItem.Id);
                if (minilandObject != null)
                {
                    if (!minilandObjectItem.Item.IsMinilandObject)
                    {
                        byte game = (byte)(minilandObject.ItemInstance.Item.EquipmentSlot == 0
                            ? 4 + (minilandObject.ItemInstance.ItemVNum % 10)
                            : (int)minilandObject.ItemInstance.Item.EquipmentSlot / 3);
                        const bool full = false;
                        session.SendPacket(
                            $"mlo_info {(client == session ? 1 : 0)} {minilandObjectItem.ItemVNum} {Slot} {session.Character.MinilandPoint} {(minilandObjectItem.DurabilityPoint < 1000 ? 1 : 0)} {(full ? 1 : 0)} 0 {SharedMinilandMethods.GetMinilandMaxPoint(game)[0]} {SharedMinilandMethods.GetMinilandMaxPoint(game)[0] + 1} {SharedMinilandMethods.GetMinilandMaxPoint(game)[1]} {SharedMinilandMethods.GetMinilandMaxPoint(game)[1] + 1} {SharedMinilandMethods.GetMinilandMaxPoint(game)[2]} {SharedMinilandMethods.GetMinilandMaxPoint(game)[2] + 2} {SharedMinilandMethods.GetMinilandMaxPoint(game)[3]} {SharedMinilandMethods.GetMinilandMaxPoint(game)[3] + 1} {SharedMinilandMethods.GetMinilandMaxPoint(game)[4]} {SharedMinilandMethods.GetMinilandMaxPoint(game)[4] + 1} {SharedMinilandMethods.GetMinilandMaxPoint(game)[5]}");
                    }
                    else
                    {
                        session.SendPacket(session.Character.GenerateStashAll());
                    }
                }
            }
        }