/// <summary> /// </summary> /// <param name="sendingPage"> /// </param> /// <param name="fromPlacement"> /// </param> /// <param name="toPlacement"> /// </param> /// <exception cref="NotImplementedException"> /// </exception> public void HotSwap(IInventoryPage sendingPage, int fromPlacement, int toPlacement) { IItem toEquip = sendingPage[fromPlacement]; IItem hotSwapItem = this[toPlacement]; sendingPage.Remove(fromPlacement); this.Remove(toPlacement); sendingPage.Add(fromPlacement, hotSwapItem); this.Add(toPlacement, toEquip); }
/// <summary> /// </summary> /// <param name="sendingPage"> /// </param> /// <param name="fromPlacement"> /// </param> /// <param name="toPlacement"> /// </param> /// <exception cref="NotImplementedException"> /// </exception> public void Equip(IInventoryPage sendingPage, int fromPlacement, int toPlacement) { IItem toEquip = sendingPage[fromPlacement]; // First: Check if the item can be worn bool canBeWornCheck = (toEquip.GetAttribute(30) & (int)CanFlags.Wear) == (int)CanFlags.Wear; if (canBeWornCheck) { this.Add(toPlacement, toEquip); sendingPage.Remove(fromPlacement); } }
/// <summary> /// </summary> /// <param name="sourceContainerType"> /// </param> /// <param name="sourcePlacement"> /// </param> /// <param name="target"> /// </param> /// <param name="targetPlacement"> /// </param> /// <returns> /// </returns> /// <exception cref="NotImplementedException"> /// </exception> public bool ContainerAddItem(int sourceContainerType, int sourcePlacement, Identity target, int targetPlacement) { // Procedure: // 1. Check if source location has item // 2. Check if target container exists // 3. Switch source with target // Source container exists if (this.Character.BaseInventory.Pages.ContainsKey(sourceContainerType)) { IInventoryPage sourcePage = this.Character.BaseInventory.Pages[sourceContainerType]; // Source is not null if (sourcePage[sourcePlacement] != null) { if (this.Character.Identity == target) { IInventoryPage targetPage = this.Character.BaseInventory.PageFromSlot(targetPlacement); if (targetPage != null) { IItem itemSource = sourcePage.Remove(sourcePlacement); IItem itemTarget = targetPage.Remove(targetPlacement); if (itemTarget != null) { sourcePage.Add(sourcePlacement, itemTarget); } if (itemSource != null) { targetPage.Add(targetPlacement, itemSource); } } } else { // Put it into the other players/npcs trade window? } } } return(true); }
/// <summary> /// </summary> /// <param name="message"> /// </param> /// <param name="cli"> /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// </exception> /// <exception cref="NotImplementedException"> /// </exception> public static void AddItemToContainer(ContainerAddItemMessage message, ZoneClient cli) { 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) It's bank now (when you put something into the bank) */ var fromContainerID = (int)message.SourceContainer.Type; int fromPlacement = message.SourceContainer.Instance; Identity toIdentity = message.Target; int toPlacement = message.TargetPlacement; // Where and what does need to be moved/added? IInventoryPage sendingPage = cli.Character.BaseInventory.Pages[fromContainerID]; IItem itemFrom = sendingPage[fromPlacement]; // Receiver of the item (IInstancedEntity, can be mostly all from NPC, Character or Bag, later even playfields) // Turn 0xDEAD into C350 if instance is the same if (toIdentity.Type == IdentityType.IncomingTradeWindow) { toIdentity.Type = IdentityType.CanbeAffected; } IItemContainer itemReceiver = cli.Playfield.FindByIdentity(toIdentity) as IItemContainer; if (itemReceiver == null) { throw new ArgumentOutOfRangeException( "No Entity found: " + message.Target.Type.ToString() + ":" + message.Target.Instance); } // On which inventorypage should the item be added? IInventoryPage receivingPage; if ((toPlacement == 0x6f) && (message.Target.Type == IdentityType.IncomingTradeWindow)) { receivingPage = itemReceiver.BaseInventory.Pages[(int)IdentityType.Bank]; } else { receivingPage = itemReceiver.BaseInventory.PageFromSlot(toPlacement); } // Get standard page if toplacement cant be found (0x6F for next free slot) // TODO: If Entities are not the same (other player, bag etc) then always add to the standard page if ((receivingPage == null) || (itemReceiver.GetType() != cli.Character.GetType())) { receivingPage = itemReceiver.BaseInventory.Pages[itemReceiver.BaseInventory.StandardPage]; } if (receivingPage == null) { throw new ArgumentOutOfRangeException("No inventorypage found."); } if (toPlacement == 0x6f) { toPlacement = receivingPage.FindFreeSlot(); } // Is there already a item? IItem itemTo; try { itemTo = receivingPage[toPlacement]; } catch (Exception) { itemTo = null; } // Calculating delay for equip/unequip/switch gear int delay = 20; cli.Character.DoNotDoTimers = true; IItemSlotHandler equipTo = receivingPage as IItemSlotHandler; IItemSlotHandler unequipFrom = sendingPage as IItemSlotHandler; noAppearanceUpdate = !((equipTo is WeaponInventoryPage) || (equipTo is ArmorInventoryPage) || (equipTo is SocialArmorInventoryPage)); noAppearanceUpdate &= !((unequipFrom is WeaponInventoryPage) || (unequipFrom is ArmorInventoryPage) || (unequipFrom is SocialArmorInventoryPage)); if (equipTo != null) { if (itemTo != null) { if (receivingPage.NeedsItemCheck) { Actions action = GetAction(sendingPage, itemFrom); if (action.CheckRequirements(cli.Character)) { UnEquip.Send(cli, receivingPage, toPlacement); if (!noAppearanceUpdate) { // 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 delay = (itemFrom.GetAttribute(211) == 1234567890 ? 20 : itemFrom.GetAttribute(211)) + (itemTo.GetAttribute(211) == 1234567890 ? 20 : itemTo.GetAttribute(211)); } Thread.Sleep(delay * 10); // social has to wait for 0.2 secs too (for helmet update) cli.Character.Send(message); equipTo.HotSwap(sendingPage, fromPlacement, toPlacement); Equip.Send(cli, receivingPage, toPlacement); } } } else { if (receivingPage.NeedsItemCheck) { if (itemFrom == null) { throw new NullReferenceException("itemFrom can not be null, possible inventory error"); } Actions action = GetAction(receivingPage, itemFrom); if (action.CheckRequirements(cli.Character)) { if (!noAppearanceUpdate) { // 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 delay = itemFrom.GetAttribute(211); if ((equipTo is SocialArmorInventoryPage) || (delay == 1234567890)) { delay = 20; } Thread.Sleep(delay * 10); } if (sendingPage == receivingPage) { // Switch rings for example UnEquip.Send(cli, sendingPage, fromPlacement); } cli.Character.Send(message); equipTo.Equip(sendingPage, fromPlacement, toPlacement); Equip.Send(cli, receivingPage, toPlacement); } } } } else { if (unequipFrom != null) { // Send to client first if (!noAppearanceUpdate) { // 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 delay = itemFrom.GetAttribute(211); if ((unequipFrom is SocialArmorInventoryPage) || (delay == 1234567890)) { delay = 20; } Thread.Sleep(delay * 10); } UnEquip.Send(cli, sendingPage, fromPlacement); unequipFrom.Unequip(fromPlacement, receivingPage, toPlacement); cli.Character.Send(message); } else { // No equipment page involved, just send ContainerAddItemMessage back message.TargetPlacement = receivingPage.FindFreeSlot(); IItem item = sendingPage.Remove(fromPlacement); receivingPage.Add(message.TargetPlacement, item); cli.Character.Send(message); } } cli.Character.DoNotDoTimers = false; cli.Character.Stats.ClearChangedFlags(); // Apply item functions before sending the appearanceupdate message cli.Character.CalculateSkills(); if (!noAppearanceUpdate) { AppearanceUpdate.AnnounceAppearanceUpdate(cli.Character); } }