LS_Api.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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;
  30. using System.Collections.Generic;
  31. using System.Threading;
  32. using OpenMetaverse;
  33. using Nini.Config;
  34. using OpenSim;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.CoreModules.World.LightShare;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Region.ScriptEngine.Shared;
  40. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  41. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  42. using OpenSim.Region.ScriptEngine.Interfaces;
  43. using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
  44. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  45. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  46. using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  47. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  48. using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
  49. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  50. using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
  51. namespace OpenSim.Region.ScriptEngine.Shared.Api
  52. {
  53. [Serializable]
  54. public class LS_Api : ILS_Api, IScriptApi
  55. {
  56. internal IScriptEngine m_ScriptEngine;
  57. internal SceneObjectPart m_host;
  58. internal bool m_LSFunctionsEnabled = false;
  59. internal IScriptModuleComms m_comms = null;
  60. internal IConfig m_osslconfig;
  61. internal IEnvironmentModule m_environment = null;
  62. public void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
  63. {
  64. m_ScriptEngine = scriptEngine;
  65. m_host = host;
  66. m_osslconfig = m_ScriptEngine.ConfigSource.Configs["OSSL"];
  67. if(m_osslconfig == null)
  68. m_osslconfig = m_ScriptEngine.Config;
  69. if (m_osslconfig.GetBoolean("AllowLightShareFunctions", false))
  70. m_LSFunctionsEnabled = true;
  71. m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
  72. if (m_comms == null)
  73. m_LSFunctionsEnabled = false;
  74. m_environment = m_ScriptEngine.World.RequestModuleInterface<IEnvironmentModule>();
  75. }
  76. public Scene World
  77. {
  78. get { return m_ScriptEngine.World; }
  79. }
  80. /// <summary>
  81. /// Dumps an error message on the debug console.
  82. /// </summary>
  83. internal void LSShoutError(string message)
  84. {
  85. if (message.Length > 1023)
  86. message = message.Substring(0, 1023);
  87. World.SimChat(Utils.StringToBytes(message),
  88. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  89. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  90. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message, m_host.AbsolutePosition);
  91. }
  92. /// <summary>
  93. /// Get the current Windlight scene
  94. /// </summary>
  95. /// <returns>List of windlight parameters</returns>
  96. public LSL_List lsGetWindlightScene(LSL_List rules)
  97. {
  98. if (!m_LSFunctionsEnabled || m_environment == null)
  99. {
  100. LSShoutError("LightShare functions are not enabled.");
  101. return new LSL_List();
  102. }
  103. RegionLightShareData wl = m_environment.ToLightShare();
  104. LSL_List values = new();
  105. int idx = 0;
  106. while (idx < rules.Length)
  107. {
  108. int rule = rules.GetIntegerItem(idx);
  109. LSL_List toadd = new();
  110. switch (rule)
  111. {
  112. case ScriptBaseClass.WL_AMBIENT:
  113. toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
  114. break;
  115. case ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
  116. toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
  117. break;
  118. case ScriptBaseClass.WL_BLUE_DENSITY:
  119. toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
  120. break;
  121. case ScriptBaseClass.WL_BLUR_MULTIPLIER:
  122. toadd.Add(new LSL_Float(wl.blurMultiplier));
  123. break;
  124. case ScriptBaseClass.WL_CLOUD_COLOR:
  125. toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
  126. break;
  127. case ScriptBaseClass.WL_CLOUD_COVERAGE:
  128. toadd.Add(new LSL_Float(wl.cloudCoverage));
  129. break;
  130. case ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
  131. toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
  132. break;
  133. case ScriptBaseClass.WL_CLOUD_SCALE:
  134. toadd.Add(new LSL_Float(wl.cloudScale));
  135. break;
  136. case ScriptBaseClass.WL_CLOUD_SCROLL_X:
  137. toadd.Add(new LSL_Float(wl.cloudScrollX));
  138. break;
  139. case ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
  140. toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
  141. break;
  142. case ScriptBaseClass.WL_CLOUD_SCROLL_Y:
  143. toadd.Add(new LSL_Float(wl.cloudScrollY));
  144. break;
  145. case ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
  146. toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
  147. break;
  148. case ScriptBaseClass.WL_CLOUD_XY_DENSITY:
  149. toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
  150. break;
  151. case ScriptBaseClass.WL_DENSITY_MULTIPLIER:
  152. toadd.Add(new LSL_Float(wl.densityMultiplier));
  153. break;
  154. case ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
  155. toadd.Add(new LSL_Float(wl.distanceMultiplier));
  156. break;
  157. case ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
  158. toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
  159. break;
  160. case ScriptBaseClass.WL_EAST_ANGLE:
  161. toadd.Add(new LSL_Float(wl.eastAngle));
  162. break;
  163. case ScriptBaseClass.WL_FRESNEL_OFFSET:
  164. toadd.Add(new LSL_Float(wl.fresnelOffset));
  165. break;
  166. case ScriptBaseClass.WL_FRESNEL_SCALE:
  167. toadd.Add(new LSL_Float(wl.fresnelScale));
  168. break;
  169. case ScriptBaseClass.WL_HAZE_DENSITY:
  170. toadd.Add(new LSL_Float(wl.hazeDensity));
  171. break;
  172. case ScriptBaseClass.WL_HAZE_HORIZON:
  173. toadd.Add(new LSL_Float(wl.hazeHorizon));
  174. break;
  175. case ScriptBaseClass.WL_HORIZON:
  176. toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
  177. break;
  178. case ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
  179. toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
  180. break;
  181. case ScriptBaseClass.WL_MAX_ALTITUDE:
  182. toadd.Add(new LSL_Integer(wl.maxAltitude));
  183. break;
  184. case ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
  185. toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
  186. break;
  187. case ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
  188. toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
  189. break;
  190. case ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
  191. toadd.Add(new LSL_Float(wl.refractScaleAbove));
  192. break;
  193. case ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
  194. toadd.Add(new LSL_Float(wl.refractScaleBelow));
  195. break;
  196. case ScriptBaseClass.WL_SCENE_GAMMA:
  197. toadd.Add(new LSL_Float(wl.sceneGamma));
  198. break;
  199. case ScriptBaseClass.WL_STAR_BRIGHTNESS:
  200. toadd.Add(new LSL_Float(wl.starBrightness));
  201. break;
  202. case ScriptBaseClass.WL_SUN_GLOW_FOCUS:
  203. toadd.Add(new LSL_Float(wl.sunGlowFocus));
  204. break;
  205. case ScriptBaseClass.WL_SUN_GLOW_SIZE:
  206. toadd.Add(new LSL_Float(wl.sunGlowSize));
  207. break;
  208. case ScriptBaseClass.WL_SUN_MOON_COLOR:
  209. toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
  210. break;
  211. case ScriptBaseClass.WL_SUN_MOON_POSITION:
  212. toadd.Add(new LSL_Float(wl.sunMoonPosition));
  213. break;
  214. case ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
  215. toadd.Add(new LSL_Float(wl.underwaterFogModifier));
  216. break;
  217. case ScriptBaseClass.WL_WATER_COLOR:
  218. toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
  219. break;
  220. case ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
  221. toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
  222. break;
  223. }
  224. if (toadd.Length > 0)
  225. {
  226. values.Add(new LSL_Integer(rule));
  227. values.Add(toadd.Data[0]);
  228. }
  229. idx++;
  230. }
  231. return values;
  232. }
  233. private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
  234. {
  235. RegionLightShareData wl = m_environment.ToLightShare();
  236. int idx = 0;
  237. while (idx < rules.Length)
  238. {
  239. int rule;
  240. try
  241. {
  242. rule = rules.GetIntegerItem(idx);
  243. }
  244. catch (InvalidCastException)
  245. {
  246. throw new InvalidCastException(string.Format("Error running rule type: arg #{0} - parameter type must be integer", idx));
  247. }
  248. LSL_Types.Quaternion iQ;
  249. LSL_Types.Vector3 iV;
  250. switch (rule)
  251. {
  252. case ScriptBaseClass.WL_SUN_MOON_POSITION:
  253. idx++;
  254. try
  255. {
  256. wl.sunMoonPosition = rules.GetStrictFloatItem(idx);
  257. }
  258. catch (InvalidCastException)
  259. {
  260. throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_POSITION: arg #{0} - parameter 1 must be float", idx));
  261. }
  262. break;
  263. case ScriptBaseClass.WL_AMBIENT:
  264. idx++;
  265. try
  266. {
  267. iQ = rules.GetVector4Item(idx);
  268. }
  269. catch (InvalidCastException)
  270. {
  271. throw new InvalidCastException(string.Format("Error running rule WL_AMBIENT: arg #{0} - parameter 1 must be rotation", idx));
  272. }
  273. wl.ambient = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  274. break;
  275. case ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
  276. idx++;
  277. try
  278. {
  279. iV = rules.GetVector3Item(idx);
  280. }
  281. catch (InvalidCastException)
  282. {
  283. throw new InvalidCastException(string.Format("Error running rule WL_BIG_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
  284. }
  285. wl.bigWaveDirection = new Vector2((float)iV.x, (float)iV.y);
  286. break;
  287. case ScriptBaseClass.WL_BLUE_DENSITY:
  288. idx++;
  289. try
  290. {
  291. iQ = rules.GetVector4Item(idx);
  292. }
  293. catch (InvalidCastException)
  294. {
  295. throw new InvalidCastException(string.Format("Error running rule WL_BLUE_DENSITY: arg #{0} - parameter 1 must be rotation", idx));
  296. }
  297. wl.blueDensity = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  298. break;
  299. case ScriptBaseClass.WL_BLUR_MULTIPLIER:
  300. idx++;
  301. try
  302. {
  303. wl.blurMultiplier = rules.GetStrictFloatItem(idx);
  304. }
  305. catch (InvalidCastException)
  306. {
  307. throw new InvalidCastException(string.Format("Error running rule WL_BLUR_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
  308. }
  309. break;
  310. case ScriptBaseClass.WL_CLOUD_COLOR:
  311. idx++;
  312. try
  313. {
  314. iQ = rules.GetVector4Item(idx);
  315. }
  316. catch (InvalidCastException)
  317. {
  318. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COLOR: arg #{0} - parameter 1 must be rotation", idx));
  319. }
  320. wl.cloudColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  321. break;
  322. case ScriptBaseClass.WL_CLOUD_COVERAGE:
  323. idx++;
  324. try
  325. {
  326. wl.cloudCoverage = rules.GetStrictFloatItem(idx);
  327. }
  328. catch (InvalidCastException)
  329. {
  330. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_COVERAGE: arg #{0} - parameter 1 must be float", idx));
  331. }
  332. break;
  333. case ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
  334. idx++;
  335. try
  336. {
  337. iV = rules.GetVector3Item(idx);
  338. }
  339. catch (InvalidCastException)
  340. {
  341. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_DETAIL_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
  342. }
  343. wl.cloudDetailXYDensity = iV;
  344. break;
  345. case ScriptBaseClass.WL_CLOUD_SCALE:
  346. idx++;
  347. try
  348. {
  349. wl.cloudScale = rules.GetStrictFloatItem(idx);
  350. }
  351. catch (InvalidCastException)
  352. {
  353. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCALE: arg #{0} - parameter 1 must be float", idx));
  354. }
  355. break;
  356. case ScriptBaseClass.WL_CLOUD_SCROLL_X:
  357. idx++;
  358. try
  359. {
  360. wl.cloudScrollX = rules.GetStrictFloatItem(idx);
  361. }
  362. catch (InvalidCastException)
  363. {
  364. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_X: arg #{0} - parameter 1 must be float", idx));
  365. }
  366. break;
  367. case ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
  368. idx++;
  369. try
  370. {
  371. wl.cloudScrollXLock = rules.GetIntegerItem(idx) == 1 ? true : false;
  372. }
  373. catch (InvalidCastException)
  374. {
  375. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
  376. }
  377. break;
  378. case ScriptBaseClass.WL_CLOUD_SCROLL_Y:
  379. idx++;
  380. try
  381. {
  382. wl.cloudScrollY = rules.GetStrictFloatItem(idx);
  383. }
  384. catch (InvalidCastException)
  385. {
  386. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y: arg #{0} - parameter 1 must be float", idx));
  387. }
  388. break;
  389. case ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
  390. idx++;
  391. try
  392. {
  393. wl.cloudScrollYLock = rules.GetIntegerItem(idx) != 0;
  394. }
  395. catch (InvalidCastException)
  396. {
  397. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_SCROLL_Y_LOCK: arg #{0} - parameter 1 must be integer", idx));
  398. }
  399. break;
  400. case ScriptBaseClass.WL_CLOUD_XY_DENSITY:
  401. idx++;
  402. try
  403. {
  404. iV = rules.GetVector3Item(idx);
  405. }
  406. catch (InvalidCastException)
  407. {
  408. throw new InvalidCastException(string.Format("Error running rule WL_CLOUD_XY_DENSITY: arg #{0} - parameter 1 must be vector", idx));
  409. }
  410. wl.cloudXYDensity = iV;
  411. break;
  412. case ScriptBaseClass.WL_DENSITY_MULTIPLIER:
  413. idx++;
  414. try
  415. {
  416. wl.densityMultiplier = rules.GetStrictFloatItem(idx);
  417. }
  418. catch (InvalidCastException)
  419. {
  420. throw new InvalidCastException(string.Format("Error running rule WL_DENSITY_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
  421. }
  422. break;
  423. case ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
  424. idx++;
  425. try
  426. {
  427. wl.distanceMultiplier = rules.GetStrictFloatItem(idx);
  428. }
  429. catch (InvalidCastException)
  430. {
  431. throw new InvalidCastException(string.Format("Error running rule WL_DISTANCE_MULTIPLIER: arg #{0} - parameter 1 must be float", idx));
  432. }
  433. break;
  434. case ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
  435. idx++;
  436. try
  437. {
  438. wl.drawClassicClouds = rules.GetIntegerItem(idx) != 0;
  439. }
  440. catch (InvalidCastException)
  441. {
  442. throw new InvalidCastException(string.Format("Error running rule WL_DRAW_CLASSIC_CLOUDS: arg #{0} - parameter 1 must be integer", idx));
  443. }
  444. break;
  445. case ScriptBaseClass.WL_EAST_ANGLE:
  446. idx++;
  447. try
  448. {
  449. wl.eastAngle = rules.GetStrictFloatItem(idx);
  450. }
  451. catch (InvalidCastException)
  452. {
  453. throw new InvalidCastException(string.Format("Error running rule WL_EAST_ANGLE: arg #{0} - parameter 1 must be float", idx));
  454. }
  455. break;
  456. case ScriptBaseClass.WL_FRESNEL_OFFSET:
  457. idx++;
  458. try
  459. {
  460. wl.fresnelOffset = rules.GetStrictFloatItem(idx);
  461. }
  462. catch (InvalidCastException)
  463. {
  464. throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_OFFSET: arg #{0} - parameter 1 must be float", idx));
  465. }
  466. break;
  467. case ScriptBaseClass.WL_FRESNEL_SCALE:
  468. idx++;
  469. try
  470. {
  471. wl.fresnelScale = rules.GetStrictFloatItem(idx);
  472. }
  473. catch (InvalidCastException)
  474. {
  475. throw new InvalidCastException(string.Format("Error running rule WL_FRESNEL_SCALE: arg #{0} - parameter 1 must be float", idx));
  476. }
  477. break;
  478. case ScriptBaseClass.WL_HAZE_DENSITY:
  479. idx++;
  480. try
  481. {
  482. wl.hazeDensity = rules.GetStrictFloatItem(idx);
  483. }
  484. catch (InvalidCastException)
  485. {
  486. throw new InvalidCastException(string.Format("Error running rule WL_HAZE_DENSITY: arg #{0} - parameter 1 must be float", idx));
  487. }
  488. break;
  489. case ScriptBaseClass.WL_HAZE_HORIZON:
  490. idx++;
  491. try
  492. {
  493. wl.hazeHorizon = rules.GetStrictFloatItem(idx);
  494. }
  495. catch (InvalidCastException)
  496. {
  497. throw new InvalidCastException(string.Format("Error running rule WL_HAZE_HORIZON: arg #{0} - parameter 1 must be float", idx));
  498. }
  499. break;
  500. case ScriptBaseClass.WL_HORIZON:
  501. idx++;
  502. try
  503. {
  504. iQ = rules.GetVector4Item(idx);
  505. }
  506. catch (InvalidCastException)
  507. {
  508. throw new InvalidCastException(string.Format("Error running rule WL_HORIZON: arg #{0} - parameter 1 must be rotation", idx));
  509. }
  510. wl.horizon = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  511. break;
  512. case ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
  513. idx++;
  514. try
  515. {
  516. iV = rules.GetVector3Item(idx);
  517. }
  518. catch (InvalidCastException)
  519. {
  520. throw new InvalidCastException(string.Format("Error running rule WL_LITTLE_WAVE_DIRECTION: arg #{0} - parameter 1 must be vector", idx));
  521. }
  522. wl.littleWaveDirection = new Vector2((float)iV.x, (float)iV.y);
  523. break;
  524. case ScriptBaseClass.WL_MAX_ALTITUDE:
  525. idx++;
  526. try
  527. {
  528. wl.maxAltitude = (ushort)rules.GetIntegerItem(idx);
  529. }
  530. catch (InvalidCastException)
  531. {
  532. throw new InvalidCastException(string.Format("Error running rule WL_MAX_ALTITUDE: arg #{0} - parameter 1 must be integer", idx));
  533. }
  534. break;
  535. case ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
  536. idx++;
  537. try
  538. {
  539. wl.normalMapTexture = new UUID(rules.GetStrictStringItem(idx));
  540. }
  541. catch (ArgumentException)
  542. {
  543. throw new InvalidCastException(string.Format("Error running rule WL_NORMAL_MAP_TEXTURE: arg #{0} - parameter 1 must be key", idx));
  544. }
  545. break;
  546. case ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
  547. idx++;
  548. try
  549. {
  550. iV = rules.GetVector3Item(idx);
  551. }
  552. catch (InvalidCastException)
  553. {
  554. throw new InvalidCastException(string.Format("Error running rule WL_REFLECTION_WAVELET_SCALE: arg #{0} - parameter 1 must be vector", idx));
  555. }
  556. wl.reflectionWaveletScale = iV;
  557. break;
  558. case ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
  559. idx++;
  560. try
  561. {
  562. wl.refractScaleAbove = rules.GetStrictFloatItem(idx);
  563. }
  564. catch (InvalidCastException)
  565. {
  566. throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_ABOVE: arg #{0} - parameter 1 must be float", idx));
  567. }
  568. break;
  569. case ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
  570. idx++;
  571. try
  572. {
  573. wl.refractScaleBelow = rules.GetStrictFloatItem(idx);
  574. }
  575. catch (InvalidCastException)
  576. {
  577. throw new InvalidCastException(string.Format("Error running rule WL_REFRACT_SCALE_BELOW: arg #{0} - parameter 1 must be float", idx));
  578. }
  579. break;
  580. case ScriptBaseClass.WL_SCENE_GAMMA:
  581. idx++;
  582. try
  583. {
  584. wl.sceneGamma = rules.GetStrictFloatItem(idx);
  585. }
  586. catch (InvalidCastException)
  587. {
  588. throw new InvalidCastException(string.Format("Error running rule WL_SCENE_GAMMA: arg #{0} - parameter 1 must be float", idx));
  589. }
  590. break;
  591. case ScriptBaseClass.WL_STAR_BRIGHTNESS:
  592. idx++;
  593. try
  594. {
  595. wl.starBrightness = rules.GetStrictFloatItem(idx);
  596. }
  597. catch (InvalidCastException)
  598. {
  599. throw new InvalidCastException(string.Format("Error running rule WL_STAR_BRIGHTNESS: arg #{0} - parameter 1 must be float", idx));
  600. }
  601. break;
  602. case ScriptBaseClass.WL_SUN_GLOW_FOCUS:
  603. idx++;
  604. try
  605. {
  606. wl.sunGlowFocus = rules.GetStrictFloatItem(idx);
  607. }
  608. catch (InvalidCastException)
  609. {
  610. throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_FOCUS: arg #{0} - parameter 1 must be float", idx));
  611. }
  612. break;
  613. case ScriptBaseClass.WL_SUN_GLOW_SIZE:
  614. idx++;
  615. try
  616. {
  617. wl.sunGlowSize = rules.GetStrictFloatItem(idx);
  618. }
  619. catch (InvalidCastException)
  620. {
  621. throw new InvalidCastException(string.Format("Error running rule WL_SUN_GLOW_SIZE: arg #{0} - parameter 1 must be float", idx));
  622. }
  623. break;
  624. case ScriptBaseClass.WL_SUN_MOON_COLOR:
  625. idx++;
  626. iQ = rules.GetVector4Item(idx);
  627. try
  628. {
  629. wl.sunMoonColor = new Vector4((float)iQ.x, (float)iQ.y, (float)iQ.z, (float)iQ.s);
  630. }
  631. catch (InvalidCastException)
  632. {
  633. throw new InvalidCastException(string.Format("Error running rule WL_SUN_MOON_COLOR: arg #{0} - parameter 1 must be rotation", idx));
  634. }
  635. break;
  636. case ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
  637. idx++;
  638. try
  639. {
  640. wl.underwaterFogModifier = rules.GetStrictFloatItem(idx);
  641. }
  642. catch (InvalidCastException)
  643. {
  644. throw new InvalidCastException(string.Format("Error running rule WL_UNDERWATER_FOG_MODIFIER: arg #{0} - parameter 1 must be float", idx));
  645. }
  646. break;
  647. case ScriptBaseClass.WL_WATER_COLOR:
  648. idx++;
  649. try
  650. {
  651. iV = rules.GetVector3Item(idx);
  652. }
  653. catch (InvalidCastException)
  654. {
  655. throw new InvalidCastException(string.Format("Error running rule WL_WATER_COLOR: arg #{0} - parameter 1 must be vector", idx));
  656. }
  657. wl.waterColor = iV;
  658. break;
  659. case ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
  660. idx++;
  661. try
  662. {
  663. wl.waterFogDensityExponent = rules.GetStrictFloatItem(idx);
  664. }
  665. catch (InvalidCastException)
  666. {
  667. throw new InvalidCastException(string.Format("Error running rule WL_WATER_FOG_DENSITY_EXPONENT: arg #{0} - parameter 1 must be float", idx));
  668. }
  669. break;
  670. }
  671. idx++;
  672. }
  673. return wl;
  674. }
  675. /// <summary>
  676. /// Set the current Windlight scene
  677. /// </summary>
  678. /// <param name="rules"></param>
  679. /// <returns>success: true or false</returns>
  680. public int lsSetWindlightScene(LSL_List rules)
  681. {
  682. if (!m_LSFunctionsEnabled || m_environment == null)
  683. {
  684. LSShoutError("LightShare functions are not enabled.");
  685. return 0;
  686. }
  687. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  688. {
  689. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  690. if (sp == null || !sp.IsViewerUIGod)
  691. {
  692. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  693. return 0;
  694. }
  695. }
  696. try
  697. {
  698. RegionLightShareData wl = getWindlightProfileFromRules(rules);
  699. m_environment.FromLightShare(wl);
  700. }
  701. catch(InvalidCastException e)
  702. {
  703. LSShoutError(e.Message);
  704. return 0;
  705. }
  706. return 1;
  707. }
  708. public void lsClearWindlightScene()
  709. {
  710. if (!m_LSFunctionsEnabled || m_environment == null)
  711. {
  712. LSShoutError("LightShare functions are not enabled.");
  713. return;
  714. }
  715. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  716. {
  717. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  718. if (sp == null || !sp.IsViewerUIGod)
  719. {
  720. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  721. return;
  722. }
  723. }
  724. m_environment.ResetEnvironmentSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
  725. }
  726. /// <summary>
  727. /// Set the current Windlight scene to a target avatar
  728. /// </summary>
  729. /// <param name="rules"></param>
  730. /// <returns>success: true or false</returns>
  731. public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
  732. {
  733. LSShoutError("Function temporary not supported");
  734. return 0;
  735. /* disabled code until we add force a WL into a single user
  736. if (!m_LSFunctionsEnabled)
  737. {
  738. LSShoutError("LightShare functions are not enabled.");
  739. return 0;
  740. }
  741. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  742. {
  743. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  744. if (sp == null || !sp.IsViewerUIGod)
  745. {
  746. LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
  747. return 0;
  748. }
  749. }
  750. int success = 0;
  751. if (m_environment != null)
  752. {
  753. RegionLightShareData wl;
  754. try
  755. {
  756. wl = getWindlightProfileFromRules(rules);
  757. }
  758. catch(InvalidCastException e)
  759. {
  760. LSShoutError(e.Message);
  761. return 0;
  762. }
  763. World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
  764. success = 1;
  765. }
  766. else
  767. {
  768. LSShoutError("Windlight module is disabled");
  769. return 0;
  770. }
  771. return success;
  772. */
  773. }
  774. }
  775. }