SensorRepeat.cs 27 KB

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