private static void ProvideReward(TrophyGradeMetadata grade, GameSession session)
        {
            switch (grade.RewardType)
            {
            // this cases don't require any handling.
            case RewardType.None:
            case RewardType.itemcoloring:
            case RewardType.beauty_hair:
            case RewardType.skillPoint:
            case RewardType.beauty_makeup:
            case RewardType.shop_build:
            case RewardType.shop_weapon:
            case RewardType.dynamicaction:
            case RewardType.etc:
            case RewardType.beauty_skin:
            case RewardType.statPoint:
            case RewardType.shop_ride:
            default:
                break;

            case RewardType.item:
                InventoryController.Add(session, new Item(grade.RewardCode, grade.RewardValue), true);
                break;

            case RewardType.title:
                session.Player.Titles.Add(grade.RewardCode);
                session.Send(UserEnvPacket.AddTitle(grade.RewardCode));
                break;
            }
        }
Exemplo n.º 2
0
        private static void HandleUnequipItem(GameSession session, PacketReader packet)
        {
            long itemUid = packet.ReadLong();

            // Unequip gear
            KeyValuePair <ItemSlot, Item> kvpEquips = session.Player.Equips.FirstOrDefault(x => x.Value.Uid == itemUid);

            if (kvpEquips.Value != null)
            {
                if (session.Player.Equips.Remove(kvpEquips.Key, out Item unequipItem))
                {
                    unequipItem.Slot = -1;
                    InventoryController.Add(session, unequipItem, false);
                    session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, unequipItem));

                    DecreaseStats(session, unequipItem);
                }

                return;
            }

            // Unequip cosmetics
            KeyValuePair <ItemSlot, Item> kvpCosmetics = session.Player.Cosmetics.FirstOrDefault(x => x.Value.Uid == itemUid);

            if (kvpCosmetics.Value != null)
            {
                if (session.Player.Cosmetics.Remove(kvpCosmetics.Key, out Item unequipItem))
                {
                    unequipItem.Slot = -1;
                    InventoryController.Add(session, unequipItem, false);
                    session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, unequipItem));
                }
            }
        }
Exemplo n.º 3
0
        private static void HandlePurchaseMembership(GameSession session, PacketReader packet)
        {
            int vipId = packet.ReadInt();

            if (!PremiumClubPackageMetadataStorage.IsValid(vipId))
            {
                return;
            }

            PremiumClubPackageMetadata vipPackage = PremiumClubPackageMetadataStorage.GetMetadata(vipId);

            if (!session.Player.Wallet.RemoveMerets(vipPackage.Price))
            {
                return;
            }

            session.Send(PremiumClubPacket.PurchaseMembership(vipId));

            foreach (BonusItem item in vipPackage.BonusItem)
            {
                Item bonusItem = new(item.Id)
                {
                    Rarity = item.Rarity,
                    Amount = item.Amount
                };
                InventoryController.Add(session, bonusItem, true);
            }

            int vipTime = vipPackage.VipPeriod * 3600; // Convert to seconds, as vipPeriod is given as hours

            ActivatePremium(session, vipTime);
        }
Exemplo n.º 4
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            // [bow] Henesys 47 Bow - 15100216
            // [staff] Modded Student Staff - 15200223
            // [longsword] Sword of tria - 13200220
            // [shield] Shield of tria - 14100190
            // [greatsword] Riena - 15000224
            // [scepter] Saint Mushliel Mace - 13300219
            // [codex] Words of Saint mushliel - 14000181
            // [cannon] Cannon of beginnings - 15300199
            // [dagger] Walker knife - 13100225
            // [star] Rook's Star - 13400218
            // [blade] Runesteel Blade - 15400274
            // [knuckles] Pugilist knuckles - 15500514
            // [orb] Guidance training orb - 15600514

            int[] itemIds = new int[] { 15100216, 15200223, 13200220, 14100190, 15000224, 13300219, 14000181, 15300199, 13100225, 13400218, 15400274, 15500514, 15600514 };
            foreach (int id in itemIds)
            {
                ItemMetadata metadata = ItemMetadataStorage.GetMetadata(id);

                if (!metadata.RecommendJobs.Contains((int)session.Player.Job))
                {
                    continue;
                }

                Item item = new Item(id);
                if (session.Player.Job == Job.Thief || session.Player.Job == Job.Assassin)
                {
                    item.Amount = 2;
                }

                InventoryController.Add(session, item, true);
            }
        }
