Example #1
0
        private void SendItems(NecClient client, int[] itemIds)
        {
            ItemSpawnParams[] spawmParams = new ItemSpawnParams[itemIds.Length];
            for (int i = 0; i < itemIds.Length; i++)
            {
                spawmParams[i] = new ItemSpawnParams();
                spawmParams[i].itemStatuses = ItemStatuses.Identified;
            }

            ItemService         itemService = new ItemService(client.character);
            List <ItemInstance> items       = itemService.SpawnItemInstances(ItemZoneType.AdventureBag, itemIds, spawmParams);

            RecvSituationStart recvSituationStart = new RecvSituationStart(2);

            router.Send(client, recvSituationStart.ToPacket());

            foreach (ItemInstance itemInstance in items)
            {
                _Logger.Debug(itemInstance.type.ToString());
                RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                router.Send(client, recvItemInstance.ToPacket());
            }

            RecvSituationEnd recvSituationEnd = new RecvSituationEnd();

            router.Send(client, recvSituationEnd.ToPacket());
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            ItemService  itemService = new ItemService(client.character);
            int          result      = 0;
            int          instanceId  = packet.data.ReadInt32();
            MonsterSpawn monster     = client.map.GetMonsterByInstanceId((uint)instanceId);

            _Logger.Debug($"{client.character.name} is trying to loot object {instanceId}.  Inventory Space {client.character.itemLocationVerifier.GetTotalFreeSpace(ItemZoneType.AdventureBag)}");
            ItemLocation nextOpenLocation = client.character.itemLocationVerifier.NextOpenSlot(ItemZoneType.AdventureBag);

            if (monster == null)
            {
                result = -10;
            }
            else if (monster.loot.itemCountRng == 0)
            {
                result = -1;
            }
            else if (nextOpenLocation.zoneType == ItemZoneType.InvalidZone)
            {
                result = -207;                                                             //expand to all inventory. TODO
            }
            IBuffer res2 = BufferProvider.Provide();

            res2.WriteInt32(result);
            router.Send(client, (ushort)AreaPacketId.recv_loot_access_object_r, res2, ServerType.Area);
            //LOOT, -1, I don't have anything. , SYSTEM_WARNING,
            //LOOT, -10, no route target, SYSTEM_WARNING,
            //LOOT, -207, There is no space in the inventory. , SYSTEM_WARNING,
            //LOOT, -1500, no root authority. , SYSTEM_WARNING,

            if (result == 0)
            {
                IBuffer res = BufferProvider.Provide();
                res.WriteInt32(2);
                router.Send(client, (ushort)AreaPacketId.recv_situation_start, res, ServerType.Area);

                int             itemId     = monster.loot.dropTableItemSerialIds[monster.loot.itemCountRng];
                ItemSpawnParams spawmParam = new ItemSpawnParams();
                spawmParam.itemStatuses = ItemStatuses.Identified;
                ItemInstance itemInstance = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, itemId, spawmParam);
                _Logger.Debug(itemInstance.type.ToString());
                RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                router.Send(client, recvItemInstance.ToPacket());
                monster.loot.itemCountRng--; //decrement available items

                res = BufferProvider.Provide();
                router.Send(client, (ushort)AreaPacketId.recv_situation_end, res, ServerType.Area);
            }
        }
        public void LoadInventory(NecClient client, NecServer server)
        {
            ItemService         itemService = new ItemService(client.character);
            List <ItemInstance> ownedItems  = itemService.LoadOwneditemInstances(server);

            foreach (ItemInstance itemInstance in ownedItems)
            {
                if (itemInstance.statuses.HasFlag(ItemStatuses.Unidentified))
                {
                    RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, itemInstance);
                    router.Send(client, recvItemInstanceUnidentified.ToPacket());
                    _Logger.Debug($" Unidentified item : {itemInstance.location.zoneType}");
                }
                else
                {
                    RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                    router.Send(client, recvItemInstance.ToPacket());
                }
            }
        }
