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); }
public MapleItem(MapleItem item, string source) { ItemId = item.ItemId; Position = item.Position; Flags = item.Flags; Quantity = item.Quantity; Creator = item.Creator; DbId = -1; Source = source; }
public static PacketWriter ShowItemGain(MapleItem item) { PacketWriter pw = new PacketWriter(); pw.WriteHeader(SendHeader.ShowStatusInfo); pw.WriteShort(0); pw.WriteInt(item.ItemId); pw.WriteInt(item.Quantity); return(pw); }
public static void AddItemPosition(PacketWriter pw, MapleItem item) { short position = item.Position; if (position < 0) { position = Math.Abs(position); if (position > 100 && position < 1000) { position -= 100; } } if (item.Type == 1) //equip { pw.WriteShort(position); } else { pw.WriteByte((byte)position); } }
public static bool UseBonusPotentialScroll(MapleEquip equip, MapleItem scroll, MapleCharacter chr) { if (equip.PotentialState == MaplePotentialState.None) { return(false); //Can only be used on items that already have regular potential } int successChance; int curseChance; switch (scroll.ItemId) { case 2048305: { successChance = 70; curseChance = 100; break; } case 2048308: case 2048311: { successChance = 50; curseChance = 50; break; } case 2048309: case 2048314: { successChance = 60; curseChance = 0; break; } case 2048310: { successChance = 60; curseChance = 100; break; } case 2048307: case 2048315: case 2048329: { successChance = 100; curseChance = 0; break; } default: { chr.SendPopUpMessage("You cannot use this item."); chr.EnableActions(); return(false); } } if (equip.CheckAndRemoveFlag(MapleItemFlags.LuckyDay)) { successChance += 10; } bool destroyed = false; bool removeScroll = true; bool scrollProtection = equip.CheckAndRemoveFlag(MapleItemFlags.ScrollProtection); bool curseProtection = curseChance > 0 && equip.CheckAndRemoveFlag(MapleItemFlags.CurseProtection); byte scrollResult; if (Functions.MakeChance(successChance)) { scrollResult = 1; AddRandomBonusPotential(equip); } else { scrollResult = 0; destroyed = !curseProtection && Functions.MakeChance(curseChance); removeScroll = !scrollProtection; } if (removeScroll) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); } if (destroyed) { chr.Inventory.RemoveItem(equip.InventoryType, equip.Position); scrollResult = 2; } else { chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); //Update item stats } chr.Map.BroadcastPacket(Packets.ShowScrollEffect(chr.Id, scrollResult, scroll.ItemId, equip.ItemId), chr, true); return(true); }
public static bool UsePotentialScroll(MapleEquip equip, MapleItem scroll, MapleCharacter chr) { int successChance; int curseChance = 0; MaplePotentialState grade = MaplePotentialState.Rare; switch (scroll.ItemId) { //Potential scrolls: case 2049401: case 2049408: { successChance = 70; curseChance = 100; break; } case 2049416: { successChance = 70; break; } case 2049400: case 2049407: case 2049412: case 2049413: { successChance = 90; curseChance = 100; break; } case 2049402: case 2049417: case 2049406: { successChance = 100; break; } //Epic potential scrolls: case 2049700: //case 2049702: ? case 2049703: case 2049706: { successChance = 100; grade = MaplePotentialState.Epic; break; } case 2049702: { successChance = 80; curseChance = 20; grade = MaplePotentialState.Epic; break; } case 2049704: case 2049707: { successChance = 40; grade = MaplePotentialState.Epic; break; } case 2049709: { curseChance = 50; goto case 2049705; } case 2049705: case 2049708: case 2049710: { successChance = 50; grade = MaplePotentialState.Epic; break; } //Unique potential scrolls: case 2049750: case 2049753: { successChance = 80; grade = MaplePotentialState.Unique; break; } case 2049751: case 2049754: { successChance = 60; grade = MaplePotentialState.Unique; break; } case 2049757: case 2049758: { successChance = 50; grade = MaplePotentialState.Unique; break; } case 2049752: case 2049755: case 2049756: { successChance = 30; grade = MaplePotentialState.Unique; break; } default: { chr.SendPopUpMessage("You cannot use this item"); chr.EnableActions(); return(false); } } //Item has potential but it's hidden or is same rank as the potential given by the scroll if (equip.PotentialState != MaplePotentialState.None && (equip.PotentialState < MaplePotentialState.Rare || equip.PotentialState >= grade)) { return(false); } if (equip.CheckAndRemoveFlag(MapleItemFlags.LuckyDay)) { successChance += 10; } bool destroyed = false; bool removeScroll = true; bool scrollProtection = equip.CheckAndRemoveFlag(MapleItemFlags.ScrollProtection); bool curseProtection = curseChance > 0 && equip.CheckAndRemoveFlag(MapleItemFlags.CurseProtection); byte scrollResult; if (Functions.MakeChance(successChance)) { scrollResult = 1; AddRandomPotential(equip); } else { scrollResult = 0; destroyed = !curseProtection && Functions.MakeChance(curseChance); removeScroll = !scrollProtection; } if (removeScroll) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); } if (destroyed) { chr.Inventory.RemoveItem(equip.InventoryType, equip.Position); scrollResult = 2; } else { chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); //Update item stats } chr.Map.BroadcastPacket(Packets.ShowScrollEffect(chr.Id, scrollResult, scroll.ItemId, equip.ItemId), chr, true); return(true); }
public static void UseRegularEquipScroll(MapleCharacter chr, MapleEquip equip, MapleItem scroll, bool whiteScroll) { WzItemEnhancer scrollInfo = DataBuffer.GetItemById(scroll.ItemId) as WzItemEnhancer; if (scrollInfo == null) { return; } WzEquip equipInfo = DataBuffer.GetEquipById(equip.ItemId); string reason = ""; if (equipInfo == null || !CanScroll(equip, equipInfo, scrollInfo, out reason)) { chr.SendPopUpMessage("You cannot use that scroll on this item. " + reason); chr.EnableActions(); return; } byte upgradeSlotsUsed = 1; int scrollBaseId = scroll.ItemId / 100; if (scrollBaseId == 20490 || //clean slate scroll scrollBaseId == 20493 || //equip enhancement scroll scrollBaseId == 20496) //innocence scroll { upgradeSlotsUsed = 0; } switch (scroll.ItemId) { case 2040727: //Scroll for Spikes on Shoes case 2041058: //Scroll for Cape for Cold Protection upgradeSlotsUsed = 0; break; } int value; if (scrollInfo.StatEnhancements.TryGetValue("tuc", out value)) //Uses multiple upgrade slots { upgradeSlotsUsed = (byte)value; } if (equip.RemainingUpgradeCount < upgradeSlotsUsed) { chr.SendPopUpMessage(string.Format("This item does not have enough upgrades available")); chr.EnableActions(); return; } byte scrollResult = 0; bool destroyed = false; bool removeScroll = true; int chance = scrollInfo.Chance; bool scrollProtection = equip.CheckAndRemoveFlag(MapleItemFlags.ScrollProtection); bool upgradeCountProtection = upgradeSlotsUsed > 0 && equip.CheckAndRemoveFlag(MapleItemFlags.UpgradeCountProtection); bool curseProtection = equip.CheckAndRemoveFlag(MapleItemFlags.CurseProtection); if (equip.CheckAndRemoveFlag(MapleItemFlags.LuckyDay)) { chance += 10; } if (Functions.MakeChance(chance)) { scrollResult = 1; equip.UpgradeCount += upgradeSlotsUsed; foreach (var kvp in scrollInfo.StatEnhancements) { switch (kvp.Key) { case "incPDD": equip.Pdd += (short)kvp.Value; break; case "incMDD": equip.Mdd += (short)kvp.Value; break; case "incACC": equip.Acc += (short)kvp.Value; break; case "incMHP": equip.IncMhp += (short)kvp.Value; break; case "incINT": equip.Int += (short)kvp.Value; break; case "incDEX": equip.Dex += (short)kvp.Value; break; case "incMAD": equip.Mad += (short)kvp.Value; break; case "incPAD": equip.Pad += (short)kvp.Value; break; case "incEVA": equip.Eva += (short)kvp.Value; break; case "incLUK": equip.Luk += (short)kvp.Value; break; case "incMMP": equip.IncMmp += (short)kvp.Value; break; case "incSTR": equip.Str += (short)kvp.Value; break; case "incSpeed": equip.Speed += (short)kvp.Value; break; case "incJump": equip.Jump += (short)kvp.Value; break; case "incCraft": equip.Diligence += (short)kvp.Value; break; case "preventslip": equip.Flags |= MapleItemFlags.NoSlip; break; case "warmsupport": equip.Flags |= MapleItemFlags.ColdResistance; break; case "recover": { int totalPossibleUpgrades = equipInfo.TotalUpgradeCount + equip.HammersApplied; int failedUpgrades = totalPossibleUpgrades - equip.UpgradeCount - equip.RemainingUpgradeCount; int toRestore = Math.Min(failedUpgrades, kvp.Value); if (toRestore > 0) { equip.RemainingUpgradeCount += (byte)toRestore; } break; } case "randstat": //chaos scroll { bool betterStats = scrollInfo.StatEnhancements.ContainsKey("incRandVol"); bool noNegative = scrollInfo.StatEnhancements.ContainsKey("noNegative"); if (equip.Str > 0) { equip.Str = GetNewChaosStat(equip.Str, betterStats, noNegative); } if (equip.Dex > 0) { equip.Dex = GetNewChaosStat(equip.Dex, betterStats, noNegative); } if (equip.Int > 0) { equip.Int = GetNewChaosStat(equip.Int, betterStats, noNegative); } if (equip.Luk > 0) { equip.Luk = GetNewChaosStat(equip.Luk, betterStats, noNegative); } if (equip.Pad > 0) { equip.Pad = GetNewChaosStat(equip.Pad, betterStats, noNegative); } if (equip.Mad > 0) { equip.Mad = GetNewChaosStat(equip.Mad, betterStats, noNegative); } if (equip.Pdd > 0) { equip.Pdd = GetNewChaosStat(equip.Pdd, betterStats, noNegative); } if (equip.Mdd > 0) { equip.Mdd = GetNewChaosStat(equip.Mdd, betterStats, noNegative); } if (equip.Acc > 0) { equip.Acc = GetNewChaosStat(equip.Acc, betterStats, noNegative); } if (equip.Eva > 0) { equip.Eva = GetNewChaosStat(equip.Eva, betterStats, noNegative); } if (equip.Speed > 0) { equip.Speed = GetNewChaosStat(equip.Speed, betterStats, noNegative); } if (equip.Jump > 0) { equip.Jump = GetNewChaosStat(equip.Jump, betterStats, noNegative); } if (equip.IncMhp > 0) { equip.IncMhp = GetNewChaosStat(equip.IncMhp, betterStats, noNegative); } if (equip.IncMmp > 0) { equip.IncMmp = GetNewChaosStat(equip.IncMmp, betterStats, noNegative); } break; } case "reset": { equip.SetDefaultStats(equipInfo, true); break; } case "perfectReset": { equip.SetDefaultStats(equipInfo); break; } } equip.SaveToDatabase(chr); } } else //Fail { int cursedChance; if (scrollInfo.StatEnhancements.TryGetValue("cursed", out cursedChance)) { destroyed = !curseProtection && Functions.MakeChance(cursedChance); } if (scrollProtection) { removeScroll = false; } if (upgradeCountProtection) { upgradeSlotsUsed = 0; } //todo: white scroll } equip.RemainingUpgradeCount -= upgradeSlotsUsed; if (removeScroll) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); } if (destroyed) { chr.Inventory.RemoveItem(equip.InventoryType, equip.Position); scrollResult = 2; } else { chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); //Update item stats } chr.Map.BroadcastPacket(Packets.ShowScrollEffect(chr.Id, scrollResult, scroll.ItemId, equip.ItemId), chr, true); }
public static void UseSpecialEquipScroll(MapleEquip equip, MapleItem scroll, MapleCharacter chr) { WzEquip equipInfo = DataBuffer.GetEquipById(equip.ItemId); if (equipInfo == null || equipInfo.IsCashItem) { return; } bool success = false; switch (scroll.ItemId) { //Safety scroll: case 5064101: //Safety Scroll Lite { if (equipInfo.ReqLevel > 105) { break; } goto case 2532000; } case 2532001: // Pet equip Safety Scrolls case 2532004: case 5068100: { //todo: check if it's a pet equip goto case 2532000; } case 2532000: case 2532002: case 2532003: case 5064100: { if (equip.RemainingUpgradeCount > 0 && !equip.Flags.HasFlag(MapleItemFlags.UpgradeCountProtection)) { equip.Flags |= MapleItemFlags.UpgradeCountProtection; success = true; } break; } //Recovery scroll: case 5064301: //lite { if (equipInfo.ReqLevel > 105) { break; } goto case 2533000; } case 2533001: case 2533002: case 5068200: { //todo: check if it's a pet equip goto case 2533000; } case 2533000: case 5064300: { if (!equip.Flags.HasFlag(MapleItemFlags.ScrollProtection)) { equip.Flags |= MapleItemFlags.ScrollProtection; success = true; } break; } //Lucky day scroll: case 5068000: case 2530003: case 2530006: { //todo: check if it's a pet equip goto case 2530000; } case 2530000: case 2530002: case 2530004: case 5063000: { if (equip.RemainingUpgradeCount > 0 && !equip.Flags.HasFlag(MapleItemFlags.LuckyDay)) { equip.Flags |= MapleItemFlags.LuckyDay; success = true; } break; } //Protection scroll: case 5064002: //Protection Scroll Lite { if (equipInfo.ReqLevel > 105) { break; } goto case 2531000; } case 2531000: case 2531001: case 2531004: case 2531005: case 2531007: case 5064000: { if (equip.Enhancements < 12 && !equip.Flags.HasFlag(MapleItemFlags.CurseProtection)) { equip.Flags |= MapleItemFlags.CurseProtection; success = true; } break; } } if (success) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, MapleInventoryType.Equip, equip.Position)); chr.Client.SendPacket(Packets.ShowScrollEffect(chr.Id, 1, scroll.ItemId, equip.ItemId)); } else { chr.SendPopUpMessage("You cannot use that on this item"); } }
public static void UseEquipEnhancementScroll(MapleEquip equip, MapleItem scroll, MapleCharacter chr) { if (equip == null || scroll == null) { return; } WzItemEnhancer wzScrollInfo = DataBuffer.GetItemById(scroll.ItemId) as WzItemEnhancer; WzEquip equipInfo = DataBuffer.GetEquipById(equip.ItemId); if (wzScrollInfo == null || equipInfo == null) { return; } int maxEnhancements; if (wzScrollInfo == null || equipInfo == null || (maxEnhancements = equipInfo.MaxStarEnhance) - equip.Enhancements < 1 || equip.RemainingUpgradeCount > 0) { chr.SendPopUpMessage("You cannot use that on this item."); chr.EnableActions(); return; } int chance; bool diminishChance = false; int enhancements; int curseChance = 100; switch (scroll.ItemId) { case 2049323: //advanced equip enhancement scroll curseChance = 0; goto case 2049300; case 2049300: case 2049303: case 2049306: case 2049325: { chance = 100; diminishChance = true; enhancements = 1; break; } case 2049301: //equip enhancement scroll case 2049307: { chance = 80; diminishChance = true; enhancements = 1; break; } default: { if (wzScrollInfo.StatEnhancements.TryGetValue("forceUpgrade", out enhancements) && //multiple star enhances wzScrollInfo.StatEnhancements.TryGetValue("success", out chance)) { if (!wzScrollInfo.StatEnhancements.TryGetValue("cursed", out curseChance)) { curseChance = 100; } break; } chr.SendPopUpMessage("This item is not coded, please report it on the forums. ItemId " + scroll.ItemId); ServerConsole.Debug("ItemID {0} is unhandled in UseEnhancementScroll", scroll.ItemId); return; } } bool scrollProtection = equip.CheckAndRemoveFlag(MapleItemFlags.ScrollProtection); bool curseProtection = equip.CheckAndRemoveFlag(MapleItemFlags.CurseProtection) && equip.Enhancements < 12; bool success = EnhanceEquip(equip, chance, diminishChance, enhancements, maxEnhancements); bool destroyed = false; byte scrollResult = 1; bool removeScroll = success || !scrollProtection; if (!success) { scrollResult = 0; if (!curseProtection && Functions.MakeChance(curseChance)) { scrollResult = 2; destroyed = true; } } if (removeScroll) { chr.Inventory.RemoveItemsFromSlot(scroll.InventoryType, scroll.Position, 1); } if (destroyed) { chr.Inventory.RemoveItem(equip.InventoryType, equip.Position); } else { chr.Client.SendPacket(MapleInventory.Packets.AddItem(equip, equip.InventoryType, equip.Position)); //Update item } chr.Map.BroadcastPacket(Packets.ShowScrollEffect(chr.Id, scrollResult, scroll.ItemId, equip.ItemId), chr, true); }
public static void AddItemInfo(PacketWriter pw, MapleItem item) { pw.WriteByte(item.Type); //TODO: pets = 3 pw.WriteInt(item.ItemId); pw.WriteByte(0); //TODO:UniqueID, //pw.WriteLong(uniqueId) if uniqueId = 1; pw.WriteLong(MapleFormatHelper.GetMapleTimeStamp(-1)); //TODO: item expiration pw.WriteInt(-1); //TODO: extended slots if (item.Type == 1) //Equip { MapleEquip equip = (MapleEquip)item; MapleEquip.AddStats(equip, pw); pw.WriteInt(4); //no clue pw.WriteByte(0xFF); //no clue pw.WriteMapleString(equip.Creator); pw.WriteByte((byte)equip.PotentialState); pw.WriteByte(equip.Enhancements); if (equip.PotentialState >= MaplePotentialState.Rare) { pw.WriteUShort(equip.Potential1); pw.WriteUShort(equip.Potential2); pw.WriteUShort(equip.Potential3); } else { pw.WriteZeroBytes(6); //Don't show the client the potentials if they're hidden } pw.WriteUShort(equip.BonusPotential1); pw.WriteUShort(equip.BonusPotential2); pw.WriteShort(0); //bonus pot 3 pw.WriteShort(0); pw.WriteShort(0); //socket state pw.WriteShort(equip.Socket1); pw.WriteShort(equip.Socket2); pw.WriteShort(equip.Socket3); //if (!HasUniqueId) pw.WriteLong(equip.DbId); pw.WriteLong(MapleFormatHelper.GetMapleTimeStamp(-2)); //don't know pw.WriteInt(-1); pw.WriteLong(0); //new v142 pw.WriteLong(MapleFormatHelper.GetMapleTimeStamp(-2)); //new v142 for (int i = 0; i < 5; i++) { pw.WriteInt(0); } pw.WriteShort(0x1); } else { pw.WriteShort(item.Quantity); pw.WriteMapleString(item.Creator); pw.WriteShort((short)item.Flags); if (item.IsAmmo || item.IsFamiliarCard) { pw.WriteLong(-1); } } }
public bool CanStackWith(MapleItem otherItem) { return(ItemId == otherItem.ItemId && Creator == otherItem.Creator); }