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

