Helpers.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 OpenSim 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 System.IO;
  29. using System.Threading;
  30. using System.Collections;
  31. using System.Collections.Generic;
  32. using System.Runtime.Serialization;
  33. using libsecondlife;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Environment;
  36. using OpenSim.Region.Environment.Scenes;
  37. namespace OpenSim.Region.ScriptEngine.Shared
  38. {
  39. [Serializable]
  40. public class EventAbortException : Exception
  41. {
  42. public EventAbortException()
  43. {
  44. }
  45. protected EventAbortException(
  46. SerializationInfo info,
  47. StreamingContext context)
  48. {
  49. }
  50. }
  51. public class DetectParams
  52. {
  53. public DetectParams()
  54. {
  55. Key = LLUUID.Zero;
  56. OffsetPos = new LSL_Types.Vector3();
  57. LinkNum = 0;
  58. Group = LLUUID.Zero;
  59. Name = String.Empty;
  60. Owner = LLUUID.Zero;
  61. Position = new LSL_Types.Vector3();
  62. Rotation = new LSL_Types.Quaternion();
  63. Type = 0;
  64. Velocity = new LSL_Types.Vector3();
  65. }
  66. public LLUUID Key;
  67. public LSL_Types.Vector3 OffsetPos;
  68. public int LinkNum;
  69. public LLUUID Group;
  70. public string Name;
  71. public LLUUID Owner;
  72. public LSL_Types.Vector3 Position;
  73. public LSL_Types.Quaternion Rotation;
  74. public int Type;
  75. public LSL_Types.Vector3 Velocity;
  76. public void Populate(Scene scene)
  77. {
  78. SceneObjectPart part = scene.GetSceneObjectPart(Key);
  79. if (part == null) // Avatar, maybe?
  80. {
  81. ScenePresence presence = scene.GetScenePresence(Key);
  82. if (presence == null)
  83. return;
  84. Name = presence.Firstname + " " + presence.Lastname;
  85. Owner = Key;
  86. Position = new LSL_Types.Vector3(
  87. presence.AbsolutePosition.X,
  88. presence.AbsolutePosition.X,
  89. presence.AbsolutePosition.Z);
  90. Rotation = new LSL_Types.Quaternion(
  91. presence.Rotation.x,
  92. presence.Rotation.y,
  93. presence.Rotation.z,
  94. presence.Rotation.w);
  95. Velocity = new LSL_Types.Vector3(
  96. presence.Velocity.X,
  97. presence.Velocity.X,
  98. presence.Velocity.Z);
  99. Type = 0x01; // Avatar
  100. if (presence.Velocity != LLVector3.Zero)
  101. Type |= 0x02; // Active
  102. Group = presence.ControllingClient.ActiveGroupId;
  103. return;
  104. }
  105. part=part.ParentGroup.RootPart; // We detect objects only
  106. LinkNum = 0; // Not relevant
  107. Group = part.GroupID;
  108. Name = part.Name;
  109. Owner = part.OwnerID;
  110. if (part.Velocity == LLVector3.Zero)
  111. Type = 0x04; // Passive
  112. else
  113. Type = 0x02; // Passive
  114. foreach (SceneObjectPart p in part.ParentGroup.Children.Values)
  115. {
  116. if (p.ContainsScripts())
  117. {
  118. Type |= 0x08; // Scripted
  119. break;
  120. }
  121. }
  122. Position = new LSL_Types.Vector3(part.AbsolutePosition.X,
  123. part.AbsolutePosition.Y,
  124. part.AbsolutePosition.Z);
  125. LLQuaternion wr = part.GetWorldRotation();
  126. Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
  127. Velocity = new LSL_Types.Vector3(part.Velocity.X,
  128. part.Velocity.Y,
  129. part.Velocity.Z);
  130. }
  131. }
  132. public class EventParams
  133. {
  134. public EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
  135. {
  136. EventName=eventName;
  137. Params=eventParams;
  138. DetectParams=detectParams;
  139. }
  140. public string EventName;
  141. public Object[] Params;
  142. public DetectParams[] DetectParams;
  143. }
  144. }