public override void Handle(NecClient client, NecPacket packet)
        {
            client.map.deadBodies.TryGetValue(client.character.eventSelectReadyCode, out DeadBody deadBody);
            Character deadCharacter = _server.instances.GetCharacterByInstanceId(deadBody.characterInstanceId);
            //Todo - server or map needs to maintain characters in memory for a period of time after disconnect
            NecClient deadClient = _server.clients.GetByCharacterInstanceId(deadBody.characterInstanceId);

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0); //result, 0 sucess.  interupted, etc.
            res.WriteFloat(0); // time remaining
            router.Send(client, (ushort)AreaPacketId.recv_charabody_loot_complete2_r, res, ServerType.Area);

            if (deadClient != null)
            {
                res = BufferProvider.Provide();
                res.WriteByte((byte)deadCharacter.lootNotify.zoneType);
                res.WriteByte(deadCharacter.lootNotify.container);
                res.WriteInt16(deadCharacter.lootNotify.slot);

                res.WriteInt16(1 /*iteminstance.Quantity*/);  //Number here is "pieces"
                res.WriteCString($"{client.soul.name}");      // soul name
                res.WriteCString($"{client.character.name}"); // chara name
                router.Send(deadClient, (ushort)AreaPacketId.recv_charabody_notify_loot_item, res, ServerType.Area);
            }

            //if (successfull loot condition here)
            {
                ItemService itemService = new ItemService(client.character);
                ItemService deadCharacterItemService = new ItemService(deadCharacter);

                ItemInstance iteminstance = deadCharacterItemService.GetLootedItem(deadCharacter.lootNotify);
                //remove the icon from the deadClient's inventory if they are online.
                RecvItemRemove recvItemRemove = new RecvItemRemove(deadClient, iteminstance);
                if (deadClient != null)
                {
                    router.Send(recvItemRemove);
                }

                //Add RecvItemRemove to remove the icon from the charabody window on successfull loot as well.//ToDo - this didnt work
                RecvItemRemove recvItemRemove2 = new RecvItemRemove(client, iteminstance);
                router.Send(recvItemRemove2);

                //update the item statuses to unidentified
                iteminstance.statuses |= ItemStatuses.Unidentified;
                //put the item in the new owners inventory
                itemService.PutLootedItem(iteminstance);

                RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, iteminstance);
                router.Send(client, recvItemInstanceUnidentified.ToPacket());
            }
        }
        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());
                }
            }
        }
        public override void Handle(NecClient client, NecPacket packet)
        {
            ItemZoneType fromZone      = (ItemZoneType)packet.data.ReadByte();
            byte         fromContainer = packet.data.ReadByte();
            short        fromSlot      = packet.data.ReadInt16();
            ItemLocation fromLoc       = new ItemLocation(fromZone, fromContainer, fromSlot);

            client.map.deadBodies.TryGetValue(client.character.eventSelectReadyCode, out DeadBody deadBody);
            Character   deadCharacter            = _server.instances.GetInstance(deadBody.characterInstanceId) as Character;
            ItemService itemService              = new ItemService(client.character);
            ItemService deadCharacterItemService = new ItemService(deadCharacter);

            ItemInstance iteminstance = deadCharacterItemService.GetLootedItem(fromLoc);

            itemService.PutLootedItem(iteminstance);

            RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, iteminstance);

            router.Send(client, recvItemInstanceUnidentified.ToPacket());
        }
Exemplo n.º 4
0
        public override void Handle(NecClient client, NecPacket packet)
        {
            uint instanceId = packet.data.ReadUInt32();

            _Logger.Debug($"Accessing Body ID {instanceId}");
            client.character.eventSelectReadyCode = instanceId; // store the Instance of the body you are looting on your character.

            IBuffer res = BufferProvider.Provide();

            res.WriteInt32(0); //Insert logic gate here. should not always succeed
            router.Send(client, (ushort)AreaPacketId.recv_charabody_access_start_r, res, ServerType.Area);
            //SALVAGE_DEADBODY,-510,It is protected by a mysterious power., SYSTEM_IMPORTANCE,
            //SALVAGE_DEADBODY,-513, It is protected by a mysterious power., SYSTEM_IMPORTANCE,
            // SALVAGE_DEADBODY,-514, It is protected by a mysterious power., SYSTEM_IMPORTANCE,
            //  SALVAGE_DEADBODY,-528, It is protected by a mysterious power., SYSTEM_IMPORTANCE,
            //   SALVAGE_DEADBODY,-526, It cannot be stolen from party members., SYSTEM_IMPORTANCE,
            //   SALVAGE_DEADBODY,-519, The soul is about to revive..., SYSTEM_NOTIFY,
            //   SALVAGE_DEADBODY,-507, No more corpses can be recovered., SYSTEM_NOTIFY,


            if (instanceId == 0)
            {
                return;
            }
            if (instanceId == client.character.deadBodyInstanceId)
            {
                _Logger.Debug("You've met with a terrible fate haven't you!");
                /////////
                //////  Insert Warp to Ressurection statue logic here.
                ///////
                return;
            }

            IInstance instance = server.instances.GetInstance(instanceId);

            switch (instance)
            {
            case DeadBody deadBody1:
                client.map.deadBodies.TryGetValue(deadBody1.instanceId, out deadBody1);
                _Logger.Debug($"Lootin  {deadBody1.soulName}? You Criminal!!");
                ItemService         itemService   = new ItemService(client.character);
                List <ItemInstance> lootableItems = itemService.GetLootableItems(deadBody1.characterInstanceId);
                foreach (ItemInstance itemInstance in lootableItems)
                {
                    ItemLocation originalLocation = itemInstance.location;
                    if (itemInstance.location.zoneType == ItemZoneType.AdventureBag)
                    {
                        itemInstance.location = new ItemLocation(ItemZoneType.CorpseAdventureBag, originalLocation.container, originalLocation.slot);
                    }
                    ;
                    if (itemInstance.location.zoneType == ItemZoneType.EquippedBags)
                    {
                        itemInstance.location = new ItemLocation(ItemZoneType.CorpseEquippedBags, originalLocation.container, originalLocation.slot);
                    }
                    ;
                    if (itemInstance.location.zoneType == ItemZoneType.PremiumBag)
                    {
                        itemInstance.location = new ItemLocation(ItemZoneType.CorpsePremiumBag, originalLocation.container, originalLocation.slot);
                    }
                    ;
                    RecvItemInstanceUnidentified recvItemInstanceUnidentified = new RecvItemInstanceUnidentified(client, itemInstance);
                    router.Send(client, recvItemInstanceUnidentified.ToPacket());
                    itemInstance.location = originalLocation;
                }

                break;

            case MonsterSpawn monsterSpawn:
                client.map.monsterSpawns.TryGetValue(monsterSpawn.instanceId, out monsterSpawn);
                _Logger.Debug($"Lootin a {monsterSpawn.name}? Hope you get some good stuff");
                /////
                ///     ---- Insert Monster Loot table logic here.  including draw box for parties
                /////
                break;

            case Character character:
                //NecClient targetClient = client.Map.ClientLookup.GetByCharacterInstanceId(instance.InstanceId);
                _Logger.Error($"Lootin a {character.name}? Shouldn't be doin that.  only deadbodies are lootable");
                break;

            case NpcSpawn npcSpawn:
                client.map.npcSpawns.TryGetValue(npcSpawn.instanceId, out npcSpawn);
                _Logger.Error("how are you looting an NPC?");
                break;

            default:
                _Logger.Error($"Instance with InstanceId: {instance.instanceId} does not exist");
                break;
            }
        }
