private int SpawnItem(int lowid, int highid, int ql) { // Copied from ChatCmd giveitem. int firstfree = 64; firstfree = Cli.Character.GetNextFreeInventory(104); if (firstfree <= 93) { InventoryEntries ie = new InventoryEntries(); AOItem item = ItemHandler.GetItemTemplate(Convert.ToInt32(lowid)); ie.Placement = firstfree; ie.Container = 104; ie.Item.lowID = Convert.ToInt32(lowid); ie.Item.highID = Convert.ToInt32(highid); ie.Item.Quality = Convert.ToInt32(ql); if (item.ItemType != 1) { ie.Item.multiplecount = Math.Max(1, (int)item.getItemAttribute(212)); } else { bool found = false; foreach (AOItemAttribute a in ie.Item.Stats) { if (a.Stat != 212) { continue; } found = true; a.Value = Math.Max(1, (int)item.getItemAttribute(212)); break; } if (!found) { AOItemAttribute aoi = new AOItemAttribute(); aoi.Stat = 212; aoi.Value = Math.Max(1, (int)item.getItemAttribute(212)); ie.Item.Stats.Add(aoi); } } Cli.Character.Inventory.Add(ie); Packets.AddTemplate.Send(Cli, ie); return(firstfree); } else { // TODO: open overflow Cli.SendChatText("Your Inventory is full"); return(0); } }
public override void ExecuteCommand(Client client, Identity target, string[] args) { Client targetClient = null; if ((targetClient = FindClient.FindClientByName(args[1])) != null) { int firstfree = 64; firstfree = targetClient.Character.GetNextFreeInventory(104); if (firstfree <= 93) { InventoryEntries mi = new InventoryEntries(); AOItem it = ItemHandler.GetItemTemplate(Convert.ToInt32(args[2])); mi.Placement = firstfree; mi.Container = 104; mi.Item.LowID = Convert.ToInt32(args[2]); mi.Item.HighID = Convert.ToInt32(args[3]); mi.Item.Quality = Convert.ToInt32(args[4]); if (it.ItemType != 1) { mi.Item.MultipleCount = Math.Max(1, it.getItemAttribute(212)); } else { bool found = false; foreach (AOItemAttribute a in mi.Item.Stats) { if (a.Stat != 212) { continue; } found = true; a.Value = Math.Max(1, it.getItemAttribute(212)); break; } if (!found) { AOItemAttribute aoi = new AOItemAttribute(); aoi.Stat = 212; aoi.Value = Math.Max(1, it.getItemAttribute(212)); mi.Item.Stats.Add(aoi); } } targetClient.Character.Inventory.Add(mi); AddTemplate.Send(targetClient, mi); } else { client.SendChatText("Your Inventory is full"); } } }
private int SpawnItem() { int firstfree = this.client.Character.GetNextFreeInventory(104); if (firstfree <= 93) { InventoryEntries mi = new InventoryEntries(); AOItem it = ItemHandler.GetItemTemplate(this.ResultLowId); mi.Placement = firstfree; mi.Container = 104; mi.Item.LowID = this.ResultLowId; mi.Item.HighID = this.ResultHighId; mi.Item.Quality = this.Quality; if (it.ItemType != 1) { mi.Item.MultipleCount = Math.Max(1, it.getItemAttribute(212)); } else { bool found = false; foreach (AOItemAttribute a in mi.Item.Stats) { if (a.Stat != 212) { continue; } found = true; a.Value = Math.Max(1, it.getItemAttribute(212)); break; } if (!found) { AOItemAttribute aoi = new AOItemAttribute(); aoi.Stat = 212; aoi.Value = Math.Max(1, it.getItemAttribute(212)); mi.Item.Stats.Add(aoi); } } this.client.Character.Inventory.Add(mi); AddTemplate.Send(this.client, mi); return(firstfree); } else { this.client.SendChatText("Your Inventory is full"); return(0); } }
public static void AddItemToContainer(byte[] packet, Client cli) { PacketReader packetReader = new PacketReader(packet); bool noAppearanceUpdate = false; /* Container ID's: * 0065 Weaponpage * 0066 Armorpage * 0067 Implantpage * 0068 Inventory (places 64-93) * 0069 Bank * 006B Backpack * 006C KnuBot Trade Window * 006E Overflow window * 006F Trade Window * 0073 Socialpage * 0767 Shop Inventory * 0790 Playershop Inventory * DEAD Trade Window (incoming) */ packetReader.PopInt(); packetReader.PopInt(); int sender = packetReader.PopInt(); packetReader.PopInt(); packetReader.PopInt(); Identity fromIdentity = packetReader.PopIdentity(); byte flag = packetReader.PopByte(); int c350 = fromIdentity.Type; int fromId = fromIdentity.Instance; int fromContainerID = packetReader.PopInt(); int fromPlacement = packetReader.PopInt(); Identity toIdentity = packetReader.PopIdentity(); int toid = toIdentity.Instance; c350 = toIdentity.Type; int toPlacement = packetReader.PopInt(); int counterFrom = 0; if ((fromContainerID <= 0x68) || (fromContainerID == 0x73)) // Inventory or Equipmentpages? { for (counterFrom = 0; (counterFrom < cli.Character.Inventory.Count) && (fromPlacement != cli.Character.Inventory[counterFrom].Placement); counterFrom++) { ; } } else { if (fromContainerID == 0x69) { for (counterFrom = 0; (counterFrom < cli.Character.Bank.Count) && (fromPlacement != cli.Character.Bank[counterFrom].Flags); counterFrom++) { ; } } else { counterFrom = -1; } } // TODO: Add check for instanced items (fromcontainerid:fromplacement) if (counterFrom == -1) { return; } int counterTo; if (toIdentity.Type == 0xdead) // Transferring to a trade window??? (only bank trade window yet) { counterTo = cli.Character.Bank.Count; } else { for (counterTo = 0; (counterTo < cli.Character.Inventory.Count) && (toPlacement != cli.Character.Inventory[counterTo].Placement); counterTo++) { ; } } AOItem itemFrom = null; if (counterFrom < cli.Character.Inventory.Count) { itemFrom = ItemHandler.interpolate( cli.Character.Inventory[counterFrom].Item.LowID, cli.Character.Inventory[counterFrom].Item.HighID, cli.Character.Inventory[counterFrom].Item.Quality); } AOItem itemTo = null; if (counterTo < cli.Character.Inventory.Count) { itemTo = ItemHandler.interpolate( cli.Character.Inventory[counterTo].Item.LowID, cli.Character.Inventory[counterTo].Item.HighID, cli.Character.Inventory[counterTo].Item.Quality); } // Calculating delay for equip/unequip/switch gear int delay = 0; if (itemFrom != null) { delay += itemFrom.getItemAttribute(211); } if (itemTo != null) { delay += itemTo.getItemAttribute(211); } if (delay == 0) { delay = 200; } int counter; if (toPlacement == 0x6f) // 0x6f = next free inventory place, we need to send back the actual spot where the item goes // something has to be free, client checks for full inventory { counter = 0; int counter2 = 0; int counter3 = 0; if (toIdentity.Type == 0xdead) { while (counter3 == 0) { counter3 = 1; for (counter2 = 0; counter2 < cli.Character.Bank.Count; counter2++) { if (cli.Character.Bank[counter2].Flags == counter) // using flags for placement { counter++; counter3 = 0; continue; } } } } else { counter = 64; while (counter3 == 0) { counter3 = 1; for (counter2 = 0; counter2 < cli.Character.Inventory.Count; counter2++) { if (cli.Character.Inventory[counter2].Placement == counter) { counter++; counter3 = 0; continue; } } } } toPlacement = counter; } cli.Character.DoNotDoTimers = true; if (toIdentity.Type == 0xdead) // 0xdead only stays for bank at the moment { cli.Character.TransferItemtoBank(fromPlacement, toPlacement); noAppearanceUpdate = true; } else { switch (fromContainerID) { case 0x68: // from Inventory if (toPlacement <= 30) { // to Weaponspage or Armorpage // TODO: Send some animation if (itemTo != null) { cli.Character.UnequipItem(itemTo, cli.Character, false, fromPlacement); // send interpolated item Unequip.Send(cli, itemTo, InventoryPage(toPlacement), toPlacement); // client takes care of hotswap cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement); Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement); } else { cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement); Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement); } } else { if (toPlacement < 46) { if (itemTo == null) { cli.Character.EquipItem(itemFrom, cli.Character, false, toPlacement); Equip.Send(cli, itemFrom, InventoryPage(toPlacement), toPlacement); } } // Equiping to social page if ((toPlacement >= 49) && (toPlacement <= 63)) { if (itemTo != null) { cli.Character.UnequipItem(itemTo, cli.Character, true, fromPlacement); // send interpolated item cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement); } else { cli.Character.EquipItem(itemFrom, cli.Character, true, toPlacement); } //cli.Character.switchItems(cli, fromplacement, toplacement); } } cli.Character.SwitchItems(fromPlacement, toPlacement); cli.Character.CalculateSkills(); noAppearanceUpdate = false; break; case 0x66: // from Armorpage cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement); // send interpolated item Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement); cli.Character.SwitchItems(fromPlacement, toPlacement); cli.Character.CalculateSkills(); noAppearanceUpdate = false; break; case 0x65: // from Weaponspage cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement); // send interpolated item Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement); cli.Character.SwitchItems(fromPlacement, toPlacement); cli.Character.CalculateSkills(); noAppearanceUpdate = false; break; case 0x67: // from Implantpage cli.Character.UnequipItem(itemFrom, cli.Character, false, fromPlacement); // send interpolated item Unequip.Send(cli, itemFrom, InventoryPage(fromPlacement), fromPlacement); cli.Character.SwitchItems(fromPlacement, toPlacement); cli.Character.CalculateSkills(); noAppearanceUpdate = true; break; case 0x73: cli.Character.UnequipItem(itemFrom, cli.Character, true, fromPlacement); cli.Character.SwitchItems(fromPlacement, toPlacement); cli.Character.CalculateSkills(); break; case 0x69: cli.Character.TransferItemfromBank(fromPlacement, toPlacement); toPlacement = 0x6f; // setting back to 0x6f for packet reply noAppearanceUpdate = true; break; case 0x6c: // KnuBot Trade Window cli.Character.TransferItemfromKnuBotTrade(fromPlacement, toPlacement); break; default: break; } } cli.Character.DoNotDoTimers = false; if ((fromPlacement < 0x30) || (toPlacement < 0x30)) // Equipmentpages need delays { // Delay when equipping/unequipping // has to be redone, jumping breaks the equiping/unequiping // and other messages have to be done too // like heartbeat timer, damage from environment and such Thread.Sleep(delay); } else { Thread.Sleep(200); //social has to wait for 0.2 secs too (for helmet update) } SwitchItem.Send(cli, fromContainerID, fromPlacement, toIdentity, toPlacement); cli.Character.Stats.ClearChangedFlags(); if (!noAppearanceUpdate) { cli.Character.AppearanceUpdate(); } itemFrom = null; itemTo = null; }
public static List <AOItem> GetLoot(NonPlayerCharacterClass npc) { List <AOItem> drops = new List <AOItem>(); int minql = (int)Math.Ceiling(npc.Stats.Level.Value - 0.2 * npc.Stats.Level.Value); int maxql = (int)Math.Floor(npc.Stats.Level.Value + 0.2 * npc.Stats.Level.Value); var lootinfo = new SqlWrapper().ReadDatatable( "SELECT drophashes, dropslots, droppercents FROM mobtemplate WHERE hash = " + npc.Hash + ";").Rows; int numberOfSlots = 0; string[] hashes = lootinfo[0][0].ToString().ToLower().Split(','); string[] slots = lootinfo[0][1].ToString().ToLower().Split(','); string[] percents = lootinfo[0][2].ToString().ToLower().Split(','); if (!hashes.Any()) { return(null); } if (hashes[0] == string.Empty) { return(null); } foreach (string s in slots) { numberOfSlots = Math.Max(numberOfSlots, Convert.ToInt32(s.Trim())); } List <PartialSlot> list = new List <PartialSlot>(); for (int hashNumber = 0; hashNumber < hashes.Count(); ++hashNumber) { list.Add( new PartialSlot(hashes[hashNumber].Trim(), slots[hashNumber].Trim(), percents[hashNumber].Trim())); } for (int slotNumber = 1; slotNumber <= numberOfSlots; ++slotNumber) { var fullSlot = list.Where(match => match.Slot == slotNumber).Select(match => match); Random rand = new Random(); double num = rand.NextDouble(); double chance = 0; foreach (PartialSlot slot in fullSlot) { chance = chance + (slot.Chance / (double)10000); if (num <= chance) { List <LootItem> union = new List <LootItem>(); foreach (string hash in slot.HashList) { var matches = FullDropList.Where( match => ((match.MinQL <= minql && match.MaxQL >= maxql) || (match.MinQL < maxql && match.MaxQL >= maxql) || (match.MinQL <= minql && match.MaxQL > minql) || (match.MinQL >= minql && match.MaxQL <= maxql) || !match.RangeCheck) && match.Hash == hash).Select(match => match); foreach (LootItem li in matches) { if ( !union.Exists( duplicate => duplicate.HighId == li.HighId && duplicate.MaxQL == li.MaxQL)) { union.Add(li); } } } int ql = rand.Next(minql - 1, maxql + 1); if (union.Any()) { int select = rand.Next(-1, union.Count()); AOItem item = ItemHandler.interpolate( union.ElementAt(@select).LowId, union.ElementAt(@select).HighId, ql); if (item.ItemType != 1) { item.MultipleCount = Math.Max(1, item.getItemAttribute(212)); } else { bool found = false; foreach (AOItemAttribute a in item.Stats) { if (a.Stat != 212) { continue; } found = true; a.Value = Math.Max(1, item.getItemAttribute(212)); break; } if (!found) { AOItemAttribute aoi = new AOItemAttribute { Stat = 212, Value = Math.Max(1, item.getItemAttribute(212)) }; item.Stats.Add(aoi); } } drops.Add(item); break; } } } } return(drops); }