Exemplo n.º 5
0
        private static void HandleUnequipItem(GameSession session, PacketReader packet)
        {
            byte index = packet.ReadByte();

            List <Item> badges = session.Player.Inventory.Badges;

            if (badges.Count < index + 1)
            {
                return;
            }

            Item item = badges[index];

            // Add to inventory
            item.IsEquipped = false;
            InventoryController.Add(session, item, false);

            // Unequip
            bool removed = badges.Remove(item);

            if (removed)
            {
                session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, (byte)item.GemSlot));
            }
        }
Exemplo n.º 6
0
        private static void HandleBuy(GameSession session, PacketReader packet)
        {
            int itemUid  = packet.ReadInt();
            int quantity = packet.ReadInt();

            ShopItem shopItem = ShopMetadataStorage.GetItem(itemUid);

            switch (shopItem.TokenType)
            {
            case ShopCurrencyType.Meso:
                session.Player.Wallet.Meso.Modify(-(shopItem.Price * quantity));
                break;

            case ShopCurrencyType.ValorToken:
                session.Player.Wallet.ValorToken.Modify(-(shopItem.Price * quantity));
                break;

            case ShopCurrencyType.Treva:
                session.Player.Wallet.Treva.Modify(-(shopItem.Price * quantity));
                break;

            case ShopCurrencyType.Rue:
                session.Player.Wallet.Rue.Modify(-(shopItem.Price * quantity));
                break;

            case ShopCurrencyType.HaviFruit:
                session.Player.Wallet.HaviFruit.Modify(-(shopItem.Price * quantity));
                break;

            case ShopCurrencyType.Meret:
            case ShopCurrencyType.GameMeret:
            case ShopCurrencyType.EventMeret:
                session.Player.Wallet.RemoveMerets(shopItem.Price * quantity);
                break;

            case ShopCurrencyType.Item:
                Item itemCost = session.Player.Inventory.Items.FirstOrDefault(x => x.Value.Id == shopItem.RequiredItemId).Value;
                if (itemCost.Amount < shopItem.Price)
                {
                    return;
                }
                InventoryController.Consume(session, itemCost.Uid, shopItem.Price);
                break;

            default:
                session.SendNotice($"Unknown currency: {shopItem.TokenType}");
                return;
            }

            // add item to inventory
            Item item = new(shopItem.ItemId)
            {
                Amount = quantity * shopItem.Quantity
            };

            InventoryController.Add(session, item, true);

            // complete purchase
            session.Send(ShopPacket.Buy(shopItem.ItemId, quantity, shopItem.Price, shopItem.TokenType));
        }
Exemplo n.º 7
0
        private static void HandleMarketItemPay(GameSession session, MeretMarketItem marketItem, int itemIndex, int totalQuantity)
        {
            switch (marketItem.TokenType)
            {
            case MeretMarketCurrencyType.Meret:
                if (!session.Player.Account.RemoveMerets(marketItem.SalePrice))
                {
                    return;
                }
                break;

            case MeretMarketCurrencyType.Meso:
                if (!session.Player.Wallet.Meso.Modify(marketItem.SalePrice))
                {
                    return;
                }
                break;
            }

            Item item = new Item(marketItem.ItemId)
            {
                Amount = marketItem.Quantity + marketItem.BonusQuantity,
                Rarity = marketItem.Rarity
            };

            if (marketItem.Duration != 0)
            {
                item.ExpiryTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + Environment.TickCount + (marketItem.Duration * (24 * 60 * 60));
            }
            InventoryController.Add(session, item, true);
            session.Send(MeretMarketPacket.Purchase(marketItem, itemIndex, totalQuantity));
        }
        public void MiniGameGiveReward(int winnerBoxId, string contentType, MiniGame type)
        {
            MapTriggerBox box = MapEntityStorage.GetTriggerBox(Field.MapId, winnerBoxId);
            List <IFieldObject <Player> > players = new List <IFieldObject <Player> >();

            foreach (IFieldObject <Player> player in Field.State.Players.Values)
            {
                if (FieldManager.IsPlayerInBox(box, player))
                {
                    players.Add(player);
                }
            }
            foreach (IFieldObject <Player> player in players)
            {
                if (contentType == "miniGame")
                {
                    List <Item> items = RewardContentMetadataStorage.GetRewardItems(3, player.Value.Levels.Level);
                    foreach (Item item in items)
                    {
                        InventoryController.Add(player.Value.Session, item, true);
                    }
                }
                else if (contentType == "UserOpenMiniGameExtraReward")
                {
                }
            }
        }
