public static void UnEquip(MapleClient c, short src, short dst) { byte srcSlot = (byte)src; byte dstSlot = (byte)dst; Equip source = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == srcSlot).Value as Equip; Equip target = c.Player.Inventorys[MapleInventoryType.Equip.Value].Inventory.FirstOrDefault(x => x.Key == dstSlot).Value as Equip; if (dstSlot > 127) { Console.WriteLine("Unequipping to negative slot. ({0}: {1}->{2})", c.Player.Name, srcSlot, dstSlot); } if (source == null) { return; } if (target != null && (srcSlot > 127 || srcSlot == 0)) { // do not allow switching with equip c.Send(PacketCreator.GetInventoryFull()); return; } c.Player.Inventorys[MapleInventoryType.Equipped.Value].RemoveSlot(srcSlot); if (target != null) { c.Player.Inventorys[MapleInventoryType.Equip.Value].RemoveSlot(dstSlot); } source.Position = dstSlot; c.Player.Inventorys[MapleInventoryType.Equip.Value].AddFromDb(source); if (target != null) { target.Position = srcSlot; c.Player.Inventorys[MapleInventoryType.Equipped.Value].AddFromDb(target); } c.Send(PacketCreator.MoveInventoryItem(MapleInventoryType.Equip, src, dst, 1)); c.Player.EquipChanged(); }
public static bool AddById(MapleClient c, int itemId, short quantity, string logInfo, string owner = null, int petid = -1) { if (quantity < 0) { return(false); } var ii = MapleItemInformationProvider.Instance; var type = ii.GetInventoryType(itemId); if (type != MapleInventoryType.Equip) { var slotMax = ii.GetSlotMax(c, itemId); var existing = c.Player.Inventorys[type.Value].ListById(itemId); if (!ii.IsThrowingStar(itemId) && !ii.IsBullet(itemId)) { if (existing.Any()) { // first update all existing slots to slotMax for (var i = 0; i < existing.Count && quantity > 0; i++) { var eItem = (Item)existing[i]; var oldQ = eItem.Quantity; if (oldQ < slotMax && (eItem.Owner == owner || owner == null)) { var newQ = (short)Math.Min(oldQ + quantity, slotMax); quantity -= (short)(newQ - oldQ); eItem.Quantity = newQ; //eItem.log("Added " + (newQ - oldQ) + " items to stack, new quantity is " + newQ + " (" + logInfo + " )", false); c.Send(PacketCreator.UpdateInventorySlot(type, eItem)); } } } while (quantity > 0) { // add new slots if there is still something left var newQ = Math.Min(quantity, slotMax); if (newQ != 0) { quantity -= newQ; var nItem = new Item(itemId, 0, newQ); //, petid); //nItem.log("Created while adding by id. Quantity: " + newQ + " (" + logInfo + ")", false); var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem); if (newSlot == 128) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return(false); } if (owner != null) { nItem.Owner = owner; } c.Send(PacketCreator.AddInventorySlot(type, nItem)); if ((ii.IsThrowingStar(itemId) || ii.IsBullet(itemId)) && quantity == 0) { break; } } else { c.Send(PacketCreator.EnableActions()); return(false); } } } else { // Throwing Stars and Bullets - Add all into one slot regardless of quantity. var nItem = new Item(itemId, 0, quantity); //nItem.log("Created while adding by id. Quantity: " + quantity + " (" + logInfo + " )", false); var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem); if (newSlot == 128) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return(false); } c.Send(PacketCreator.AddInventorySlot(type, nItem)); c.Send(PacketCreator.EnableActions()); } } else { if (quantity == 1) { var nEquip = ii.GetEquipById(itemId); //nEquip.log("Created while adding by id. (" + logInfo + " )", false); if (owner != null) { nEquip.Owner = owner; } var newSlot = c.Player.Inventorys[type.Value].AddItem(nEquip); if (newSlot == 128) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return(false); } c.Send(PacketCreator.AddInventorySlot(type, nEquip)); } else { throw new Exception("Trying to create equip with non-one quantity"); } } return(true); }
public static void Equip(MapleClient c, short src, short dst) { MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; byte srcSlot = (byte)src; byte dstSlot = (byte)dst; Equip source = c.Player.Inventorys[MapleInventoryType.Equip.Value].Inventory.FirstOrDefault(x => x.Key == srcSlot).Value as Equip; Equip target = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == dstSlot).Value as Equip; if (source == null) { return; } if (!c.Player.IsGm) { switch (source.ItemId) { case 1002140: // Wizet Invincible Hat case 1042003: // Wizet Plain Suit case 1062007: // Wizet Plain Suit Pants case 1322013: // Wizet Secret Agent Suitcase RemoveAllById(c, source.ItemId, false); c.Player.DropMessage(PacketCreator.ServerMessageType.Popup, "无法佩带此物品"); return; } } int reqLevel = ii.GetReqLevel(source.ItemId); int reqStr = ii.GetReqStr(source.ItemId); int reqDex = ii.GetReqDex(source.ItemId); int reqInt = ii.GetReqInt(source.ItemId); int reqLuk = ii.GetReqLuk(source.ItemId); bool cashSlot = false; if (source.ItemId == 1812006) { RemoveAllById(c, source.ItemId, false); c.Player.DropMessage(PacketCreator.ServerMessageType.Popup, "物品已被封印"); return; } if (dstSlot < 0x9D) { cashSlot = true; } if (!ii.IsCash(source.ItemId)) { string type = ii.GetType(source.ItemId); if ((type.Equals("Cp", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFF) || (type.Equals("Af", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFE) || (type.Equals("Ay", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFD) || (type.Equals("Ae", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFC) || ((type.Equals("Ma", StringComparison.CurrentCultureIgnoreCase) || type.Equals("MaPn", StringComparison.CurrentCultureIgnoreCase)) && dstSlot != 0xFB) || (type.Equals("Pn", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFA) || (type.Equals("So", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF9) || (type.Equals("Gv", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF8) || (type.Equals("Sr", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF7) || (type.Equals("Si", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF6) || ((type.Equals("Wp", StringComparison.CurrentCultureIgnoreCase) || type.Equals("WpSi", StringComparison.CurrentCultureIgnoreCase)) && dstSlot != 0xF5) || (type.Equals("Pe", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xEF)) { c.Send(PacketCreator.EnableActions()); return; } } if ((ii.GetName(source.ItemId).Contains("(Male)") && !c.Player.Gender) || (ii.GetName(source.ItemId).Contains("(Female)") && c.Player.Gender) || reqLevel > c.Player.Level || reqStr > c.Player.Localstr || reqDex > c.Player.Localdex || reqInt > c.Player.Localint || reqLuk > c.Player.Localluk || (cashSlot && !ii.IsCash(source.ItemId))) { c.Send(PacketCreator.EnableActions()); return; } switch (dstSlot) { case 0xFA: { // unequip the overall IMapleItem top; if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xFB, out top) && ii.IsOverall(top.ItemId)) { if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull()) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return; } UnEquip(c, -5, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot()); } } break; case 0xFB: { // unequip the bottom and top IMapleItem top = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == 0xFB).Value; IMapleItem bottom = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == 0xFA).Value; if (top != null && ii.IsOverall(source.ItemId)) { if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull(bottom != null && ii.IsOverall(source.ItemId) ? 1 : 0)) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return; } UnEquip(c, -5, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot()); } if (bottom != null && ii.IsOverall(source.ItemId)) { if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull()) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return; } UnEquip(c, -6, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot()); } } break; case 0xF6: // check if weapon is two-handed IMapleItem weapon; if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xF5, out weapon) && ii.IsTwoHanded(weapon.ItemId)) { if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull()) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return; } UnEquip(c, -11, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot()); } break; case 0xF5: IMapleItem shield; if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xF6, out shield) && ii.IsTwoHanded(source.ItemId)) { if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull()) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return; } UnEquip(c, -10, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot()); } break; case 0xEE: //if (c.Player.Mount != null) //{ // c.Player.getMount().setItemId(source.ItemId); //} break; } source = c.Player.Inventorys[MapleInventoryType.Equip.Value].Inventory.FirstOrDefault(x => x.Key == srcSlot).Value as Equip; target = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == dstSlot).Value as Equip; c.Player.Inventorys[MapleInventoryType.Equip.Value].RemoveSlot(srcSlot); if (target != null) { c.Player.Inventorys[MapleInventoryType.Equipped.Value].RemoveSlot(dstSlot); } source.Position = dstSlot; c.Player.Inventorys[MapleInventoryType.Equipped.Value].AddFromDb(source); if (target != null) { target.Position = srcSlot; c.Player.Inventorys[MapleInventoryType.Equip.Value].AddFromDb(target); } if (c.Player.GetBuffedValue(MapleBuffStat.Booster) != null && ii.IsWeapon(source.ItemId)) { c.Player.CancelBuffStats(MapleBuffStat.Booster); } c.Send(PacketCreator.MoveInventoryItem(MapleInventoryType.Equip, src, dst, 2)); c.Player.EquipChanged(); }
public static bool AddFromDrop(MapleClient c, IMapleItem item, bool show, string loginfo = "") { var ii = MapleItemInformationProvider.Instance; var type = ii.GetInventoryType(item.ItemId); if (!c.ChannelServer.AllowMoreThanOne && ii.IsPickupRestricted(item.ItemId) && c.Player.HaveItem(item.ItemId, 1, true, false)) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.ShowItemUnavailable()); return(false); } var quantity = item.Quantity; if (quantity >= 4000 || quantity < 0) { AutobanManager.Instance.Autoban(c, $"XSource| PE Item: {quantity} x {item.ItemId}"); return(false); } if (type != MapleInventoryType.Equip) { var slotMax = ii.GetSlotMax(c, item.ItemId); var existing = c.Player.Inventorys[type.Value].ListById(item.ItemId); if (!ii.IsThrowingStar(item.ItemId) && !ii.IsBullet(item.ItemId)) { if (existing.Any()) { var i = existing.GetEnumerator(); while (quantity > 0) { if (i.MoveNext()) { var eItem = (Item)i.Current; if (eItem != null) { var oldQ = eItem.Quantity; if (oldQ < slotMax && item.Owner == eItem.Owner) { var newQ = (short)Math.Min(oldQ + quantity, slotMax); quantity -= (short)(newQ - oldQ); eItem.Quantity = newQ; c.Send(PacketCreator.UpdateInventorySlot(type, eItem, true)); } } } else { break; } } } // add new slots if there is still something left while (quantity > 0 || ii.IsThrowingStar(item.ItemId) || ii.IsBullet(item.ItemId)) { var newQ = Math.Min(quantity, slotMax); quantity -= newQ; var nItem = new Item(item.ItemId, 0, newQ) { Owner = item.Owner }; var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem); if (newSlot == 0xFF) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); item.Quantity = (short)(quantity + newQ); return(false); } c.Send(PacketCreator.AddInventorySlot(type, nItem, true)); } } else { // Throwing Stars and Bullets - Add all into one slot regardless of quantity. var nItem = new Item(item.ItemId, 0, quantity); var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem); if (newSlot == 0xFF) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return(false); } c.Send(PacketCreator.AddInventorySlot(type, nItem)); c.Send(PacketCreator.EnableActions()); } } else { if (quantity == 1) { var newSlot = c.Player.Inventorys[type.Value].AddItem(item); if (newSlot == 0xFF) { c.Send(PacketCreator.GetInventoryFull()); c.Send(PacketCreator.GetShowInventoryFull()); return(false); } c.Send(PacketCreator.AddInventorySlot(type, item, true)); } else { throw new Exception("Trying to create equip with non-one quantity"); } } if (show) { c.Send(PacketCreator.GetShowItemGain(item.ItemId, item.Quantity)); } return(true); }