public MessageDataFiller FillData(ICharacter character, IInventoryPage page)
        {
            return(x =>
            {
                x.BagIdentity = page.Identity;
                x.NumberOfSlots = page.MaxSlots;
                x.SlotnumberInMainInventory = 0;
                List <InventoryEntry> temp = new List <InventoryEntry>();

                foreach (KeyValuePair <int, IItem> kv in page.List())
                {
                    temp.Add(
                        new InventoryEntry()
                    {
                        Slotnumber = kv.Key,
                        Identity = Identity.None,
                        Quality = kv.Value.Quality,
                        HighId = kv.Value.HighID,
                        LowId = kv.Value.LowID,
                        UnknownFlags = 0x21,
                        Unknown1 = (short)kv.Value.MultipleCount,
                        Unknown2 = 0
                    });
                }
                x.Entries = temp.ToArray();
                x.Unknown2 = 1;
                x.Unknown1 = 3;
                x.Identity = character.Identity;
                x.Unknown = 1;
            });
        }
        /// <summary>
        /// </summary>
        /// <param name="fromPlacement">
        /// </param>
        /// <param name="receivingPage">
        /// </param>
        /// <param name="toPlacement">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void Unequip(int fromPlacement, IInventoryPage receivingPage, int toPlacement)
        {
            IItem toUnEquip = this[fromPlacement];

            receivingPage.Add(toPlacement, toUnEquip);
            this.Remove(fromPlacement);
        }