Exemplo n.º 9
0
        private static void HandleReward(GameSession session, PacketReader packet)
        {
            int rank = packet.ReadInt();

            session.Send(PrestigePacket.Reward(rank));

            // Get reward data
            PrestigeReward reward = PrestigeMetadataStorage.GetReward(rank);

            if (reward.Type.Equals("item"))
            {
                Item item = new Item(reward.Id)
                {
                    CreationTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                    Rarity       = 4
                };

                InventoryController.Add(session, item, true);
            }
            else if (reward.Type.Equals("statPoint"))
            {
                session.Player.StatPointDistribution.AddTotalStatPoints(reward.Value);
            }
            session.Player.PrestigeRewardsClaimed.Add(rank);
        }
Exemplo n.º 10
0
        private static void HandleChooseRandomHair(GameSession session, PacketReader packet)
        {
            byte selection = packet.ReadByte();

            if (selection == 0) // player chose previous hair
            {
                Dictionary <ItemSlot, Item> cosmetics = session.Player.Inventory.Cosmetics;
                //Remove current hair
                if (cosmetics.Remove(ItemSlot.HR, out Item newHair))
                {
                    newHair.Slot = -1;
                    DatabaseManager.Items.Delete(newHair.Uid);
                    session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, newHair));
                }

                cosmetics[ItemSlot.HR] = session.Player.HairInventory.RandomHair; // apply the previous hair

                session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.FieldPlayer, session.Player.HairInventory.RandomHair, ItemSlot.HR));

                Item voucher = new Item(20300246)
                {
                };                                     // Chic Salon Voucher
                InventoryController.Add(session, voucher, true);

                session.Send(BeautyPacket.ChooseRandomHair(voucher.Id));
            }
            else // player chose new hair
            {
                session.Send(BeautyPacket.ChooseRandomHair());
            }

            session.Player.HairInventory.RandomHair = null; // remove random hair option from hair inventory
        }
Exemplo n.º 11
0
        private void HandleRewardBox(GameSession session, PacketReader packet)
        {
            int rewardBoxDetails = packet.ReadInt();
            int type             = rewardBoxDetails / 1000;
            int grade            = rewardBoxDetails % 100;

            // get the reward box item ID
            MasteryMetadata mastery = MasteryMetadataStorage.GetMastery(type);

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

            int  rewardBoxItemId = mastery.Grades[grade - 1].RewardJobItemID;
            Item rewardBox       = new Item(rewardBoxItemId)
            {
                Amount = 1
            };

            // give player the reward box item
            InventoryController.Add(session, rewardBox, true);

            // mark reward box as claimed
            session.Send(MasteryPacket.ClaimReward(rewardBoxDetails, 1, (int)rewardBoxItemId));
        }
