Annotation of /branches/os-0.6.9-post-fixes/ModularRex/RexParts/RexPython/RexScriptInterface.cs
Parent Directory
|
Revision Log
Revision 364 - (view) (download)
| 1 : | mikkopa | 12 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | using System.Text; | ||
| 4 : | using System.IO; | ||
| 5 : | mikkopa | 14 | using System.Reflection; |
| 6 : | mikkopa | 12 | using OpenSim.Framework; |
| 7 : | using OpenSim.Framework.Communications.Cache; | ||
| 8 : | |||
| 9 : | mikkopa | 63 | using OpenSim.Region.Framework.Scenes; |
| 10 : | using OpenSim.Region.Framework.Scenes.Scripting; | ||
| 11 : | using OpenSim.Region.Framework.Interfaces; | ||
| 12 : | mikkopa | 12 | using OpenSim.Region.ScriptEngine.Shared; |
| 13 : | using OpenSim.Region.ScriptEngine.Interfaces; | ||
| 14 : | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
| 15 : | mikkopa | 14 | using log4net; |
| 16 : | mikkopa | 12 | using OpenMetaverse; |
| 17 : | mikkopa | 120 | using ModularRex.RexParts.Modules; |
| 18 : | mikkopa | 12 | |
| 19 : | namespace ModularRex.RexParts.RexPython | ||
| 20 : | { | ||
| 21 : | public class RexScriptInterface : Rex_BuiltIn_Commands | ||
| 22 : | { | ||
| 23 : | private RexScriptEngine myScriptEngine; | ||
| 24 : | mikkopa | 14 | private static readonly ILog m_log = |
| 25 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 26 : | mikkopa | 49 | private ModrexObjects m_rexObjects; |
| 27 : | mikkopa | 12 | |
| 28 : | public RexScriptInterface(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID, RexScriptEngine vScriptEngine) | ||
| 29 : | { | ||
| 30 : | myScriptEngine = vScriptEngine; | ||
| 31 : | |||
| 32 : | mikkopa | 111 | IScriptModule[] scriptModules = myScriptEngine.World.RequestModuleInterfaces<IScriptModule>(); |
| 33 : | foreach (IScriptModule sm in scriptModules) | ||
| 34 : | mikkopa | 12 | { |
| 35 : | mikkopa | 111 | if (sm is IScriptEngine) |
| 36 : | mikkopa | 12 | { |
| 37 : | mikkopa | 111 | IScriptEngine ise = (IScriptEngine)sm; |
| 38 : | mikkopa | 243 | if (ise.ScriptEngineName == "XEngine") |
| 39 : | mikkopa | 14 | { |
| 40 : | mikkopa | 111 | m_ScriptEngine = ise; |
| 41 : | mikkopa | 243 | m_log.Info("[REXSCRIPT]: Found XEngine"); |
| 42 : | mikkopa | 14 | } |
| 43 : | mikkopa | 12 | } |
| 44 : | } | ||
| 45 : | mikkopa | 111 | |
| 46 : | mikkopa | 12 | if (m_ScriptEngine == null) |
| 47 : | mikkopa | 43 | { |
| 48 : | mikkopa | 243 | m_log.Error("[REXSCRIPT]: Could not find XEngine"); |
| 49 : | throw new Exception("Could not find XEngine"); | ||
| 50 : | mikkopa | 43 | } |
| 51 : | mikkopa | 12 | //this was causing lots of errors. instead of creating a new instance of .Net script engine, check for an existing one and use that |
| 52 : | //this requires of using .NET scripting engine when using the python engine. | ||
| 53 : | //m_ScriptEngine = new OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine(); | ||
| 54 : | //m_ScriptEngine.World = myScriptEngine.World; | ||
| 55 : | mikkopa | 14 | try |
| 56 : | { | ||
| 57 : | base.Initialize(m_ScriptEngine, host, localID, itemID); | ||
| 58 : | } | ||
| 59 : | catch (Exception e) | ||
| 60 : | { | ||
| 61 : | m_log.Error("[REXSCRIPT]: Initializting rex scriptengine failed: " + e.ToString()); | ||
| 62 : | } | ||
| 63 : | mikkopa | 49 | |
| 64 : | mikkopa | 63 | OpenSim.Region.Framework.Interfaces.IRegionModule module = myScriptEngine.World.Modules["RexObjectsModule"]; |
| 65 : | mikkopa | 49 | if (module != null && module is ModrexObjects) |
| 66 : | { | ||
| 67 : | m_rexObjects = (ModrexObjects)module; | ||
| 68 : | } | ||
| 69 : | mikkopa | 12 | } |
| 70 : | |||
| 71 : | private EntityBase GetEntityBase(uint vId) | ||
| 72 : | { | ||
| 73 : | mikkopa | 93 | EntityBase entity; |
| 74 : | if (myScriptEngine.World.Entities.TryGetValue(vId, out entity)) | ||
| 75 : | { | ||
| 76 : | if(entity is SceneObjectGroup) | ||
| 77 : | return entity; | ||
| 78 : | } | ||
| 79 : | return null; | ||
| 80 : | mikkopa | 12 | } |
| 81 : | |||
| 82 : | // Functions exposed to Python! | ||
| 83 : | // ********************************* | ||
| 84 : | public bool SetScriptRunner(string vId) | ||
| 85 : | { | ||
| 86 : | uint id = System.Convert.ToUInt32(vId, 10); | ||
| 87 : | |||
| 88 : | mikkopa | 93 | EntityBase entity; |
| 89 : | if (myScriptEngine.World.Entities.TryGetValue(id, out entity)) | ||
| 90 : | mikkopa | 12 | { |
| 91 : | mikkopa | 93 | if (entity is SceneObjectGroup) |
| 92 : | { | ||
| 93 : | SceneObjectGroup sog = (SceneObjectGroup)entity; | ||
| 94 : | m_host = sog.RootPart; | ||
| 95 : | m_localID = sog.LocalId; | ||
| 96 : | m_itemID = sog.UUID; | ||
| 97 : | return true; | ||
| 98 : | } | ||
| 99 : | mikkopa | 364 | m_log.DebugFormat("[PythonScript]: entity not scene object group: {0}", entity.GetType().ToString()); |
| 100 : | mikkopa | 12 | } |
| 101 : | else | ||
| 102 : | mikkopa | 93 | { |
| 103 : | mikkopa | 364 | m_log.Debug("[PythonScript]: no entity found with id"); |
| 104 : | mikkopa | 93 | } |
| 105 : | return false; | ||
| 106 : | mikkopa | 12 | } |
| 107 : | |||
| 108 : | public void CommandToClient(string vPresenceId, string vUnit, string vCommand, string vCmdParams) | ||
| 109 : | { | ||
| 110 : | UUID TempId = new UUID(vPresenceId); | ||
| 111 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 112 : | if (temppre != null) | ||
| 113 : | { | ||
| 114 : | mikkopa | 156 | if (temppre.ControllingClient is RexNetwork.RexClientViewBase) |
| 115 : | mikkopa | 12 | { |
| 116 : | mikkopa | 156 | RexNetwork.RexClientViewBase client = (RexNetwork.RexClientViewBase)temppre.ControllingClient; |
| 117 : | mikkopa | 12 | client.SendRexScriptCommand(vUnit, vCommand, vCmdParams); |
| 118 : | } | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | public bool GetPhysics(string vId) | ||
| 123 : | { | ||
| 124 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 125 : | if (tempobj != null) | ||
| 126 : | return ((tempobj.ObjectFlags & (uint)PrimFlags.Physics) != 0); | ||
| 127 : | else | ||
| 128 : | return false; | ||
| 129 : | } | ||
| 130 : | |||
| 131 : | public void SetPhysics(string vId, bool vbUsePhysics) | ||
| 132 : | { | ||
| 133 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 134 : | if (tempobj != null) | ||
| 135 : | { | ||
| 136 : | if (vbUsePhysics) | ||
| 137 : | tempobj.AddFlag(PrimFlags.Physics); | ||
| 138 : | else | ||
| 139 : | tempobj.RemFlag(PrimFlags.Physics); | ||
| 140 : | |||
| 141 : | tempobj.DoPhysicsPropertyUpdate(vbUsePhysics, false); | ||
| 142 : | tempobj.ScheduleFullUpdate(); | ||
| 143 : | } | ||
| 144 : | else | ||
| 145 : | myScriptEngine.Log.WarnFormat("[PythonScript]: SetPhysics for nonexisting object:" + vId); | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | |||
| 149 : | |||
| 150 : | public void SetMass(string vId, float vMass) | ||
| 151 : | mikkopa | 42 | { |
| 152 : | tuco | 85 | m_log.Warn("[REXSCRIPT]: SetMass not implemented"); |
| 153 : | mikkopa | 42 | //SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); |
| 154 : | //if (tempobj != null) | ||
| 155 : | //{ | ||
| 156 : | // if (tempobj is RexObjects.RexObjectPart) | ||
| 157 : | // { | ||
| 158 : | // RexObjects.RexObjectPart rexObj = (RexObjects.RexObjectPart)tempobj; | ||
| 159 : | // rexObj.SetMass(vMass); | ||
| 160 : | // } | ||
| 161 : | //} | ||
| 162 : | //else | ||
| 163 : | // myScriptEngine.Log.WarnFormat("[PythonScript]: SetMass for nonexisting object:" + vId); | ||
| 164 : | mikkopa | 12 | |
| 165 : | } | ||
| 166 : | |||
| 167 : | public void SetVelocity(string vId, LSL_Types.Vector3 vVelocity) | ||
| 168 : | { | ||
| 169 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 170 : | if (((SceneObjectPart)tempobj) != null) | ||
| 171 : | { | ||
| 172 : | Vector3 tempvel = new Vector3((float)vVelocity.x, (float)vVelocity.y, (float)vVelocity.z); | ||
| 173 : | tempobj.Velocity = tempvel; | ||
| 174 : | } | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | public bool GetUsePrimVolumeCollision(string vId) | ||
| 178 : | { | ||
| 179 : | mikkopa | 127 | uint primId = Convert.ToUInt32(vId, 10); |
| 180 : | |||
| 181 : | SceneObjectPart prim = myScriptEngine.World.GetSceneObjectPart(primId); | ||
| 182 : | if (prim != null) | ||
| 183 : | { | ||
| 184 : | return prim.VolumeDetectActive; | ||
| 185 : | } | ||
| 186 : | else | ||
| 187 : | { | ||
| 188 : | m_log.Warn("[PythonScript]: GetPrimVolumeCollision for nonexisting object: " + vId); | ||
| 189 : | return false; | ||
| 190 : | } | ||
| 191 : | |||
| 192 : | mikkopa | 12 | } |
| 193 : | |||
| 194 : | public void SetUsePrimVolumeCollision(string vId, bool vUseVolumeCollision) | ||
| 195 : | { | ||
| 196 : | mikkopa | 127 | uint primId = Convert.ToUInt32(vId, 10); |
| 197 : | |||
| 198 : | SceneObjectPart prim = myScriptEngine.World.GetSceneObjectPart(primId); | ||
| 199 : | if (prim != null) | ||
| 200 : | { | ||
| 201 : | prim.ScriptSetVolumeDetect(vUseVolumeCollision); | ||
| 202 : | prim.SetScriptEvents(prim.UUID, (int)scriptEvents.collision); //this needs to be set so the collision event is used | ||
| 203 : | } | ||
| 204 : | else | ||
| 205 : | m_log.Warn("[PythonScript]: SetPrimVolumeCollision for nonexisting object: " + vId); | ||
| 206 : | mikkopa | 12 | } |
| 207 : | |||
| 208 : | public int GetPrimLocalIdFromUUID(string vUUID) | ||
| 209 : | { | ||
| 210 : | UUID tempid = UUID.Zero; | ||
| 211 : | try | ||
| 212 : | { | ||
| 213 : | tempid = new UUID(vUUID); | ||
| 214 : | } | ||
| 215 : | catch (Exception) { } | ||
| 216 : | |||
| 217 : | if(tempid != UUID.Zero) | ||
| 218 : | { | ||
| 219 : | mikkopa | 93 | EntityBase entity; |
| 220 : | if (myScriptEngine.World.Entities.TryGetValue(tempid, out entity)) | ||
| 221 : | { | ||
| 222 : | return (int)entity.LocalId; | ||
| 223 : | } | ||
| 224 : | mikkopa | 12 | else |
| 225 : | myScriptEngine.Log.WarnFormat("[PythonScript]: GetPrimLocalIdFromUUID did not find prim with uuid:" + vUUID); | ||
| 226 : | } | ||
| 227 : | return 0; | ||
| 228 : | } | ||
| 229 : | |||
| 230 : | |||
| 231 : | |||
| 232 : | // text messaging | ||
| 233 : | // ****************************** | ||
| 234 : | public void SendGeneralAlertAll(string vId, string vMessage) | ||
| 235 : | { | ||
| 236 : | tuco | 85 | m_log.Warn("[REXSCRIPT]: SendGeneralAlertAll not implemented"); |
| 237 : | mikkopa | 34 | //TODO: Fix this. Broken in newest OpenSim |
| 238 : | //myScriptEngine.World.SendGeneralAlert(vMessage); | ||
| 239 : | mikkopa | 12 | } |
| 240 : | |||
| 241 : | public void SendAlertToAvatar(string vId,string vPresenceId, string vMessage, bool vbModal) | ||
| 242 : | { | ||
| 243 : | UUID TempId = new UUID(vPresenceId); | ||
| 244 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 245 : | if (temppre != null) | ||
| 246 : | { | ||
| 247 : | temppre.ControllingClient.SendAgentAlertMessage(vMessage, vbModal); | ||
| 248 : | } | ||
| 249 : | } | ||
| 250 : | |||
| 251 : | |||
| 252 : | |||
| 253 : | // Actor finding. | ||
| 254 : | public List<string> GetRadiusActors(string vId,float vRadius) | ||
| 255 : | { | ||
| 256 : | List<string> TempList = new List<string>(); | ||
| 257 : | EntityBase tempobj = null; | ||
| 258 : | try | ||
| 259 : | { | ||
| 260 : | tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); | ||
| 261 : | } | ||
| 262 : | catch (Exception) { } | ||
| 263 : | try | ||
| 264 : | { | ||
| 265 : | if (tempobj == null) | ||
| 266 : | tempobj = myScriptEngine.World.GetScenePresence(new UUID(vId)); | ||
| 267 : | } | ||
| 268 : | catch (Exception) { } | ||
| 269 : | |||
| 270 : | if (tempobj != null) | ||
| 271 : | { | ||
| 272 : | List<EntityBase> EntitiesList = myScriptEngine.World.GetEntities(); | ||
| 273 : | foreach (EntityBase ent in EntitiesList) | ||
| 274 : | { | ||
| 275 : | if (ent is SceneObjectGroup || ent is ScenePresence) | ||
| 276 : | { | ||
| 277 : | if (Util.GetDistanceTo(ent.AbsolutePosition, tempobj.AbsolutePosition) < vRadius) | ||
| 278 : | TempList.Add(ent.LocalId.ToString()); | ||
| 279 : | } | ||
| 280 : | } | ||
| 281 : | } | ||
| 282 : | return TempList; | ||
| 283 : | } | ||
| 284 : | |||
| 285 : | public List<string> GetRadiusAvatars(string vId, float vRadius) | ||
| 286 : | { | ||
| 287 : | List<string> TempList = new List<string>(); | ||
| 288 : | EntityBase tempobj = null; | ||
| 289 : | |||
| 290 : | try | ||
| 291 : | { | ||
| 292 : | tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); | ||
| 293 : | } | ||
| 294 : | catch(Exception) { } | ||
| 295 : | try | ||
| 296 : | { | ||
| 297 : | if (tempobj == null) | ||
| 298 : | tempobj = myScriptEngine.World.GetScenePresence(new UUID(vId)); | ||
| 299 : | } | ||
| 300 : | catch (Exception) { } | ||
| 301 : | |||
| 302 : | if (tempobj != null) | ||
| 303 : | { | ||
| 304 : | List<EntityBase> EntitiesList = myScriptEngine.World.GetEntities(); | ||
| 305 : | foreach (EntityBase ent in EntitiesList) | ||
| 306 : | { | ||
| 307 : | if (ent is ScenePresence) | ||
| 308 : | { | ||
| 309 : | if (Util.GetDistanceTo(ent.AbsolutePosition, tempobj.AbsolutePosition) < vRadius) | ||
| 310 : | TempList.Add(ent.LocalId.ToString()); | ||
| 311 : | } | ||
| 312 : | } | ||
| 313 : | } | ||
| 314 : | return TempList; | ||
| 315 : | } | ||
| 316 : | |||
| 317 : | |||
| 318 : | |||
| 319 : | mikkopa | 49 | public string SpawnActor(LSL_Types.Vector3 location, int shape, bool temporary, string pythonClass) |
| 320 : | mikkopa | 12 | { |
| 321 : | mikkopa | 49 | UUID TempID = myScriptEngine.World.RegionInfo.MasterAvatarAssignedUUID; |
| 322 : | Vector3 pos = new Vector3((float)location.x, (float)location.y, (float)location.z); | ||
| 323 : | Quaternion rot = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); | ||
| 324 : | mikkopa | 12 | |
| 325 : | mikkopa | 49 | SceneObjectGroup sog = myScriptEngine.World.AddNewPrim(TempID, TempID, pos, rot, GetShape(shape)); |
| 326 : | uint AddResult = sog.RootPart.LocalId; | ||
| 327 : | |||
| 328 : | tuco | 57 | ModularRex.RexFramework.RexObjectProperties rop = m_rexObjects.GetObject(sog.RootPart.UUID); |
| 329 : | mikkopa | 49 | rop.RexClassName = pythonClass; |
| 330 : | |||
| 331 : | //TODO: vbTemporary | ||
| 332 : | //uint AddResult = myScriptEngine.World.AddNewPrimReturningId(TempID, pos, rot, GetShape(vShape), vbTemporary, vPyClass); | ||
| 333 : | return AddResult.ToString(); | ||
| 334 : | mikkopa | 12 | } |
| 335 : | |||
| 336 : | public bool DestroyActor(string vId) | ||
| 337 : | { | ||
| 338 : | mikkopa | 328 | UUID objectUUID; |
| 339 : | SceneObjectPart part = null; | ||
| 340 : | if (UUID.TryParse(vId, out objectUUID)) | ||
| 341 : | { | ||
| 342 : | part = myScriptEngine.World.GetSceneObjectPart(objectUUID); | ||
| 343 : | } | ||
| 344 : | else | ||
| 345 : | { | ||
| 346 : | part = myScriptEngine.World.GetSceneObjectPart(Convert.ToUInt32(vId)); | ||
| 347 : | } | ||
| 348 : | |||
| 349 : | if (part == null) | ||
| 350 : | { | ||
| 351 : | m_log.ErrorFormat("[REXSCRIPT]: Could not delete actor {0}, because it was not found", vId); | ||
| 352 : | return false; | ||
| 353 : | } | ||
| 354 : | |||
| 355 : | myScriptEngine.World.DeleteSceneObject(part.ParentGroup, false); | ||
| 356 : | tuco | 85 | return true; |
| 357 : | mikkopa | 328 | |
| 358 : | //m_log.Warn("[REXSCRIPT]: DestroyActor not implemented"); | ||
| 359 : | //return true; | ||
| 360 : | mikkopa | 42 | //EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); |
| 361 : | //if (tempobj != null && tempobj is RexObjects.RexObjectGroup) | ||
| 362 : | //{ | ||
| 363 : | // ((RexObjects.RexObjectGroup)tempobj).DeleteMe = true; // Do not call DeleteSceneObjectGroup for deleting directly | ||
| 364 : | // return true; | ||
| 365 : | //} | ||
| 366 : | //return false; | ||
| 367 : | mikkopa | 12 | } |
| 368 : | |||
| 369 : | private static PrimitiveBaseShape GetShape(int vShape) | ||
| 370 : | { | ||
| 371 : | PrimitiveBaseShape shape = new PrimitiveBaseShape(); | ||
| 372 : | |||
| 373 : | shape.PCode = 9; | ||
| 374 : | shape.PathBegin = 0; | ||
| 375 : | shape.PathEnd = 0; | ||
| 376 : | shape.PathScaleX = 100; | ||
| 377 : | shape.PathScaleY = 100; | ||
| 378 : | shape.PathShearX = 0; | ||
| 379 : | shape.PathShearY = 0; | ||
| 380 : | shape.PathSkew = 0; | ||
| 381 : | shape.ProfileBegin = 0; | ||
| 382 : | shape.ProfileEnd = 0; | ||
| 383 : | shape.Scale = new Vector3(0.5f, 0.5f, 0.5f); | ||
| 384 : | //shape.Scale.X = shape.Scale.Y = shape.Scale.Z = 0.5f; | ||
| 385 : | shape.PathCurve = 16; | ||
| 386 : | shape.ProfileCurve = 1; | ||
| 387 : | shape.ProfileHollow = 0; | ||
| 388 : | shape.PathRadiusOffset = 0; | ||
| 389 : | shape.PathRevolutions = 0; | ||
| 390 : | shape.PathTaperX = 0; | ||
| 391 : | shape.PathTaperY = 0; | ||
| 392 : | shape.PathTwist = 0; | ||
| 393 : | shape.PathTwistBegin = 0; | ||
| 394 : | Primitive.TextureEntry ntex = new Primitive.TextureEntry(new UUID("00000000-0000-1111-9999-000000000005")); | ||
| 395 : | mikkopa | 100 | shape.TextureEntry = ntex.GetBytes();//ntex.ToBytes(); |
| 396 : | mikkopa | 12 | return shape; |
| 397 : | } | ||
| 398 : | |||
| 399 : | // Scenepresence related | ||
| 400 : | mikkopa | 20 | // These are now in RexClientView, although most of them are not working properly yet. |
| 401 : | |||
| 402 : | mikkopa | 12 | public string SPGetFullName(string vPresenceId) |
| 403 : | { | ||
| 404 : | UUID TempId = new UUID(vPresenceId); | ||
| 405 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 406 : | if (temppre != null) | ||
| 407 : | { | ||
| 408 : | string TempString = temppre.Firstname + " " + temppre.Lastname; | ||
| 409 : | return TempString; | ||
| 410 : | } | ||
| 411 : | else | ||
| 412 : | return ""; | ||
| 413 : | } | ||
| 414 : | public string SPGetFirstName(string vPresenceId) | ||
| 415 : | { | ||
| 416 : | UUID TempId = new UUID(vPresenceId); | ||
| 417 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 418 : | if (temppre != null) | ||
| 419 : | return temppre.Firstname; | ||
| 420 : | else | ||
| 421 : | return ""; | ||
| 422 : | } | ||
| 423 : | public string SPGetLastName(string vPresenceId) | ||
| 424 : | { | ||
| 425 : | UUID TempId = new UUID(vPresenceId); | ||
| 426 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 427 : | if (temppre != null) | ||
| 428 : | return temppre.Lastname; | ||
| 429 : | else | ||
| 430 : | return ""; | ||
| 431 : | } | ||
| 432 : | |||
| 433 : | public void SPDoLocalTeleport(string vPresenceId, LSL_Types.Vector3 vLocation) | ||
| 434 : | { | ||
| 435 : | UUID TempId = new UUID(vPresenceId); | ||
| 436 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 437 : | if (temppre != null) | ||
| 438 : | { | ||
| 439 : | Vector3 position = new Vector3((float)vLocation.x, (float)vLocation.y, (float)vLocation.z); | ||
| 440 : | Vector3 lookAt = new Vector3(0,0,0); | ||
| 441 : | temppre.ControllingClient.SendTeleportLocationStart(); | ||
| 442 : | temppre.ControllingClient.SendLocalTeleport(position, lookAt,0); | ||
| 443 : | temppre.Teleport(position); | ||
| 444 : | } | ||
| 445 : | } | ||
| 446 : | |||
| 447 : | public float SPGetMovementModifier(string vPresenceId) | ||
| 448 : | { | ||
| 449 : | mikkopa | 115 | UUID avatarID = new UUID(vPresenceId); |
| 450 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarID); | ||
| 451 : | return avatar.SpeedModifier; | ||
| 452 : | mikkopa | 12 | } |
| 453 : | |||
| 454 : | public void SPSetMovementModifier(string vPresenceId,float vSpeedModifier) | ||
| 455 : | { | ||
| 456 : | mikkopa | 115 | UUID avatarID = new UUID(vPresenceId); |
| 457 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarID); | ||
| 458 : | avatar.SpeedModifier = vSpeedModifier; | ||
| 459 : | mikkopa | 12 | } |
| 460 : | |||
| 461 : | public LSL_Types.Vector3 SPGetPos(string vPresenceId) | ||
| 462 : | { | ||
| 463 : | LSL_Types.Vector3 loc = new LSL_Types.Vector3(0, 0, 0); | ||
| 464 : | |||
| 465 : | UUID TempId = new UUID(vPresenceId); | ||
| 466 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 467 : | if (temppre != null) | ||
| 468 : | { | ||
| 469 : | loc.x = temppre.AbsolutePosition.X; | ||
| 470 : | loc.y = temppre.AbsolutePosition.Y; | ||
| 471 : | loc.z = temppre.AbsolutePosition.Z; | ||
| 472 : | } | ||
| 473 : | return loc; | ||
| 474 : | } | ||
| 475 : | |||
| 476 : | public LSL_Types.Quaternion SPGetRot(string vPresenceId) | ||
| 477 : | { | ||
| 478 : | LSL_Types.Quaternion rot = new LSL_Types.Quaternion(0, 0, 0, 1); | ||
| 479 : | |||
| 480 : | UUID TempId = new UUID(vPresenceId); | ||
| 481 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 482 : | if (temppre != null) | ||
| 483 : | { | ||
| 484 : | rot.x = temppre.Rotation.X; | ||
| 485 : | rot.y = temppre.Rotation.Y; | ||
| 486 : | rot.z = temppre.Rotation.Z; | ||
| 487 : | rot.s = temppre.Rotation.W; | ||
| 488 : | } | ||
| 489 : | return rot; | ||
| 490 : | } | ||
| 491 : | |||
| 492 : | public void SPSetRot(string vPresenceId,LSL_Types.Quaternion vRot, bool vbRelative) | ||
| 493 : | { | ||
| 494 : | UUID TempId = new UUID(vPresenceId); | ||
| 495 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 496 : | if (temppre != null) | ||
| 497 : | { | ||
| 498 : | mikkopa | 156 | if (temppre.ControllingClient is RexNetwork.RexClientViewBase) |
| 499 : | mikkopa | 12 | { |
| 500 : | mikkopa | 156 | RexNetwork.RexClientViewBase client = (RexNetwork.RexClientViewBase)temppre.ControllingClient; |
| 501 : | mikkopa | 12 | string sparams = vRot.x.ToString() + " " + vRot.y.ToString() + " " + vRot.z.ToString() + " " + vRot.s.ToString(); |
| 502 : | sparams = sparams.Replace(",", "."); | ||
| 503 : | if (vbRelative) | ||
| 504 : | client.SendRexScriptCommand("client", "setrelrot", sparams); | ||
| 505 : | else | ||
| 506 : | mikkopa | 98 | { |
| 507 : | temppre.Rotation = new Quaternion((float)vRot.x, (float)vRot.y, (float)vRot.z, (float)vRot.s); | ||
| 508 : | temppre.UpdateMovement(); | ||
| 509 : | //client.SendRexScriptCommand("client", "setrot", sparams); | ||
| 510 : | } | ||
| 511 : | mikkopa | 12 | } |
| 512 : | } | ||
| 513 : | } | ||
| 514 : | |||
| 515 : | public bool SPGetWalkDisabled(string vPresenceId) | ||
| 516 : | { | ||
| 517 : | |||
| 518 : | mikkopa | 117 | UUID avatarId = new UUID(vPresenceId); |
| 519 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarId); | ||
| 520 : | return avatar.ForceFly; | ||
| 521 : | mikkopa | 12 | } |
| 522 : | |||
| 523 : | public void SPSetWalkDisabled(string vPresenceId, bool vbValue) | ||
| 524 : | { | ||
| 525 : | |||
| 526 : | mikkopa | 117 | UUID avatarId = new UUID(vPresenceId); |
| 527 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarId); | ||
| 528 : | avatar.ForceFly = vbValue; | ||
| 529 : | mikkopa | 12 | } |
| 530 : | |||
| 531 : | public bool SPGetFlyDisabled(string vPresenceId) | ||
| 532 : | { | ||
| 533 : | |||
| 534 : | mikkopa | 117 | UUID avatarId = new UUID(vPresenceId); |
| 535 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarId); | ||
| 536 : | return avatar.FlyDisabled; | ||
| 537 : | mikkopa | 12 | } |
| 538 : | |||
| 539 : | public void SPSetFlyDisabled(string vPresenceId, bool vbValue) | ||
| 540 : | { | ||
| 541 : | |||
| 542 : | mikkopa | 117 | UUID avatarId = new UUID(vPresenceId); |
| 543 : | ScenePresence avatar = myScriptEngine.World.GetScenePresence(avatarId); | ||
| 544 : | avatar.FlyDisabled = vbValue; | ||
| 545 : | mikkopa | 12 | } |
| 546 : | |||
| 547 : | mikkopa | 20 | public float SPGetVertMovementModifier(string vPresenceId) |
| 548 : | { | ||
| 549 : | UUID TempId = new UUID(vPresenceId); | ||
| 550 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 551 : | if (temppre != null) | ||
| 552 : | { | ||
| 553 : | mikkopa | 156 | if (temppre.ControllingClient is RexNetwork.RexClientViewBase) |
| 554 : | mikkopa | 20 | { |
| 555 : | mikkopa | 156 | RexNetwork.RexClientViewBase rexclient = (RexNetwork.RexClientViewBase)temppre.ControllingClient; |
| 556 : | mikkopa | 20 | return rexclient.RexVertMovementSpeedMod; |
| 557 : | } | ||
| 558 : | } | ||
| 559 : | return 0.0f; | ||
| 560 : | } | ||
| 561 : | |||
| 562 : | public void SPSetVertMovementModifier(string vPresenceId, float vSpeedModifier) | ||
| 563 : | { | ||
| 564 : | |||
| 565 : | UUID TempId = new UUID(vPresenceId); | ||
| 566 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 567 : | if (temppre != null) | ||
| 568 : | mikkopa | 156 | if (temppre.ControllingClient is RexNetwork.RexClientViewBase) |
| 569 : | mikkopa | 20 | { |
| 570 : | mikkopa | 156 | RexNetwork.RexClientViewBase rexclient = (RexNetwork.RexClientViewBase)temppre.ControllingClient; |
| 571 : | mikkopa | 20 | rexclient.RexVertMovementSpeedMod = vSpeedModifier; |
| 572 : | } | ||
| 573 : | } | ||
| 574 : | |||
| 575 : | |||
| 576 : | public bool SPGetSitDisabled(string vPresenceId) | ||
| 577 : | { | ||
| 578 : | |||
| 579 : | mikkopa | 113 | UUID avatarID = new UUID(vPresenceId); |
| 580 : | ISitMod mod = m_ScriptEngine.World.RequestModuleInterface<ISitMod>(); | ||
| 581 : | return mod.GetSitDisabled(avatarID); | ||
| 582 : | mikkopa | 20 | } |
| 583 : | |||
| 584 : | public void SPSetSitDisabled(string vPresenceId, bool vbValue) | ||
| 585 : | { | ||
| 586 : | |||
| 587 : | mikkopa | 113 | UUID avatarID = new UUID(vPresenceId); |
| 588 : | ISitMod mod = m_ScriptEngine.World.RequestModuleInterface<ISitMod>(); | ||
| 589 : | mod.SetSitDisabled(avatarID, vbValue); | ||
| 590 : | mikkopa | 20 | } |
| 591 : | |||
| 592 : | |||
| 593 : | mikkopa | 12 | // Rexbot related |
| 594 : | public void BotWalkTo(string vPresenceId, LSL_Types.Vector3 vDest) | ||
| 595 : | { | ||
| 596 : | UUID TempId = new UUID(vPresenceId); | ||
| 597 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 598 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 599 : | { | ||
| 600 : | Vector3 dest = new Vector3((float)vDest.x, (float)vDest.y, (float)vDest.z); | ||
| 601 : | (temppre.ControllingClient as IRexBot).WalkTo(dest); | ||
| 602 : | } | ||
| 603 : | mikkopa | 34 | |
| 604 : | |||
| 605 : | mikkopa | 12 | } |
| 606 : | |||
| 607 : | public void BotFlyTo(string vPresenceId, LSL_Types.Vector3 vDest) | ||
| 608 : | { | ||
| 609 : | UUID TempId = new UUID(vPresenceId); | ||
| 610 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 611 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 612 : | { | ||
| 613 : | Vector3 dest = new Vector3((float)vDest.x, (float)vDest.y, (float)vDest.z); | ||
| 614 : | (temppre.ControllingClient as IRexBot).FlyTo(dest); | ||
| 615 : | } | ||
| 616 : | } | ||
| 617 : | |||
| 618 : | public void BotRotateTo(string vPresenceId, LSL_Types.Vector3 vTarget) | ||
| 619 : | { | ||
| 620 : | UUID TempId = new UUID(vPresenceId); | ||
| 621 : | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); | ||
| 622 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 623 : | { | ||
| 624 : | Vector3 dest = new Vector3((float)vTarget.x, (float)vTarget.y, (float)vTarget.z); | ||
| 625 : | (temppre.ControllingClient as IRexBot).RotateTo(dest); | ||
| 626 : | } | ||
| 627 : | } | ||
| 628 : | |||
| 629 : | mikkopa | 20 | /// <summary> |
| 630 : | /// deprecated. prefer BotPauseAutoMove() or BotStopAutoMove() | ||
| 631 : | /// </summary> | ||
| 632 : | [Obsolete("use BotPauseAutoMove() or BotStopAutoMove()")] | ||
| 633 : | public void BotEnableAutoMove(string botId, bool vEnable) | ||
| 634 : | mikkopa | 12 | { |
| 635 : | mikkopa | 20 | UUID TempId = new UUID(botId); |
| 636 : | mikkopa | 12 | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); |
| 637 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 638 : | { | ||
| 639 : | (temppre.ControllingClient as IRexBot).EnableAutoMove(vEnable, true); | ||
| 640 : | } | ||
| 641 : | } | ||
| 642 : | |||
| 643 : | mikkopa | 20 | /// <summary> |
| 644 : | /// Temporarily pause bot auto movement. bot will still warp to destination if it is deemed stuck | ||
| 645 : | /// </summary> | ||
| 646 : | /// <param name="botId">UUID of the bots ScenePresence</param> | ||
| 647 : | /// <param name="vEnable"></param> | ||
| 648 : | public void BotPauseAutoMove(string botId, bool vEnable) | ||
| 649 : | mikkopa | 12 | { |
| 650 : | mikkopa | 20 | UUID TempId = new UUID(botId); |
| 651 : | mikkopa | 12 | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); |
| 652 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 653 : | { | ||
| 654 : | (temppre.ControllingClient as IRexBot).PauseAutoMove(vEnable); | ||
| 655 : | } | ||
| 656 : | } | ||
| 657 : | |||
| 658 : | mikkopa | 20 | /// <summary> |
| 659 : | /// Stop/start bot auto movement. Bot will not warp to destination after it has been stopped, | ||
| 660 : | /// no logic for checking if bot is stuck | ||
| 661 : | /// </summary> | ||
| 662 : | /// <param name="botId">UUID of the bots ScenePresence</param> | ||
| 663 : | /// <param name="vEnable"></param> | ||
| 664 : | public void BotStopAutoMove(string botId, bool vEnable) | ||
| 665 : | mikkopa | 12 | { |
| 666 : | mikkopa | 20 | UUID TempId = new UUID(botId); |
| 667 : | mikkopa | 12 | ScenePresence temppre = myScriptEngine.World.GetScenePresence(TempId); |
| 668 : | if (temppre != null && temppre.ControllingClient is IRexBot) | ||
| 669 : | { | ||
| 670 : | (temppre.ControllingClient as IRexBot).StopAutoMove(vEnable); | ||
| 671 : | } | ||
| 672 : | } | ||
| 673 : | |||
| 674 : | mikkopa | 306 | public void AddUserGenericPacketHandler(string presenceId, string method, GenericMessage handler) |
| 675 : | { | ||
| 676 : | UUID userId = new UUID(presenceId); | ||
| 677 : | ScenePresence sp = myScriptEngine.World.GetScenePresence(userId); | ||
| 678 : | if (sp != null) | ||
| 679 : | { | ||
| 680 : | sp.ControllingClient.AddGenericPacketHandler(method, handler); | ||
| 681 : | } | ||
| 682 : | } | ||
| 683 : | |||
| 684 : | mikkopa | 20 | #region Functions not supported at the moment. |
| 685 : | mikkopa | 12 | /* |
| 686 : | public bool GetFreezed(string vId) | ||
| 687 : | { | ||
| 688 : | EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); | ||
| 689 : | if (tempobj != null) | ||
| 690 : | { | ||
| 691 : | return tempobj.IsFreezed; | ||
| 692 : | } | ||
| 693 : | else | ||
| 694 : | { | ||
| 695 : | return false; | ||
| 696 : | } | ||
| 697 : | |||
| 698 : | return false; | ||
| 699 : | } | ||
| 700 : | |||
| 701 : | public void SetFreezed(string vId, bool vbFreeze) | ||
| 702 : | { | ||
| 703 : | EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); | ||
| 704 : | if (tempobj != null) | ||
| 705 : | { | ||
| 706 : | tempobj.IsFreezed = vbFreeze; | ||
| 707 : | if (tempobj is ScenePresence && vbFreeze) | ||
| 708 : | ((ScenePresence)tempobj).rxStopAvatarMovement(); | ||
| 709 : | } | ||
| 710 : | |||
| 711 : | } */ | ||
| 712 : | |||
| 713 : | /* | ||
| 714 : | public int GetPhysicsMode(string vId) | ||
| 715 : | { | ||
| 716 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 717 : | if (tempobj != null) | ||
| 718 : | return tempobj.GetPhysicsMode(); | ||
| 719 : | else | ||
| 720 : | return 0; | ||
| 721 : | |||
| 722 : | return 0; | ||
| 723 : | } | ||
| 724 : | |||
| 725 : | public void SetPhysicsMode(string vId, int vPhysicsMode) | ||
| 726 : | { | ||
| 727 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 728 : | if (tempobj != null) | ||
| 729 : | { | ||
| 730 : | tempobj.SetPhysicsMode(vPhysicsMode); | ||
| 731 : | } | ||
| 732 : | else | ||
| 733 : | myScriptEngine.Log.Verbose("PythonScript", "SetPhysicsMode for nonexisting object:" + vId); | ||
| 734 : | } | ||
| 735 : | */ | ||
| 736 : | |||
| 737 : | |||
| 738 : | /* | ||
| 739 : | public bool GetUseGravity(string vId) | ||
| 740 : | { | ||
| 741 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 742 : | if (tempobj != null) | ||
| 743 : | return tempobj.GetUseGravity(); | ||
| 744 : | else | ||
| 745 : | return false; | ||
| 746 : | |||
| 747 : | return false; | ||
| 748 : | } | ||
| 749 : | |||
| 750 : | public void SetUseGravity(string vId, bool vbUseGravity) | ||
| 751 : | { | ||
| 752 : | SceneObjectPart tempobj = myScriptEngine.World.GetSceneObjectPart(System.Convert.ToUInt32(vId, 10)); | ||
| 753 : | if (tempobj != null) | ||
| 754 : | tempobj.SetUseGravity(vbUseGravity); | ||
| 755 : | else | ||
| 756 : | myScriptEngine.Log.Verbose("PythonScript", "SetUseGravity for nonexisting object:" + vId); | ||
| 757 : | } | ||
| 758 : | */ | ||
| 759 : | |||
| 760 : | /* | ||
| 761 : | public void SetLocationFast(string vId,rxVector vLoc) | ||
| 762 : | { | ||
| 763 : | EntityBase tempobj = GetEntityBase(System.Convert.ToUInt32(vId, 10)); | ||
| 764 : | if (((SceneObjectGroup)tempobj) != null) | ||
| 765 : | { | ||
| 766 : | bool hasPrim = ((SceneObjectGroup)tempobj).HasChildPrim(tempobj.UUID); | ||
| 767 : | if (hasPrim != false) | ||
| 768 : | { | ||
| 769 : | LLVector3 TempLoc = new LLVector3((float)vLoc.x, (float)vLoc.y, (float)vLoc.z); | ||
| 770 : | LLVector3 TempOffset = new LLVector3(0, 0, 0); | ||
| 771 : | ((SceneObjectGroup)tempobj).GrabMovement(TempOffset, TempLoc, null); // tucofixme, might break some day, because sending null remoteClient parameter | ||
| 772 : | } | ||
| 773 : | } | ||
| 774 : | } | ||
| 775 : | */ | ||
| 776 : | mikkopa | 20 | #endregion |
| 777 : | mikkopa | 12 | |
| 778 : | public float TimeOfDay //is double in LL interface, but float inside opensim estate info | ||
| 779 : | { | ||
| 780 : | get | ||
| 781 : | { | ||
| 782 : | return (float)myScriptEngine.World.RegionInfo.EstateSettings.SunPosition;//sunHour; //llGetTimeOfDay(); | ||
| 783 : | } | ||
| 784 : | |||
| 785 : | set | ||
| 786 : | { | ||
| 787 : | myScriptEngine.World.RegionInfo.EstateSettings.SunPosition = value; | ||
| 788 : | IEstateModule estate = myScriptEngine.World.RequestModuleInterface<IEstateModule>(); | ||
| 789 : | tuco | 65 | if (estate is OpenSim.Region.CoreModules.World.Estate.EstateManagementModule) |
| 790 : | ((OpenSim.Region.CoreModules.World.Estate.EstateManagementModule)estate).sendRegionInfoPacketToAll(); | ||
| 791 : | mikkopa | 12 | } |
| 792 : | } | ||
| 793 : | } | ||
| 794 : | } | ||
| 795 : | |||
| 796 : | |||
| 797 : | |||
| 798 : | |||
| 799 : | |||
| 800 : | |||
| 801 : | |||
| 802 : | |||
| 803 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