Exemplo n.º 3
0
 public RustItemContainerInventory(ItemContainer itemContainer)
 {
     ItemContainer = itemContainer;
     Pages         = new IInventoryPage[]
     {
         new RustInventoryPage(ItemContainer, this, ItemContainer.parent?.info?.displayName?.translated)
     };
 }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="page">
        /// </param>
        /// <param name="slotNumber">
        /// </param>
        public static void Send(IZoneClient client, IInventoryPage page, int slotNumber)
        {
            switch (slotNumber)
            {
            case 6:
                var action167Message = new CharacterActionMessage()
                {
                    Identity =
                        client.Controller.Character.Identity,
                    Action =
                        CharacterActionType
                        .ChangeAnimationAndStance,
                };
                client.Controller.Character.Playfield.Announce(action167Message);

                var equipMessage = new CharacterActionMessage()
                {
                    Identity   = client.Controller.Character.Identity,
                    Action     = CharacterActionType.Equip,
                    Target     = page.Identity,
                    Parameter1 = 0,
                    Parameter2 = 6,
                };
                client.Controller.Character.Send(equipMessage);
                break;

            default:
                IItem item = page[slotNumber];
                var   templateActionMessage = new TemplateActionMessage()
                {
                    Identity =
                        client.Controller.Character.Identity,
                    ItemHighId = item.HighID,
                    ItemLowId  = item.LowID,
                    Quality    = item.Quality,
                    Unknown1   = 1,
                    Unknown2   =
                        page is SocialArmorInventoryPage
                                                            ? 7
                                                            : 6,
                    Placement =
                        new Identity()
                    {
                        Type =
                            page.Identity
                            .Type,
                        Instance =
                            slotNumber
                    },
                    Unknown = 0,
                };
                client.Controller.Character.Send(templateActionMessage);
                break;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="sendingPage">
        /// </param>
        /// <param name="fromPlacement">
        /// </param>
        /// <param name="toPlacement">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void HotSwap(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
        {
            IItem toEquip     = sendingPage[fromPlacement];
            IItem hotSwapItem = this[toPlacement];

            sendingPage.Remove(fromPlacement);
            this.Remove(toPlacement);

            sendingPage.Add(fromPlacement, hotSwapItem);
            this.Add(toPlacement, toEquip);
        }
Exemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="page">
        /// </param>
        /// <param name="slotNumber">
        /// </param>
        public static void Send(IZoneClient client, IInventoryPage page, int slotNumber)
        {
            switch (slotNumber)
            {
                case 6:
                    var action167Message = new CharacterActionMessage()
                                           {
                                               Identity =
                                                   client.Controller.Character.Identity,
                                               Action =
                                                   CharacterActionType
                                                   .ChangeAnimationAndStance,
                                           };
                    client.Controller.Character.Playfield.Announce(action167Message);

                    var equipMessage = new CharacterActionMessage()
                                       {
                                           Identity = client.Controller.Character.Identity,
                                           Action = CharacterActionType.Equip,
                                           Target = page.Identity,
                                           Parameter1 = 0,
                                           Parameter2 = 6,
                                       };
                    client.Controller.Character.Send(equipMessage);
                    break;
                default:
                    IItem item = page[slotNumber];
                    var templateActionMessage = new TemplateActionMessage()
                                                {
                                                    Identity =
                                                        client.Controller.Character.Identity,
                                                    ItemHighId = item.HighID,
                                                    ItemLowId = item.LowID,
                                                    Quality = item.Quality,
                                                    Unknown1 = 1,
                                                    Unknown2 =
                                                        page is SocialArmorInventoryPage
                                                            ? 7
                                                            : 6,
                                                    Placement =
                                                        new Identity()
                                                        {
                                                            Type =
                                                                page.Identity
                                                                .Type,
                                                            Instance =
                                                                slotNumber
                                                        },
                                                    Unknown = 0,
                                                };
                    client.Controller.Character.Send(templateActionMessage);
                    break;
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="sendingPage">
        /// </param>
        /// <param name="fromPlacement">
        /// </param>
        /// <param name="toPlacement">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void Equip(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
        {
            IItem toEquip = sendingPage[fromPlacement];

            // First: Check if the item can be worn
            bool canBeWornCheck = (toEquip.GetAttribute(30) & (int)CanFlags.Wear) == (int)CanFlags.Wear;

            if (canBeWornCheck)
            {
                this.Add(toPlacement, toEquip);
                sendingPage.Remove(fromPlacement);
            }
        }
Exemplo n.º 8
0
        public RustItemContainerInventory(ItemContainer itemContainer)
        {
            ItemContainer = itemContainer;

            string?name = null;

            if (ItemContainer.parent != null && itemContainer.parent.info != null)
            {
                name = ItemContainer.parent.info.displayName?.translated;
            }

            Pages = new IInventoryPage[]
            {
                new RustInventoryPage(ItemContainer, this, name)
            };
        }
 private MessageDataFiller Filler(IEntity shop, IInventoryPage page)
 {
     return(x =>
     {
         x.Identity = shop.Identity;
         x.Unknown = 1;
         List <VendingMachineSlot> tempList = new List <VendingMachineSlot>();
         foreach (IItem item in page.List().Values)
         {
             VendingMachineSlot temp = new VendingMachineSlot();
             temp.ItemHighId = item.HighID;
             temp.ItemLowId = item.LowID;
             temp.Quality = item.Quality;
             tempList.Add(temp);
         }
         x.VendingMachineSlots = tempList.ToArray();
     });
 }
        /// <summary>
        /// </summary>
        /// <param name="page">
        /// </param>
        /// <param name="item">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// </exception>
        public static Actions GetAction(IInventoryPage page, IItem item)
        {
            Actions action = null;

            // TODO: Add special check for social page
            if ((page is ArmorInventoryPage) || (page is ImplantInventoryPage))
            {
                action = item.ItemActions.SingleOrDefault(x => x.ActionType == (int)ActionType.ToWear);
                if (action == null)
                {
                    return(new Actions());
                }
            }

            if (page is WeaponInventoryPage)
            {
                action = item.ItemActions.SingleOrDefault(x => x.ActionType == (int)ActionType.ToWield);
                if (action == null)
                {
                    return(new Actions());
                }
            }

            if (page is PlayerInventoryPage)
            {
                // No checks needed for unequipping
                return(new Actions());
            }

            if (page is SocialArmorInventoryPage)
            {
                // TODO: Check for side, sex, breed conditionals
                return(new Actions());
            }

            if (action == null)
            {
                throw new NotSupportedException(
                          "No suitable action found for equipping to this page: " + page.GetType());
            }

            return(action);
        }
Exemplo n.º 11
0
        /// <summary>
        /// </summary>
        /// <param name="sourceContainerType">
        /// </param>
        /// <param name="sourcePlacement">
        /// </param>
        /// <param name="target">
        /// </param>
        /// <param name="targetPlacement">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public bool ContainerAddItem(int sourceContainerType, int sourcePlacement, Identity target, int targetPlacement)
        {
            // Procedure:
            // 1. Check if source location has item
            // 2. Check if target container exists
            // 3. Switch source with target

            // Source container exists
            if (this.Character.BaseInventory.Pages.ContainsKey(sourceContainerType))
            {
                IInventoryPage sourcePage = this.Character.BaseInventory.Pages[sourceContainerType];

                // Source is not null
                if (sourcePage[sourcePlacement] != null)
                {
                    if (this.Character.Identity == target)
                    {
                        IInventoryPage targetPage = this.Character.BaseInventory.PageFromSlot(targetPlacement);
                        if (targetPage != null)
                        {
                            IItem itemSource = sourcePage.Remove(sourcePlacement);
                            IItem itemTarget = targetPage.Remove(targetPlacement);
                            if (itemTarget != null)
                            {
                                sourcePage.Add(sourcePlacement, itemTarget);
                            }

                            if (itemSource != null)
                            {
                                targetPage.Add(targetPlacement, itemSource);
                            }
                        }
                    }
                    else
                    {
                        // Put it into the other players/npcs trade window?
                    }
                }
            }

            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// </summary>
        /// <param name="container">
        /// </param>
        /// <param name="placement">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="NullReferenceException">
        /// </exception>
        public Item GetItemInContainer(int container, int placement)
        {
            try
            {
                IInventoryPage inventoryPage = this.Pages[container];
                if (inventoryPage.ValidSlot(placement))
                {
                    if (inventoryPage[placement] != null)
                    {
                        return((Item)inventoryPage[placement]);
                    }
                }

                throw new NullReferenceException("Container/Placement error: " + container + "/" + placement);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public IItem[] GetItems(IInventoryPage page)
 {
     List<IItem> result = new List<IItem>();
     foreach (KeyValuePair<int, int> kv in this.Content)
     {
         IItem item = page[kv.Key];
         if (ItemLoader.ItemList[item.LowID].IsStackable())
         {
             item.MultipleCount *= kv.Value;
             result.Add(item);
         }
         else
         {
             for (int i = 0; i < kv.Value; i++)
             {
                 result.Add(item);
             }
         }
     }
     return result.ToArray();
 }
Exemplo n.º 14
0
        /// <summary>
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="page">
        /// </param>
        /// <param name="slotNumber">
        /// </param>
        public static void Send(IZoneClient client, IInventoryPage page, int slotNumber)
        {
            switch (slotNumber)
            {
            case 6:
                var action97Message = new CharacterActionMessage()
                {
                    Identity   = client.Controller.Character.Identity,
                    Action     = CharacterActionType.Unknown3,
                    Parameter2 = 6
                };
                client.Controller.Character.Send(action97Message);
                break;

            default:
                IItem item = page[slotNumber];
                var   templateActionMessage = new TemplateActionMessage()
                {
                    Identity =
                        client.Controller.Character.Identity,
                    ItemHighId = item.HighID,
                    ItemLowId  = item.LowID,
                    Quality    = item.Quality,
                    Unknown1   = 1,
                    Unknown2   = 7,
                    Placement  =
                        new Identity()
                    {
                        Type =
                            page.Identity
                            .Type,
                        Instance =
                            slotNumber
                    },
                    Unknown = 0,
                };
                client.Controller.Character.Send(templateActionMessage);
                break;
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// </summary>
 /// <param name="client">
 /// </param>
 /// <param name="page">
 /// </param>
 /// <param name="slotNumber">
 /// </param>
 public static void Send(IZoneClient client, IInventoryPage page, int slotNumber)
 {
     switch (slotNumber)
     {
         case 6:
             var action97Message = new CharacterActionMessage()
                                   {
                                       Identity = client.Controller.Character.Identity,
                                       Action = CharacterActionType.Unknown3,
                                       Parameter2 = 6
                                   };
             client.Controller.Character.Send(action97Message);
             break;
         default:
             IItem item = page[slotNumber];
             var templateActionMessage = new TemplateActionMessage()
                                         {
                                             Identity =
                                                 client.Controller.Character.Identity,
                                             ItemHighId = item.HighID,
                                             ItemLowId = item.LowID,
                                             Quality = item.Quality,
                                             Unknown1 = 1,
                                             Unknown2 = 7,
                                             Placement =
                                                 new Identity()
                                                 {
                                                     Type =
                                                         page.Identity
                                                         .Type,
                                                     Instance =
                                                         slotNumber
                                                 },
                                             Unknown = 0,
                                         };
             client.Controller.Character.Send(templateActionMessage);
             break;
     }
 }
Exemplo n.º 16
0
        public IItem[] GetItems(IInventoryPage page)
        {
            List <IItem> result = new List <IItem>();

            foreach (KeyValuePair <int, int> kv in this.Content)
            {
                IItem item = page[kv.Key];
                if (ItemLoader.ItemList[item.LowID].IsStackable())
                {
                    item.MultipleCount *= kv.Value;
                    result.Add(item);
                }
                else
                {
                    for (int i = 0; i < kv.Value; i++)
                    {
                        result.Add(item);
                    }
                }
            }
            return(result.ToArray());
        }
 /// <summary>
 /// </summary>
 /// <param name="fromPlacement">
 /// </param>
 /// <param name="receivingPage">
 /// </param>
 /// <param name="toPlacement">
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public void Unequip(int fromPlacement, IInventoryPage receivingPage, int toPlacement)
 {
     IItem toUnEquip = this[fromPlacement];
     receivingPage.Add(toPlacement, toUnEquip);
     this.Remove(fromPlacement);
 }
 public void Send(ICharacter receiver, IEntity shop, IInventoryPage page)
 {
     base.Send(receiver, this.Filler(shop, page));
 }
Exemplo n.º 19
0
 /// <summary>
 /// </summary>
 /// <param name="pageFrom">
 /// </param>
 /// <param name="fromSlot">
 /// </param>
 /// <param name="pageTo">
 /// </param>
 /// <param name="toSlot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool EquipItem(IInventoryPage pageFrom, int fromSlot, IInventoryPage pageTo, int toSlot)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
 public void Unequip(int fromPlacement, IInventoryPage receivingPage, int toPlacement)
 {
     throw new NotImplementedException();
 }
 public void Send(ICharacter character, IInventoryPage page)
 {
     this.Send(character, this.FillData(character, page));
 }
        /// <summary>
        /// </summary>
        /// <param name="sendingPage">
        /// </param>
        /// <param name="fromPlacement">
        /// </param>
        /// <param name="toPlacement">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void Equip(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
        {
            IItem toEquip = sendingPage[fromPlacement];

            // First: Check if the item can be worn
            bool canBeWornCheck = (toEquip.GetAttribute(30) & (int)CanFlags.Wear) == (int)CanFlags.Wear;

            if (canBeWornCheck)
            {
                this.Add(toPlacement, toEquip);
                sendingPage.Remove(fromPlacement);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="sendingPage">
        /// </param>
        /// <param name="fromPlacement">
        /// </param>
        /// <param name="toPlacement">
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public void HotSwap(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
        {
            IItem toEquip = sendingPage[fromPlacement];
            IItem hotSwapItem = this[toPlacement];

            sendingPage.Remove(fromPlacement);
            this.Remove(toPlacement);

            sendingPage.Add(fromPlacement, hotSwapItem);
            this.Add(toPlacement, toEquip);
        }
Exemplo n.º 24
0
        /// <summary>
        /// </summary>
        /// <param name="page">
        /// </param>
        /// <param name="item">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// </exception>
        public static Actions GetAction(IInventoryPage page, IItem item)
        {
            Actions action = null;

            // TODO: Add special check for social page
            if ((page is ArmorInventoryPage) || (page is ImplantInventoryPage))
            {
                action = item.ItemActions.SingleOrDefault(x => x.ActionType == (int)ActionType.ToWear);
                if (action == null)
                {
                    return new Actions();
                }
            }

            if (page is WeaponInventoryPage)
            {
                action = item.ItemActions.SingleOrDefault(x => x.ActionType == (int)ActionType.ToWield);
                if (action == null)
                {
                    return new Actions();
                }
            }

            if (page is PlayerInventoryPage)
            {
                // No checks needed for unequipping
                return new Actions();
            }

            if (page is SocialArmorInventoryPage)
            {
                // TODO: Check for side, sex, breed conditionals
                return new Actions();
            }

            if (action == null)
            {
                throw new NotSupportedException(
                    "No suitable action found for equipping to this page: " + page.GetType());
            }

            return action;
        }
 public void Unequip(int fromPlacement, IInventoryPage receivingPage, int toPlacement)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 /// <summary>
 /// </summary>
 /// <param name="item1Page">
 /// </param>
 /// <param name="item1Slot">
 /// </param>
 /// <param name="item2Page">
 /// </param>
 /// <param name="item2Slot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool UseItemOnItem(IInventoryPage item1Page, int item1Slot, IInventoryPage item2Page, int item2Slot)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 27
0
        public static void AddItemToContainer(ContainerAddItemMessage message, Client cli)
        {
            var noAppearanceUpdate = false;

            /* Container ID's:
             * 0065 Weaponpage
             * 0066 Armorpage
             * 0067 Implantpage
             * 0068 Inventory (places 64-93)
             * 0069 Bank
             * 006B Backpack
             * 006C KnuBot Trade Window
             * 006E Overflow window
             * 006F Trade Window
             * 0073 Socialpage
             * 0767 Shop Inventory
             * 0790 Playershop Inventory
             * DEAD Trade Window (incoming)
             */
            var fromContainerID = (int)message.SourceContainer.Type;
            var fromPlacement   = message.SourceContainer.Instance;
            var toIdentity      = message.Target;
            var toPlacement     = message.TargetPlacement;

            // Where and what does need to be moved/added?
            IInventoryPage sendingPage = cli.Character.BaseInventory.Pages[fromContainerID];
            IItem          itemFrom    = sendingPage[fromPlacement];

            // Receiver of the item (IInstancedEntity, can be mostly all from NPC, Character or Bag, later even playfields)
            IItemContainer itemReceiver = cli.Playfield.FindByIdentity(toIdentity) as IItemContainer;

            if (itemReceiver == null)
            {
                throw new ArgumentOutOfRangeException("No Entity found: " + message.Target.Type.ToString() + ":" + message.Target.Instance);
            }

            // On which inventorypage should the item be added?
            IInventoryPage receivingPage = itemReceiver.BaseInventory.PageFromSlot(toPlacement);

            // Get standard page if toplacement cant be found (0x6F for next free slot)
            // TODO: If Entities are not the same (other player, bag etc) then always add to the standard page
            if (receivingPage == null)
            {
                receivingPage = itemReceiver.BaseInventory.Pages[itemReceiver.BaseInventory.StandardPage];
            }

            if (receivingPage == null)
            {
                throw new ArgumentOutOfRangeException("No inventorypage found.");
            }

            if (toPlacement == 0x6f)
            {
                toPlacement = receivingPage.FindFreeSlot();
            }

            // Is there already a item?
            IItem itemTo;

            try
            {
                itemTo = receivingPage[toPlacement];
            }
            catch (Exception)
            {
                itemTo = null;
            }

            // Calculating delay for equip/unequip/switch gear
            var delay = 0;

            if (itemFrom != null)
            {
                delay += itemFrom.GetAttribute(211);
            }

            if (itemTo != null)
            {
                delay += itemTo.GetAttribute(211);
            }

            if (delay == 0)
            {
                delay = 200;
            }

            int counter;

            cli.Character.DoNotDoTimers = true;
            IItemSlotHandler equipTo     = receivingPage as IItemSlotHandler;
            IItemSlotHandler unequipFrom = sendingPage as IItemSlotHandler;

            if (equipTo != null)
            {
                if (itemTo != null)
                {
                    equipTo.HotSwap(sendingPage, fromPlacement, toPlacement);
                }
                else
                {
                    equipTo.Equip(sendingPage, fromPlacement, toPlacement);
                }
            }
            else
            {
                if (unequipFrom != null)
                {
                    unequipFrom.Unequip(fromPlacement, receivingPage, toPlacement);
                }
            }

            /*
             * switch (fromContainerID)
             * {
             *  case 0x68:
             *
             *      // from Inventory
             *      if (toPlacement <= 30)
             *      {
             *          // to Weaponspage or Armorpage
             *          // TODO: Send some animation
             *          if (itemTo != null)
             *          {
             *              cli.Character.UnequipItem(itemTo, cli.Character, false, fromPlacement);
             *
             *              // send interpolated item
             *              Unequip.Send(cli, itemTo, InventoryPage(toPlacement), toPlacement);
             *
             *              // client takes care of hotswap
             *              cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
             *              Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
             *          }
             *          else
             *          {
             *              cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
             *              Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
             *          }
             *      }
             *      else
             *      {
             *          if (toPlacement < 46)
             *          {
             *              if (itemTo == null)
             *              {
             *                  cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement);
             *                  Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement);
             *              }
             *          }
             *
             *          // Equiping to social page
             *          if ((toPlacement >= 49) && (toPlacement <= 63))
             *          {
             *              if (itemTo != null)
             *              {
             *                  cli.Character.UnequipItem(itemTo, cli.Character, true, fromPlacement);
             *
             *                  // send interpolated item
             *                  cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement);
             *              }
             *              else
             *              {
             *                  cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement);
             *              }
             *
             *              // cli.Character.switchItems(cli, fromplacement, toplacement);
             *          }
             *      }
             *
             *      cli.Character.SwitchItems(fromPlacement, toPlacement);
             *      cli.Character.CalculateSkills();
             *      noAppearanceUpdate = false;
             *      break;
             *  case 0x66:
             *
             *      // from Armorpage
             *      cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
             *
             *      // send interpolated item
             *      Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
             *      cli.Character.SwitchItems(fromPlacement, toPlacement);
             *      cli.Character.CalculateSkills();
             *      noAppearanceUpdate = false;
             *      break;
             *  case 0x65:
             *
             *      // from Weaponspage
             *      cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
             *
             *      // send interpolated item
             *      Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
             *      cli.Character.SwitchItems(fromPlacement, toPlacement);
             *      cli.Character.CalculateSkills();
             *      noAppearanceUpdate = false;
             *      break;
             *  case 0x67:
             *
             *      // from Implantpage
             *      cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement);
             *
             *      // send interpolated item
             *      Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement);
             *      cli.Character.SwitchItems(fromPlacement, toPlacement);
             *      cli.Character.CalculateSkills();
             *      noAppearanceUpdate = true;
             *      break;
             *  case 0x73:
             *      cli.Character.UnequipItem(itemFrom, cli.Character, true, fromPlacement);
             *
             *      cli.Character.SwitchItems(fromPlacement, toPlacement);
             *      cli.Character.CalculateSkills();
             *      break;
             *  case 0x69:
             *      cli.Character.TransferItemfromBank(fromPlacement, toPlacement);
             *      toPlacement = 0x6f; // setting back to 0x6f for packet reply
             *      noAppearanceUpdate = true;
             *      break;
             *  case 0x6c:
             *
             *      // KnuBot Trade Window
             *      cli.Character.TransferItemfromKnuBotTrade(fromPlacement, toPlacement);
             *      break;
             *  default:
             *      break;
             * }
             * }*/

            cli.Character.DoNotDoTimers = false;
            if ((equipTo != null) || (unequipFrom != null))
            {
                // Equipmentpages need delays
                // Delay when equipping/unequipping
                // has to be redone, jumping breaks the equiping/unequiping
                // and other messages have to be done too
                // like heartbeat timer, damage from environment and such
                Thread.Sleep(delay);
            }
            else
            {
                Thread.Sleep(200); // social has to wait for 0.2 secs too (for helmet update)
            }

            /*
             * SwitchItem.Send(
             *  cli,
             *  fromContainerID,
             *  fromPlacement,
             *  new Identity { Type = toIdentity.Type, Instance = toIdentity.Instance },
             *  toPlacement);
             */
            cli.Character.Stats.ClearChangedFlags();
            if (!noAppearanceUpdate)
            {
                throw new NotImplementedException("TODO");
                //cli.Character.AppearanceUpdate();
            }

            itemFrom = null;
            itemTo   = null;
        }
Exemplo n.º 28
0
 public static IItem FindByAssetId(this IInventoryPage page, string itemAssetId, IComparer <IItem> comparer = null)
 {
     return(FindByAssetId((IEnumerable <IItem>)page, itemAssetId, comparer));
 }
        /// <summary>
        /// </summary>
        /// <param name="message">
        /// </param>
        /// <param name="cli">
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// </exception>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public static void AddItemToContainer(ContainerAddItemMessage message, ZoneClient cli)
        {
            bool noAppearanceUpdate = false;

            /* Container ID's:
             * 0065 Weaponpage
             * 0066 Armorpage
             * 0067 Implantpage
             * 0068 Inventory (places 64-93)
             * 0069 Bank
             * 006B Backpack
             * 006C KnuBot Trade Window
             * 006E Overflow window
             * 006F Trade Window
             * 0073 Socialpage
             * 0767 Shop Inventory
             * 0790 Playershop Inventory
             * DEAD Trade Window (incoming) It's bank now (when you put something into the bank)
             */
            var      fromContainerID = (int)message.SourceContainer.Type;
            int      fromPlacement   = message.SourceContainer.Instance;
            Identity toIdentity      = message.Target;
            int      toPlacement     = message.TargetPlacement;

            // Where and what does need to be moved/added?
            IInventoryPage sendingPage = cli.Character.BaseInventory.Pages[fromContainerID];
            IItem          itemFrom    = sendingPage[fromPlacement];

            // Receiver of the item (IInstancedEntity, can be mostly all from NPC, Character or Bag, later even playfields)
            // Turn 0xDEAD into C350 if instance is the same
            if (toIdentity.Type == IdentityType.IncomingTradeWindow)
            {
                toIdentity.Type = IdentityType.CanbeAffected;
            }

            IItemContainer itemReceiver = cli.Playfield.FindByIdentity(toIdentity) as IItemContainer;

            if (itemReceiver == null)
            {
                throw new ArgumentOutOfRangeException(
                          "No Entity found: " + message.Target.Type.ToString() + ":" + message.Target.Instance);
            }

            // On which inventorypage should the item be added?
            IInventoryPage receivingPage;

            if ((toPlacement == 0x6f) && (message.Target.Type == IdentityType.IncomingTradeWindow))
            {
                receivingPage = itemReceiver.BaseInventory.Pages[(int)IdentityType.Bank];
            }
            else
            {
                receivingPage = itemReceiver.BaseInventory.PageFromSlot(toPlacement);
            }

            // Get standard page if toplacement cant be found (0x6F for next free slot)
            // TODO: If Entities are not the same (other player, bag etc) then always add to the standard page
            if ((receivingPage == null) || (itemReceiver.GetType() != cli.Character.GetType()))
            {
                receivingPage = itemReceiver.BaseInventory.Pages[itemReceiver.BaseInventory.StandardPage];
            }

            if (receivingPage == null)
            {
                throw new ArgumentOutOfRangeException("No inventorypage found.");
            }

            if (toPlacement == 0x6f)
            {
                toPlacement = receivingPage.FindFreeSlot();
            }

            // Is there already a item?
            IItem itemTo;

            try
            {
                itemTo = receivingPage[toPlacement];
            }
            catch (Exception)
            {
                itemTo = null;
            }

            // Calculating delay for equip/unequip/switch gear
            int delay = 20;

            cli.Character.DoNotDoTimers = true;
            IItemSlotHandler equipTo     = receivingPage as IItemSlotHandler;
            IItemSlotHandler unequipFrom = sendingPage as IItemSlotHandler;

            noAppearanceUpdate =
                !((equipTo is WeaponInventoryPage) || (equipTo is ArmorInventoryPage) ||
                  (equipTo is SocialArmorInventoryPage));
            noAppearanceUpdate &=
                !((unequipFrom is WeaponInventoryPage) || (unequipFrom is ArmorInventoryPage) ||
                  (unequipFrom is SocialArmorInventoryPage));

            if (equipTo != null)
            {
                if (itemTo != null)
                {
                    if (receivingPage.NeedsItemCheck)
                    {
                        Actions action = GetAction(sendingPage, itemFrom);

                        if (action.CheckRequirements(cli.Character))
                        {
                            UnEquip.Send(cli, receivingPage, toPlacement);
                            if (!noAppearanceUpdate)
                            {
                                // Equipmentpages need delays
                                // Delay when equipping/unequipping
                                // has to be redone, jumping breaks the equiping/unequiping
                                // and other messages have to be done too
                                // like heartbeat timer, damage from environment and such

                                delay = (itemFrom.GetAttribute(211) == 1234567890 ? 20 : itemFrom.GetAttribute(211))
                                        + (itemTo.GetAttribute(211) == 1234567890 ? 20 : itemTo.GetAttribute(211));
                            }

                            Thread.Sleep(delay * 10); // social has to wait for 0.2 secs too (for helmet update)

                            cli.Character.Send(message);
                            equipTo.HotSwap(sendingPage, fromPlacement, toPlacement);
                            Equip.Send(cli, receivingPage, toPlacement);
                        }
                    }
                }
                else
                {
                    if (receivingPage.NeedsItemCheck)
                    {
                        if (itemFrom == null)
                        {
                            throw new NullReferenceException("itemFrom can not be null, possible inventory error");
                        }

                        Actions action = GetAction(receivingPage, itemFrom);

                        if (action.CheckRequirements(cli.Character))
                        {
                            if (!noAppearanceUpdate)
                            {
                                // Equipmentpages need delays
                                // Delay when equipping/unequipping
                                // has to be redone, jumping breaks the equiping/unequiping
                                // and other messages have to be done too
                                // like heartbeat timer, damage from environment and such

                                delay = itemFrom.GetAttribute(211);
                                if ((equipTo is SocialArmorInventoryPage) || (delay == 1234567890))
                                {
                                    delay = 20;
                                }

                                Thread.Sleep(delay * 10);
                            }

                            if (sendingPage == receivingPage)
                            {
                                // Switch rings for example
                                UnEquip.Send(cli, sendingPage, fromPlacement);
                            }

                            cli.Character.Send(message);
                            equipTo.Equip(sendingPage, fromPlacement, toPlacement);
                            Equip.Send(cli, receivingPage, toPlacement);
                        }
                    }
                }
            }
            else
            {
                if (unequipFrom != null)
                {
                    // Send to client first
                    if (!noAppearanceUpdate)
                    {
                        // Equipmentpages need delays
                        // Delay when equipping/unequipping
                        // has to be redone, jumping breaks the equiping/unequiping
                        // and other messages have to be done too
                        // like heartbeat timer, damage from environment and such

                        delay = itemFrom.GetAttribute(211);
                        if ((unequipFrom is SocialArmorInventoryPage) || (delay == 1234567890))
                        {
                            delay = 20;
                        }

                        Thread.Sleep(delay * 10);
                    }

                    UnEquip.Send(cli, sendingPage, fromPlacement);
                    unequipFrom.Unequip(fromPlacement, receivingPage, toPlacement);
                    cli.Character.Send(message);
                }
                else
                {
                    // No equipment page involved, just send ContainerAddItemMessage back
                    message.TargetPlacement = receivingPage.FindFreeSlot();
                    IItem item = sendingPage.Remove(fromPlacement);
                    receivingPage.Add(message.TargetPlacement, item);
                    cli.Character.Send(message);
                }
            }

            cli.Character.DoNotDoTimers = false;

            cli.Character.Stats.ClearChangedFlags();

            // Apply item functions before sending the appearanceupdate message
            cli.Character.CalculateSkills();

            if (!noAppearanceUpdate)
            {
                AppearanceUpdate.AnnounceAppearanceUpdate(cli.Character);
            }
        }
Exemplo n.º 30
0
 public static IItem FindByType(this IInventoryPage page, string itemType, IComparer <IItem> comparer = null)
 {
     return(FindByType((IEnumerable <IItem>)page, itemType, comparer));
 }
Exemplo n.º 31
0
 /// <summary>
 /// </summary>
 /// <param name="item1Page">
 /// </param>
 /// <param name="item1Slot">
 /// </param>
 /// <param name="item2Page">
 /// </param>
 /// <param name="item2Slot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool UseItemOnItem(IInventoryPage item1Page, int item1Slot, IInventoryPage item2Page, int item2Slot)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 32
0
 /// <summary>
 /// </summary>
 /// <param name="page">
 /// </param>
 /// <param name="slot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool DeleteItem(IInventoryPage page, int slot)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
 public void Equip(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 34
0
 /// <summary>
 /// </summary>
 /// <param name="pageFrom">
 /// </param>
 /// <param name="fromSlot">
 /// </param>
 /// <param name="pageTo">
 /// </param>
 /// <param name="toSlot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool EquipItem(IInventoryPage pageFrom, int fromSlot, IInventoryPage pageTo, int toSlot)
 {
     throw new NotImplementedException();
 }
 public void HotSwap(IInventoryPage sendingPage, int fromPlacement, int toPlacement)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 36
0
 /// <summary>
 /// </summary>
 /// <param name="page">
 /// </param>
 /// <param name="slot">
 /// </param>
 /// <returns>
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public bool DeleteItem(IInventoryPage page, int slot)
 {
     throw new NotImplementedException();
 }