Exemplo n.º 12
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.º 13
0
        private static void HandleCollect(GameSession session, PacketReader packet)
        {
            int id = packet.ReadInt();

            packet.ReadInt();

            // Get items and add to inventory
            List <Item> items = session.Player.Mailbox.Collect(id);

            if (items == null)
            {
                return;
            }

            foreach (Item item in items)
            {
                session.Player.Inventory.Remove(item.Uid, out Item removed);
                InventoryController.Add(session, item, true);

                // Item packet, not sure if this is only used for mail, it also doesn't seem to do anything
                session.Send(ItemPacket.ItemData(item));
            }

            session.Send(MailPacket.CollectedAmount(id, DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
            session.Send(MailPacket.CollectResponse(id, DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
        }
Exemplo n.º 14
0
        private static void HandleCheckIn(GameSession session)
        {
            Guild guild = GameServer.GuildManager.GetGuildById(session.Player.Guild.Id);

            if (guild == null)
            {
                return;
            }
            GuildMember member = guild.Members.First(x => x.Player == session.Player);

            // Check if attendance timestamp is today
            DateTimeOffset date = DateTimeOffset.FromUnixTimeSeconds(member.AttendanceTimestamp);

            if (date == DateTime.Today)
            {
                return;
            }

            int contributionAmount         = GuildContributionMetadataStorage.GetContributionAmount("attend");
            GuildPropertyMetadata property = GuildPropertyMetadataStorage.GetMetadata(guild.Exp);

            member.AddContribution(contributionAmount);
            member.AttendanceTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + Environment.TickCount;
            session.Send(GuildPacket.CheckInBegin());
            Item guildCoins = new Item(30000861)
            {
                Amount = property.AttendGuildCoin
            };

            InventoryController.Add(session, guildCoins, true);
            guild.AddExp(session, property.AttendExp);
            guild.ModifyFunds(session, property, property.AttendFunds);
            guild.BroadcastPacketGuild(GuildPacket.UpdatePlayerContribution(member, contributionAmount));
            session.Send(GuildPacket.FinishCheckIn(member));
        }
        private void HandleEquipItem(GameSession session, PacketReader packet)
        {
            long itemUid = packet.ReadLong();

            // Remove from inventory
            bool success = InventoryController.Remove(session, itemUid, out Item item);

            if (!success)
            {
                return;
            }

            // Unequip existing item in slot
            int index = session.Player.Badges.FindIndex(i => i.GemSlot == item.GemSlot);

            if (index >= 0)
            {
                // Add to inventory
                InventoryController.Add(session, session.Player.Badges[index], false);

                // Unequip
                session.Player.Badges.RemoveAt(index);
                session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, (byte)item.GemSlot));
            }

            // Equip
            session.Player.Badges.Add(item);
            session.FieldManager.BroadcastPacket(GemPacket.EquipItem(session, item));
        }
Exemplo n.º 16
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
                };
                InventoryController.Add(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.
            }
        }
        public async Task Add_Return_Entity()
        {
            var expected = new InventoryDTO()
            {
                Id = 1
            };

            _service.Setup(s => s.Add(It.IsAny <InventoryDTO>())).ReturnsAsync(new Result <int>(1, true, ""));

            var actual = await _controller.Add(expected);

            var actualObject = actual as OkObjectResult;

            Assert.IsNotNull(actualObject);
            Assert.AreEqual(actualObject.Value, 1);
        }
Exemplo n.º 18
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            long boxUid = packet.ReadLong();

            if (!session.Player.Inventory.Items.ContainsKey(boxUid))
            {
                return;
            }

            // Get the box item
            Item box = session.Player.Inventory.Items[boxUid];

            // Remove box if amount is 1 or less
            // TODO remove these inventory packets
            if (box.Amount <= 1)
            {
                InventoryController.Remove(session, boxUid, out Item removed);
            }
            // Decrement box amount to otherwise
            else
            {
                box.Amount -= 1;
                InventoryController.Update(session, boxUid, box.Amount);
            }

            // Normally would look up which item to create, instead always add poisonous mushroom
            Item item = new Item(30001001);

            InventoryController.Add(session, item, true);
        }
