LS_Api.cs 38 KB

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