Inheritance: Item
Example #1
0
 public static Packet Equip(ZoneCharacter character, Equip equip)
 {
     //B2 00 - AB 38 - 07 - 0D 00 04
     Packet packet = new Packet(SH7Type.ShowEquip);
     packet.WriteUShort(character.MapObjectID);
     packet.WriteUShort(equip.ItemID);
     packet.WriteByte(equip.Upgrades);
     packet.Fill(3, 0xff);
     return packet;
 }
Example #2
0
        public static void ModifyEquipSlot(ZoneCharacter character, byte modifyslot, byte otherslot, Equip equip)
        {
            using (var packet = new Packet(SH12Type.ModifyEquipSlot))
            {
                packet.WriteByte(otherslot);
                packet.WriteByte(0x24); //aka the 'equipped' bool
                packet.WriteByte(modifyslot);

                if (equip == null)
                {
                    packet.WriteUShort(ushort.MaxValue);
                }
                else
                {
                    equip.WriteEquipStats(packet);
                }
                character.Client.SendPacket(packet);
            }
        }
Example #3
0
        public void LootItem(ushort id)
        {
            sbyte freeslot;
            bool gotslot = GetFreeInventorySlot(out freeslot);

            Drop drop;
            if (Map.Drops.TryGetValue(id, out drop))
            {
                if (!drop.CanTake || Vector2.Distance(this.Position, drop.Position) >= 500)
                {
                    Handler12.ObtainedItem(this, drop.Item, ObtainedItemStatus.FAILED);
                    return;
                }
                else if (!gotslot)
                {
                    Handler12.ObtainedItem(this, drop.Item, ObtainedItemStatus.INV_FULL);
                    return;
                }

                drop.CanTake = false; //just to be sure
                Map.RemoveDrop(drop);
                Item item = null;
                if (drop.Item is DroppedEquip)
                {
                    item = new Equip(drop.Item as DroppedEquip, this, freeslot);
                }
                else
                {
                    item = new Item(drop.Item, this, freeslot);
                }
                Handler12.ObtainedItem(this, drop.Item, ObtainedItemStatus.OBTAINED);
                Handler12.ModifyInventorySlot(this, 0x24, (byte)freeslot, 0, item);
            }
        }
Example #4
0
        public InventoryStatus GiveItem(string InxName, byte amount = 1)
        {
            ItemInfo info;

            if (DataProvider.Instance.ItemsByName.TryGetValue(InxName, out info))
            {
                ushort id = DataProvider.Instance.GetItemByInxNameInfo(InxName).ItemID;

                if (info.Slot == FiestaLib.ItemSlot.Normal)
                {
                    foreach (var i in InventoryItems.Values)
                    {
                        if (i.ItemID == id && i.Amount < i.Info.MaxLot)
                        {
                            // We found the same item and it can stack more!
                            byte left = (byte)(i.Info.MaxLot - i.Amount);
                            if (left > amount)
                            {
                                i.Amount += left;
                                amount -= left;
                            }
                            else
                            {
                                i.Amount += amount;
                                amount = 0;
                            }
                            Handler12.ModifyInventorySlot(this, 0x24, (byte)i.Slot, (byte)i.Slot, i);
                            if (amount == 0)
                            {
                                break;
                            }
                        }
                    }
                    // If we have still some stuff left, go ahead and create new stacks!
                    if (amount > 0)
                    {
                        while (amount > 0)
                        {
                            sbyte invslot;
                            if (GetFreeInventorySlot(out invslot))
                            {
                                DatabaseItem item = new DatabaseItem();
                                item.Amount = amount;
                                item.Character = character;
                                item.ObjectID = info.ItemID;
                                item.Slot = invslot;
                                Program.Entity.AddToDatabaseItems(item);
                                Item nitem = new Item(item);
                                InventoryItems.Add(invslot, nitem);
                                Handler12.ModifyInventorySlot(this, 0x24, (byte)invslot, (byte)invslot, nitem);
                                amount -= info.MaxLot;
                            }
                            else return InventoryStatus.FULL;
                        }
                    }
                    Save();
                    return InventoryStatus.ADDED;
                }
                else
                {
                    sbyte invslot;
                    if (GetFreeInventorySlot(out invslot))
                    {
                        DatabaseEquip equip = new DatabaseEquip();
                        equip.Character = character;
                        equip.EquipID = info.ItemID;
                        equip.Slot = invslot;
                        Program.Entity.AddToDatabaseEquips(equip);
                        Equip nequip = new Equip(equip);
                        InventoryItems.Add(invslot, nequip);
                        Save();
                        Handler12.ModifyInventorySlot(this, 0x24, (byte)invslot, (byte)invslot, nequip);
                        return InventoryStatus.ADDED;
                    }
                    else return InventoryStatus.FULL;
                }
            }
            else return InventoryStatus.NOT_FOUND;
        }