Exemplo n.º 19
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            List <TutorialItemMetadata> metadata = JobMetadataStorage.GetTutorialItems((int)session.Player.Job);

            foreach (TutorialItemMetadata tutorialItem in metadata)
            {
                int tutorialItemsCount = session.Player.Inventory.Items.Where(x => x.Value.Id == tutorialItem.ItemId).Count();
                tutorialItemsCount += session.Player.Inventory.Cosmetics.Where(x => x.Value.Id == tutorialItem.ItemId).Count();
                tutorialItemsCount += session.Player.Inventory.Equips.Where(x => x.Value.Id == tutorialItem.ItemId).Count();

                if (tutorialItemsCount >= tutorialItem.Amount)
                {
                    continue;
                }

                int amountRemaining = tutorialItem.Amount - tutorialItemsCount;

                Item item = new Item(tutorialItem.ItemId)
                {
                    Rarity = tutorialItem.Rarity,
                    Amount = amountRemaining,
                };
                InventoryController.Add(session, item, true);
            }
        }
Exemplo n.º 20
0
        public static void HandleOpenCoupleEffectBox(GameSession session, PacketReader packet, Item item)
        {
            string targetUser = packet.ReadUnicodeString();

            Player otherPlayer = GameServer.Storage.GetPlayerByName(targetUser);

            if (otherPlayer == null)
            {
                session.Send(NoticePacket.Notice(SystemNotice.CharacterNotFound, type: NoticeType.Popup));
                return;
            }

            Item badge = new Item(item.Function.OpenCoupleEffectBox.Id)
            {
                Rarity              = item.Function.OpenCoupleEffectBox.Rarity,
                PairedCharacterId   = otherPlayer.CharacterId,
                PairedCharacterName = otherPlayer.Name
            };

            Item otherUserBadge = new Item(item.Function.Id)
            {
                Rarity              = item.Function.OpenCoupleEffectBox.Rarity,
                PairedCharacterId   = session.Player.CharacterId,
                PairedCharacterName = session.Player.Name
            };

            //InventoryController.Consume(session, item.Uid, 1);
            InventoryController.Add(session, badge, true);
            //session.Send(NoticePacket.Notice(SystemNotice.BuddyBadgeMailedToUser, otherPlayer.Name, NoticeType.ChatAndFastText));

            //otherPlayer.Session.Send(MailPacket.Notify(otherPlayer.Session));
            // TODO: Mail the badge to the other user
        }
Exemplo n.º 21
0
        private void OpenBox(GameSession session, ItemContent content)
        {
            // Currency
            if (content.Id.ToString().StartsWith("9"))
            {
                switch (content.Id)
                {
                case 90000001:     // Meso
                    session.Player.Wallet.Meso.Modify(content.Amount);
                    break;

                case 90000004:     // Meret
                case 90000011:     // Meret
                case 90000015:     // Meret
                case 90000016:     // Meret
                    session.Player.Wallet.Meret.Modify(content.Amount);
                    break;
                }
            }
            // Items
            else
            {
                Item item = new Item(content.Id)
                {
                    Amount = content.Amount
                };
                InventoryController.Add(session, item, true);
            }
        }
Exemplo n.º 22
0
        private static void HandleCollect(GameSession session, PacketReader packet)
        {
            long id   = packet.ReadLong();
            Mail mail = session.Player.Mailbox.FirstOrDefault(x => x.Id == id);

            if (mail == null)
            {
                return;
            }

            if (mail.Items.Count == 0)
            {
                return;
            }

            foreach (Item item in mail.Items)
            {
                item.MailId = 0;
                InventoryController.Add(session, item, true);
            }
            mail.Items.Clear();
            DatabaseManager.Mails.UpdateReadTime(mail);

            session.Send(MailPacket.Collect(mail));
            session.Send(MailPacket.UpdateReadTime(mail));
        }