Example #4
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            byte  index = packet.data.ReadByte();
            ulong price = packet.data.ReadUInt64();
            byte  count = packet.data.ReadByte();

            client.character.adventureBagGold -= count * price;
            server.database.UpdateCharacter(client.character);

            RecvSelfMoneyNotify recvSelfMoneyNotify = new RecvSelfMoneyNotify(client, client.character.adventureBagGold);

            router.Send(recvSelfMoneyNotify, client);

            if (client.character.shopItemIndex != null)
            {
                int             itemId     = client.character.shopItemIndex[index];
                ItemSpawnParams spawmParam = new ItemSpawnParams();
                spawmParam.itemStatuses = ItemStatuses.Identified;
                spawmParam.quantity     = count;
                ItemService  itemService  = new ItemService(client.character);
                ItemInstance itemInstance = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, itemId, spawmParam);

                RecvSituationStart recvSituationStart = new RecvSituationStart(2);
                router.Send(client, recvSituationStart.ToPacket());

                RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                router.Send(client, recvItemInstance.ToPacket());

                RecvSituationEnd recvSituationEnd = new RecvSituationEnd();
                router.Send(client, recvSituationEnd.ToPacket());
            }

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0);
            router.Send(client, (ushort)AreaPacketId.recv_shop_buy_r, res, ServerType.Area);
        }
        public override void Execute(string[] command, NecClient client, ChatMessage message,
                                     List <ChatResponse> responses)
        {
            if (command.Length < 1)
            {
                responses.Add(ChatResponse.CommandError(client, "To few arguments"));
                return;
            }

            if (!int.TryParse(command[0], out int itemId))
            {
                responses.Add(ChatResponse.CommandError(client, $"Invalid Number: {command[0]}"));
                return;
            }

            if (client.character == null)
            {
                responses.Add(ChatResponse.CommandError(client, "Character is null"));
                return;
            }

            if (!server.settingRepository.itemInfo.ContainsKey(itemId))
            {
                responses.Add(ChatResponse.CommandError(client, $"ItemId: '{itemId}' does not exist"));
                return;
            }


            ItemSpawnParams spawmParam = new ItemSpawnParams();

            spawmParam.itemStatuses = ItemStatuses.Identified;
            if (command.Length > 1 && command[1] == "u")
            {
                spawmParam.itemStatuses = ItemStatuses.Unidentified;
            }

            ItemService  itemService      = new ItemService(client.character);
            ItemInstance itemInstance     = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, itemId, spawmParam);
            byte         itemZoneOverride = 0;
            IBuffer      res = BufferProvider.Provide();

            res.WriteInt32(2);
            router.Send(client, (ushort)AreaPacketId.recv_situation_start, res, ServerType.Area);

            if (command.Length > 1 && command[1] == "u")
            {
                if (command.Length > 2 && command[2] != "")
                {
                    itemZoneOverride = byte.Parse(command[2]);
                }
                else
                {
                    itemZoneOverride = (byte)itemInstance.location.zoneType;
                }
                _Logger.Debug(itemInstance.type.ToString());
                RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, itemInstance);
                router.Send(client, recvItemInstanceUnidentified.ToPacket());
            }
            else
            {
                _Logger.Debug(itemInstance.type.ToString());
                RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                router.Send(client, recvItemInstance.ToPacket());
            }

            res = BufferProvider.Provide();
            router.Send(client, (ushort)AreaPacketId.recv_situation_end, res, ServerType.Area);
        }
        private void RandomItemGuy(NecClient client, NpcSpawn npcSpawn)
        {
            ItemSpawnParams spawmParam = new ItemSpawnParams();

            spawmParam.itemStatuses = ItemStatuses.Unidentified;
            ItemService  itemService  = new ItemService(client.character);
            ItemInstance itemInstance = null;

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(2);
            router.Send(client, (ushort)AreaPacketId.recv_situation_start, res, ServerType.Area);

            ItemLocation nextOpenLocation = client.character.itemLocationVerifier.NextOpenSlot(ItemZoneType.AdventureBag);

            if (nextOpenLocation.zoneType == ItemZoneType.InvalidZone)
            {
                res = BufferProvider.Provide();
                res.WriteCString($"Your Adventure Bag is full.  Go away already! {client.soul.name}");     // Length 0xC01
                router.Send(client, (ushort)AreaPacketId.recv_event_system_message, res, ServerType.Area); // show system message on middle of the screen.
            }
            else
            {
                if (client.character.eventSelectExecCode == 0)
                {
                    List <ItemInfoSetting> weaponlist = new List <ItemInfoSetting>();
                    foreach (ItemInfoSetting weapon in server.settingRepository.itemInfo.Values)
                    {
                        if ((weapon.id > 10100101) & (weapon.id < 15300101))
                        {
                            weaponlist.Add(weapon);
                        }
                    }

                    int baseId = weaponlist[Util.GetRandomNumber(0, weaponlist.Count)].id;
                    itemInstance = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, baseId, spawmParam);

                    RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, itemInstance);
                    router.Send(client, recvItemInstanceUnidentified.ToPacket());
                }
                else if (client.character.eventSelectExecCode == 1)
                {
                    List <ItemInfoSetting> armorList = new List <ItemInfoSetting>();
                    foreach (ItemInfoSetting armor in server.settingRepository.itemInfo.Values)
                    {
                        if ((armor.id > 16100101) & (armor.id < 30499901))
                        {
                            armorList.Add(armor);
                        }
                    }

                    int baseId = armorList[Util.GetRandomNumber(0, armorList.Count)].id;
                    itemInstance = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, baseId, spawmParam);

                    RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, itemInstance);
                    router.Send(client, recvItemInstanceUnidentified.ToPacket());
                }
                else if (client.character.eventSelectExecCode == 2)
                {
                    //50401040,Moist Cudgel
                    int baseId = 50401040; //This can select from a small array of items, and a small array of custom names
                    spawmParam.itemStatuses = ItemStatuses.Identified;
                    itemInstance            = itemService.SpawnItemInstance(ItemZoneType.AdventureBag, baseId, spawmParam);

                    RecvItemInstance recvItemInstance = new RecvItemInstance(client, itemInstance);
                    router.Send(client, recvItemInstance.ToPacket());
                }

                if (itemInstance == null)
                {
                    res = BufferProvider.Provide();
                    res.WriteCString("Better Luck Next Time.  I ran out of items!");                           // Length 0xC01
                    router.Send(client, (ushort)AreaPacketId.recv_event_system_message, res, ServerType.Area); // show system message on middle of the screen.
                    res = BufferProvider.Provide();
                    router.Send(client, (ushort)AreaPacketId.recv_situation_end, res, ServerType.Area);
                    RecvEventEnd(client); //End The Event
                    return;
                }

                res = BufferProvider.Provide();
                res.WriteCString($"Enjoy your new Super {itemInstance.unidentifiedName}");                 // Length 0xC01
                router.Send(client, (ushort)AreaPacketId.recv_event_system_message, res, ServerType.Area); // show system message on middle of the screen.
            }

            res = BufferProvider.Provide();
            router.Send(client, (ushort)AreaPacketId.recv_situation_end, res, ServerType.Area);
            RecvEventEnd(client); //End The Event
        }