Exemplo n.º 5
0
        public void Move(NecServer server, NecClient client)
        {
            InventoryItem fromInvItem = client.Character.GetInventoryItem(fromStoreType, fromBagId, fromSlot);
            InventoryItem toInvItem   = client.Character.GetInventoryItem(toStoreType, toBagId, toSlot);

            if (toInvItem != null && (fromInvItem.StorageCount + toInvItem.StorageCount > 255))
            {
                RecvNormalSystemMessage unlikeItems =
                    new RecvNormalSystemMessage("The move would place too many items in destination slot!");
                server.Router.Send(unlikeItems, client);
                return;
            }

            if (fromInvItem.StorageCount == itemCount)
            {
                if (toInvItem != null)
                {
                    toInvItem.StorageCount =
                        (byte)(fromInvItem.StorageCount +
                               toInvItem.StorageCount);  // huh??? byte - byte is cast as int????
                    RecvItemUpdateNum itemNum = new RecvItemUpdateNum(toInvItem.InstanceId, toInvItem.StorageCount);
                    server.Router.Send(itemNum, client);
                    RecvItemRemove removeItem = new RecvItemRemove(fromInvItem.InstanceId);
                    server.Router.Send(removeItem, client);
                    client.Character.RemoveInventoryItem(fromInvItem);
                    client.Character.UpdateInventoryItem(toInvItem);
                }
                else
                {
                    fromInvItem.StorageType = toStoreType;
                    fromInvItem.StorageId   = toBagId;
                    fromInvItem.StorageSlot = toSlot;
                    RecvItemUpdatePlace itemPlace = new RecvItemUpdatePlace(fromInvItem.InstanceId,
                                                                            fromInvItem.StorageType, fromInvItem.StorageId, fromInvItem.StorageSlot);
                    server.Router.Send(itemPlace, client);
                    client.Character.UpdateInventoryItem(fromInvItem);
                }
            }
            else
            {
                byte remainCount =
                    (byte)(fromInvItem.StorageCount - itemCount);  // huh??? byte - byte is cast as int????
                if (toInvItem != null)
                {
                    toInvItem.StorageCount =
                        (byte)(itemCount + toInvItem.StorageCount);  // huh??? byte - byte is cast as int????
                    fromInvItem.StorageCount = remainCount;
                    RecvItemUpdateNum toItemNum = new RecvItemUpdateNum(toInvItem.InstanceId, toInvItem.StorageCount);
                    server.Router.Send(toItemNum, client);
                    RecvItemUpdateNum fromItemNum =
                        new RecvItemUpdateNum(fromInvItem.InstanceId, fromInvItem.StorageCount);
                    server.Router.Send(fromItemNum, client);
                    client.Character.RemoveInventoryItem(fromInvItem);
                    client.Character.UpdateInventoryItem(toInvItem);
                }
                else
                {
                    RecvItemUpdateNum updateNum = new RecvItemUpdateNum(fromInvItem.InstanceId, remainCount);
                    server.Router.Send(updateNum, client);
                    InventoryItem newInvItem = client.Character.GetNextInventoryItem(server);
                    newInvItem.StorageCount = (byte)itemCount;
                    newInvItem.StorageType  = toStoreType;
                    newInvItem.StorageId    = toBagId;
                    newInvItem.StorageSlot  = toSlot;
                    newInvItem.StorageItem  = item;
                    RecvItemInstanceUnidentified itemUnidentified = new RecvItemInstanceUnidentified(newInvItem);
                    server.Router.Send(itemUnidentified, client);
                    fromInvItem.StorageCount = remainCount;
                    client.Character.UpdateInventoryItem(fromInvItem);
                }
            }
        }
        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
        }