Example #5
0
        public void EquipItem(Equip equip)
        {
            if (equip.IsEquipped || Level < equip.Info.Level) return;

            sbyte oldslot = equip.Slot;

            Equip oldequip;
            EquippedItems.TryGetValue(equip.Info.Slot, out oldequip);

            if (oldequip != null)
            {
                oldequip.Slot = oldslot;
                EquippedItems.Remove(equip.Info.Slot);
            }

            InventoryItems.Remove(oldslot);
            Handler12.ModifyInventorySlot(this, 0x20,  (byte)oldslot, (byte)equip.Info.Slot, oldequip);
            if (oldequip != null)
            {
                InventoryItems.Add(oldequip.Slot, oldequip);
            }

            equip.Slot = (sbyte)equip.Info.Slot;
            equip.IsEquipped = true;
            EquippedItems.Add(equip.Info.Slot, equip);
            Handler12.ModifyEquipSlot(this, (byte)equip.Info.Slot, (byte)oldslot, equip);
            Save();

            using (var broad = Handler7.Equip(this, equip))
            {
                Broadcast(broad);
            }
        }
Example #6
0
        private void LoadItems()
        {
            EquippedItems = new Dictionary<ItemSlot, Equip>();
            foreach (var eqp in character.Equips.Where(e => e.Slot < 0))
            {
                Equip equip = new Equip(eqp);
                if (EquippedItems.ContainsKey(equip.SlotType))
                {
                    Log.WriteLine(LogLevel.Warn, "{0} has duplicate equipped in slot {1}.", Name, equip.SlotType);
                    continue;
                }
                EquippedItems.Add(equip.SlotType, equip);
            }

            InventoryItems = new Dictionary<sbyte, Item>();
            foreach (var eqp in character.Equips.Where(e => e.Slot >= 0))
            {
                Equip equip = new Equip(eqp);
                if (InventoryItems.ContainsKey(equip.Slot))
                {
                    Log.WriteLine(LogLevel.Warn, "{0} has a duplicate item in slot {0}.", Name, equip.Slot);
                    continue;
                }
                InventoryItems.Add(equip.Slot, equip);
            }

            foreach (var ditem in character.Items)
            {
                Item item = new Item(ditem);
                InventoryItems.Add((sbyte)item.Slot, item);
            }

            SkillsActive = new Dictionary<ushort, Skill>();
            SkillsPassive = new Dictionary<ushort, Skill>();
            foreach (var skill in character.Skills)
            {
                Skill s = new Skill(skill);
                if (s.IsPassive)
                {
                    SkillsPassive.Add(s.ID, s);
                }
                else
                {
                    SkillsActive.Add(s.ID, s);
                }
            }
        }
Example #7
0
 public static Packet Unequip(ZoneCharacter character, Equip equip)
 {
     Packet packet = new Packet(SH7Type.ShowUnequip);
     packet.WriteUShort(character.MapObjectID);
     packet.WriteByte((byte)equip.Info.Slot);
     return packet;
 }