/// <summary> /// 实现后置条件检查器逻辑 /// </summary> /// <returns></returns> protected override bool ImplementAfterValidator() { var validator = PCode.BeginValidator().IsNullOrEmpty().StartsWith("P").EndValidator(); return(ProductStockLocalMember.LocalStockMember.ContainsKey(PCode) && //检查是否存在该商品的库存 validator.IsTrue());//检查各项返回的属性是否正确 }
/// <summary> /// Button click event was detected. Raises the mouse click event /// to notify the app /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void button_EvtMouseClicked(object sender, WidgetEventArgs e) { if (_player == null) { return; } var widget = e.SourceWidget; var animationWidget = _player.GetAnimationWidgetInCurrentAnimation(widget); PCode onMouseClick = null; SetSelectedWidget(widget); if (animationWidget != null && animationWidget.OnMouseClick != null) { onMouseClick = animationWidget.OnMouseClick; } else if (widget.OnMouseClick != null) { onMouseClick = widget.OnMouseClick; } if (onMouseClick != null && onMouseClick.HasCode()) { _interpreter.Execute(onMouseClick); } else if (widget.IsMouseClickActuateOn) { widget.Actuate(); } }
/// <summary> /// Load attribute from the XML node /// </summary> /// <param name="xmlNode">Xml node</param> /// <returns>true on success</returns> public bool Load(XmlNode xmlNode) { SwitchName = XmlUtils.GetXMLAttrString(xmlNode, "name"); var script = XmlUtils.GetXMLAttrString(xmlNode, "onTrigger"); // a switch action of default() means this is used as a selector. if (!String.IsNullOrEmpty(script)) { OnTrigger = new PCode(); if (String.Compare(script, "default()", true) != 0) { Log.Debug("Name: " + SwitchName + " onTrigger: " + script); _parser.Parse(script, ref OnTrigger); } else { Log.Debug("Name: " + SwitchName + " onTrigger: default()"); } } else { Log.Debug("Name: " + SwitchName + " script is empty. setting onTrigger to NULL"); OnTrigger = null; } return(true); }
/// <summary> /// Runds the command mapped to the specified switch. Checks /// the command permissions if it CAN be executed. /// </summary> /// <param name="switchObj">The switch object</param> private void runSwitchMappedCommand(IActuatorSwitch switchObj) { bool runCommand = true; String onTrigger = switchObj.Command; var form = _currentPanel.UIControl; if (form is IScannerPanel) { var panelCommon = (form as IScannerPanel).PanelCommon; var arg = new CommandEnabledArg(null, onTrigger); panelCommon.CheckCommandEnabled(new CommandEnabledArg(null, onTrigger)); if (arg.Handled) { if (!arg.Enabled) { Log.Debug("Command " + onTrigger + " is not currently enabled"); return; } else { Log.Debug("Command " + onTrigger + " IS ENABLED"); } } else { Log.Debug("arg.handled is false for " + onTrigger); var cmdDescriptor = CommandManager.Instance.AppCommandTable.Get(onTrigger); if (cmdDescriptor != null && !cmdDescriptor.EnableSwitchMap) { Log.Debug("EnableswitchMap is not enabled for " + onTrigger); runCommand = false; } } } else { Log.Debug("Dialog is active. Will not handle"); runCommand = false; } if (runCommand) { Log.Debug("Executing OnTrigger command " + onTrigger + " for panel..." + _currentPanel.Name); PCode pcode = new PCode { Script = "run(" + onTrigger + ")" }; var parser = new Parser(); if (parser.Parse(pcode.Script, ref pcode)) { _interpreter.Execute(pcode); } } }
/// <summary> /// Returns the action associated with the switch. These actions /// are configured in the switch map config file. First checks the /// animation config file to see if there is a mapping there. If not /// goes to the global mapping table /// </summary> /// <param name="switchObj">the switch object</param> /// <returns>associated pCode</returns> private PCode getOnTrigger(IActuatorSwitch switchObj) { const string defaultWidgetClass = "default"; Log.Debug(); if (_switchConfig == null) { return(null); } // check local switchmap first PCode pCode = _switchConfig.GetOnTrigger(switchObj); if (pCode != null) { Log.Debug("Found local pcode for " + switchObj.Name); return(pCode); } Log.Debug("Did not find local switchconfig. Checking global one"); // if this panel is a member of a 'class' of panels(configured thru // the subclass attribute), check if there is a switch map for the class. // otherwise, just use the default one. var widgetClass = (_currentPanel != null) ? _currentPanel.SubClass : String.Empty; if (String.IsNullOrEmpty(widgetClass)) { widgetClass = defaultWidgetClass; } Log.Debug("widgetclass: " + widgetClass); SwitchConfig switchConfig = ActuatorManager.Instance.SwitchConfigMap; PCode retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); if (retVal != null) { return(retVal); } if (widgetClass != defaultWidgetClass) { Log.Debug("Could not find PCode for " + widgetClass + ", trying default"); widgetClass = defaultWidgetClass; retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); } Log.IsNull("retval ", retVal); return(retVal); }
/// <summary> /// Initializes the animation widget object /// </summary> public AnimationWidget() { _parser = new Parser(); OnSelect = new PCode(); OnBack = new PCode(); OnHighlightOn = new PCode(); OnHighlightOff = new PCode(); HesitateTime = CoreGlobals.AppPreferences.FirstPauseTime; CoreGlobals.AppPreferences.EvtPreferencesChanged += AppPreferences_EvtPreferencesChanged; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public WidgetAttribute() { FontName = CoreGlobals.AppPreferences.FontName; FontSize = CoreGlobals.AppPreferences.FontSize; FontBold = true; Name = String.Empty; Label = String.Empty; Value = String.Empty; Modifiers = null; MouseClickActuate = true; OnMouseClick = new PCode(); }
/// <summary> /// Initialzies an instance of the class /// </summary> public Animation() { _parser = new Parser(); Screen = String.Empty; Iterations = "1"; OnEnterExecutionNotDone = false; AnimationWidgetList = new List <AnimationWidget>(); OnEnd = new PCode(); OnSelect = new PCode(); OnEnter = new PCode(); SteppingTime = CoreGlobals.AppPreferences.ScanTime; HesitateTime = CoreGlobals.AppPreferences.FirstPauseTime; CoreGlobals.AppPreferences.EvtPreferencesChanged += AppPreferences_EvtPreferencesChanged; }
private void Email_OnKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { if (Phone.Visibility == Visibility.Visible) { PCode.Focus(); PCode.Select(PCode.Text.Length, 0); } else { ViewModel.Validate(); } } }
public SimObject AsObject(string fromName, UUID id, PCode isAvatar) { SimObject p = null; if (id != UUID.Zero) { SimObject obj = GetSimObjectFromUUID(id); if (obj != null) { return(obj); } } else { if (string.IsNullOrEmpty(fromName)) { return(null); } if (IsSystemName(fromName)) { return(null); } int au; List <SimObject> ps = GetSingleArg(new string[] { fromName }, out au); if (ps.Count == 1) { p = ps[0]; } } if (p != null) { return(p); } Object o = null; if (false && isAvatar == PCode.Avatar && !string.IsNullOrEmpty(fromName)) { if (!fromName.Contains(" ")) { isAvatar = PCode.Prim; } else { //isAvatar = PCode.UN; } } return(GetSource(client.Network.CurrentSim, id, null, ref o, isAvatar)); }
private void PhoneNumber_OnKeyDown(object sender, KeyEventArgs args) { if (args.Key == Key.D8 || args.Key == Key.Unknown || args.Key == Key.D3 || args.Key == Key.A || args.Key == Key.Space) { args.Handled = true; } if (args.Key == Key.Back && PhoneNumber.Text.Length == 0) { args.Handled = true; PCode.Focus(); PCode.Select(PCode.Text.Length, 0); } }
private void PhoneNumber_OnKeyDown(object sender, KeyEventArgs args) { if (args.Key == Key.D8 || //звёздочка args.Key == Key.Unknown || //плюс (долгий тап по 0), или чёрточка/точка args.Key == Key.D3 || //решётка args.Key == Key.A || args.Key == Key.Space) { args.Handled = true; } if (args.Key == Key.Back && PhoneNumber.Text.Length == 0) { args.Handled = true; PCode.Focus(); PCode.Select(PCode.Text.Length, 0); } }
private void PhoneNumber_OnKeyDown(object sender, KeyEventArgs args) { if (args.Key == Key.Enter) { ViewModel.Validate(); } if (args.Key == Key.D8 || // * args.Key == Key.Unknown || // +(long tap on 0) or -/. args.Key == Key.D3 || // # args.Key == Key.A || args.Key == Key.Space) { args.Handled = true; } if (args.Key == Key.Back && PhoneNumberLabel.Text.Length == 0) { args.Handled = true; PCode.Focus(); PCode.Select(PCode.Text.Length, 0); } }
unsafe void Parse(SR1_Reader reader, Event scriptEvent, ScriptType type, SR1_PrimativeArray <short> scriptData) { if ((reader.File._ImportFlags & SR1_File.ImportFlags.LogScripts) != 0) { try { string script = ""; short[] opCodes = new short[scriptData.Count]; int c = 0; foreach (short code in scriptData) { opCodes[c] = code; c++; } List <VarType> stack = new List <VarType>(); fixed(short *codeStreamStart = opCodes) { short *codeStream = codeStreamStart; c = 0; while (c < opCodes.Length) { PCode opcode = (PCode)(*codeStream - 1); int mathOp = _PCodes[(int)opcode].mathOp; int additionalBytes = 0; script += "\t\t"; if (mathOp > -1) { Operation operation = GetCompareOperationFromID(stack[stack.Count - 1], _PCodes[(int)opcode].mathOp, stack, codeStream); VarType param0VarType = stack[stack.Count - 2]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2); VarType param1VarType = stack[stack.Count - 1]; string param1 = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1); string result = "(" + _VarTypes[(int)operation.t] + ")"; script += "object var" + stack.Count + " = " + result + operation.n + "(" + param0 + ", " + param1 + ")"; stack.Add(operation.t); } else if (opcode == PCode.AddObjectToStack) { int param = *(codeStream + 1); EventBaseObject scriptEventInstance = (EventBaseObject)scriptEvent.instances[param]; VarType param0Type = GetVarType_AddObjectToStack(scriptEventInstance, stack, codeStream); string param0 = "(" + _VarTypes[(int)param0Type] + ")instances[" + param.ToString() + "]"; script += "object var" + stack.Count + " = " + param0; stack.Add(param0Type); } else if (opcode == PCode.AddPlayerObjectToStack) { int param = *(codeStream + 1); VarType param0Type = VarType.InstanceObject; string param0 = "(" + _VarTypes[(int)param0Type] + ")gameTrackerX.playerInstance"; script += "object var" + stack.Count + " = " + param0; stack.Add(param0Type); } else if (opcode == PCode.ModifyObjectToStackWithAttribute) { int param = *(codeStream + 1); Operation operation = GetTranformOperationFromID(stack[stack.Count - 1], param, stack, codeStream); VarType param0VarType = stack[stack.Count - 1]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 1); string result = "(" + _VarTypes[(int)operation.t] + ")"; if (operation.t != VarType.None) { script += "var" + (stack.Count - 1) + " = " + result; } if (param0VarType == VarType.EventObject) { // SavedEvent and SavedEventSmallVars both inherit from SavedBasic. // Hopefully the opcodes don't care where these come from and behave the same as local events. if (operation.p == 1) { string param1 = (*(codeStream + 2)).ToString(); script += operation.n + "(" + param0 + ", " + param1 + ")"; additionalBytes++; } else { script += operation.n + "(" + param0 + ")"; } } else { script += operation.n + "(" + param0 + ")"; } if (operation.t != VarType.None) { stack[stack.Count - 1] = operation.t; } } else if (opcode == PCode.AddNumberToStack) { int param = *(codeStream + 1); VarType param0Type = VarType.Number; string param0 = "(" + _VarTypes[(int)param0Type] + ")" + param.ToString(); script += "object var" + stack.Count + " = " + param0; stack.Add(VarType.Number); } else if (opcode == PCode.DoStackOperationEquals) { VarType param0VarType = stack[stack.Count - 2]; string param0 = "(" + _VarTypes[(int)param0VarType] + ")var" + (stack.Count - 2); VarType param1VarType = stack[stack.Count - 1]; string param1 = "(" + _VarTypes[(int)param1VarType] + ")var" + (stack.Count - 1); script += _PCodes[*codeStream - 1].n + "(" + param0 + ", " + param1 + ")"; } else if (opcode == PCode.Execute) { script += _PCodes[*codeStream - 1].n + "()"; stack.Clear(); } else { script += _PCodes[*codeStream - 1].n + "()"; } script += ";\r\n"; codeStream += _PCodes[*codeStream - 1].l; codeStream += additionalBytes; c += _PCodes[opCodes[c] - 1].l; c += additionalBytes; if (c < opCodes.Length && (opcode == PCode.Execute || opcode == PCode.EndConditional || opcode == PCode.EndAction || opcode == PCode.EndOfLine2)) { script += "\r\n"; } } reader.LogScript(script); } } catch { reader.LogScript("\t\t// Error reading " + type.ToString() + " script.\r\n"); } } }
/// <summary> /// A switch was activated. Figure out the context and execute the /// appropriate action. The input manager triggers this event. Every /// switch has an action that is configured in the swtichconfigmap file. /// The action is executed depending on the state of the animation player. /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void actuatorManager_EvtSwitchActivated(object sender, ActuatorSwitchEventArgs e) { IActuatorSwitch switchObj = e.SwitchObj; try { if (_player == null || _currentPanel == null) { return; } Log.Debug("switch: " + switchObj.Name); Log.Debug(" Panel: " + _currentPanel.Name); if (_currentPanel.UIControl is System.Windows.Forms.Form) { bool visible = Windows.GetVisible(_currentPanel.UIControl); Log.Debug("Form: " + _currentPanel.UIControl.Name + ", playerState: " + _player.State + ", visible: " + visible); if (!visible) { return; } } // get the action associated with the switch PCode onTrigger = getOnTrigger(switchObj); if (onTrigger == null) { Log.Debug("OnTrigger is null. returning"); return; } Log.Debug("onTrigger.HasCode: " + onTrigger.HasCode()); // execute action if the player is in the right state. if (_player.State != PlayerState.Stopped && _player.State != PlayerState.Unknown && _player.State != PlayerState.Paused && onTrigger.HasCode()) { Log.Debug("Executing OnTrigger for panel..." + _currentPanel.Name); _interpreter.Execute(onTrigger); return; } if (_player.State == PlayerState.Timeout || _player.State == PlayerState.Interrupted) { Log.Debug("Calling player transition for firstanimation"); _player.Transition(_firstAnimation); return; } Log.Debug("PLayer state is " + _player.State); if (_player.State != PlayerState.Running) { Log.Debug(_currentPanel.Name + ": Player is not Running. Returning"); return; } playBeep(switchObj); AnimationWidget highlightedWidget = _player.HighlightedWidget; Animation currentAnimation = _player.CurrentAnimation; highlightedWidget = _switchDownHighlightedWidget; currentAnimation = _switchDownAnimation; if (highlightedWidget == null) { highlightedWidget = _switchAcceptedHighlightedWidget; currentAnimation = _switchAcceptedAnimation; } if (highlightedWidget == null) { highlightedWidget = _player.HighlightedWidget; currentAnimation = _player.CurrentAnimation; } resetSwitchEventStates(); if (currentAnimation != null && highlightedWidget != null) { setSwitchState(false); var widgetName = (highlightedWidget.UIWidget is IButtonWidget) ? "Button" : highlightedWidget.UIWidget.Name; AuditLog.Audit(new AuditEventUISwitchDetect(switchObj.Name, _currentPanel.Name, highlightedWidget.UIWidget.GetType().Name, widgetName)); Log.Debug(_currentPanel.Name + ": Switch on " + highlightedWidget.UIWidget.Name + " type: " + highlightedWidget.UIWidget.GetType().Name); // check if the widget has a onSelect code fragment. If so execute it. Otherwise // then check if the animation seq that this widget is a part of, has a onSelect. // If it does, execute that. PCode code; SetSelectedWidget(highlightedWidget.UIWidget); if (highlightedWidget.OnSelect.HasCode()) { code = highlightedWidget.OnSelect; _interpreter.Execute(code); } else if (currentAnimation.OnSelect.HasCode()) { code = currentAnimation.OnSelect; _interpreter.Execute(code); } } else { Log.Debug(_currentPanel.Name + ": No current animation or highlighed widget!!"); } } catch (Exception ex) { Log.Debug(ex.ToString()); } finally { setSwitchState(false); } }
/// <summary> /// Initializes the object /// </summary> /// <param name="animationWidget">animation widget</param> /// <param name="onMouseClick">the code for handling the click</param> public AnimationMouseClickEventArgs(AnimationWidget animationWidget, PCode onMouseClick) { AnimationWidget = animationWidget; OnMouseClick = onMouseClick; }
private SimObject GetSource(Simulator sim, UUID sourceID, SimObject source, ref object s, PCode isAvatar) { if (source != null) { s = source; return(source); } source = GetSimObjectFromUUID(sourceID); if (source != null) { s = source; return(source); } //TODO can we ever find a Primitive we hadnt yet interned?! Primitive sp = null;// GetPrimitive(sourceID, null); if (sp != null) { source = GetSimObject(sp); } else { if (sim != null && !RequestParcelObjects) { RequestParcelObjects = true; client.Parcels.RequestAllSimParcels(sim, false, 250); client.Grid.RequestMapItems(sim.Handle, GridItemType.AgentLocations, GridLayerType.Objects); } switch (isAvatar) { case PCode.Tree: case PCode.Grass: case PCode.NewTree: case PCode.Prim: if (!CogbotHelpers.IsNullOrZero(sourceID)) { source = CreateSimObject(sourceID, this, null); } break; case PCode.Avatar: DeclareAvatar(sourceID); break; case PCode.None: case PCode.ParticleSystem: SourceDetect(sourceID); break; default: throw new ArgumentOutOfRangeException("isAvatar hint = " + isAvatar); } // client.Self.RequestSit(sourceID,Vector3.Zero); // client.Directory. } if (source != null) { s = source; } else { lock (AvatarRegion) if (AvatarRegion.ContainsKey(sourceID)) { Debug("found it!"); } else { lock (Name2Key) { foreach (KeyValuePair <string, UUID> key in Name2Key) { string name = key.Key; if (name.StartsWith("(")) { } if (key.Value == sourceID) { var list = SimAccounts.CopyOf(); foreach (SimAvatar set in list) { if (set.ID == sourceID) { s = source = set; return(source); } } foreach (SimAvatar set in list) { string n = set.GetName(); if (n != null && n.Equals(name)) { s = source = set; return(source); } } Debug("No avatar object for " + name); SimAvatar impl = CreateSimAvatar(key.Value, this, sim); impl.AspectName = name; s = source = impl; return(source); } } } } } if (isAvatar == PCode.Prim) { SimObject impl = CreateSimObject(sourceID, this, sim); s = source = impl; return(source); } if (s == null) { s = sourceID; } return(source); }
// Processes object update packets (Avatars and Objects entering drawing distance) private Packet ProcessObjectUpdate(Packet packet, IPEndPoint endpoint) { ObjectUpdatePacket update = (ObjectUpdatePacket)packet; for (int b = 0; b < update.ObjectData.Length; b++) { ObjectUpdatePacket.ObjectDataBlock block = update.ObjectData[b]; ObjectMovementUpdate objectupdate = new ObjectMovementUpdate(); NameValue[] nameValues; string firstname = ""; string lastname = ""; PCode pcode = (PCode)block.PCode; #region NameValue parsing string nameValue = Utils.BytesToString(block.NameValue); if (nameValue.Length > 0) { string[] lines = nameValue.Split('\n'); nameValues = new NameValue[lines.Length]; for (int i = 0; i < lines.Length; i++) { if (!String.IsNullOrEmpty(lines[i])) { NameValue nv = new NameValue(lines[i]); if (nv.Name == "FirstName") { firstname = nv.Value.ToString(); } if (nv.Name == "LastName") { lastname = nv.Value.ToString(); } nameValues[i] = nv; } } } else { nameValues = new NameValue[0]; } #endregion NameValue parsing #region Decode Object (primitive) parameters Primitive.ConstructionData data = new Primitive.ConstructionData(); data.State = block.State; data.Material = (Material)block.Material; data.PathCurve = (PathCurve)block.PathCurve; data.profileCurve = block.ProfileCurve; data.PathBegin = Primitive.UnpackBeginCut(block.PathBegin); data.PathEnd = Primitive.UnpackEndCut(block.PathEnd); data.PathScaleX = Primitive.UnpackPathScale(block.PathScaleX); data.PathScaleY = Primitive.UnpackPathScale(block.PathScaleY); data.PathShearX = Primitive.UnpackPathShear((sbyte)block.PathShearX); data.PathShearY = Primitive.UnpackPathShear((sbyte)block.PathShearY); data.PathTwist = Primitive.UnpackPathTwist(block.PathTwist); data.PathTwistBegin = Primitive.UnpackPathTwist(block.PathTwistBegin); data.PathRadiusOffset = Primitive.UnpackPathTwist(block.PathRadiusOffset); data.PathTaperX = Primitive.UnpackPathTaper(block.PathTaperX); data.PathTaperY = Primitive.UnpackPathTaper(block.PathTaperY); data.PathRevolutions = Primitive.UnpackPathRevolutions(block.PathRevolutions); data.PathSkew = Primitive.UnpackPathTwist(block.PathSkew); data.ProfileBegin = Primitive.UnpackBeginCut(block.ProfileBegin); data.ProfileEnd = Primitive.UnpackEndCut(block.ProfileEnd); data.ProfileHollow = Primitive.UnpackProfileHollow(block.ProfileHollow); data.PCode = pcode; #endregion #region Decode Additional packed parameters in ObjectData int pos = 0; switch (block.ObjectData.Length) { case 76: // Collision normal for avatar objectupdate.CollisionPlane = new Vector4(block.ObjectData, pos); pos += 16; goto case 60; case 60: // Position objectupdate.Position = new Vector3(block.ObjectData, pos); pos += 12; // Velocity objectupdate.Velocity = new Vector3(block.ObjectData, pos); pos += 12; // Acceleration objectupdate.Acceleration = new Vector3(block.ObjectData, pos); pos += 12; // Rotation (theta) objectupdate.Rotation = new Quaternion(block.ObjectData, pos, true); pos += 12; // Angular velocity (omega) objectupdate.AngularVelocity = new Vector3(block.ObjectData, pos); pos += 12; break; case 48: // Collision normal for avatar objectupdate.CollisionPlane = new Vector4(block.ObjectData, pos); pos += 16; goto case 32; case 32: // The data is an array of unsigned shorts // Position objectupdate.Position = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -0.5f * 256.0f, 1.5f * 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -0.5f * 256.0f, 1.5f * 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 3.0f * 256.0f)); pos += 6; // Velocity objectupdate.Velocity = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; // Acceleration objectupdate.Acceleration = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; // Rotation (theta) objectupdate.Rotation = new Quaternion( Utils.UInt16ToFloat(block.ObjectData, pos, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 6, -1.0f, 1.0f)); pos += 8; // Angular velocity (omega) objectupdate.AngularVelocity = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; break; case 16: // The data is an array of single bytes (8-bit numbers) // Position objectupdate.Position = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Velocity objectupdate.Velocity = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Accleration objectupdate.Acceleration = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Rotation objectupdate.Rotation = new Quaternion( Utils.ByteToFloat(block.ObjectData, pos, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 3, -1.0f, 1.0f)); pos += 4; // Angular Velocity objectupdate.AngularVelocity = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; break; default: SayToUser("ERROR: Got an ObjectUpdate block with ObjectUpdate field length of " + block.ObjectData.Length); continue; } #endregion // Determine the object type and create the appropriate class switch (pcode) { #region Prim and Foliage case PCode.Grass: case PCode.Tree: case PCode.NewTree: case PCode.Prim: break; #endregion Prim and Foliage #region Avatar case PCode.Avatar: if (block.FullID == this.frame.AgentID) { mylocalid = block.ID; StatusSetLocalID(mylocalid.ToString()); } #region Create an Avatar from the decoded data Avatar avatar = new Avatar(); if (Avatars.ContainsKey(block.ID)) { avatar = Avatars[block.ID]; } objectupdate.Avatar = true; // Textures objectupdate.Textures = new Primitive.TextureEntry(block.TextureEntry, 0, block.TextureEntry.Length); uint oldSeatID = avatar.ParentID; avatar.ID = block.FullID; avatar.LocalID = block.ID; avatar.CollisionPlane = objectupdate.CollisionPlane; avatar.Position = objectupdate.Position; avatar.Velocity = objectupdate.Velocity; avatar.Acceleration = objectupdate.Acceleration; avatar.Rotation = objectupdate.Rotation; avatar.AngularVelocity = objectupdate.AngularVelocity; avatar.NameValues = nameValues; avatar.PrimData = data; if (block.Data.Length > 0) { SayToUser("ERROR: Unexpected Data field for an avatar update, length " + block.Data.Length); } avatar.ParentID = block.ParentID; avatar.RegionHandle = update.RegionData.RegionHandle; // Textures avatar.Textures = objectupdate.Textures; // Save the avatar lock (Avatars) Avatars[block.ID] = avatar; // Fill up the translation dictionaries lock (AvatarIDtoUUID) AvatarIDtoUUID[block.ID] = block.FullID; lock (AvatarUUIDtoID) AvatarUUIDtoID[block.FullID] = block.ID; lock (AvatarUUIDToName) AvatarUUIDToName[block.FullID] = firstname + " " + lastname; lock (AvatarNameToUUID) AvatarNameToUUID[firstname + " " + lastname] = block.FullID; #endregion Create an Avatar from the decoded data break; #endregion Avatar case PCode.ParticleSystem: // ConsoleWriteLine("ERROR: Got a particle system update."); // // TODO: Create a callback for particle updates break; default: SayToUser("ERROR: Got an ObjectUpdate block with an unrecognized PCode " + pcode.ToString()); break; } } return(packet); }
private SimObject GetSource(Simulator sim, UUID sourceID, SimObject source, ref object s, PCode isAvatar) { if (source != null) { s = source; return source; } source = GetSimObjectFromUUID(sourceID); if (source != null) { s = source; return source; } //TODO can we ever find a Primitive we hadnt yet interned?! Primitive sp = null;// GetPrimitive(sourceID, null); if (sp != null) { source = GetSimObject(sp); } else { if (sim != null && !RequestParcelObjects) { RequestParcelObjects = true; client.Parcels.RequestAllSimParcels(sim, false, 250); client.Grid.RequestMapItems(sim.Handle, GridItemType.AgentLocations, GridLayerType.Objects); } switch (isAvatar) { case PCode.Tree: case PCode.Grass: case PCode.NewTree: case PCode.Prim: if (!CogbotHelpers.IsNullOrZero(sourceID)) { source = CreateSimObject(sourceID, this, null); } break; case PCode.Avatar: DeclareAvatar(sourceID); break; case PCode.None: case PCode.ParticleSystem: SourceDetect(sourceID); break; default: throw new ArgumentOutOfRangeException("isAvatar hint = " + isAvatar); } // client.Self.RequestSit(sourceID,Vector3.Zero); // client.Directory. } if (source != null) { s = source; } else { lock (AvatarRegion) if (AvatarRegion.ContainsKey(sourceID)) { Debug("found it!"); } else { lock (Name2Key) { foreach (KeyValuePair<string, UUID> key in Name2Key) { string name = key.Key; if (name.StartsWith("(")) { } if (key.Value == sourceID) { var list = SimAccounts.CopyOf(); foreach (SimAvatar set in list) { if (set.ID == sourceID) { s = source = set; return source; } } foreach (SimAvatar set in list) { string n = set.GetName(); if (n != null && n.Equals(name)) { s = source = set; return source; } } Debug("No avatar object for " + name); SimAvatar impl = CreateSimAvatar(key.Value, this, sim); impl.AspectName = name; s = source = impl; return source; } } } } } if (isAvatar == PCode.Prim) { SimObject impl = CreateSimObject(sourceID, this, sim); s = source = impl; return source; } if (s == null) { s = sourceID; } return source; }
/// <summary> /// Process an incoming effect /// </summary> private void ViewerEffectHandler(object sender, PacketReceivedEventArgs e) { Simulator simulator = e.Simulator; var packet = e.Packet; if (!IsMaster(simulator)) { return; } if (simulator != client.Network.CurrentSim) { //Debug("ViewerEffectHandler: from a differnt sim than current " + simulator); } if (!MaintainEffects) { return; } ViewerEffectPacket effect = (ViewerEffectPacket)packet; GridClient Client = client; foreach (ViewerEffectPacket.EffectBlock block in effect.Effect) { EffectType type = (EffectType)block.Type; // most effect types have at least these properties UUID sourceAvatar = CogbotHelpers.GetUUID(block.TypeData, 0); UUID targetObject = CogbotHelpers.GetUUID(block.TypeData, 16); Vector3d targetPos = new Vector3d(block.TypeData, 32); //Color4 color; //if (block.Color.Length == 4) //{ // color = new Color4(block.Color, 0); //} //else //{ // Client.Log("Received a ViewerEffect.EffectBlock.Color array with " + block.Color.Length + // " bytes", Helpers.LogLevel.Warning); // color = Color4.Black; //} if (sourceAvatar == UUID.Zero) { var ag1 = Client.Self.AgentID; var ag2 = block.AgentID; var ag3 = effect.AgentData.AgentID; Debug("Received a " + type.ToString() + " ViewerEffect sourceAvatar==NULL " + targetObject + " " + GetObject(ag1) + " " + GetObject(ag2) + " " + GetObject(ag3), Helpers.LogLevel.Warning, Client); } // Each ViewerEffect type uses it's own custom binary format for additional BVHData. Fun eh? switch (type) { case EffectType.Beam: case EffectType.Point: case EffectType.Trail: case EffectType.Sphere: case EffectType.Spiral: case EffectType.Edit: // if (Avatars_OnEffect != null) { if (block.TypeData.Length == 56) { PCode sourceType = PCode.Avatar; if (type == EffectType.Edit || type == EffectType.Point || type == EffectType.Beam) { sourceType = PCode.Avatar; } try { SendEffect(simulator, sourceAvatar, targetObject, targetPos, "EffectType-" + type.ToString(), block.Duration, block.ID, sourceType); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } } else { Debug("ERROR: Received a " + type.ToString() + " ViewerEffect with an incorrect TypeData size of " + block.TypeData.Length + " bytes", Helpers.LogLevel.Warning, Client); } return; } break; case EffectType.LookAt: //if (OnLookAt != null) { if (block.TypeData.Length == 57) { LookAtType lookAt = (LookAtType)block.TypeData[56]; try { SendEffect(simulator, sourceAvatar, targetObject, targetPos, "LookAtType-" + lookAt.ToString(), block.Duration, block.ID, PCode.Avatar); } catch (Exception ex) { Debug(ex.Message, Helpers.LogLevel.Error, Client, ex); } return; } else { Debug("Received a LookAt ViewerEffect with an incorrect TypeData size of " + block.TypeData.Length + " bytes", Helpers.LogLevel.Warning, Client); } } break; case EffectType.PointAt: // if (Avatars_OnPointAt != null) { if (block.TypeData.Length == 57) { PointAtType pointAt = (PointAtType)block.TypeData[56]; try { SendEffect(simulator, sourceAvatar, targetObject, targetPos, "PointAtType-" + pointAt.ToString(), block.Duration, block.ID, PCode.Avatar); } catch (Exception ex) { Debug(ex.Message, Helpers.LogLevel.Error, Client, ex); } return; } else { Debug("Received a PointAt ViewerEffect with an incorrect TypeData size of " + block.TypeData.Length + " bytes", Helpers.LogLevel.Warning, Client); } } break; case EffectType.Text: case EffectType.Icon: case EffectType.Connector: case EffectType.FlexibleObject: case EffectType.AnimalControls: case EffectType.AnimationObject: case EffectType.Cloth: case EffectType.Glow: default: SendNewRegionEvent(SimEventType.EFFECT, "OnViewerEffect", type, sourceAvatar, targetObject, targetPos); break; } SendEffect(simulator, sourceAvatar, targetObject, targetPos, "EffectType." + type, 0.1f, block.ID, PCode.None); } }
/// <summary> /// /// </summary> public PrimObject(SecondLife client) { Client = client; PCode = PCode.Prim; Textures = new TextureEntry(); }
/// <summary> /// Creates HashCode for use in equality comparison /// </summary> public override int GetHashCode() { string location = $"{Country ?? ""}{State ?? ""}{County ?? ""}{City ?? ""}{PostalCode ?? ""}{StreetAddress ?? ""}{FipsCode ?? ""}{PCode.GetHashCode()}{NpaNxx.GetHashCode()}"; return(location.GetHashCode()); }
void ObjectAddHandler(Packet packet, Agent agent) { ObjectAddPacket add = (ObjectAddPacket)packet; Vector3 position = Vector3.Zero; Vector3 scale = add.ObjectData.Scale; PCode pcode = (PCode)add.ObjectData.PCode; PrimFlags flags = (PrimFlags)add.ObjectData.AddFlags; bool bypassRaycast = (add.ObjectData.BypassRaycast == 1); bool rayEndIsIntersection = (add.ObjectData.RayEndIsIntersection == 1); #region Position Calculation if (rayEndIsIntersection) { // HACK: Blindly trust where the client tells us to place position = add.ObjectData.RayEnd; } else { if (add.ObjectData.RayTargetID != UUID.Zero) { SimulationObject obj; if (server.Scene.TryGetObject(add.ObjectData.RayTargetID, out obj)) { // Test for a collision with the specified object position = ObjectCollisionTest(add.ObjectData.RayStart, add.ObjectData.RayEnd, obj); } } if (position == Vector3.Zero) { // Test for a collision with the entire scene position = FullSceneCollisionTest(add.ObjectData.RayStart, add.ObjectData.RayEnd); } } // Position lies on the face of another surface, either terrain of an object. // Back up along the ray so we are not colliding with the mesh. // HACK: This is really cheesy and should be done by a collision system Vector3 rayDir = Vector3.Normalize(add.ObjectData.RayEnd - add.ObjectData.RayStart); position -= rayDir * scale; #endregion Position Calculation #region Foliage Handling // Set all foliage to phantom if (pcode == PCode.Grass || pcode == PCode.Tree || pcode == PCode.NewTree) { flags |= PrimFlags.Phantom; if (pcode != PCode.Grass) { // Resize based on the foliage type Tree tree = (Tree)add.ObjectData.State; switch (tree) { case Tree.Cypress1: case Tree.Cypress2: scale = new Vector3(4f, 4f, 10f); break; default: scale = new Vector3(4f, 4f, 4f); break; } } } #endregion Foliage Handling // Create an object Primitive prim = new Primitive(); prim.Flags = PrimFlags.ObjectModify | PrimFlags.ObjectCopy | PrimFlags.ObjectAnyOwner | PrimFlags.ObjectMove | PrimFlags.ObjectTransfer | PrimFlags.ObjectOwnerModify; // TODO: Security check prim.GroupID = add.AgentData.GroupID; prim.ID = UUID.Random(); prim.MediaURL = String.Empty; prim.OwnerID = agent.AgentID; prim.Position = position; prim.PrimData.Material = (Material)add.ObjectData.Material; prim.PrimData.PathCurve = (PathCurve)add.ObjectData.PathCurve; prim.PrimData.ProfileCurve = (ProfileCurve)add.ObjectData.ProfileCurve; prim.PrimData.PathBegin = Primitive.UnpackBeginCut(add.ObjectData.PathBegin); prim.PrimData.PathEnd = Primitive.UnpackEndCut(add.ObjectData.PathEnd); prim.PrimData.PathScaleX = Primitive.UnpackPathScale(add.ObjectData.PathScaleX); prim.PrimData.PathScaleY = Primitive.UnpackPathScale(add.ObjectData.PathScaleY); prim.PrimData.PathShearX = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearX); prim.PrimData.PathShearY = Primitive.UnpackPathShear((sbyte)add.ObjectData.PathShearY); prim.PrimData.PathTwist = Primitive.UnpackPathTwist(add.ObjectData.PathTwist); prim.PrimData.PathTwistBegin = Primitive.UnpackPathTwist(add.ObjectData.PathTwistBegin); prim.PrimData.PathRadiusOffset = Primitive.UnpackPathTwist(add.ObjectData.PathRadiusOffset); prim.PrimData.PathTaperX = Primitive.UnpackPathTaper(add.ObjectData.PathTaperX); prim.PrimData.PathTaperY = Primitive.UnpackPathTaper(add.ObjectData.PathTaperY); prim.PrimData.PathRevolutions = Primitive.UnpackPathRevolutions(add.ObjectData.PathRevolutions); prim.PrimData.PathSkew = Primitive.UnpackPathTwist(add.ObjectData.PathSkew); prim.PrimData.ProfileBegin = Primitive.UnpackBeginCut(add.ObjectData.ProfileBegin); prim.PrimData.ProfileEnd = Primitive.UnpackEndCut(add.ObjectData.ProfileEnd); prim.PrimData.ProfileHollow = Primitive.UnpackProfileHollow(add.ObjectData.ProfileHollow); prim.PrimData.PCode = pcode; prim.Properties.CreationDate = DateTime.Now; prim.Properties.CreatorID = agent.AgentID; prim.Properties.Description = String.Empty; prim.Properties.GroupID = add.AgentData.GroupID; prim.Properties.LastOwnerID = agent.AgentID; prim.Properties.Name = "New Object"; prim.Properties.ObjectID = prim.ID; prim.Properties.OwnerID = prim.OwnerID; prim.Properties.Permissions = Permissions.FullPermissions; prim.Properties.SalePrice = 10; prim.RegionHandle = server.RegionHandle; prim.Rotation = add.ObjectData.Rotation; prim.Scale = scale; prim.Textures = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE); prim.TextColor = Color4.Black; // Add this prim to the object database SimulationObject simObj = new SimulationObject(prim, server); server.Scene.ObjectAdd(this, agent, simObj, flags); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public SwitchElement() { OnTrigger = null; SwitchName = String.Empty; _parser = new Parser(); }
public SimObject AsObject(string fromName, UUID id, PCode isAvatar) { SimObject p = null; if (id != UUID.Zero) { SimObject obj = GetSimObjectFromUUID(id); if (obj != null) return obj; } else { if (string.IsNullOrEmpty(fromName)) return null; if (IsSystemName(fromName)) return null; int au; List<SimObject> ps = GetSingleArg(new string[] { fromName }, out au); if (ps.Count == 1) p = ps[0]; } if (p != null) return p; Object o = null; if (false && isAvatar == PCode.Avatar && !string.IsNullOrEmpty(fromName)) { if (!fromName.Contains(" ")) { isAvatar = PCode.Prim; } else { //isAvatar = PCode.UN; } } return GetSource(client.Network.CurrentSim, id, null, ref o, isAvatar); }
public void SendEffect(Simulator sim, UUID sourceID, UUID targetID, Vector3d targetPos, string effectType, float duration, UUID id, PCode sourceType) { if (!MaintainEffects) return; if (sourceID == client.Self.AgentID) return; //not sending our own effects if (!IsMaster(sim)) return; if (MaintainOnlyMasterEffects && client.MasterKey != UUID.Zero) { if (!(client.MasterKey == targetID || sourceID == client.MasterKey)) return; } if (id != UUID.Zero) { // if (EffectsSent.Contains(id)) return; // EffectsSent.Add(id); } object s = sourceID; object t = targetID; object p = targetPos; //if (SkippedEffects.Contains(effectType)) return; SimObject source = GetSimObjectFromUUID(sourceID); if (source == null) { if (sourceID != UUID.Zero) { source = GetSource(sim, sourceID, source, ref s, sourceType); if (source == null) return; } // RequestAsset(sourceID, AssetType.Object, true); } else { s = source; } if (source is SimObjectImpl && !(source is SimAvatar)) { Debug("Write source is Object " + source); } SimObject target = GetSimObjectFromUUID(targetID); if (target == null) { if (targetID != UUID.Zero) { target = GetSource(sim, targetID, target, ref t, PCode.None); if (target == null) return; } // RequestAsset(targetID, AssetType.Object, true); } else { t = target; } double dist; SimObject ST = target; if (ST == null) ST = source; if (targetPos.X < 256) { if (targetPos == Vector3d.Zero) { p = SimHeading.UNKNOWN; } else { if (ST != null) { Vector3d STGlobalPosition; if (ST.TryGetGlobalPosition(out STGlobalPosition)) p = (STGlobalPosition + targetPos); else { p = AsRLocation(sim, targetPos, ST); } } else { p = new Vector3((float) targetPos.X, (float) targetPos.Y, (float) targetPos.Z); } } } else { SimObject posTarget = GetSimObjectFromVector(targetPos, out dist); if (dist < 0.5) { p = posTarget; if (targetID == UUID.Zero) { // now we have a target t = posTarget; // todo should we revert back to position? //p = targetPos; } } else { if (targetID == UUID.Zero) { // now we have a target t = targetPos; // todo should we revert back to position? //p = targetPos; } } } EventQueue.Enqueue(() => { source = SecondChanceUUID(ref s, source); target = SecondChanceUUID(ref t, target); //if (source != null) source; // WriteLine("ClientManager Avatars_OnLookAt: " + sourceID.ToString() + " to " + targetID.ToString() + " at " + targetID.ToString() + " with type " + lookType.ToString() + " duration " + duration.ToString()); if (targetID == client.Self.AgentID) { // if (lookType == LookAtType.Idle) return; //WriteLine(" (TARGET IS SELF)"); client.SendPersonalEvent(SimEventType.EFFECT, "on-effect-targeted-self", ToParameter("doneBy", s), ToParameter("objectActedOn", TheSimAvatar), ToParameter("eventPartiallyOccursAt", p), ToParameter("simDuration", duration), ToParameter("effectType", effectType)); // ()/*GetObject*/(sourceID), effectType); } if (source != null) { source.OnEffect(client, effectType, t, p, duration, id); } else { CogbotEvent evt = ACogbotEvent.CreateEvent(client, effectType, SimEventType.Once | SimEventType.EFFECT | SimEventType.REGIONAL, ToParameter("doneBy", s), ToParameter("objectActedOn", t), ToParameter( "eventPartiallyOccursAt", p), ToParameter("simDuration", duration), AsEffectID(id)); if (t is SimObject) { ((SimObject) t).AddCanBeTargetOf(2, evt); } RegisterUUID(id, effectType); //TODO if (UseEventSource(s) || UseEventSource(t)) SendPipelineEvent(evt); //SendNewEvent("on-effect", effectType, s, t, p, duration, AsEffectID(id)); } }); }
/// <summary> /// Used for new prims, or significant changes to existing prims (From OpenMetaverse, with edits) /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> private Packet UpdateHandler(Packet packet, IPEndPoint simulator) { ObjectUpdatePacket update = (ObjectUpdatePacket)packet; //UpdateDilation(simulator, update.RegionData.TimeDilation); for (int b = 0; b < update.ObjectData.Length; b++) { ObjectUpdatePacket.ObjectDataBlock block = update.ObjectData[b]; if (block.FullID == frame.AgentID) { Vector4 collisionPlane = Vector4.Zero; Vector3 position; Vector3 velocity; Vector3 acceleration; Quaternion rotation; Vector3 angularVelocity; //NameValue[] nameValues; //bool attachment = false; PCode pcode = (PCode)block.PCode; #region Decode Additional packed parameters in ObjectData int pos = 0; switch (block.ObjectData.Length) { case 76: // Collision normal for avatar collisionPlane = new Vector4(block.ObjectData, pos); pos += 16; goto case 60; case 60: // Position position = new Vector3(block.ObjectData, pos); pos += 12; // Velocity velocity = new Vector3(block.ObjectData, pos); pos += 12; // Acceleration acceleration = new Vector3(block.ObjectData, pos); pos += 12; // Rotation (theta) rotation = new Quaternion(block.ObjectData, pos, true); pos += 12; // Angular velocity (omega) angularVelocity = new Vector3(block.ObjectData, pos); pos += 12; break; case 48: // Collision normal for avatar collisionPlane = new Vector4(block.ObjectData, pos); pos += 16; goto case 32; case 32: // The data is an array of unsigned shorts // Position position = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -0.5f * 256.0f, 1.5f * 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -0.5f * 256.0f, 1.5f * 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 3.0f * 256.0f)); pos += 6; // Velocity velocity = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; // Acceleration acceleration = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; // Rotation (theta) rotation = new Quaternion( Utils.UInt16ToFloat(block.ObjectData, pos, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -1.0f, 1.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 6, -1.0f, 1.0f)); pos += 8; // Angular velocity (omega) angularVelocity = new Vector3( Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f), Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f)); pos += 6; break; case 16: // The data is an array of single bytes (8-bit numbers) // Position position = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Velocity velocity = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Accleration acceleration = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; // Rotation rotation = new Quaternion( Utils.ByteToFloat(block.ObjectData, pos, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f), Utils.ByteToFloat(block.ObjectData, pos + 3, -1.0f, 1.0f)); pos += 4; // Angular Velocity angularVelocity = new Vector3( Utils.ByteToFloat(block.ObjectData, pos, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f), Utils.ByteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f)); pos += 3; break; default: //Logger.Log("Got an ObjectUpdate block with ObjectUpdate field length of " + //block.ObjectData.Length, Helpers.LogLevel.Warning, Client); continue; } #endregion mpos = position; //Console.WriteLine("mpos = " + mpos.ToString()); mid = block.ID; } } return(packet); }
private async void RunByStep(object sender, RoutedEventArgs e) { if (_firstStep) { var tmp = Path.GetTempFileName(); await File.WriteAllTextAsync(tmp, PCode.Text); Input.IsReadOnly = false; var buffer = new StringBuilder(); var stepOutput = ""; var curIns = ""; var pc = 0; _firstStep = false; await RunAsync( tmp, (_, e) => { // Console.Out.WriteLine(e.Data); if (e.Data?.StartsWith("**") ?? false) { var output = stepOutput; var ins = curIns; Dispatcher.Invoke(() => { Stack.Text = buffer.ToString(); Exec.Text += output; PCode.Focus(); //Console.Out.WriteLine(pc); if (pc == -99) { return; } var idx = PCode.GetCharacterIndexFromLineIndex(pc); PCode.Select(idx, ins.Length); }, DispatcherPriority.Render); buffer.Clear(); stepOutput = ""; curIns = ""; } else if (e.Data?.StartsWith("print") ?? false) { stepOutput = e.Data + "\n"; } else if (e.Data?.StartsWith("Press") ?? false) { // do nothing } else { if (e.Data?.StartsWith("-->") ?? false) { curIns = e.Data.Substring(9); // catch ins } if (e.Data?.StartsWith("PC =") ?? false) { Console.Out.WriteLine(e.Data.Substring(5)); pc = int.Parse(e.Data.Substring(5)); // catch PC } buffer.AppendLine(e.Data); } }, true ); } await(_inputWriter?.WriteLineAsync("c") ?? Task.FromResult(1)); }
/// <summary> /// /// </summary> /// <param name="texture"></param> public PrimObject(SecondLife client, LLUUID texture) { Client = client; PCode = PCode.Prim; Textures = new TextureEntry(); Textures.DefaultTexture.TextureID = texture; }
public override void Self_OnInstantMessage(object sender, InstantMessageEventArgs e) { var im = e.IM; if (im.FromAgentID != UUID.Zero) { AddName2Key(im.FromAgentName, im.FromAgentID); if (im.RegionID != UUID.Zero) { AvatarRegion[im.FromAgentID] = im.RegionID; Debug("Avatar region " + im.FromAgentName + " " + im.RegionID); } } bool Conference = false; bool GroupIM = im.GroupIM || client.Groups.GroupName2KeyCache.ContainsKey(im.IMSessionID); if (GroupIM) { DeclareGroup(im.IMSessionID); } if (im.Dialog == InstantMessageDialog.SessionSend) { if (!GroupIM) { Conference = true; } } PCode pcode = PCode.None; object s = im.FromAgentName; if (string.IsNullOrEmpty(im.FromAgentName) || im.FromAgentName == "Object" || !im.FromAgentName.Contains(" ")) { s = im.FromAgentID; pcode = PCode.Prim; } else { pcode = PCode.Avatar; } InstantMessageDialog d = im.Dialog; if (d == InstantMessageDialog.StartTyping || d == InstantMessageDialog.StopTyping) { pcode = PCode.Avatar; } if (!Conference && GroupIM) { //"recipientOfInfo-Intended"; } SimObject source = AsObject(im.FromAgentName, im.FromAgentID, pcode); if (source != null) { s = source; } object location = AsLocation(im.RegionID, im.Position); EventQueue.Enqueue(() => client.SendPersonalEvent(SimEventType.SOCIAL, "InstantMessageDialog-" + im.Dialog.ToString() + (GroupIM ? "-Group" : ""), ToParameter("senderOfInfo", s), ToParameter("infoTransferred-NLString", im.Message), ToParameter("recipientOfInfo-Intended", im.ToAgentID), im.Offline, im.IMSessionID, ToParameter("eventPrimarilyOccursAt", location), //(im.GroupIM ? "GroupIM" : ""), //im.Dialog, im.ParentEstateID)); }
public override void Self_OnChat(object sender, ChatEventArgs e) { var type = e.Type; var message = e.Message; var id = e.SourceID; var fromName = e.FromName; var sourceType = e.SourceType; var position = e.Position; var ownerid = e.OwnerID; var audible = e.AudibleLevel; PCode pCode = PCode.None; if (sourceType == ChatSourceType.Agent) { pCode = PCode.Avatar; } if (sourceType == ChatSourceType.Object) { pCode = PCode.Prim; } SimObject source = AsObject(fromName, id, pCode); object s1 = source; if (source == null) { s1 = id; } if (!string.IsNullOrEmpty(fromName)) { s1 = fromName; } if (source != null) { s1 = source; } object location = AsLocation(e.Simulator, position, source); if (ownerid != id) { SendNewRegionEvent(SimEventType.NETWORK, "Bug", "id!=ownerID?", "on-chat", message, audible, type, sourceType, fromName, id, ownerid, location); } if (type == ChatType.Normal || type == ChatType.Shout || type == ChatType.Whisper) { EventQueue.Enqueue(() => SendNewRegionEvent(SimEventType.SOCIAL, "ChatType-" + type.ToString(), ToParameter("senderOfInfo", s1), ToParameter("infoTransferred-NLString", message), audible, type, sourceType, ToParameter("eventPrimarilyOccursAt", location))); return; } if (string.IsNullOrEmpty(message)) { EventQueue.Enqueue( () => SendNewRegionEvent(SimEventType.SOCIAL, "ChatType-" + type.ToString(), audible, sourceType, type, ToParameter("senderOfInfo", s1), ToParameter("eventPrimarilyOccursAt", location))); return; } EventQueue.Enqueue(() => SendNewRegionEvent(SimEventType.SOCIAL, "ChatType-" + type.ToString(), ToParameter("senderOfInfo", s1), ToParameter("infoTransferred-NLString", message), audible, type, sourceType, ToParameter("eventPrimarilyOccursAt", location))); }
public void SendEffect(Simulator sim, UUID sourceID, UUID targetID, Vector3d targetPos, string effectType, float duration, UUID id, PCode sourceType) { if (!MaintainEffects) { return; } if (sourceID == client.Self.AgentID) { return; //not sending our own effects } if (!IsMaster(sim)) { return; } if (MaintainOnlyMasterEffects && client.MasterKey != UUID.Zero) { if (!(client.MasterKey == targetID || sourceID == client.MasterKey)) { return; } } if (id != UUID.Zero) { // if (EffectsSent.Contains(id)) return; // EffectsSent.Add(id); } object s = sourceID; object t = targetID; object p = targetPos; //if (SkippedEffects.Contains(effectType)) return; SimObject source = GetSimObjectFromUUID(sourceID); if (source == null) { if (sourceID != UUID.Zero) { source = GetSource(sim, sourceID, source, ref s, sourceType); if (source == null) { return; } } // RequestAsset(sourceID, AssetType.Object, true); } else { s = source; } if (source is SimObjectImpl && !(source is SimAvatar)) { Debug("Write source is Object " + source); } SimObject target = GetSimObjectFromUUID(targetID); if (target == null) { if (targetID != UUID.Zero) { target = GetSource(sim, targetID, target, ref t, PCode.None); if (target == null) { return; } } // RequestAsset(targetID, AssetType.Object, true); } else { t = target; } double dist; SimObject ST = target; if (ST == null) { ST = source; } if (targetPos.X < 256) { if (targetPos == Vector3d.Zero) { p = SimHeading.UNKNOWN; } else { if (ST != null) { Vector3d STGlobalPosition; if (ST.TryGetGlobalPosition(out STGlobalPosition)) { p = (STGlobalPosition + targetPos); } else { p = AsRLocation(sim, targetPos, ST); } } else { p = new Vector3((float)targetPos.X, (float)targetPos.Y, (float)targetPos.Z); } } } else { SimObject posTarget = GetSimObjectFromVector(targetPos, out dist); if (dist < 0.5) { p = posTarget; if (targetID == UUID.Zero) { // now we have a target t = posTarget; // todo should we revert back to position? //p = targetPos; } } else { if (targetID == UUID.Zero) { // now we have a target t = targetPos; // todo should we revert back to position? //p = targetPos; } } } EventQueue.Enqueue(() => { source = SecondChanceUUID(ref s, source); target = SecondChanceUUID(ref t, target); //if (source != null) source; // WriteLine("ClientManager Avatars_OnLookAt: " + sourceID.ToString() + " to " + targetID.ToString() + " at " + targetID.ToString() + " with type " + lookType.ToString() + " duration " + duration.ToString()); if (targetID == client.Self.AgentID) { // if (lookType == LookAtType.Idle) return; //WriteLine(" (TARGET IS SELF)"); client.SendPersonalEvent(SimEventType.EFFECT, "on-effect-targeted-self", ToParameter("doneBy", s), ToParameter("objectActedOn", TheSimAvatar), ToParameter("eventPartiallyOccursAt", p), ToParameter("simDuration", duration), ToParameter("effectType", effectType)); // ()/*GetObject*/(sourceID), effectType); } if (source != null) { source.OnEffect(client, effectType, t, p, duration, id); } else { CogbotEvent evt = ACogbotEvent.CreateEvent(client, effectType, SimEventType.Once | SimEventType.EFFECT | SimEventType.REGIONAL, ToParameter("doneBy", s), ToParameter("objectActedOn", t), ToParameter( "eventPartiallyOccursAt", p), ToParameter("simDuration", duration), AsEffectID(id)); if (t is SimObject) { ((SimObject)t).AddCanBeTargetOf(2, evt); } RegisterUUID(id, effectType); //TODO if (UseEventSource(s) || UseEventSource(t)) { SendPipelineEvent(evt); } //SendNewEvent("on-effect", effectType, s, t, p, duration, AsEffectID(id)); } }); }