public virtual IItemContainer Unfold(string name, IItemContainer parent) { Guard.NotNullOrEmpty(() => name, name); Guard.NotNull(() => parent, parent); if (!typeof(HierarchyItem).IsAssignableFrom(parent.GetType())) { throw new NotSupportedException(Resources.VsFileTemplate_ErrorParentNotHierarchy); } Guard.NotNullOrEmpty(() => parent.PhysicalPath, parent.PhysicalPath); var targetPath = Path.Combine(Path.GetDirectoryName(parent.PhysicalPath), name); if (File.Exists(targetPath)) { VsHelper.CheckOut(targetPath); } if (!this.SourcePath.Equals(targetPath, StringComparison.OrdinalIgnoreCase)) { File.Copy(this.SourcePath, targetPath, this.overwrite); } var container = parent.As <dynamic>(); EnvDTE.ProjectItem newlyAddedFile = null; if (!parent.Items.Any(i => i.Name == name)) { newlyAddedFile = container.ProjectItems.AddFromFile(targetPath) as EnvDTE.ProjectItem; } if (this.openFile) { container.DTE.ItemOperations.OpenFile(targetPath); } else if (newlyAddedFile != null) { // // The file may have opened anyway, if we're not supposed to open it, we'll search for // the matching window and close it // foreach (EnvDTE.Window w in container.DTE.Windows) { if (newlyAddedFile.Equals(w.ProjectItem)) { w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); break; } } } return(parent.Items.FirstOrDefault(item => item.Kind == ItemKind.Item && item.Name == name)); }
public virtual IItemContainer Unfold(string name, IItemContainer parent) { Guard.NotNullOrEmpty(() => name, name); Guard.NotNull(() => parent, parent); if (!typeof(HierarchyItem).IsAssignableFrom(parent.GetType())) throw new NotSupportedException(Resources.VsFileTemplate_ErrorParentNotHierarchy); Guard.NotNullOrEmpty(() => parent.PhysicalPath, parent.PhysicalPath); var targetPath = Path.Combine(Path.GetDirectoryName(parent.PhysicalPath), name); if (File.Exists(targetPath)) { VsHelper.CheckOut(targetPath); } if (!this.SourcePath.Equals(targetPath, StringComparison.OrdinalIgnoreCase)) { File.Copy(this.SourcePath, targetPath, this.overwrite); } var container = parent.As<dynamic>(); EnvDTE.ProjectItem newlyAddedFile = null; if (!parent.Items.Any(i => i.Name == name)) { newlyAddedFile = container.ProjectItems.AddFromFile(targetPath) as EnvDTE.ProjectItem; } if (this.openFile) { container.DTE.ItemOperations.OpenFile(targetPath); } else if (newlyAddedFile != null) { // // The file may have opened anyway, if we're not supposed to open it, we'll search for // the matching window and close it // foreach (EnvDTE.Window w in container.DTE.Windows) { if (newlyAddedFile.Equals(w.ProjectItem)) { w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); break; } } } return parent.Items.FirstOrDefault(item => item.Kind == ItemKind.Item && item.Name == name); }
/// <summary> /// Converts the value to the destination type. /// </summary> protected virtual object ConvertValue(ITypeDescriptorContext context, IServiceProvider provider, IItemContainer value) { Guard.NotNull(() => context, context); var converter = context.PropertyDescriptor.Converter; if (converter != null && value != null && !context.PropertyDescriptor.PropertyType.IsAssignableFrom(value.GetType()) && converter.CanConvertTo(context, context.PropertyDescriptor.PropertyType)) { return converter.ConvertTo(context, CultureInfo.CurrentCulture, value, context.PropertyDescriptor.PropertyType); } return value; }
/// <summary> /// Converts the value to the destination type. /// </summary> protected virtual object ConvertValue(ITypeDescriptorContext context, IServiceProvider provider, IItemContainer value) { Guard.NotNull(() => context, context); var converter = context.PropertyDescriptor.Converter; if (converter != null && value != null && !context.PropertyDescriptor.PropertyType.IsAssignableFrom(value.GetType()) && converter.CanConvertTo(context, context.PropertyDescriptor.PropertyType)) { return(converter.ConvertTo(context, CultureInfo.CurrentCulture, value, context.PropertyDescriptor.PropertyType)); } return(value); }
/// <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); } }