TaskInventoryHelpers.cs 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using OpenMetaverse;
  29. using OpenMetaverse.Assets;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.Framework.Scenes;
  32. using OpenSim.Services.Interfaces;
  33. namespace OpenSim.Tests.Common
  34. {
  35. /// <summary>
  36. /// Utility functions for carrying out task inventory tests.
  37. /// </summary>
  38. ///
  39. public static class TaskInventoryHelpers
  40. {
  41. /// <summary>
  42. /// Add a notecard item to the given part.
  43. /// </summary>
  44. /// <param name="scene"></param>
  45. /// <param name="part"></param>
  46. /// <returns>The item that was added</returns>
  47. public static TaskInventoryItem AddNotecard(Scene scene, SceneObjectPart part)
  48. {
  49. AssetNotecard nc = new AssetNotecard();
  50. nc.BodyText = "Hello World!";
  51. nc.Encode();
  52. UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
  53. UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000");
  54. AssetBase ncAsset
  55. = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);
  56. scene.AssetService.Store(ncAsset);
  57. TaskInventoryItem ncItem
  58. = new TaskInventoryItem
  59. { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid,
  60. Type = (int)AssetType.Notecard, InvType = (int)InventoryType.Notecard };
  61. part.Inventory.AddInventoryItem(ncItem, true);
  62. return ncItem;
  63. }
  64. /// <summary>
  65. /// Add a scene object item to the given part.
  66. /// </summary>
  67. /// <param name="scene"></param>
  68. /// <param name="sop"></param>
  69. /// <param name="itemName"></param>
  70. /// <param name="id"></param>
  71. public static TaskInventoryItem AddSceneObject(Scene scene, SceneObjectPart sop, string itemName, UUID id)
  72. {
  73. SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, UUID.Zero);
  74. AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(0x10, taskSceneObject);
  75. scene.AssetService.Store(taskSceneObjectAsset);
  76. TaskInventoryItem taskSceneObjectItem
  77. = new TaskInventoryItem
  78. { Name = itemName, AssetID = taskSceneObjectAsset.FullID, ItemID = id,
  79. Type = (int)AssetType.Object, InvType = (int)InventoryType.Object };
  80. sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
  81. return taskSceneObjectItem;
  82. }
  83. }
  84. }