Пример #1
0
 public Item this[ItemConstants.EquipmentSlot slot]
 {
     get
     {
         foreach (Item item in this)
         {
             if (item.Slot == (sbyte)slot)
             {
                 return(item);
             }
         }
         return(null); // TODO: Should be keynotfoundexception, but I'm lazy.
     }
 }
Пример #2
0
        public void Equip()
        {
            if (this.Type != ItemConstants.ItemType.Equipment)
            {
                throw new InvalidOperationException("Can only equip equipment items.");
            }

            if ((this.Character.Strength < this.RequiredStrength ||
                 this.Character.Dexterity < this.RequiredDexterity ||
                 this.Character.Intelligence < this.RequiredIntelligence ||
                 this.Character.Luck < this.RequiredLuck) &&
                !this.Character.IsMaster)
            {
                return;
            }

            short sourceSlot = this.Slot;

            ItemConstants.EquipmentSlot destinationSlot = this.GetEquippedSlot();

            Item top    = this.Parent[ItemConstants.EquipmentSlot.Top];
            Item bottom = this.Parent[ItemConstants.EquipmentSlot.Bottom];
            Item weapon = this.Parent[ItemConstants.EquipmentSlot.Weapon];
            Item shield = this.Parent[ItemConstants.EquipmentSlot.Shield];

            Item destination = this.Parent[destinationSlot];

            if (destination != null)
            {
                destination.Slot = sourceSlot;
            }

            this.Slot = (short)destinationSlot;

            using (Packet oPacket = new Packet(ServerOperationCode.InventoryOperation))
            {
                oPacket
                .WriteBool(true)
                .WriteByte(1)
                .WriteByte((byte)ItemConstants.InventoryOperationType.ModifySlot)
                .WriteByte((byte)this.Type)
                .WriteShort(sourceSlot)
                .WriteShort((short)destinationSlot)
                .WriteByte(1);

                this.Character.Client.Send(oPacket);
            }

            switch (destinationSlot)
            {
            case ItemConstants.EquipmentSlot.Bottom:
            {
                if (top != null && top.IsOverall)
                {
                    top.Unequip();
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Top:
            {
                if (this.IsOverall && bottom != null)
                {
                    bottom.Unequip();
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Shield:
            {
                if (weapon != null && weapon.IsTwoHanded)
                {
                    weapon.Unequip();
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Weapon:
            {
                if (this.IsTwoHanded && shield != null)
                {
                    shield.Unequip();
                }
            }
            break;
            }

            Character.UpdateApperance(this.Character);
        }
Пример #3
0
        public static void EquipItem(Item item)
        {
            // Check ItemType
            if (item.ItemType != ItemConstants.ItemType.Equipment)
            {
                throw new InvalidOperationException("Can only equip equipment items.");
            }

            // If were not VIP user then check for requirements
            if (!item.Character.IsMaster)
            {
                if (item.Character.Stats.Strength < item.RequiredStrength || item.Character.Stats.Dexterity < item.RequiredDexterity ||
                    item.Character.Stats.Intelligence < item.RequiredIntelligence || item.Character.Stats.Luck < item.RequiredLuck ||
                    item.Character.Stats.Fame < item.RequiredFame)
                {
                    return;
                }
            }

            // slot to move item from
            short sourceSlot = item.Slot;

            // slot to move item into
            ItemConstants.EquipmentSlot destinationSlot = item.GetEquippedSlot();

            // get char's items
            Item top    = item.Parent[ItemConstants.EquipmentSlot.Top];
            Item bottom = item.Parent[ItemConstants.EquipmentSlot.Bottom];
            Item weapon = item.Parent[ItemConstants.EquipmentSlot.Weapon];
            Item shield = item.Parent[ItemConstants.EquipmentSlot.Shield];

            // get item at char's destination slot
            Item destination = item.Parent[destinationSlot];

            // if there is an item
            if (destination != null)
            {
                // put it into slot of item to be replaced with
                destination.Slot = sourceSlot;
            }

            // item to replace acquires destination slot
            item.Slot = (short)destinationSlot;

            // unequipped blocking items
            switch (destinationSlot)
            {
            case ItemConstants.EquipmentSlot.Bottom:
            {
                if (top?.IsOverall == true)
                {
                    UnequipItem(top);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Top:
            {
                if (item.IsOverall && bottom != null)
                {
                    UnequipItem(bottom);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Shield:
            {
                if (weapon?.IsTwoHanded == true)
                {
                    UnequipItem(weapon);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Weapon:
            {
                if (item.IsTwoHanded && shield != null)
                {
                    UnequipItem(shield);
                }
            }
            break;
            }

            // send packet to carry out the equipped action
            item.Character.Client.Send(ItemPackets.EquipOrUnequipItems(item, sourceSlot, (short)destinationSlot));

            // update char appearance
            CharacterAppearance.UpdateApperance(item.Character);
        }
Пример #4
0
        private ItemConstants.EquipmentSlot GetEquippedSlot()
        {
            ItemConstants.EquipmentSlot slot = 0;

            if (EquipmentConstants.HatsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Hat;
            }
            else if (EquipmentConstants.FaceAccMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.FaceAccessory;
            }
            else if (EquipmentConstants.EyeAccMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.EyeAccessory;
            }
            else if (EquipmentConstants.EarringsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Earrings;
            }
            else if (EquipmentConstants.TopsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Top;
            }
            else if (EquipmentConstants.BottomsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Bottom;
            }
            else if (EquipmentConstants.ShoesMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Shoes;
            }
            else if (EquipmentConstants.GlovesMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Gloves;
            }
            else if (EquipmentConstants.CapesMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Cape;
            }
            else if (EquipmentConstants.ShieldsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Shield;
            }
            else if (EquipmentConstants.WeaponsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Weapon;
            }
            else if (EquipmentConstants.RingsMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Ring1;
            }
            else if (EquipmentConstants.NecklacesMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.Necklace;
            }
            else if (EquipmentConstants.MountsEquipMapleIDs.Contains(MapleID))
            {
                slot = ItemConstants.EquipmentSlot.MountEquip;
            }

            if (IsCash)
            {
                slot -= 100;
            }

            return(slot);
        }