public void AddDura(MsgItemPosition position) { if (!Items.TryGetValue(position, out var found)) { return; } if (found.CurrentDurability < found.MaximumDurability) { found.CurrentDurability += 1; } else { found.CurrentDurability = found.MaximumDurability; } var packet = new MsgItemInformation(found, MsgItemInfoAction.Update); (_owner as Player)?.ForceSend(packet, packet.Size); }
public void RemoveDura(MsgItemPosition position, bool arrows = false) { if (!arrows && !YiCore.Success(25)) { return; } if (!Items.TryGetValue(position, out var found)) { return; } if (found.CurrentDurability > 0) { found.CurrentDurability -= 1; } if (found.CurrentDurability < 10 && !arrows) { Message.SendTo(_owner, "Your " + Enum.GetName(typeof(MsgItemPosition), position) + " is about to break. (" + found.CurrentDurability + " uses left)", MsgTextType.Center); } var packet = new MsgItemInformation(found, MsgItemInfoAction.Update); (_owner as Player)?.ForceSend(packet, packet.Size); if (found.CurrentDurability == 0) { if (position == MsgItemPosition.RightWeapon) { Unequip(MsgItemPosition.LeftWeapon); (_owner as Player)?.ForceSend(MsgItem.Create(found.UniqueId, 0, (int)MsgItemPosition.LeftWeapon, MsgItemType.RemoveEquipment), 24); } Unequip(position); (_owner as Player)?.ForceSend(MsgItem.Create(found.UniqueId, 0, (int)position, MsgItemType.RemoveEquipment), 24); (_owner as Player)?.Inventory.RemoveItem(found); if (!arrows) { Message.SendTo(_owner, "Your " + Enum.GetName(typeof(MsgItemPosition), position) + " broke.", MsgTextType.Center); } } }
public bool Add(Item item, bool isLogin = false) { ItemPosition pos = Calculations.GetItemPosition(item.Type); #region Sanity Checks if (!isLogin) { // Level check if (item.Itemtype.ReqLevel > m_pOwner.Level) { return(false); } // Profession check if (m_pOwner.Metempsychosis > 0 && m_pOwner.Level >= 70 && item.Itemtype.ReqLevel <= 70) { } else { if (item.Itemtype.ReqProfession > 0) { // item int iProfession = item.Itemtype.ReqProfession / 10; int iProfessionLevel = item.Itemtype.ReqProfession % 10; if (iProfession == 19) { iProfession = 10; } // user int uProfession = m_pOwner.Profession / 10; int uProfessionLevel = m_pOwner.Profession % 10; if (uProfession > 10 && iProfession == 10) { uProfession = 10; } if (iProfession == uProfession) { if (iProfessionLevel > uProfessionLevel) { return(false); } } else { return(false); } } // Attribute check if (item.Itemtype.ReqForce != 0 && item.Itemtype.ReqForce > m_pOwner.Strength) { return(false); } if (item.Itemtype.ReqSpeed != 0 && item.Itemtype.ReqSpeed > m_pOwner.Agility) { return(false); } if (item.Itemtype.ReqHealth != 0 && item.Itemtype.ReqHealth > m_pOwner.Vitality) { return(false); } if (item.Itemtype.ReqSoul != 0 && item.Itemtype.ReqSoul > m_pOwner.Spirit) { return(false); } ushort type = (ushort)(item.Type / 1000); if (pos == ItemPosition.RIGHT_HAND && !m_pOwner.WeaponSkill.Skills.ContainsKey(type) && item.Itemtype.ReqWeaponskill > 0) { return(false); } if (m_pOwner.WeaponSkill.Skills.ContainsKey(type)) { if (pos == ItemPosition.RIGHT_HAND && m_pOwner.WeaponSkill.Skills[type].Level < item.Itemtype.ReqWeaponskill) { return(false); } } if (type == 421 && item.Position < (ItemPosition)20 && Items.ContainsKey(ItemPosition.LEFT_HAND)) { m_pOwner.Send("Please remove the equipment in your left hand first."); return(false); } if (type == 900 && Items.ContainsKey(ItemPosition.RIGHT_HAND) && Items[ItemPosition.RIGHT_HAND].GetItemSubtype() == 421) { m_pOwner.Send("You cannot equip a shield while wearing a backsword."); return(false); } } // Gender check if (item.Itemtype.ReqSex != 0) { if (item.Itemtype.ReqSex != m_pOwner.Gender) { return(false); } } } ItemSort itemSort = item.GetSort(); if ((itemSort == ItemSort.ITEMSORT_USABLE || itemSort == ItemSort.ITEMSORT_USABLE2 || itemSort == ItemSort.ITEMSORT_USABLE3) && pos == ItemPosition.INVENTORY && item.Type / 1000 != 1050) { // Stores the item temporary data. m_pOwner.LastItemResource = 0; m_pOwner.LastUsedItem = item.Identity; m_pOwner.LastUsedItemTime = (uint)UnixTimestamp.Timestamp(); m_pOwner.LastUsedItemtype = item.Type; if ((item.Type >= 1000000 && item.Type < 1050000) || item.Type == 725065 || item.Type == 725066) // potion { if (!m_pOwner.IsAlive) { m_pOwner.Send(ServerString.STR_NOT_ALIVE); return(false); } if (item.Itemtype.Life > 0 && m_pOwner.QueryStatus(FlagInt.POISON_STAR) != null) { //m_pOwner.Send(ServerString.STR_CANT_HEAL_POISON_STAR); return(false); } if (item.Itemtype.Life > 0 && m_pOwner.Life >= m_pOwner.MaxLife) { //m_pOwner.Send(ServerString.STR_YOUR_LIFE_FULL); return(false); // return false so it wont spend processing recalculating the user stts } if (item.Itemtype.Mana > 0 && m_pOwner.Mana >= m_pOwner.MaxMana) { //m_pOwner.Send(ServerString.STR_YOUR_MANA_FULL); return(false); // return false so it wont spend processing recalculating the user stts } if (m_pOwner.IsGm) { m_pOwner.FillLife(); m_pOwner.FillMana(); return(false); } if (m_pOwner.Inventory.Remove(item.Type, 1)) { m_pOwner.AddAttribute(ClientUpdateType.HITPOINTS, item.Itemtype.Life, true); m_pOwner.AddAttribute(ClientUpdateType.MANA, item.Itemtype.Mana, true); } return(false); } if (item.Type == SpecialItem.MEMORY_AGATE) { item.SendCarry(); return(false); } if (item.Type == 723726) { if (m_pOwner.Inventory.Remove(item.Type, 1)) { m_pOwner.FillLife(); m_pOwner.FillMana(); } return(false); } if (item.Type == 723790 && m_pOwner.Inventory.Remove(723790)) { m_pOwner.AddAttribute(ClientUpdateType.HITPOINTS, 500, true); return(false); } if (item.Type == SpecialItem.TYPE_EXP_BALL || item.Type == 723834) { if (m_pOwner.ExpBallAmount >= 10) { int nDayOfYear = UnixTimestamp.ToDateTime(m_pOwner.LastUsedExpBall).DayOfYear; int nDayOfYear2 = DateTime.Now.DayOfYear; if (nDayOfYear == nDayOfYear2) { return(false); } m_pOwner.ExpBallAmount = 0; } if (m_pOwner.Inventory.Remove(item.Identity)) { m_pOwner.ExpBallAmount = (byte)(m_pOwner.ExpBallAmount + 1); m_pOwner.LastUsedExpBall = (uint)UnixTimestamp.Timestamp(); m_pOwner.Save(); m_pOwner.AwardExperience(ServerKernel.GetExpBallExperience(m_pOwner.Level), true, true); } return(false); } if ((item.Type >= 1060020 && item.Type <= 1060039) || item.Type == 1060102) { if (m_pOwner.Map.IsChgMapDisable()) { return(false); } m_pOwner.Inventory.Remove(item.Identity); } else if (item.Type / 1000 == 1060) { m_pOwner.Inventory.Remove(item.Identity); } m_pOwner.TaskItem = item; m_pOwner.GameAction.ProcessAction(item.Itemtype.IdAction, m_pOwner, null, item, null); return(false); } if (pos == ItemPosition.INVENTORY) { return(false); } if (pos == ItemPosition.LEFT_HAND && itemSort == ItemSort.ITEMSORT_WEAPON_SHIELD) { if (Items.ContainsKey(ItemPosition.RIGHT_HAND) && Items[ItemPosition.RIGHT_HAND].GetSort() == ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND) { if (!m_pOwner.Magics.CheckType(10311)) { return(false); } } if (!Items.ContainsKey(ItemPosition.RIGHT_HAND)) { return(false); } } #endregion if (item.IsArrowSort()) { item.Position = ItemPosition.LEFT_HAND; } switch (item.Position) { case ItemPosition.RIGHT_HAND: if (pos != ItemPosition.RIGHT_HAND || (itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND2)) { item.Position = 0; return(false); } if ((itemSort == ItemSort.ITEMSORT_WEAPON_DOUBLE_HAND && Items.ContainsKey(ItemPosition.LEFT_HAND))) { Remove(ItemPosition.LEFT_HAND); } if (Items.ContainsKey(ItemPosition.RIGHT_HAND) && item.Position == ItemPosition.RIGHT_HAND) { Remove(ItemPosition.RIGHT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } break; case ItemPosition.LEFT_HAND: if (itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND && itemSort != ItemSort.ITEMSORT_WEAPON_SHIELD && itemSort != ItemSort.ITEMSORT_WEAPON_SINGLE_HAND2 && item.Type / 1000 != 1050) { item.Position = 0; return(false); } if (m_pOwner.Profession >= 100) { if (Items.ContainsKey(ItemPosition.LEFT_HAND) && Items[ItemPosition.LEFT_HAND] == item) { Remove(ItemPosition.LEFT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } item.Position = 0; return(false); } if (item.IsArrowSort() && (!Items.ContainsKey(ItemPosition.RIGHT_HAND) || !Items[ItemPosition.RIGHT_HAND].IsBow())) { item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.LEFT_HAND)) { Remove(ItemPosition.LEFT_HAND, ItemRemoveMethod.REMOVE_TO_INVENTORY); } break; case ItemPosition.ACCESSORY_R: { if ((itemSort != ItemSort.ITEMSORT_ACCESSORY) || item.Type / 10000 == 38) { item.Position = 0; return(false); } switch (item.Type / 10000) { case 38: item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.ACCESSORY_R)) { Remove(ItemPosition.ACCESSORY_R); } break; } case ItemPosition.ACCESSORY_L: { if (itemSort != ItemSort.ITEMSORT_ACCESSORY || item.Type / 10000 == 37) { item.Position = 0; return(false); } switch (item.Type / 10000) { case 37: item.Position = 0; return(false); } if (Items.ContainsKey(ItemPosition.ACCESSORY_L)) { Remove(ItemPosition.ACCESSORY_L); } break; } default: if (pos == item.Position && Items.ContainsKey(item.Position)) { Remove(item.Position); } else if (pos != item.Position) { if (item.Position < ItemPosition.ALT_HEAD && pos != item.Position) { item.Position = 0; return(false); } if (item.Position >= ItemPosition.ALT_HEAD && item.Position <= ItemPosition.ALT_STEED) { switch (item.Position) { case ItemPosition.ALT_HEAD: { if (pos != ItemPosition.HEADWEAR) { return(false); } break; } case ItemPosition.ALT_NECKLACE: { if (pos != ItemPosition.NECKLACE) { return(false); } break; } case ItemPosition.ALT_RING: { if (pos != ItemPosition.RING) { return(false); } break; } case ItemPosition.ALT_WEAPON_R: { if (pos != ItemPosition.RIGHT_HAND) { return(false); } break; } case ItemPosition.ALT_WEAPON_L: { if (pos != ItemPosition.LEFT_HAND && pos != ItemPosition.RIGHT_HAND) { return(false); } break; } case ItemPosition.ALT_ARMOR: { if (pos != ItemPosition.ARMOR) { return(false); } break; } case ItemPosition.ALT_BOOTS: { if (pos != ItemPosition.BOOTS) { return(false); } break; } case ItemPosition.ALT_BOTTLE: { if (pos != ItemPosition.BOTTLE) { return(false); } break; } case ItemPosition.ALT_GARMENT: { if (pos != ItemPosition.GARMENT) { return(false); } break; } default: item.Position = 0; return(false); } if (Items.ContainsKey(item.Position) && Items.Count >= 40) { item.Position = 0; return(false); } if (Items.ContainsKey(item.Position)) { Remove(item.Position); } } else { item.Position = 0; return(false); } } break; } var itemEquip = new MsgItem { Identity = item.Identity, Action = ItemAction.EQUIP, Param1 = (uint)item.Position }; // We build the item information packet MsgItemInformation itemInfo = item.InformationPacket(!isLogin); // If we are logging in, we set this as default, because the item hasnt been // created yet, otherwise, we send this as an update. if (isLogin) { itemInfo.ItemMode = ItemMode.DEFAULT; m_pOwner.Send(itemInfo); } else { //itemInfo.ItemMode = ItemMode.Update; if (!m_pOwner.Inventory.Contains(item.Identity)) { return(false); } Item trash; m_pOwner.Inventory.Items.TryRemove(item.Identity, out trash); item.Save(); m_pOwner.RecalculateAttributes(); } m_pOwner.Send(itemEquip); Items.TryAdd(item.Position, item); SendEquipedItems(); item.SendPurification(); item.TryUnlockItem(); item.SendItemLockTime(); switch (item.Position) { case ItemPosition.HEADWEAR: m_pOwner.Helmet = item.Type; m_pOwner.HelmetColor = (ushort)item.Color; break; case ItemPosition.ARMOR: m_pOwner.Armor = item.Type; m_pOwner.ArmorColor = (ushort)item.Color; break; case ItemPosition.LEFT_HAND: m_pOwner.LeftHand = item.Type; m_pOwner.ShieldColor = (ushort)item.Color; break; case ItemPosition.RIGHT_HAND: m_pOwner.RightHand = item.Type; break; case ItemPosition.GARMENT: m_pOwner.Garment = item.Type; break; case ItemPosition.ACCESSORY_R: m_pOwner.RightAccessory = item.Type; break; case ItemPosition.ACCESSORY_L: m_pOwner.LeftAccessory = item.Type; break; case ItemPosition.STEED: m_pOwner.MountType = item.Type; m_pOwner.MountColor = item.SocketProgress; m_pOwner.MountPlus = item.Plus; break; case ItemPosition.STEED_ARMOR: m_pOwner.MountArmor = item.Type; break; } return(true); }