SensorRepeat.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 System.Reflection;
  29. using System.Collections.Generic;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using log4net;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Region.ScriptEngine.Shared;
  36. using OpenSim.Region.ScriptEngine.Shared.Api;
  37. namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
  38. {
  39. public class SensorRepeat
  40. {
  41. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. public AsyncCommandManager m_CmdManager;
  43. /// <summary>
  44. /// Number of sensors active.
  45. /// </summary>
  46. public int SensorsCount
  47. {
  48. get
  49. {
  50. return SenseRepeaters.Count;
  51. }
  52. }
  53. public SensorRepeat(AsyncCommandManager CmdManager)
  54. {
  55. m_CmdManager = CmdManager;
  56. maximumRange = CmdManager.m_ScriptEngine.Config.GetDouble("SensorMaxRange", 96.0d);
  57. maximumToReturn = CmdManager.m_ScriptEngine.Config.GetInt("SensorMaxResults", 16);
  58. m_npcModule = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<INPCModule>();
  59. }
  60. private INPCModule m_npcModule;
  61. private Object SenseLock = new Object();
  62. private const int AGENT = 1;
  63. private const int AGENT_BY_USERNAME = 0x10;
  64. private const int NPC = 0x20;
  65. private const int OS_NPC = 0x01000000;
  66. private const int ACTIVE = 2;
  67. private const int PASSIVE = 4;
  68. private const int SCRIPTED = 8;
  69. private double maximumRange = 96.0;
  70. private int maximumToReturn = 16;
  71. //
  72. // SenseRepeater and Sensors
  73. //
  74. private class SenseRepeatClass
  75. {
  76. public uint localID;
  77. public UUID itemID;
  78. public double interval;
  79. public DateTime next;
  80. public string name;
  81. public UUID keyID;
  82. public int type;
  83. public double range;
  84. public double arc;
  85. public SceneObjectPart host;
  86. }
  87. //
  88. // Sensed entity
  89. //
  90. private class SensedEntity : IComparable
  91. {
  92. public SensedEntity(double detectedDistance, UUID detectedID)
  93. {
  94. distance = detectedDistance;
  95. itemID = detectedID;
  96. }
  97. public int CompareTo(object obj)
  98. {
  99. if (!(obj is SensedEntity)) throw new InvalidOperationException();
  100. SensedEntity ent = (SensedEntity)obj;
  101. if (ent == null || ent.distance < distance) return 1;
  102. if (ent.distance > distance) return -1;
  103. return 0;
  104. }
  105. public UUID itemID;
  106. public double distance;
  107. }
  108. /// <summary>
  109. /// Sensors to process.
  110. /// </summary>
  111. /// <remarks>
  112. /// Do not add or remove sensors from this list directly. Instead, copy the list and substitute the updated
  113. /// copy. This is to avoid locking the list for the duration of the sensor sweep, which increases the danger
  114. /// of deadlocks with future code updates.
  115. ///
  116. /// Always lock SenseRepeatListLock when updating this list.
  117. /// </remarks>
  118. private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>();
  119. private object SenseRepeatListLock = new object();
  120. public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID,
  121. string name, UUID keyID, int type, double range,
  122. double arc, double sec, SceneObjectPart host)
  123. {
  124. // Always remove first, in case this is a re-set
  125. UnSetSenseRepeaterEvents(m_localID, m_itemID);
  126. if (sec == 0) // Disabling timer
  127. return;
  128. // Add to timer
  129. SenseRepeatClass ts = new SenseRepeatClass();
  130. ts.localID = m_localID;
  131. ts.itemID = m_itemID;
  132. ts.interval = sec;
  133. ts.name = name;
  134. ts.keyID = keyID;
  135. ts.type = type;
  136. if (range > maximumRange)
  137. ts.range = maximumRange;
  138. else
  139. ts.range = range;
  140. ts.arc = arc;
  141. ts.host = host;
  142. ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
  143. AddSenseRepeater(ts);
  144. }
  145. private void AddSenseRepeater(SenseRepeatClass senseRepeater)
  146. {
  147. lock (SenseRepeatListLock)
  148. {
  149. List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(SenseRepeaters);
  150. newSenseRepeaters.Add(senseRepeater);
  151. SenseRepeaters = newSenseRepeaters;
  152. }
  153. }
  154. public void UnSetSenseRepeaterEvents(uint m_localID, UUID m_itemID)
  155. {
  156. // Remove from timer
  157. lock (SenseRepeatListLock)
  158. {
  159. List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>();
  160. foreach (SenseRepeatClass ts in SenseRepeaters)
  161. {
  162. if (ts.localID != m_localID || ts.itemID != m_itemID)
  163. {
  164. newSenseRepeaters.Add(ts);
  165. }
  166. }
  167. SenseRepeaters = newSenseRepeaters;
  168. }
  169. }
  170. public void CheckSenseRepeaterEvents()
  171. {
  172. // Go through all timers
  173. foreach (SenseRepeatClass ts in SenseRepeaters)
  174. {
  175. // Time has passed?
  176. if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
  177. {
  178. SensorSweep(ts);
  179. // set next interval
  180. ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
  181. }
  182. }
  183. }
  184. public void SenseOnce(uint m_localID, UUID m_itemID,
  185. string name, UUID keyID, int type,
  186. double range, double arc, SceneObjectPart host)
  187. {
  188. // Add to timer
  189. SenseRepeatClass ts = new SenseRepeatClass();
  190. ts.localID = m_localID;
  191. ts.itemID = m_itemID;
  192. ts.interval = 0;
  193. ts.name = name;
  194. ts.keyID = keyID;
  195. ts.type = type;
  196. if (range > maximumRange)
  197. ts.range = maximumRange;
  198. else
  199. ts.range = range;
  200. ts.arc = arc;
  201. ts.host = host;
  202. SensorSweep(ts);
  203. }
  204. private void SensorSweep(SenseRepeatClass ts)
  205. {
  206. if (ts.host == null)
  207. {
  208. return;
  209. }
  210. List<SensedEntity> sensedEntities = new List<SensedEntity>();
  211. // Is the sensor type is AGENT and not SCRIPTED then include agents
  212. if ((ts.type & (AGENT | AGENT_BY_USERNAME | NPC | OS_NPC)) != 0 && (ts.type & SCRIPTED) == 0)
  213. {
  214. sensedEntities.AddRange(doAgentSensor(ts));
  215. }
  216. // If SCRIPTED or PASSIVE or ACTIVE check objects
  217. if ((ts.type & SCRIPTED) != 0 || (ts.type & PASSIVE) != 0 || (ts.type & ACTIVE) != 0)
  218. {
  219. sensedEntities.AddRange(doObjectSensor(ts));
  220. }
  221. lock (SenseLock)
  222. {
  223. if (sensedEntities.Count == 0)
  224. {
  225. // send a "no_sensor"
  226. // Add it to queue
  227. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  228. new EventParams("no_sensor", new Object[0],
  229. new DetectParams[0]));
  230. }
  231. else
  232. {
  233. // Sort the list to get everything ordered by distance
  234. sensedEntities.Sort();
  235. int count = sensedEntities.Count;
  236. int idx;
  237. List<DetectParams> detected = new List<DetectParams>();
  238. for (idx = 0; idx < count; idx++)
  239. {
  240. try
  241. {
  242. DetectParams detect = new DetectParams();
  243. detect.Key = sensedEntities[idx].itemID;
  244. detect.Populate(m_CmdManager.m_ScriptEngine.World);
  245. detected.Add(detect);
  246. }
  247. catch (Exception)
  248. {
  249. // Ignore errors, the object has been deleted or the avatar has gone and
  250. // there was a problem in detect.Populate so nothing added to the list
  251. }
  252. if (detected.Count == maximumToReturn)
  253. break;
  254. }
  255. if (detected.Count == 0)
  256. {
  257. // To get here with zero in the list there must have been some sort of problem
  258. // like the object being deleted or the avatar leaving to have caused some
  259. // difficulty during the Populate above so fire a no_sensor event
  260. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  261. new EventParams("no_sensor", new Object[0],
  262. new DetectParams[0]));
  263. }
  264. else
  265. {
  266. m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
  267. new EventParams("sensor",
  268. new Object[] {new LSL_Types.LSLInteger(detected.Count) },
  269. detected.ToArray()));
  270. }
  271. }
  272. }
  273. }
  274. private List<SensedEntity> doObjectSensor(SenseRepeatClass ts)
  275. {
  276. List<EntityBase> Entities;
  277. List<SensedEntity> sensedEntities = new List<SensedEntity>();
  278. // If this is an object sense by key try to get it directly
  279. // rather than getting a list to scan through
  280. if (ts.keyID != UUID.Zero)
  281. {
  282. EntityBase e = null;
  283. m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out e);
  284. if (e == null)
  285. return sensedEntities;
  286. Entities = new List<EntityBase>();
  287. Entities.Add(e);
  288. }
  289. else
  290. {
  291. Entities = new List<EntityBase>(m_CmdManager.m_ScriptEngine.World.GetEntities());
  292. }
  293. SceneObjectPart SensePoint = ts.host;
  294. Vector3 fromRegionPos = SensePoint.GetWorldPosition();
  295. // pre define some things to avoid repeated definitions in the loop body
  296. Vector3 toRegionPos;
  297. double dis;
  298. int objtype;
  299. SceneObjectPart part;
  300. float dx;
  301. float dy;
  302. float dz;
  303. Quaternion q = SensePoint.GetWorldRotation();
  304. if (SensePoint.ParentGroup.IsAttachment)
  305. {
  306. // In attachments, rotate the sensor cone with the
  307. // avatar rotation. This may include a nonzero elevation if
  308. // in mouselook.
  309. // This will not include the rotation and position of the
  310. // attachment point (e.g. your head when a sensor is in your
  311. // hair attached to your scull. Your hair will turn with
  312. // your head but the sensor will stay with your (global)
  313. // avatar rotation and position.
  314. // Position of a sensor in a child prim attached to an avatar
  315. // will be still wrong.
  316. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
  317. q = avatar.Rotation * q;
  318. }
  319. LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
  320. LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
  321. double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
  322. Vector3 ZeroVector = new Vector3(0, 0, 0);
  323. bool nameSearch = (ts.name != null && ts.name != "");
  324. foreach (EntityBase ent in Entities)
  325. {
  326. bool keep = true;
  327. if (nameSearch && ent.Name != ts.name) // Wrong name and it is a named search
  328. continue;
  329. if (ent.IsDeleted) // taken so long to do this it has gone from the scene
  330. continue;
  331. if (!(ent is SceneObjectGroup)) // dont bother if it is a pesky avatar
  332. continue;
  333. toRegionPos = ent.AbsolutePosition;
  334. // Calculation is in line for speed
  335. dx = toRegionPos.X - fromRegionPos.X;
  336. dy = toRegionPos.Y - fromRegionPos.Y;
  337. dz = toRegionPos.Z - fromRegionPos.Z;
  338. // Weed out those that will not fit in a cube the size of the range
  339. // no point calculating if they are within a sphere the size of the range
  340. // if they arent even in the cube
  341. if (Math.Abs(dx) > ts.range || Math.Abs(dy) > ts.range || Math.Abs(dz) > ts.range)
  342. dis = ts.range + 1.0;
  343. else
  344. dis = Math.Sqrt(dx * dx + dy * dy + dz * dz);
  345. if (keep && dis <= ts.range && ts.host.UUID != ent.UUID)
  346. {
  347. // In Range and not the object containing the script, is it the right Type ?
  348. objtype = 0;
  349. part = ((SceneObjectGroup)ent).RootPart;
  350. if (part.ParentGroup.AttachmentPoint != 0) // Attached so ignore
  351. continue;
  352. if (part.Inventory.ContainsScripts())
  353. {
  354. objtype |= ACTIVE | SCRIPTED; // Scripted and active. It COULD have one hidden ...
  355. }
  356. else
  357. {
  358. if (ent.Velocity.Equals(ZeroVector))
  359. {
  360. objtype |= PASSIVE; // Passive non-moving
  361. }
  362. else
  363. {
  364. objtype |= ACTIVE; // moving so active
  365. }
  366. }
  367. // If any of the objects attributes match any in the requested scan type
  368. if (((ts.type & objtype) != 0))
  369. {
  370. // Right type too, what about the other params , key and name ?
  371. if (ts.arc < Math.PI)
  372. {
  373. // not omni-directional. Can you see it ?
  374. // vec forward_dir = llRot2Fwd(llGetRot())
  375. // vec obj_dir = toRegionPos-fromRegionPos
  376. // dot=dot(forward_dir,obj_dir)
  377. // mag_fwd = mag(forward_dir)
  378. // mag_obj = mag(obj_dir)
  379. // ang = acos(dot /(mag_fwd*mag_obj))
  380. double ang_obj = 0;
  381. try
  382. {
  383. Vector3 diff = toRegionPos - fromRegionPos;
  384. double dot = LSL_Types.Vector3.Dot(forward_dir, diff);
  385. double mag_obj = LSL_Types.Vector3.Mag(diff);
  386. ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
  387. }
  388. catch
  389. {
  390. }
  391. if (ang_obj > ts.arc) keep = false;
  392. }
  393. if (keep == true)
  394. {
  395. // add distance for sorting purposes later
  396. sensedEntities.Add(new SensedEntity(dis, ent.UUID));
  397. }
  398. }
  399. }
  400. }
  401. return sensedEntities;
  402. }
  403. private List<SensedEntity> doAgentSensor(SenseRepeatClass ts)
  404. {
  405. List<SensedEntity> sensedEntities = new List<SensedEntity>();
  406. // If nobody about quit fast
  407. if (m_CmdManager.m_ScriptEngine.World.GetRootAgentCount() == 0)
  408. return sensedEntities;
  409. SceneObjectPart SensePoint = ts.host;
  410. Vector3 fromRegionPos = SensePoint.GetWorldPosition();
  411. Quaternion q = SensePoint.GetWorldRotation();
  412. if (SensePoint.ParentGroup.IsAttachment)
  413. {
  414. // In attachments, rotate the sensor cone with the
  415. // avatar rotation. This may include a nonzero elevation if
  416. // in mouselook.
  417. // This will not include the rotation and position of the
  418. // attachment point (e.g. your head when a sensor is in your
  419. // hair attached to your scull. Your hair will turn with
  420. // your head but the sensor will stay with your (global)
  421. // avatar rotation and position.
  422. // Position of a sensor in a child prim attached to an avatar
  423. // will be still wrong.
  424. ScenePresence avatar = m_CmdManager.m_ScriptEngine.World.GetScenePresence(SensePoint.ParentGroup.AttachedAvatar);
  425. q = avatar.Rotation * q;
  426. }
  427. LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
  428. LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
  429. double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
  430. bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
  431. Vector3 toRegionPos;
  432. double dis;
  433. Action<ScenePresence> senseEntity = new Action<ScenePresence>(presence =>
  434. {
  435. // m_log.DebugFormat(
  436. // "[SENSOR REPEAT]: Inspecting scene presence {0}, type {1} on sensor sweep for {2}, type {3}",
  437. // presence.Name, presence.PresenceType, ts.name, ts.type);
  438. if ((ts.type & NPC) == 0 && (ts.type & OS_NPC) == 0 && presence.PresenceType == PresenceType.Npc)
  439. {
  440. INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
  441. if (npcData == null || !npcData.SenseAsAgent)
  442. {
  443. // m_log.DebugFormat(
  444. // "[SENSOR REPEAT]: Discarding NPC {0} from agent sense sweep for script item id {1}",
  445. // presence.Name, ts.itemID);
  446. return;
  447. }
  448. }
  449. if ((ts.type & AGENT) == 0)
  450. {
  451. if (presence.PresenceType == PresenceType.User)
  452. {
  453. return;
  454. }
  455. else
  456. {
  457. INPC npcData = m_npcModule.GetNPC(presence.UUID, presence.Scene);
  458. if (npcData != null && npcData.SenseAsAgent)
  459. {
  460. // m_log.DebugFormat(
  461. // "[SENSOR REPEAT]: Discarding NPC {0} from non-agent sense sweep for script item id {1}",
  462. // presence.Name, ts.itemID);
  463. return;
  464. }
  465. }
  466. }
  467. if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0)
  468. return;
  469. // if the object the script is in is attached and the avatar is the owner
  470. // then this one is not wanted
  471. if (attached && presence.UUID == SensePoint.OwnerID)
  472. return;
  473. toRegionPos = presence.AbsolutePosition;
  474. dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos));
  475. // Disabled for now since all osNpc* methods check for appropriate ownership permission.
  476. // Perhaps could be re-enabled as an NPC setting at some point since being able to make NPCs not
  477. // sensed might be useful.
  478. // if (presence.PresenceType == PresenceType.Npc && npcModule != null)
  479. // {
  480. // UUID npcOwner = npcModule.GetOwner(presence.UUID);
  481. // if (npcOwner != UUID.Zero && npcOwner != SensePoint.OwnerID)
  482. // return;
  483. // }
  484. // are they in range
  485. if (dis <= ts.range)
  486. {
  487. // Are they in the required angle of view
  488. if (ts.arc < Math.PI)
  489. {
  490. // not omni-directional. Can you see it ?
  491. // vec forward_dir = llRot2Fwd(llGetRot())
  492. // vec obj_dir = toRegionPos-fromRegionPos
  493. // dot=dot(forward_dir,obj_dir)
  494. // mag_fwd = mag(forward_dir)
  495. // mag_obj = mag(obj_dir)
  496. // ang = acos(dot /(mag_fwd*mag_obj))
  497. double ang_obj = 0;
  498. try
  499. {
  500. LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(
  501. toRegionPos - fromRegionPos);
  502. double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
  503. double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
  504. ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
  505. }
  506. catch
  507. {
  508. }
  509. if (ang_obj <= ts.arc)
  510. {
  511. sensedEntities.Add(new SensedEntity(dis, presence.UUID));
  512. }
  513. }
  514. else
  515. {
  516. sensedEntities.Add(new SensedEntity(dis, presence.UUID));
  517. }
  518. }
  519. });
  520. // If this is an avatar sense by key try to get them directly
  521. // rather than getting a list to scan through
  522. if (ts.keyID != UUID.Zero)
  523. {
  524. ScenePresence sp;
  525. // Try direct lookup by UUID
  526. if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out sp))
  527. return sensedEntities;
  528. senseEntity(sp);
  529. }
  530. else if (ts.name != null && ts.name != "")
  531. {
  532. ScenePresence sp;
  533. // Try lookup by name will return if/when found
  534. if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp))
  535. senseEntity(sp);
  536. if ((ts.type & AGENT_BY_USERNAME) != 0)
  537. {
  538. m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(
  539. delegate (ScenePresence ssp)
  540. {
  541. if (ssp.Lastname == "Resident")
  542. {
  543. if (ssp.Firstname.ToLower() == ts.name)
  544. senseEntity(ssp);
  545. return;
  546. }
  547. if (ssp.Name.Replace(" ", ".").ToLower() == ts.name)
  548. senseEntity(ssp);
  549. }
  550. );
  551. }
  552. return sensedEntities;
  553. }
  554. else
  555. {
  556. m_CmdManager.m_ScriptEngine.World.ForEachRootScenePresence(senseEntity);
  557. }
  558. return sensedEntities;
  559. }
  560. public Object[] GetSerializationData(UUID itemID)
  561. {
  562. List<Object> data = new List<Object>();
  563. foreach (SenseRepeatClass ts in SenseRepeaters)
  564. {
  565. if (ts.itemID == itemID)
  566. {
  567. data.Add(ts.interval);
  568. data.Add(ts.name);
  569. data.Add(ts.keyID);
  570. data.Add(ts.type);
  571. data.Add(ts.range);
  572. data.Add(ts.arc);
  573. }
  574. }
  575. return data.ToArray();
  576. }
  577. public void CreateFromData(uint localID, UUID itemID, UUID objectID,
  578. Object[] data)
  579. {
  580. SceneObjectPart part =
  581. m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(
  582. objectID);
  583. if (part == null)
  584. return;
  585. int idx = 0;
  586. while (idx < data.Length)
  587. {
  588. SenseRepeatClass ts = new SenseRepeatClass();
  589. ts.localID = localID;
  590. ts.itemID = itemID;
  591. ts.interval = (double)data[idx];
  592. ts.name = (string)data[idx+1];
  593. ts.keyID = (UUID)data[idx+2];
  594. ts.type = (int)data[idx+3];
  595. ts.range = (double)data[idx+4];
  596. ts.arc = (double)data[idx+5];
  597. ts.host = part;
  598. ts.next =
  599. DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
  600. AddSenseRepeater(ts);
  601. idx += 6;
  602. }
  603. }
  604. }
  605. }