1
0

IScriptHandler.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. using OpenSim.Physics.Manager;
  6. using OpenSim.world;
  7. using Avatar=OpenSim.world.Avatar;
  8. using Primitive = OpenSim.world.Primitive;
  9. namespace OpenSim.RegionServer.world.scripting
  10. {
  11. public delegate void ScriptEventHandler(IScriptContext context);
  12. public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
  13. {
  14. private World m_world;
  15. private Script m_script;
  16. private Entity m_entity;
  17. public LLUUID ScriptId
  18. {
  19. get
  20. {
  21. return m_script.ScriptId;
  22. }
  23. }
  24. public void OnFrame()
  25. {
  26. m_script.OnFrame(this);
  27. }
  28. public ScriptHandler(Script script, Entity entity, World world)
  29. {
  30. m_script = script;
  31. m_entity = entity;
  32. m_world = world;
  33. }
  34. #region IScriptContext Members
  35. IScriptEntity IScriptContext.Entity
  36. {
  37. get
  38. {
  39. return this;
  40. }
  41. }
  42. bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
  43. {
  44. foreach (Entity entity in m_world.Entities.Values )
  45. {
  46. if( entity is Avatar )
  47. {
  48. avatar = entity;
  49. return true;
  50. }
  51. }
  52. avatar = null;
  53. return false;
  54. }
  55. #endregion
  56. #region IScriptEntity and IScriptReadonlyEntity Members
  57. public string Name
  58. {
  59. get
  60. {
  61. return m_entity.Name;
  62. }
  63. }
  64. public LLVector3 Pos
  65. {
  66. get
  67. {
  68. return m_entity.Pos;
  69. }
  70. set
  71. {
  72. if (m_entity is Primitive)
  73. {
  74. Primitive prim = m_entity as Primitive;
  75. // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
  76. prim.UpdatePosition( value );
  77. }
  78. }
  79. }
  80. #endregion
  81. }
  82. }