Ejemplo n.º 1
0
 /// <summary>
 /// Sends the item data to the client.
 /// </summary>
 /// <param name="item">The item.</param>
 public void SendItemToClient(ItemInfo item)
 {
     item.Location = Enums.ItemLocation.Inventory;
     item.SendPacket(Owner, 1);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds an item to the warehouse.
 /// </summary>
 /// <param name="item">The item to add.</param>
 /// <returns>Returns true if the item was added.</returns>
 public bool AddItem(ItemInfo item)
 {
     return AddItem(item, FreeSpaces);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Removes an item from the inventory based on is iteminfo.
 /// </summary>
 /// <param name="info">The item info.</param>
 /// <returns>Returns true if the item was removed.</returns>
 public bool RemoveItem(ItemInfo info)
 {
     foreach (byte key in InventoryItems.Keys)
     {
         ItemInfo ritem;
         if (InventoryItems.TryGetValue(key, out ritem))
         {
             if (ritem.UID == info.UID)
             {
                 if (InventoryItems.TryRemove(key, out ritem))
                 {
                     Database.CharacterDatabase.SaveInventory(Owner, null, key);
                     RemoveItemFromClient(ritem);
                     return true;
                 }
                 else
                     return false;
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Removes the item data from the client.
 /// </summary>
 /// <param name="item">The item.</param>
 public void RemoveItemFromClient(ItemInfo item)
 {
     using (var remove = new Packets.ItemPacket())
     {
         remove.UID = item.UID;
         remove.Action = Enums.ItemAction.Remove;
         Owner.Send(remove);
     }
 }
Ejemplo n.º 5
0
        public void SetStats(ItemInfo fromItem)
        {
            Plus = fromItem.Plus;
            Bless = fromItem.Bless;
            Enchant = fromItem.Enchant;
            Gem1 = fromItem.Gem1;
            Gem2 = fromItem.Gem2;

            SocketAndRGB = fromItem.SocketAndRGB;
            CurrentDura = fromItem.CurrentDura;
            MaxDura = fromItem.MaxDura;
            RebornEffect = fromItem.RebornEffect;
            Free = fromItem.Free;
            GreenText = fromItem.GreenText;
            INS = fromItem.INS;
            Suspicious = fromItem.Suspicious;
            Locked = fromItem.Locked;
            Composition = fromItem.Composition;
            LockedTime = fromItem.LockedTime;
            Color = fromItem.Color;
            MaxDura = fromItem.MaxDura;
            CurrentDura = fromItem.CurrentDura;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds an item to the inventory.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <param name="pos">The position in the inventory.</param>
        /// <returns>Returns true if the item was added.</returns>
        public bool AddItem(ItemInfo item, byte pos)
        {
            if (Count >= 40)
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVENTORY_FULL))
                    Owner.Send(fmsg);
                return false;
            }

            if (InventoryItems.TryAdd(pos, item))
            {
                item.OwnerUID = Owner.EntityUID;
                item.Location = Enums.ItemLocation.Inventory;
                Database.CharacterDatabase.SaveInventory(Owner, item, pos);
                SendItemToClient(item);
                return true;
            }
            return false;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Replaces an equipment with a new item. This will REMOVE an existing item.
 /// </summary>
 /// <param name="item">The new item to equip.</param>
 /// <param name="pos">The position.</param>
 /// <returns>Returns true if the item was replaced.</returns>
 public bool Replace(ItemInfo item, Enums.ItemLocation pos)
 {
     return Equip(item, pos, false);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Equips a new item.
        /// </summary>
        /// <param name="item">The item to equip.</param>
        /// <param name="pos">The position to equip the item at.</param>
        /// <param name="unequip">Boolean defining whether to unequip an existing item at the position.</param>
        /// <returns>Returns true if the item was equipped.</returns>
        public bool Equip(ItemInfo item, Enums.ItemLocation pos, bool unequip = true, bool force_equip = false)
        {
            if (!force_equip)
            {
                #region Sex check
                if (item.Sex == Enums.Sex.Female && Owner.Sex != Enums.Sex.Female)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.ITEM_FEMALE))
                        Owner.Send(fmsg);

                    return(false);
                }
                #endregion

                #region Job Check
//			if (item.Profession != Enums.Class.Unknown && Core.Kernel.GetBaseClass(item.Profession) != Enums.Class.Unknown)
//			{
//				Enums.Class promoteclass = Core.Kernel.GetBaseClass(Owner.Class);
//				if (promoteclass != Core.Kernel.GetBaseClass(item.Profession))
//				{
//					using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, string.Format(Core.MessageConst.ITEM_JOB_INVALID, Core.Kernel.GetBaseClass(item.Profession).ToString())))
//						Owner.Send(fmsg);
//
//					return false;
//				}
//				else if (!Core.Kernel.AboveFirstPromotion(Owner.Class))
//				{
//					using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, string.Format(Core.MessageConst.ITEM_JOB_INVALID, Core.Kernel.GetBaseClass(item.Profession).ToString())))
//						Owner.Send(fmsg);
//
//					return false;
//				}
//			}
                #endregion

                #region Level Check
                if (Owner.Level < item.RequiredLevel)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.LEVEL_LOW))
                        Owner.Send(fmsg);

                    return(false);
                }
                #endregion

                #region Stats Check
                if (Owner.Strength < item.RequiredStrength ||
                    Owner.Agility < item.RequiredAgility ||
                    Owner.Vitality < item.RequiredVitality ||
                    Owner.Spirit < item.RequiredSpirit)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.STATS_LOW))
                        Owner.Send(fmsg);

                    return(false);
                }
                #endregion

                #region Prof Check
