public static int Create(int itemid, MapleCharacter chr) { try { MapleItemInformationProvider mii = MapleItemInformationProvider.Instance; using (var db = new NeoMapleStoryDatabase()) { var petmodel = new PetModel() { Name = mii.GetName(itemid), Level = 1, Closeness = 0, Fullness = 100, UniqueId = MapleCharacter.GetNextUniqueId() }; db.Pets.Add(petmodel); db.SaveChanges(); chr.Save(); return(petmodel.Id); } } catch (Exception e) { Console.WriteLine(e); return(-1); } }
public void Sell(MapleClient c, MapleInventoryType type, byte slot, short quantity) { if (quantity == short.MinValue || quantity == 0) { quantity = 1; } MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; IMapleItem item = c.Player.Inventorys[type.Value].Inventory[slot]; if (ii.IsThrowingStar(item.ItemId)) { quantity = item.Quantity; } if (quantity < 0) { AutobanManager.Instance.AddPoints(c, 1000, 0, "Selling " + quantity + " " + item.ItemId + " (" + type + "/" + slot + ")"); return; } short iQuant = item.Quantity; if (iQuant == short.MinValue) { iQuant = 1; } if (quantity <= iQuant && iQuant > 0) { MapleInventoryManipulator.RemoveFromSlot(c, type, slot, quantity, false); double price; if (ii.IsThrowingStar(item.ItemId)) { price = ii.GetWholePrice(item.ItemId) / (double)ii.GetSlotMax(c, item.ItemId); } else { price = ii.GetPrice(item.ItemId); } int recvMesos = (int)Math.Max(Math.Ceiling(price * quantity), 0); if (Math.Abs(price + 1) > 0.000001 && recvMesos > 0) { c.Player.GainMeso(recvMesos, true); } c.Send(PacketCreator.ConfirmShopTransaction(0x8)); } }
public static void Move(MapleClient c, MapleInventoryType type, short src, short dst) { byte srcSlot = (byte)src; byte dstSlot = (byte)dst; if (srcSlot > 127 || dstSlot > 127 || srcSlot > c.Player.Inventorys[type.Value].SlotLimit || dstSlot > c.Player.Inventorys[type.Value].SlotLimit) { return; } MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; IMapleItem source; IMapleItem initialTarget; if (!c.Player.Inventorys[type.Value].Inventory.TryGetValue(srcSlot, out source)) { return; } short olddstQ = -1; if (c.Player.Inventorys[type.Value].Inventory.TryGetValue(dstSlot, out initialTarget)) { olddstQ = initialTarget.Quantity; } short oldsrcQ = source.Quantity; short slotMax = ii.GetSlotMax(c, source.ItemId); bool op = c.Player.Inventorys[type.Value].Move(srcSlot, dstSlot, slotMax); if (!op) { c.Send(PacketCreator.EnableActions()); return; } if (type != MapleInventoryType.Equip && initialTarget != null && initialTarget.ItemId == source.ItemId && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { c.Send(olddstQ + oldsrcQ > slotMax ? PacketCreator.MoveAndMergeWithRestInventoryItem(type, srcSlot, dstSlot, (short)((olddstQ + oldsrcQ) - slotMax), slotMax) : PacketCreator.MoveAndMergeInventoryItem(type, srcSlot, dstSlot, ((Item)c.Player.Inventorys[type.Value].Inventory[dstSlot]).Quantity)); } else { c.Send(PacketCreator.MoveInventoryItem(type, src, dst, 0)); } }
public void Buy(MapleClient c, int itemId, short quantity) { if (quantity <= 0) { Console.WriteLine($"{c.Player.Name} is buying an invalid amount: { quantity } of itemid: { itemId}"); c.Close(); return; } MapleShopItem item = FindByItemId(itemId); MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; if (item != null && item.Price > 0 && c.Player.Meso.Value >= item.Price * quantity) { if (MapleInventoryManipulator.CheckSpace(c, itemId, quantity, "")) { if (itemId >= 5000000 && itemId <= 5000100) { if (quantity > 1) { quantity = 1; } int petId = MaplePet.Create(itemId); MapleInventoryManipulator.AddById(c, itemId, quantity, "Pet was purchased.", null, petId); } else if (ii.IsRechargable(itemId)) { short rechquantity = ii.GetSlotMax(c, item.ItemId); MapleInventoryManipulator.AddById(c, itemId, rechquantity, "Rechargable item purchased.", null, -1); } else { MapleInventoryManipulator.AddById(c, itemId, quantity, c.Player.Name + " bought " + quantity + " for " + item.Price * quantity + " from shop " + ShopId); } c.Player.GainMeso(-(item.Price * quantity), false); c.Send(PacketCreator.ConfirmShopTransaction(0)); } else { c.Send(PacketCreator.ConfirmShopTransaction(3)); } } }
public static void Drop(MapleClient c, MapleInventoryType type, byte srcSlot, short quantity) { MapleItemInformationProvider ii = MapleItemInformationProvider.Instance; if (srcSlot > 127) { type = MapleInventoryType.Equipped; } IMapleItem source = c.Player.Inventorys[type.Value].Inventory[srcSlot]; if (quantity > ii.GetSlotMax(c, source.ItemId)) { //try //{ // c.getChannelServer().getWorldInterface().broadcastGMMessage(c.Player.getName(), PacketCreator.serverNotice(0, c.Player.getName() + " is dropping more than slotMax.").getBytes()); //} //catch (Throwable u) //{ //} } if (quantity < 0 || quantity == 0 && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { //String message = "Dropping " + quantity + " " + (source == null ? "?" : source.ItemId) + " (" +type.name() + "/" + srcSlot + ")"; //log.info(MapleClient.getLogMessage(c, message)); c.Close(); // disconnect the client as is inventory is inconsistent with the serverside inventory return; } Point dropPos = c.Player.Position; if (quantity < source.Quantity && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId)) { IMapleItem target = source.Copy(); target.Quantity = quantity; source.Quantity -= quantity; c.Send(PacketCreator.DropInventoryItemUpdate(type, source)); bool weddingRing = source.ItemId == 1112804; bool liRing = source.ItemId == 1112405; if (weddingRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else if (c.Player.Map.Everlast) { if (ii.IsDropRestricted(target.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false); } } else { if (ii.IsDropRestricted(target.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false); } } } else { c.Player.Inventorys[type.Value].RemoveSlot(srcSlot); c.Send(PacketCreator.DropInventoryItem(srcSlot > 127 ? MapleInventoryType.Equip : type, srcSlot)); bool liRing = source.ItemId == 1112405; if (srcSlot > 127) { c.Player.EquipChanged(); } if (c.Player.Map.Everlast) { if (ii.IsDropRestricted(source.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, false); if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true); } } } else { if (ii.IsDropRestricted(source.ItemId)) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { if (liRing) { c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos); } else { c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, 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(); }