LS_Api.cs 38 KB

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