//			if (Owner.Level < item.RequiredProf)
//			{
//				using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.LEVEL_LOW))
//					Owner.Send(fmsg);
//
//				return false;
//			}
                #endregion
            }

            if (!force_equip)
            {
                switch (pos)
                {
                    #region Head
                case Enums.ItemLocation.Head:
                {
                    if (item.ItemType != Enums.ItemType.Head)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Necklace
                case Enums.ItemLocation.Necklace:
                {
                    if (item.ItemType != Enums.ItemType.Necklace)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Ring
                case Enums.ItemLocation.Ring:
                {
                    if (item.ItemType != Enums.ItemType.Ring)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Armor
                case Enums.ItemLocation.Armor:
                {
                    if (item.ItemType != Enums.ItemType.Armor)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Boots
                case Enums.ItemLocation.Boots:
                {
                    if (item.ItemType != Enums.ItemType.Boots)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Bottle
                case Enums.ItemLocation.Bottle:
                {
                    if (item.ItemType != Enums.ItemType.Bottle)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Garment
                case Enums.ItemLocation.Garment:
                {
                    if (MaskedGarment != null)
                    {
                        return(false);
                    }

                    if (item.ItemType != Enums.ItemType.Garment)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Steed
                case Enums.ItemLocation.Steed:
                {
                    if (Owner.ContainsFlag1(Enums.Effect1.Riding))
                    {
                        return(false);
                    }

                    if (item.ItemType != Enums.ItemType.Steed)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region SteedArmor
                case Enums.ItemLocation.SteedArmor:
                {
                    if (Owner.ContainsFlag1(Enums.Effect1.Riding))
                    {
                        return(false);
                    }

                    if (item.ItemType != Enums.ItemType.SteedArmor)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Fan
                case Enums.ItemLocation.Fan:
                {
                    return(false);

                    /*if (item.ItemType != Enums.ItemType.Fan)
                     * {
                     * using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                     *      Owner.Send(fmsg);
                     * return false;
                     * }
                     * break;*/
                }

                    #endregion
                    #region Tower
                case Enums.ItemLocation.Tower:
                {
                    return(false);

                    /*if (item.ItemType != Enums.ItemType.Tower)
                     * {
                     * using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                     *      Owner.Send(fmsg);
                     * return false;
                     * }
                     * break;*/
                }

                    #endregion
                    #region Right
                case Enums.ItemLocation.WeaponR:
                {
                    if (MaskedRightHand != null)
                    {
                        return(false);
                    }

                    if (item.ItemType != Enums.ItemType.OneHand && item.ItemType != Enums.ItemType.TwoHand &&
                        item.ItemType != Enums.ItemType.Bow)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }

                    if (Contains(Enums.ItemLocation.WeaponL) && item.ItemType == Enums.ItemType.TwoHand)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.TWO_HAND_EQUIP_FAIL))
                            Owner.Send(fmsg);
                        return(false);
                    }
                    break;
                }

                    #endregion
                    #region Left
                case Enums.ItemLocation.WeaponL:
                {
                    if (MaskedLeftHand != null)
                    {
                        return(false);
                    }

                    if (item.ItemType != Enums.ItemType.OneHand && item.ItemType != Enums.ItemType.Shield && item.ItemType != Enums.ItemType.Arrow)
                    {
                        using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                            Owner.Send(fmsg);
                        return(false);
                    }

                    if (item.ItemType == Enums.ItemType.Shield || item.ItemType == Enums.ItemType.Arrow)
                    {
                        if (!Contains(Enums.ItemLocation.WeaponR))
                        {
                            using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                Owner.Send(fmsg);
                            return(false);
                        }
                    }

                    if (!Contains(Enums.ItemLocation.WeaponR) && item.ItemType != Enums.ItemType.Shield && item.ItemType != Enums.ItemType.Arrow)
                    {
                        pos = Enums.ItemLocation.WeaponR;
                    }
                    break;
                }
                    #endregion

                    #region default
                default:
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_POS))
                        Owner.Send(fmsg);
                    return(false);
                }
                    #endregion
                }
            }
            if (Contains(pos))
            {
                if (unequip)
                {
                    if (!Unequip(pos))
                    {
                        return(false);
                    }
                }
                else if (!force_equip)
                {
                    ItemInfo ritem;
                    if (!EquipmentItems.TryRemove(pos, out ritem))
                    {
                        return(false);
                    }
                }
            }

            item.Location = pos;
            if (Owner.Inventory.ContainsByUID(item.UID) && !force_equip)
            {
                if (Owner.Inventory.RemoveItemByUID(item.UID) != null)
                {
                    item.SendPacket(Owner, 1);
                    if (EquipmentItems.TryAdd(pos, item))
                    {
                        if (Owner.LoggedIn)
                        {
                            Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                            Owner.BaseEntity.CalculateBaseStats();

                            using (var equippack = new Packets.ItemPacket())
                            {
                                equippack.UID      = item.UID;
                                equippack.Action   = Enums.ItemAction.Equip;
                                equippack.Data1Low = (ushort)pos;
                                Owner.Send(equippack);
                            }
                            SendGears();
                        }
                        return(true);
                    }
                }
            }
            else if (!force_equip)
            {
                item.SendPacket(Owner, 1);
                if (EquipmentItems.TryAdd(pos, item))
                {
                    if (Owner.LoggedIn)
                    {
                        Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                        Owner.BaseEntity.CalculateBaseStats();

                        using (var equippack = new Packets.ItemPacket())
                        {
                            equippack.UID      = item.UID;
                            equippack.Action   = Enums.ItemAction.Equip;
                            equippack.Data1Low = (ushort)pos;
                            Owner.Send(equippack);
                        }
                        SendGears();
                    }
                    return(true);
                }
            }
            else
            {
                item.SendPacket(Owner, 1);
                if (Owner.LoggedIn)
                {
                    Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                    Owner.BaseEntity.CalculateBaseStats();

                    using (var equippack = new Packets.ItemPacket())
                    {
                        equippack.UID      = item.UID;
                        equippack.Action   = Enums.ItemAction.Equip;
                        equippack.Data1Low = (ushort)pos;
                        Owner.Send(equippack);
                    }
                    SendGears();
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Clears all masked items.
 /// </summary>
 public void ClearMask()
 {
     MaskedGarment = null;
     if (Contains(Enums.ItemLocation.Garment))
         Equip(EquipmentItems[Enums.ItemLocation.Garment], Enums.ItemLocation.Garment, false, true);
     MaskedRightHand = null;
     if (Contains(Enums.ItemLocation.WeaponR))
         Equip(EquipmentItems[Enums.ItemLocation.WeaponR], Enums.ItemLocation.WeaponR, false, true);
     MaskedLeftHand = null;
     if (Contains(Enums.ItemLocation.WeaponL))
         Equip(EquipmentItems[Enums.ItemLocation.WeaponL], Enums.ItemLocation.WeaponL, false, true);
     SendGears();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Equips a new item.
        /// </summary>
        /// <param name="item">The item to equip.</param>
        /// <param name="pos">The position to equip the item at.</param>
        /// <param name="unequip">Boolean defining whether to unequip an existing item at the position.</param>
        /// <returns>Returns true if the item was equipped.</returns>
        public bool Equip(ItemInfo item, Enums.ItemLocation pos, bool unequip = true, bool force_equip = false)
        {
            if (!force_equip)
            {
                #region Sex check
                if (item.Sex == Enums.Sex.Female && Owner.Sex != Enums.Sex.Female)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.ITEM_FEMALE))
                        Owner.Send(fmsg);

                    return false;
                }
                #endregion

                #region Job Check
            //			if (item.Profession != Enums.Class.Unknown && Core.Kernel.GetBaseClass(item.Profession) != Enums.Class.Unknown)
            //			{
            //				Enums.Class promoteclass = Core.Kernel.GetBaseClass(Owner.Class);
            //				if (promoteclass != Core.Kernel.GetBaseClass(item.Profession))
            //				{
            //					using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, string.Format(Core.MessageConst.ITEM_JOB_INVALID, Core.Kernel.GetBaseClass(item.Profession).ToString())))
            //						Owner.Send(fmsg);
            //
            //					return false;
            //				}
            //				else if (!Core.Kernel.AboveFirstPromotion(Owner.Class))
            //				{
            //					using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, string.Format(Core.MessageConst.ITEM_JOB_INVALID, Core.Kernel.GetBaseClass(item.Profession).ToString())))
            //						Owner.Send(fmsg);
            //
            //					return false;
            //				}
            //			}
                #endregion

                #region Level Check
                if (Owner.Level < item.RequiredLevel)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.LEVEL_LOW))
                        Owner.Send(fmsg);

                    return false;
                }
                #endregion

                #region Stats Check
                if (Owner.Strength < item.RequiredStrength ||
                    Owner.Agility < item.RequiredAgility ||
                    Owner.Vitality < item.RequiredVitality ||
                    Owner.Spirit < item.RequiredSpirit)
                {
                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.STATS_LOW))
                        Owner.Send(fmsg);

                    return false;
                }
                #endregion

                #region Prof Check
            //			if (Owner.Level < item.RequiredProf)
            //			{
            //				using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.LEVEL_LOW))
            //					Owner.Send(fmsg);
            //
            //				return false;
            //			}
                #endregion
            }

            if (!force_equip)
            {
                switch (pos)
                {
                        #region Head
                    case Enums.ItemLocation.Head:
                        {
                            if (item.ItemType != Enums.ItemType.Head)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Necklace
                    case Enums.ItemLocation.Necklace:
                        {
                            if (item.ItemType != Enums.ItemType.Necklace)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Ring
                    case Enums.ItemLocation.Ring:
                        {
                            if (item.ItemType != Enums.ItemType.Ring)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Armor
                    case Enums.ItemLocation.Armor:
                        {
                            if (item.ItemType != Enums.ItemType.Armor)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Boots
                    case Enums.ItemLocation.Boots:
                        {
                            if (item.ItemType != Enums.ItemType.Boots)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Bottle
                    case Enums.ItemLocation.Bottle:
                        {
                            if (item.ItemType != Enums.ItemType.Bottle)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Garment
                    case Enums.ItemLocation.Garment:
                        {
                            if (MaskedGarment != null)
                                return false;

                            if (item.ItemType != Enums.ItemType.Garment)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Steed
                    case Enums.ItemLocation.Steed:
                        {
                            if (Owner.ContainsFlag1(Enums.Effect1.Riding))
                                return false;

                            if (item.ItemType != Enums.ItemType.Steed)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region SteedArmor
                    case Enums.ItemLocation.SteedArmor:
                        {
                            if (Owner.ContainsFlag1(Enums.Effect1.Riding))
                                return false;

                            if (item.ItemType != Enums.ItemType.SteedArmor)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Fan
                    case Enums.ItemLocation.Fan:
                        {
                            return false;
                            /*if (item.ItemType != Enums.ItemType.Fan)
                        {
                            using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                Owner.Send(fmsg);
                            return false;
                        }
                        break;*/
                        }
                        #endregion
                        #region Tower
                    case Enums.ItemLocation.Tower:
                        {
                            return false;
                            /*if (item.ItemType != Enums.ItemType.Tower)
                        {
                            using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                Owner.Send(fmsg);
                            return false;
                        }
                        break;*/
                        }
                        #endregion
                        #region Right
                    case Enums.ItemLocation.WeaponR:
                        {
                            if (MaskedRightHand != null)
                                return false;

                            if (item.ItemType != Enums.ItemType.OneHand && item.ItemType != Enums.ItemType.TwoHand &&
                                item.ItemType != Enums.ItemType.Bow)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }

                            if (Contains(Enums.ItemLocation.WeaponL) && item.ItemType == Enums.ItemType.TwoHand)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.TWO_HAND_EQUIP_FAIL))
                                    Owner.Send(fmsg);
                                return false;
                            }
                            break;
                        }
                        #endregion
                        #region Left
                    case Enums.ItemLocation.WeaponL:
                        {
                            if (MaskedLeftHand != null)
                                return false;

                            if (item.ItemType != Enums.ItemType.OneHand && item.ItemType != Enums.ItemType.Shield && item.ItemType != Enums.ItemType.Arrow)
                            {
                                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                    Owner.Send(fmsg);
                                return false;
                            }

                            if (item.ItemType == Enums.ItemType.Shield || item.ItemType == Enums.ItemType.Arrow)
                            {
                                if (!Contains(Enums.ItemLocation.WeaponR))
                                {
                                    using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_TYPE))
                                        Owner.Send(fmsg);
                                    return false;
                                }
                            }

                            if (!Contains(Enums.ItemLocation.WeaponR) && item.ItemType != Enums.ItemType.Shield && item.ItemType != Enums.ItemType.Arrow)
                                pos = Enums.ItemLocation.WeaponR;
                            break;
                        }
                        #endregion

                        #region default
                    default:
                        {
                            using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVALID_ITEM_POS))
                                Owner.Send(fmsg);
                            return false;
                        }
                        #endregion
                }
            }
            if (Contains(pos))
            {
                if (unequip)
                {
                    if (!Unequip(pos))
                        return false;
                }
                else if (!force_equip)
                {
                    ItemInfo ritem;
                    if (!EquipmentItems.TryRemove(pos, out ritem))
                        return false;
                }
            }

            item.Location = pos;
            if (Owner.Inventory.ContainsByUID(item.UID) && !force_equip)
            {
                if (Owner.Inventory.RemoveItemByUID(item.UID) != null)
                {
                    item.SendPacket(Owner, 1);
                    if (EquipmentItems.TryAdd(pos, item))
                    {
                        if (Owner.LoggedIn)
                        {
                            Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                            Owner.BaseEntity.CalculateBaseStats();

                            using (var equippack = new Packets.ItemPacket())
                            {
                                equippack.UID = item.UID;
                                equippack.Action = Enums.ItemAction.Equip;
                                equippack.Data1Low = (ushort)pos;
                                Owner.Send(equippack);
                            }
                            SendGears();
                        }
                        return true;
                    }
                }
            }
            else if (!force_equip)
            {
                item.SendPacket(Owner, 1);
                if (EquipmentItems.TryAdd(pos, item))
                {
                    if (Owner.LoggedIn)
                    {
                        Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                        Owner.BaseEntity.CalculateBaseStats();

                        using (var equippack = new Packets.ItemPacket())
                        {
                            equippack.UID = item.UID;
                            equippack.Action = Enums.ItemAction.Equip;
                            equippack.Data1Low = (ushort)pos;
                            Owner.Send(equippack);
                        }
                        SendGears();
                    }
                    return true;
                }
            }
            else
            {
                item.SendPacket(Owner, 1);
                if (Owner.LoggedIn)
                {
                    Database.CharacterDatabase.SaveEquipment(Owner, item, pos);

                    Owner.BaseEntity.CalculateBaseStats();

                    using (var equippack = new Packets.ItemPacket())
                    {
                        equippack.UID = item.UID;
                        equippack.Action = Enums.ItemAction.Equip;
                        equippack.Data1Low = (ushort)pos;
                        Owner.Send(equippack);
                    }
                    SendGears();
                }
            }
            return false;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds a masked equipment.
        /// </summary>
        /// <param name="item">The masked item.</param>
        /// <param name="pos">The position.</param>
        /// <returns>Returns true if the mask was added.</returns>
        public bool AddMask(ItemInfo item, Enums.ItemLocation pos)
        {
            if (pos != Enums.ItemLocation.Garment && pos != Enums.ItemLocation.WeaponR && pos != Enums.ItemLocation.WeaponL)
                return false;

            if (pos == Enums.ItemLocation.Garment)
                MaskedGarment = item;
            else if (pos == Enums.ItemLocation.WeaponR)
                MaskedRightHand = item;
            else
                MaskedLeftHand = item;

            item.SendPacket(Owner, 1);
            using (var equippack = new Packets.ItemPacket())
            {
                equippack.UID = item.UID;
                equippack.Action = Enums.ItemAction.Equip;
                equippack.Data1Low = (ushort)pos;
                Owner.Send(equippack);
            }
            SendGears();
            return true;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of GroundItem.
 /// </summary>
 /// <param name="item">The actual item info.</param>
 public GroundItem(ItemInfo item)
 {
     this.item = item;
     _screen = new ProjectX_V3_Game.Core.Screen(this);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Replaces an equipment with a new item. This will REMOVE an existing item.
 /// </summary>
 /// <param name="item">The new item to equip.</param>
 /// <param name="pos">The position.</param>
 /// <returns>Returns true if the item was replaced.</returns>
 public bool Replace(ItemInfo item, Enums.ItemLocation pos)
 {
     return(Equip(item, pos, false));
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Adds an item to the warehouse.
        /// </summary>
        /// <param name="item">The item to add.</param>
        /// <param name="pos">The position in the inventory.</param>
        /// <returns>Returns true if the item was added.</returns>
        public bool AddItem(ItemInfo item, byte pos)
        {
            if (Count >= 20)
            {
                using (var fmsg = Packets.Message.MessageCore.CreateSystem2(Owner.Name, Core.MessageConst.INVENTORY_FULL))
                    Owner.Send(fmsg);
                return false;
            }

            if (WarehouseItems.TryAdd(pos, item))
            {
                item.OwnerUID = Owner.EntityUID;
                Database.CharacterDatabase.SaveWarehouse(Owner, item, pos, WhID);
                //SendAll();
                SendSingle(item);
                return true;
            }
            return false;
        }
Ejemplo n.º 15
0
        public void Swap(ItemInfo item, ItemInfo item2, Enums.ItemLocation pos)
        {
            ItemInfo ritem;
            if (EquipmentItems.TryRemove(pos, out ritem))
            {
                Owner.BaseEntity.CalculateBaseStats();

                SendGears();

                Equip(item2, pos, false);
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Removes an item from the warehouse based on is iteminfo.
 /// </summary>
 /// <param name="info">The item info.</param>
 /// <returns>Returns true if the item was removed.</returns>
 public bool RemoveItem(ItemInfo info)
 {
     foreach (byte key in WarehouseItems.Keys)
     {
         ItemInfo ritem;
         if (WarehouseItems.TryGetValue(key, out ritem))
         {
             if (ritem.UID == info.UID)
             {
                 if (WarehouseItems.TryRemove(key, out ritem))
                 {
                     Database.CharacterDatabase.SaveWarehouse(Owner, null, key, WhID);
                     //SendAll();
                     return true;
                 }
                 else
                     return false;
             }
         }
     }
     return false;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Adds an item to the warehouse.
 /// </summary>
 /// <param name="item">The item to add.</param>
 /// <returns>Returns true if the item was added.</returns>
 public bool AddItem(ItemInfo item)
 {
     return(AddItem(item, FreeSpaces));
 }