Exemplo n.º 23
0
        public override void Handle(GameSession session, PacketReader packet) // TODO: Refactor when DB is implemented
        {
            QuestMode mode = (QuestMode)packet.ReadByte();

            switch (mode)
            {
            case QuestMode.AcceptQuest:
            {
                int questid  = packet.ReadInt();
                int objectid = packet.ReadInt();
                session.Send(QuestPacket.AcceptQuest(questid));
                break;
            }

            case QuestMode.CompleteQuest:
            {
                int questid  = packet.ReadInt();
                int objectid = packet.ReadInt();
                session.Send(QuestPacket.CompleteQuest(questid));
                QuestReward quest = QuestMetadataStorage.GetMetadata(questid).Reward;
                session.Player.Levels.GainExp(quest.Exp);
                session.Player.Wallet.Meso.Modify(quest.Money);
                break;
            }

            case QuestMode.ExplorationGoals:
                List <QuestMetadata> list = new List <QuestMetadata>();

                int listSize = packet.ReadInt();

                for (int i = 0; i < listSize; i++)
                {
                    list.Add(QuestMetadataStorage.GetMetadata(packet.ReadInt()));
                }

                session.Send(QuestPacket.SendQuests(list));
                break;

            case QuestMode.CompleteNavigator:
                int questId = packet.ReadInt();

                foreach (QuestRewardItem item in QuestMetadataStorage.GetMetadata(questId).RewardItem)
                {
                    InventoryController.Add(session, new Types.Item(item.Code), true);
                }

                session.Send(QuestPacket.CompleteQuest(questId));
                break;

            default:
                IPacketHandler <GameSession> .LogUnknownMode(mode);

                break;
            }
        }
Exemplo n.º 24
0
    public void Equip(Equipment _newItem)
    {
        int slotIndex = (int)_newItem.equipmentSlotType;

        Equipment m_OldItem = null;

        if (currentEquipment[slotIndex] != null)
        {
            m_OldItem = currentEquipment[slotIndex];
            inventory.Add(m_OldItem);
        }

        if (onEquipmentChanged != null)
        {
            // Debug.Log("Invoking onEquipmentChanged");
            onEquipmentChanged.Invoke(_newItem, m_OldItem);
        }

        currentEquipment[slotIndex] = _newItem;
    }
        public override void Handle(GameSession session, PacketReader packet)
        {
            int objectId = packet.ReadInt();

            bool foundItem = session.FieldManager.State.TryGetItem(objectId, out IFieldObject <Item> fieldItem);

            if (foundItem)
            {
                switch (fieldItem.Value.Id)
                {
                case 90000004:
                case 90000011:
                case 90000015:
                case 90000016:
                case 90000020:
                    session.Player.Account.Meret.Modify(fieldItem.Value.Amount);
                    break;

                case 90000008:
                    session.Player.Levels.GainExp(fieldItem.Value.Amount);
                    break;

                case 90000009:
                    session.Player.RecoverSp(fieldItem.Value.Amount);
                    break;

                case 90000010:
                    session.Player.RecoverStamina(fieldItem.Value.Amount);
                    break;

                default:
                    // TODO: This will be bugged when you have a full inventory, check inventory before looting
                    fieldItem.Value.Slot = -1;     // add to first empty slot
                    InventoryController.Add(session, fieldItem.Value, true);
                    break;
                }

                if (session.FieldManager.RemoveItem(objectId, out Item item))
                {
                    session.FieldManager.BroadcastPacket(FieldPacket.PickupItem(objectId, item, session.FieldPlayer.ObjectId));
                    session.FieldManager.BroadcastPacket(FieldPacket.RemoveItem(objectId));
                }
            }

            int countExtra = packet.ReadByte();

            for (int i = 0; i < countExtra; i++)
            {
            }
        }
        private static void HandleRemove(GameSession session, PacketReader packet)
        {
            packet.ReadLong();
            long  uid    = packet.ReadLong();
            short slot   = packet.ReadShort();
            int   amount = packet.ReadInt();

            if (!session.Player.Account.BankInventory.Remove(session, uid, slot, amount, out Item item))
            {
                return;
            }
            item.Slot = slot;
            InventoryController.Add(session, item, false);
        }
        public void AddProductTestSuccess()
        {
            var controller = new InventoryController();

            Product product = new Product()
            {
                ProductName = "Test product",
                Quantity    = 2
            };

            HttpResponseMessage response = controller.Add(product);

            Assert.AreEqual(201, (int)response.StatusCode);
        }
