LS_Api.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. public void Initialize(
  63. 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. }
  76. public override Object InitializeLifetimeService()
  77. {
  78. ILease lease = (ILease)base.InitializeLifetimeService();
  79. if (lease.CurrentState == LeaseState.Initial)
  80. {
  81. lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
  82. // lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
  83. // lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
  84. }
  85. return lease;
  86. }
  87. public Scene World
  88. {
  89. get { return m_ScriptEngine.World; }
  90. }
  91. /// <summary>
  92. /// Dumps an error message on the debug console.
  93. /// </summary>
  94. internal void LSShoutError(string message)
  95. {
  96. if (message.Length > 1023)
  97. message = message.Substring(0, 1023);
  98. World.SimChat(Utils.StringToBytes(message),
  99. ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
  100. IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
  101. wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
  102. }
  103. /// <summary>
  104. /// Get the current Windlight scene
  105. /// </summary>
  106. /// <returns>List of windlight parameters</returns>
  107. public LSL_List lsGetWindlightScene(LSL_List rules)
  108. {
  109. if (!m_LSFunctionsEnabled)
  110. {
  111. LSShoutError("LightShare functions are not enabled.");
  112. return new LSL_List();
  113. }
  114. m_host.AddScriptLPS(1);
  115. RegionLightShareData wl = m_host.ParentGroup.Scene.RegionInfo.WindlightSettings;
  116. LSL_List values = new LSL_List();
  117. int idx = 0;
  118. while (idx < rules.Length)
  119. {
  120. LSL_Integer ruleInt = rules.GetLSLIntegerItem(idx);
  121. uint rule = (uint)ruleInt;
  122. LSL_List toadd = new LSL_List();
  123. switch (rule)
  124. {
  125. case (int)ScriptBaseClass.WL_AMBIENT:
  126. toadd.Add(new LSL_Rotation(wl.ambient.X, wl.ambient.Y, wl.ambient.Z, wl.ambient.W));
  127. break;
  128. case (int)ScriptBaseClass.WL_BIG_WAVE_DIRECTION:
  129. toadd.Add(new LSL_Vector(wl.bigWaveDirection.X, wl.bigWaveDirection.Y, 0.0f));
  130. break;
  131. case (int)ScriptBaseClass.WL_BLUE_DENSITY:
  132. toadd.Add(new LSL_Rotation(wl.blueDensity.X, wl.blueDensity.Y, wl.blueDensity.Z, wl.blueDensity.W));
  133. break;
  134. case (int)ScriptBaseClass.WL_BLUR_MULTIPLIER:
  135. toadd.Add(new LSL_Float(wl.blurMultiplier));
  136. break;
  137. case (int)ScriptBaseClass.WL_CLOUD_COLOR:
  138. toadd.Add(new LSL_Rotation(wl.cloudColor.X, wl.cloudColor.Y, wl.cloudColor.Z, wl.cloudColor.W));
  139. break;
  140. case (int)ScriptBaseClass.WL_CLOUD_COVERAGE:
  141. toadd.Add(new LSL_Float(wl.cloudCoverage));
  142. break;
  143. case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
  144. toadd.Add(new LSL_Vector(wl.cloudDetailXYDensity.X, wl.cloudDetailXYDensity.Y, wl.cloudDetailXYDensity.Z));
  145. break;
  146. case (int)ScriptBaseClass.WL_CLOUD_SCALE:
  147. toadd.Add(new LSL_Float(wl.cloudScale));
  148. break;
  149. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X:
  150. toadd.Add(new LSL_Float(wl.cloudScrollX));
  151. break;
  152. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_X_LOCK:
  153. toadd.Add(new LSL_Integer(wl.cloudScrollXLock ? 1 : 0));
  154. break;
  155. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y:
  156. toadd.Add(new LSL_Float(wl.cloudScrollY));
  157. break;
  158. case (int)ScriptBaseClass.WL_CLOUD_SCROLL_Y_LOCK:
  159. toadd.Add(new LSL_Integer(wl.cloudScrollYLock ? 1 : 0));
  160. break;
  161. case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
  162. toadd.Add(new LSL_Vector(wl.cloudXYDensity.X, wl.cloudXYDensity.Y, wl.cloudXYDensity.Z));
  163. break;
  164. case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
  165. toadd.Add(new LSL_Float(wl.densityMultiplier));
  166. break;
  167. case (int)ScriptBaseClass.WL_DISTANCE_MULTIPLIER:
  168. toadd.Add(new LSL_Float(wl.distanceMultiplier));
  169. break;
  170. case (int)ScriptBaseClass.WL_DRAW_CLASSIC_CLOUDS:
  171. toadd.Add(new LSL_Integer(wl.drawClassicClouds ? 1 : 0));
  172. break;
  173. case (int)ScriptBaseClass.WL_EAST_ANGLE:
  174. toadd.Add(new LSL_Float(wl.eastAngle));
  175. break;
  176. case (int)ScriptBaseClass.WL_FRESNEL_OFFSET:
  177. toadd.Add(new LSL_Float(wl.fresnelOffset));
  178. break;
  179. case (int)ScriptBaseClass.WL_FRESNEL_SCALE:
  180. toadd.Add(new LSL_Float(wl.fresnelScale));
  181. break;
  182. case (int)ScriptBaseClass.WL_HAZE_DENSITY:
  183. toadd.Add(new LSL_Float(wl.hazeDensity));
  184. break;
  185. case (int)ScriptBaseClass.WL_HAZE_HORIZON:
  186. toadd.Add(new LSL_Float(wl.hazeHorizon));
  187. break;
  188. case (int)ScriptBaseClass.WL_HORIZON:
  189. toadd.Add(new LSL_Rotation(wl.horizon.X, wl.horizon.Y, wl.horizon.Z, wl.horizon.W));
  190. break;
  191. case (int)ScriptBaseClass.WL_LITTLE_WAVE_DIRECTION:
  192. toadd.Add(new LSL_Vector(wl.littleWaveDirection.X, wl.littleWaveDirection.Y, 0.0f));
  193. break;
  194. case (int)ScriptBaseClass.WL_MAX_ALTITUDE:
  195. toadd.Add(new LSL_Integer(wl.maxAltitude));
  196. break;
  197. case (int)ScriptBaseClass.WL_NORMAL_MAP_TEXTURE:
  198. toadd.Add(new LSL_Key(wl.normalMapTexture.ToString()));
  199. break;
  200. case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
  201. toadd.Add(new LSL_Vector(wl.reflectionWaveletScale.X, wl.reflectionWaveletScale.Y, wl.reflectionWaveletScale.Z));
  202. break;
  203. case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
  204. toadd.Add(new LSL_Float(wl.refractScaleAbove));
  205. break;
  206. case (int)ScriptBaseClass.WL_REFRACT_SCALE_BELOW:
  207. toadd.Add(new LSL_Float(wl.refractScaleBelow));
  208. break;
  209. case (int)ScriptBaseClass.WL_SCENE_GAMMA:
  210. toadd.Add(new LSL_Float(wl.sceneGamma));
  211. break;
  212. case (int)ScriptBaseClass.WL_STAR_BRIGHTNESS:
  213. toadd.Add(new LSL_Float(wl.starBrightness));
  214. break;
  215. case (int)ScriptBaseClass.WL_SUN_GLOW_FOCUS:
  216. toadd.Add(new LSL_Float(wl.sunGlowFocus));
  217. break;
  218. case (int)ScriptBaseClass.WL_SUN_GLOW_SIZE:
  219. toadd.Add(new LSL_Float(wl.sunGlowSize));
  220. break;
  221. case (int)ScriptBaseClass.WL_SUN_MOON_COLOR:
  222. toadd.Add(new LSL_Rotation(wl.sunMoonColor.X, wl.sunMoonColor.Y, wl.sunMoonColor.Z, wl.sunMoonColor.W));
  223. break;
  224. case (int)ScriptBaseClass.WL_SUN_MOON_POSITION:
  225. toadd.Add(new LSL_Float(wl.sunMoonPosition));
  226. break;
  227. case (int)ScriptBaseClass.WL_UNDERWATER_FOG_MODIFIER:
  228. toadd.Add(new LSL_Float(wl.underwaterFogModifier));
  229. break;
  230. case (int)ScriptBaseClass.WL_WATER_COLOR:
  231. toadd.Add(new LSL_Vector(wl.waterColor.X, wl.waterColor.Y, wl.waterColor.Z));
  232. break;
  233. case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
  234. toadd.Add(new LSL_Float(wl.waterFogDensityExponent));
  235. break;
  236. }
  237. if (toadd.Length > 0)
  238. {
  239. values.Add(ruleInt);
  240. values.Add(toadd.Data[0]);
  241. }
  242. idx++;
  243. }
  244. return values;
  245. }
  246. private RegionLightShareData getWindlightProfileFromRules(LSL_List rules)
  247. {
  248. RegionLightShareData wl = (RegionLightShareData)m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.Clone();
  249. // LSL_List values = new LSL_List();
  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)
  697. {
  698. LSShoutError("LightShare functions are not enabled.");
  699. return 0;
  700. }
  701. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  702. {
  703. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  704. if (sp == null || !sp.IsViewerUIGod)
  705. {
  706. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  707. return 0;
  708. }
  709. }
  710. int success = 0;
  711. m_host.AddScriptLPS(1);
  712. if (LightShareModule.EnableWindlight)
  713. {
  714. RegionLightShareData wl;
  715. try
  716. {
  717. wl = getWindlightProfileFromRules(rules);
  718. }
  719. catch(InvalidCastException e)
  720. {
  721. LSShoutError(e.Message);
  722. return 0;
  723. }
  724. wl.valid = true;
  725. m_host.ParentGroup.Scene.StoreWindlightProfile(wl);
  726. success = 1;
  727. }
  728. else
  729. {
  730. LSShoutError("Windlight module is disabled");
  731. return 0;
  732. }
  733. return success;
  734. }
  735. public void lsClearWindlightScene()
  736. {
  737. if (!m_LSFunctionsEnabled)
  738. {
  739. LSShoutError("LightShare functions are not enabled.");
  740. return;
  741. }
  742. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  743. {
  744. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  745. if (sp == null || !sp.IsViewerUIGod)
  746. {
  747. LSShoutError("lsSetWindlightScene can only be used by estate managers or owners.");
  748. return;
  749. }
  750. }
  751. m_host.ParentGroup.Scene.RegionInfo.WindlightSettings.valid = false;
  752. if (m_host.ParentGroup.Scene.SimulationDataService != null)
  753. m_host.ParentGroup.Scene.SimulationDataService.RemoveRegionWindlightSettings(m_host.ParentGroup.Scene.RegionInfo.RegionID);
  754. m_host.ParentGroup.Scene.EventManager.TriggerOnSaveNewWindlightProfile();
  755. }
  756. /// <summary>
  757. /// Set the current Windlight scene to a target avatar
  758. /// </summary>
  759. /// <param name="rules"></param>
  760. /// <returns>success: true or false</returns>
  761. public int lsSetWindlightSceneTargeted(LSL_List rules, LSL_Key target)
  762. {
  763. if (!m_LSFunctionsEnabled)
  764. {
  765. LSShoutError("LightShare functions are not enabled.");
  766. return 0;
  767. }
  768. if (!World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID))
  769. {
  770. ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
  771. if (sp == null || !sp.IsViewerUIGod)
  772. {
  773. LSShoutError("lsSetWindlightSceneTargeted can only be used by estate managers or owners.");
  774. return 0;
  775. }
  776. }
  777. int success = 0;
  778. m_host.AddScriptLPS(1);
  779. if (LightShareModule.EnableWindlight)
  780. {
  781. RegionLightShareData wl;
  782. try
  783. {
  784. wl = getWindlightProfileFromRules(rules);
  785. }
  786. catch(InvalidCastException e)
  787. {
  788. LSShoutError(e.Message);
  789. return 0;
  790. }
  791. World.EventManager.TriggerOnSendNewWindlightProfileTargeted(wl, new UUID(target.m_string));
  792. success = 1;
  793. }
  794. else
  795. {
  796. LSShoutError("Windlight module is disabled");
  797. return 0;
  798. }
  799. return success;
  800. }
  801. }
  802. }