public async Task <ShopResult> Sell(short position, int templateID, short count) { var inventory = User.Character.Inventories[(ItemInventoryType)(templateID / 1000000)]; if (!inventory.Items.ContainsKey(position)) { return(ShopResult.SellUnknown); } var itemSlot = inventory.Items[position]; var item = User.Service.TemplateManager.Get <ItemTemplate>(itemSlot.TemplateID); var price = item.SellPrice; if (ItemConstants.IsRechargeableItem(item.ID)) { price += (int)((itemSlot as ItemSlotBundle)?.Number * (item as ItemBundleTemplate)?.UnitPrice ?? 0); } else { price *= count; } if (int.MaxValue - User.Character.Money < price) { return(ShopResult.SellUnknown); } await User.ModifyInventory(i => i.Remove(itemSlot, count)); await User.ModifyStats(s => s.Money += price); return(ShopResult.SellSuccess); }
public static MapleItem CreateItem(int itemId, string source, short quantity = 1, bool randomStats = false) { MapleInventoryType type = ItemConstants.GetInventoryType(itemId); if (type == MapleInventoryType.Equip) { WzEquip wzInfo = DataBuffer.GetEquipById(itemId); if (wzInfo != null) { MapleEquip equip = new MapleEquip(itemId, source); equip.SetDefaultStats(wzInfo, randomStats); return(equip); } } else if (type != MapleInventoryType.Undefined) { WzItem wzInfo = DataBuffer.GetItemById(itemId); if (wzInfo != null) { if (wzInfo.SlotMax > 0 && quantity > wzInfo.SlotMax) { quantity = (short)wzInfo.SlotMax; } MapleItem item = new MapleItem(itemId, source, quantity); return(item); } } return(null); }
protected GW_ItemSlotBase(int nItemID) { this.nItemID = nItemID; InvType = ItemConstants.GetInventoryType(nItemID); IsRechargeable = ItemConstants.IsRechargeableItem(nItemID); IsArrow = ItemConstants.IsArrow(nItemID); }
public static GW_ItemSlotEquip CreateNormalStatEquip(int nItemID, long liCashItemSN = 0) { if (ItemConstants.GetInventoryType(nItemID) != InventoryType.Equip) { return(null); } var pItem = new GW_ItemSlotEquip(nItemID); pItem.niSTR = (short)pItem.EquipTemplate.incSTR; pItem.niDEX = (short)pItem.EquipTemplate.incDEX; pItem.niINT = (short)pItem.EquipTemplate.incINT; pItem.niLUK = (short)pItem.EquipTemplate.incLUK; pItem.niMaxHP = (short)pItem.EquipTemplate.incMHP; pItem.niMaxMP = (short)pItem.EquipTemplate.incMMP; pItem.niPAD = (short)pItem.EquipTemplate.incPAD; pItem.niMAD = (short)pItem.EquipTemplate.incMAD; pItem.niPDD = (short)pItem.EquipTemplate.incPDD; pItem.niMDD = (short)pItem.EquipTemplate.incMDD; pItem.niACC = (short)pItem.EquipTemplate.incACC; pItem.niEVA = (short)pItem.EquipTemplate.incEVA; pItem.niSpeed = (short)pItem.EquipTemplate.incSpeed; pItem.niJump = (short)pItem.EquipTemplate.incJump; FinishEquip(pItem, liCashItemSN); return(pItem); }
public static void UnEquip(Character pChar, short slotFrom, short slotTo) { //20:40:35[INFO] Recv[CP_UserChangeSlotPositionRequest] [4D 00] [1D A8 02 01] [01] [B3 FB] [01 00] [FF FF] //20:40:38[INFO] Recv[CP_UserChangeSlotPositionRequest] [4D 00] [7B B3 02 01] [01] [B3 FB] [01 00] [FF FF] var srcEquipInv = GetInventory(pChar, slotFrom); var source = srcEquipInv.GetKvp(slotFrom); if (slotTo != 0) //Not dropping { if (!pChar.InventoryEquip.IsFreeSlot(slotTo)) { return; // PE } } if (!srcEquipInv.Remove(slotFrom)) { return; // false means they passed an empty slot } var pItem = source.Value; if (-slotFrom == (int)BodyPart.BP_SADDLE || -slotFrom == (int)BodyPart.BP_TAMINGMOB) { pChar.Buffs.Remove(pChar.Stats.SecondaryStats.rRideVehicle); } else { // taming stuff cant have option skills pChar.Skills.ModifyOptionSkills(pItem, false); } if (slotTo == 0) //Dropping Item { pChar.Modify.Inventory(ctx => { ctx.Remove(InventoryType.Equip, slotFrom); }); if (ItemConstants.GetInventoryType(pItem.nItemID) == InventoryType.Equip) { CDropFactory.CreateDropItem(pChar.Field, pChar.Position.CurrentXY, pChar.dwId, pItem); } else { //Should never happen???? pChar.SendMessage($"You unequipped and dropped a non-equip item. Please report to staff: {pItem.nItemID}"); } } else //Unequip to inventory { pChar.InventoryEquip.Add(slotTo, source.Value); pChar.Modify.Inventory(ctx => { ctx.Move(InventoryType.Equip, slotFrom, slotTo); }); } }
public override async Task Enter() { using var p = new Packet(SendPacketOperations.OpenShopDlg); p.Encode <int>(_template.ID); var items = _template.Items.Values .OrderBy(i => i.ID) .ToList(); p.Encode <short>((short)items.Count); items.ForEach(i => { p.Encode <int>(i.TemplateID); p.Encode <int>(i.Price); p.Encode <byte>(i.DiscountRate); p.Encode <int>(i.TokenTemplateID); p.Encode <int>(i.TokenPrice); p.Encode <int>(i.ItemPeriod); p.Encode <int>(i.LevelLimited); if (!ItemConstants.IsRechargeableItem(i.TemplateID)) { p.Encode <short>(i.Quantity); } else { p.Encode <double>(i.UnitPrice); } p.Encode <short>(i.MaxPerSlot); }); await User.SendPacket(p); }
public void UseLotteryItem(short nPOS, int nItemID) { if (Parent.Stats.nHP <= 0) { return; } var pItemRaw = InventoryManipulator.GetItem(Parent, ItemConstants.GetInventoryType(nItemID), nPOS); // TODO determine if we can hardcode the inventory type var itemResult = MasterManager.CreateItem(RandomBoxes.GetRandom(nItemID)); if (itemResult != null && pItemRaw is GW_ItemSlotBundle pItem) { if (InventoryManipulator.CountFreeSlots(Parent, InventoryType.Equip) > 0 && InventoryManipulator.CountFreeSlots(Parent, InventoryType.Consume) > 0) { InventoryManipulator.RemoveFrom(Parent, pItemRaw.InvType, nPOS); InventoryManipulator.InsertInto(Parent, itemResult); } else { Parent.SendMessage("Please make some room in your inventory."); } } else { Parent.SendMessage("This item has not been implemented yet. If you believe this to be an error, please report it on the discord server."); } }
public virtual void RawEncode(COutPacket p, bool bFromCS = false) { p.Encode4(nItemID); var bCashItem = liCashItemSN != 0; p.Encode1(bCashItem); // ring equips have to have their unique ID sent instead of the cash ID // but not during the locker -> storage transaction in the cash shop // not pretty but it works ok if (!bFromCS && (ItemConstants.is_friendship_equip_item(nItemID) || ItemConstants.is_couple_equip_item(nItemID) || ItemConstants.is_wedding_ring_item(nItemID))) { p.Encode8(liSN); } else { if (bCashItem) { p.Encode8(liCashItemSN); } } p.EncodeDateTime(tDateExpire); }
public void Remove(int template, short count) { var removed = 0; _inventory.Items.Values .Where(i => i.TemplateID == template) .ForEach(i => { if (removed >= count) { return; } if (i is ItemSlotBundle bundle && !ItemConstants.IsRechargeableItem(bundle.TemplateID)) { var diff = count - removed; if (bundle.Number > diff) { removed += diff; bundle.Number = (short)(bundle.Number - diff); UpdateQuantity(bundle); } else { removed += bundle.Number; Remove(bundle); } }
public static bool HasSpace(Character pChar, int nItemID, short nAmount) { var nTI = ItemConstants.GetInventoryType(nItemID); if (nTI == InventoryType.Equip) { if (pChar.InventoryEquip.GetFreeSlot() > 0) { return(true); } } else { var inv = GetInventory(pChar, nTI); if (inv.GetFreeSlot() > 0) { return(true); } // determine if item can be merged in with existing slot { var item = inv.Get(inv.FindItemSlot(nItemID)); if (item?.nNumber < nAmount + item?.SlotMax) { return(true); } } } return(false); }
private static bool IsOneHandedWeaponScrollable(int itemId) { if (!ItemConstants.IsWeapon(itemId)) { return(false); } return(!IsTwoHandedWeaponScrollable(itemId)); }
public bool FitsItem(int itemId) { if (OptionType == 0) { return(true); } return(FitsItem(ItemConstants.GetMapleItemType(itemId))); }
private static void SellItem(Character pChar, short nSlot, int nItemId, short nCount) { var pItem = InventoryManipulator.GetItem(pChar, ItemConstants.GetInventoryType(nItemId), nSlot); if (pItem is null) { pChar.SendMessage("Trying to sell null item."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest)); return; } if (pItem.CashItem || pItem.NotSale) { pChar.SendMessage("Cannot trade cash items."); return; } var nCostPerItem = pItem.Template.Price; nCount = ItemConstants.is_treat_singly(nItemId) ? (short)1 : nCount; var nFinalCost = nCostPerItem * nCount; if (pItem.IsRechargeable) { var dUnitPrice = ((ConsumeItemTemplate)pItem.Template).UnitPrice; nFinalCost += (int)Math.Floor(dUnitPrice * pItem.nNumber); } if (pItem is GW_ItemSlotBundle && !pItem.IsRechargeable) { if (pItem.nNumber < nCount) { pChar.SendMessage("Trying to sell more than you possess."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest)); return; } if (nCount <= 0) { pChar.SendMessage("Trying to sell negative amount."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest)); return; } } else { nCount = -1; } pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellSuccess)); //pChar.SendMessage("final price: " + nFinalCost); InventoryManipulator.RemoveFrom(pChar, pItem.InvType, nSlot, nCount); pChar.Modify.GainMeso(nFinalCost, false); }
private static void RechargeItem(Character pChar, short nSlot) { var pItem = InventoryManipulator.GetItem(pChar, InventoryType.Consume, nSlot); if (pItem is null) { pChar.SendMessage("Trying to recharge null item."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.RechargeIncorrectRequest)); return; } if (!ItemConstants.IsRechargeableItem(pItem.nItemID)) { pChar.SendMessage("Trying to recharge item that isn't rechargeable."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.RechargeIncorrectRequest)); return; } var slotmax = pItem.SlotMax; if (pChar.Skills.Get(false, (int)Skills.NIGHTWALKER_JAVELIN_MASTERY, (int)Skills.ASSASSIN_JAVELIN_MASTERY) is SkillEntry se) { slotmax += (short)se.Y_Effect; } if (pItem.nNumber >= slotmax) { pChar.SendMessage("Trying to recharge item that is fully charged."); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.RechargeIncorrectRequest)); return; } var dUnitPrice = (pItem.Template as ConsumeItemTemplate).UnitPrice; var nRechargeNeeded = slotmax - pItem.nNumber; var nTotalRechargePrice = (int)Math.Floor(nRechargeNeeded * dUnitPrice); if (pChar.Stats.nMoney < nTotalRechargePrice) { pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.RechargeNoMoney)); return; } pChar.Modify.GainMeso(-nTotalRechargePrice); pItem.nNumber = slotmax; pChar.Modify.Inventory(ctx => { ctx.UpdateQuantity(InventoryType.Consume, nSlot, pItem.nNumber); }); pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.RechargeSuccess)); }
public void Add(ItemSlot item) { switch (item) { case ItemSlotBundle bundle: if (ItemConstants.IsRechargeableItem(bundle.TemplateID)) { goto default; } if (bundle.Number < 1) { bundle.Number = 1; } if (bundle.MaxNumber < 1) { bundle.MaxNumber = 1; } var mergeable = _inventory.Items.Values .OfType <ItemSlotBundle>() .Where(b => bundle.Number + b.Number <= b.MaxNumber) .FirstOrDefault(b => b.Equals(bundle)); if (mergeable != null) { var count = bundle.Number + mergeable.Number; var maxNumber = mergeable.MaxNumber; if (count > maxNumber) { var leftover = count - maxNumber; bundle.Number = (short)leftover; mergeable.Number = maxNumber; UpdateQuantity(mergeable); Add(bundle); return; } mergeable.Number += bundle.Number; UpdateQuantity(mergeable); return; } goto default; default: var slot = Enumerable.Range(1, _inventory.SlotMax) .Select(i => (short)i) .Except(_inventory.Items.Keys) .First(i => i > 0); Set(slot, item); break; } }
public void Add(ItemTemplate template, short quantity = 1, ItemVariationType type = ItemVariationType.None) { var item = template.ToItemSlot(); if (item is ItemSlotBundle bundle && !ItemConstants.IsRechargeableItem(bundle.TemplateID)) { bundle.Number = quantity; Add(bundle); }
public static PacketWriter ShowShop(ShopScript shop, int npcId) { List <ShopItem> items = shop.ShopItems; PacketWriter pw = new PacketWriter(SendHeader.NpcShop); pw.WriteByte(0); pw.WriteInt(0); pw.WriteInt(npcId); pw.WriteByte(0); pw.WriteShort((short)items.Count); foreach (ShopItem item in items) { pw.WriteInt(item.Id); pw.WriteInt(item.Price); pw.WriteByte(0); pw.WriteInt(item.ReqItemId); pw.WriteInt(item.ReqItemQuantity); pw.WriteInt(0); //unk pw.WriteInt(0); //unk pw.WriteInt(0); //unk pw.WriteZeroBytes(22); //v158 pw.WriteLong(MapleFormatHelper.GetMapleTimeStamp(-2)); pw.WriteLong(MapleFormatHelper.GetMapleTimeStamp(-1)); pw.WriteInt(item.Tab); pw.WriteByte(0); pw.WriteByte(0); pw.WriteInt(0); pw.WriteZeroBytes(3); //v158 MapleItemType itemType = ItemConstants.GetMapleItemType(item.Id); if (itemType == MapleItemType.Bullet || itemType == MapleItemType.ThrowingStar) { pw.WriteZeroBytes(6); pw.WriteShort((short)(BitConverter.DoubleToInt64Bits((double)item.Price) >> 48)); pw.WriteShort(item.BulletCount); //Todo, correct max amount } else { pw.WriteShort((short)item.DefaultQuantity); pw.WriteShort((short)item.MaximumPurchase); } pw.WriteByte(0); pw.WriteInt(0); pw.WriteInt(0); pw.WriteInt(0); pw.WriteInt(0); pw.WriteLong(9410165); pw.WriteLong(9410166); pw.WriteLong(9410167); pw.WriteLong(9410168); //pw.WriteBytes(Functions.HexToBytes("75968F000000000076968F000000000077968F000000000078968F0000000000"));//no idea } return(pw); }
public static void Equip(Character pChar, short slotFrom, short slotTo) { var itemToEquip = pChar.InventoryEquip.GetKvp(slotFrom); if (itemToEquip.Value == null) { return; // passed empty slot } var v1 = Math.Abs(slotTo); if (v1 < 200 && v1 >= 100) { v1 -= 100; } if (!ItemConstants.is_correct_bodypart(itemToEquip.Value.nItemID, (BodyPart)v1)) { pChar.SendMessage($"Unable to equip item with ID {itemToEquip.Value.nItemID} to slot {slotTo} ({v1})"); return; } var dstEquipInv = GetInventory(pChar, slotTo); var itemToUnequip = dstEquipInv.GetKvp(slotTo); // remove item from equip inventory if (!pChar.InventoryEquip.Remove(itemToEquip.Key)) { return; // means theres no item in the given slot } // remove item from equipped inventory if (dstEquipInv.Remove(itemToUnequip.Key)) { pChar.InventoryEquip.Add(itemToEquip.Key, itemToUnequip.Value); pChar.Skills.ModifyOptionSkills(itemToUnequip.Value, false); } pChar.Skills.ModifyOptionSkills(itemToEquip.Value, true); pChar.Modify.Inventory(ctx => { if (itemToEquip.Value.EquipTemplate.EquipTradeBlock) { itemToEquip.Value.nAttribute |= ItemAttributeFlags.Untradeable; ctx.Remove(InventoryType.Equip, itemToEquip.Key); ctx.Add(InventoryType.Equip, slotTo, itemToEquip.Value); // essentially forcing an equip update into a new slot } else { ctx.Move(InventoryType.Equip, itemToEquip.Key, slotTo); } dstEquipInv.Add(slotTo, itemToEquip.Value); }); }
public void OnLostQuestItem(CInPacket p, short nQuestID) { var nLostCount = p.Decode4(); var pAct = MasterManager.QuestTemplates[nQuestID].StartAct; if (pAct is null) { return; // invalid quest ID } if (nLostCount <= 0 || pAct.Items.Length <= 0) { return; // TODO trigger AB, close socket } var aLostItem = p.DecodeIntArray(nLostCount); foreach (var item in pAct.Items) { if (!aLostItem.Contains(item.Item.ItemID)) { continue; // TODO trigger AB? } if (ItemConstants.GetInventoryType(item.Item.ItemID) == InventoryType.Equip) { Parent.SendMessage("Not currently supported. Check again later."); return; // TODO } if (!MasterManager.ItemTemplates[item.Item.ItemID]?.Quest ?? true) { continue; } if (InventoryManipulator.HasSpace(Parent, item.Item.ItemID, (short)item.Item.Count)) { var itemToAdd = MasterManager.CreateItem(item.Item.ItemID); itemToAdd.nNumber = (short)item.Item.Count; InventoryManipulator.InsertInto(Parent, itemToAdd); } else { // TODO proper response packet Parent.SendMessage("Please make space in your inventory."); return; } } // TODO // if ( aChangedItem.a && *(aChangedItem.a - 1) > 0u ) // CUser::PostQuestEffect(&v16->vfptr, 1, &aChangedItem, 0, 0); }
/** * Client sends cash item SN. * We index cash items by their serial number. * WZ files indexes cash items by a commodity ID. * The commodity ID (~12000 total) is not used for anything. */ public static void Buy(WvsShopClient c, CInPacket p) { // validate packet length if (p.Available < 9) { return; } p.Decode1(); // 00 var cashType = (CashType)p.Decode4(); var nCommoditySN = p.Decode4(); var commodityInfo = MasterManager.CommodityProvider[nCommoditySN]; if (commodityInfo == null) { return; } if (!commodityInfo.OnSale) { return; // TODO proper error code/response } var item = MasterManager.CreateCashCommodityItem(nCommoditySN); if (item is null) { return; } if (!c.Account.HasCash(cashType, item.NXCost)) { return; // TODO proper error code/response } if (ItemConstants.IsPet(item.nItemID) && InventoryManipulator.GetItemByCashSN(c.Character, InventoryType.Cash, item.SN).Item2 != null) { return; // cant have two of the same pet cuz it screws up our indexing } c.CashLocker.Add(item); #if DEBUG c.Account.ModifyCash(cashType, 10000); Log.Info($"{commodityInfo.CashItemSN}"); #else c.Account.ModifyCash(cashType, -commodityInfo.Price); #endif item.dwAccountID = c.Account.ID; item.dwCharacterID = c.dwCharId; c.SendPacket(CPacket.CCashShop.BuyResponse(item)); // do best items/limited goods handling here }
private void CalculateDamageRange(MapleItemType itemType, int primaryStat, int secondaryStat, int atk, int damR, bool isFighter) { WeaponInfo weaponInfo = ItemConstants.GetWeaponModifierInfo(itemType); double damageModifier = weaponInfo.DamageModifier; if (isFighter) { damageModifier += 0.10; } int baseMaxDamage = (int)Math.Ceiling(damageModifier * (4 * primaryStat + secondaryStat) * (atk / 100.0f)); MaxDamage = (int)((damR / 100.0) * baseMaxDamage); MinDamage = (int)(((weaponInfo.BaseMastery + MasteryR) / 100.0) * MaxDamage); }
private async Task OnUserChangeSlotPositionRequest(IPacket packet) { packet.Decode <int>(); var inventoryType = (ItemInventoryType)packet.Decode <byte>(); var fromSlot = packet.Decode <short>(); var toSlot = packet.Decode <short>(); var number = packet.Decode <short>(); if (toSlot == 0) { if (Field.Template.Limit.HasFlag(FieldOpt.DropLimit)) { return; } await ModifyInventory(i => { var item = Character.GetInventory(inventoryType).Items .Single(ii => ii.Position == fromSlot); if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i.Take(bundle, number); } else { i.Remove(item); } var drop = new FieldDropItem(item) { Position = Position }; Field.Enter(drop, () => drop.GetEnterFieldPacket(0x1, this)); }, true); return; } await ModifyInventory(i => i.Move(inventoryType, fromSlot, toSlot), true); }
public override void RawEncode(COutPacket p, bool bFromCS = false) { p.Encode1(2); base.RawEncode(p, bFromCS); p.Encode2(nNumber); p.EncodeString(sTitle); p.Encode2(nAttribute); if (ItemConstants.IsRechargeableItem(nItemID)) { p.Encode8(liSN); } }
public static void Encode(this ItemSlotBundle i, IPacket p) { p.Encode <byte>(2); i.EncodeBase(p); p.Encode <short>(i.Number); p.Encode <string>(i.Title); p.Encode <short>(i.Attribute); if (ItemConstants.IsRechargeableItem(i.TemplateID)) { p.Encode <long>(0); } }
public void EncodeEquippedRings(COutPacket p) { #region COUPLE_RING p.Encode1(0); // TODO #endregion #region FRIENDSHIP_RING GW_FriendRecord pFriendshipRing = null; var nFriendshipRingID = 0; long nFriendShipSN = 0; for (var bp = BodyPart.BP_RING1; bp < BodyPart.BP_RING4; bp++) { var item = InventoryManipulator.GetItem(Parent, bp, true); if (item is null) { continue; } if (ItemConstants.is_friendship_equip_item(item.nItemID)) { pFriendshipRing = lFriendRecord.FirstOrDefault(ring => ring.liSN == item.liSN); break; } } p.Encode1(pFriendshipRing != null); if (pFriendshipRing != null) { p.Encode8(pFriendshipRing.liSN); p.Encode8(pFriendshipRing.liPairSN); p.Encode4(pFriendshipRing.dwFriendItemID); } #endregion #region MARRIAGE_RING p.Encode1(0); // TODO #endregion }
public static GW_ItemSlotBase CreateItem(int nItemID, bool bRandStats = true) { if (nItemID <= 0) { return(null); } // TODO test the below if (ItemConstants.GetInventoryType(nItemID) != InventoryType.Equip) { GW_ItemSlotBase item; if (ItemConstants.IsPet(nItemID)) { item = new GW_ItemSlotPet(nItemID); ((GW_ItemSlotPet)item).nRemainLife = 7776000; } else { item = new GW_ItemSlotBundle(nItemID); } if (item.Template is null) { throw new ArgumentOutOfRangeException(nameof(nItemID), "Doesn't exist in data files."); } if (ItemConstants.IsRechargeableItem(item.nItemID)) { item.nNumber = (short)item.Template.SlotMax; } else { item.nNumber = 1; } item.tDateExpire = DateTime.MaxValue; return(item); } if (bRandStats) { return(CreateVariableStatEquip(nItemID)); } return(CreateNormalStatEquip(nItemID)); }
private static bool IsAccessoryScrollable(int itemId) { MapleItemType type = ItemConstants.GetMapleItemType(itemId); switch (type) { case MapleItemType.FaceAccessory: case MapleItemType.EyeAccessory: case MapleItemType.Earring: case MapleItemType.Ring: case MapleItemType.Pendant: case MapleItemType.Belt: case MapleItemType.Medal: return(true); } return(false); }
public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user) { packet.Decode <int>(); var type = (ItemInventoryType)packet.Decode <byte>(); var from = packet.Decode <short>(); var to = packet.Decode <short>(); var number = packet.Decode <short>(); if (to == 0) { await user.ModifyInventory(i => { var item = user.Character.Inventories[type].Items[from]; if (!ItemConstants.IsTreatSingly(item.TemplateID)) { if (!(item is ItemSlotBundle bundle)) { return; } if (bundle.Number < number) { return; } item = i[type].Take(from, number); } else { i[type].Remove(from); } var drop = new ItemFieldDrop(item) { Position = user.Position, DateExpire = DateTime.Now.AddMinutes(3) }; user.Field.Enter(drop, () => drop.GetEnterFieldPacket(0x1, user)); }, true); return; } // TODO: equippable checks await user.ModifyInventory(i => i[type].Move(from, to), true); }
private static bool IsArmorScrollable(int itemId) { MapleItemType type = ItemConstants.GetMapleItemType(itemId); switch (type) { case MapleItemType.Cap: case MapleItemType.Top: case MapleItemType.Overall: case MapleItemType.Legs: case MapleItemType.Shoes: case MapleItemType.Glove: case MapleItemType.Cape: return(true); } return(false); }
public void HandleAddItem(CInPacket p, Character pChar) { if (dwFirstLockerId == pChar.dwId || !acceptedInvite) { return; } var nTI = (InventoryType)p.Decode1(); var nCurInvSlot = p.Decode2(); // in inventory var nCount = p.Decode2(); var nTargetSlot = p.Decode1(); // in trade window var pItem = InventoryManipulator.GetItem(pChar, nTI, nCurInvSlot); var tempInv = GetTempInv(pChar); if (pItem is null || !tempInv.CanAddToSlot(nTargetSlot)) { return; } if (ItemConstants.is_treat_singly(pItem.nItemID)) { nCount = -1; // negative amount clears the slot } else { nCount = Math.Min(pItem.nNumber, Math.Abs(nCount)); } InventoryManipulator.RemoveFrom(pChar, nTI, nCurInvSlot, nCount); if (pItem is GW_ItemSlotBundle pBundle && !pBundle.IsRechargeable) { pItem = pItem.DeepCopy(); pItem.nNumber = nCount; } var pTempItem = new TempItem(pItem, nCurInvSlot, nTargetSlot); tempInv.Add(pTempItem); Parent.SendPacket(AddItemPacket(pTempItem, !IsOwner(pChar))); Partner.SendPacket(AddItemPacket(pTempItem, IsOwner(pChar))); }
public LibraryItem(string id, string title, ItemConstants.Type type) { this.Id = id; this.Title = title; this.Type = type; }