Exemplo n.º 28
0
        public static void GiveItemFromSelectBox(GameSession session, Item sourceItem, int index)
        {
            SelectItemBox    box      = sourceItem.Function.SelectItemBox;
            ItemDropMetadata metadata = ItemDropMetadataStorage.GetItemDropMetadata(box.BoxId);

            if (metadata == null)
            {
                session.Send(NoticePacket.Notice("No items found", NoticeType.Chat));
                return;
            }

            InventoryController.Consume(session, sourceItem.Uid, 1);

            // Select boxes disregards group ID. Adding these all to a filtered list
            List <DropGroupContent> dropContentsList = new List <DropGroupContent>();

            foreach (DropGroup group in metadata.DropGroups)
            {
                foreach (DropGroupContent dropGroupContent in group.Contents)
                {
                    if (dropGroupContent.SmartDropRate == 100)
                    {
                        List <Job> recommendJobs = ItemMetadataStorage.GetRecommendJobs(dropGroupContent.ItemIds.First());
                        if (recommendJobs.Contains(session.Player.Job) || recommendJobs.Contains(Job.None))
                        {
                            dropContentsList.Add(dropGroupContent);
                        }
                        continue;
                    }
                    dropContentsList.Add(dropGroupContent);
                }
            }

            DropGroupContent dropContents = dropContentsList[index];

            Random rng    = RandomProvider.Get();
            int    amount = rng.Next((int)dropContents.MinAmount, (int)dropContents.MaxAmount);

            foreach (int id in dropContents.ItemIds)
            {
                Item newItem = new Item(id)
                {
                    Enchants = dropContents.EnchantLevel,
                    Amount   = amount,
                    Rarity   = dropContents.Rarity
                };
                InventoryController.Add(session, newItem, true);
            }
        }
Exemplo n.º 29
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            int objectId = packet.ReadInt();

            packet.ReadByte();

            // TODO: This will be bugged when you have a full inventory, check inventory before looting
            // Remove objectId from Field, make sure item still exists (multiple looters)
            if (!session.FieldManager.RemoveItem(objectId, out Item item))
            {
                return;
            }

            InventoryController.Add(session, item, true);
        }
        public override void Execute(GameCommandTrigger trigger)
        {
            int questId = trigger.Get <int>("id");

            if (questId == 0)
            {
                trigger.Session.SendNotice("Please type an quest id");
                return;
            }
            if (!QuestMetadataStorage.IsValid(questId))
            {
                trigger.Session.Send(NoticePacket.Notice($"Quest not found with id: {questId.ToString().Color(Color.Aquamarine)}.", NoticeType.Chat));
                return;
            }
            QuestStatus questStatus = trigger.Session.Player.QuestList.FirstOrDefault(x => x.Basic.Id == questId);

            if (questStatus == null)
            {
                questStatus = new QuestStatus(trigger.Session.Player, QuestMetadataStorage.GetMetadata(questId));
                trigger.Session.Player.QuestList.Add(questStatus);
            }
            questStatus.Completed         = true;
            questStatus.CompleteTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            trigger.Session.Player.Levels.GainExp(questStatus.Reward.Exp);
            trigger.Session.Player.Wallet.Meso.Modify(questStatus.Reward.Money);

            foreach (QuestRewardItem reward in questStatus.RewardItems)
            {
                Item newItem = new Item(reward.Code)
                {
                    Amount = reward.Count,
                    Rarity = reward.Rank
                };
                if (newItem.RecommendJobs.Contains(trigger.Session.Player.Job) || newItem.RecommendJobs.Contains(0))
                {
                    InventoryController.Add(trigger.Session, newItem, true);
                }
            }
            trigger.Session.Send(QuestPacket.CompleteQuest(questId, true));

            // Add next quest
            IEnumerable <KeyValuePair <int, QuestMetadata> > questList = QuestMetadataStorage.GetAllQuests().Where(x => x.Value.Require.RequiredQuests.Contains(questId));

            foreach (KeyValuePair <int, QuestMetadata> kvp in questList)
            {
                trigger.Session.Player.QuestList.Add(new QuestStatus(trigger.Session.Player, kvp.Value));
            }
        }