public override void Update() { base.Update(); if (IsAttacking) { int attackTime = MySandboxGame.TotalGamePlayTimeInMilliseconds - m_attackStart; if (attackTime > ATTACK_LENGTH) { IsAttacking = false; MyCharacter botEntity = m_bot.AgentEntity; if (botEntity != null) { botEntity.EnableAnimationCommands(); } } else if (attackTime > 500 && m_bot.AgentEntity.UseNewAnimationSystem && !m_attackPerformed) { MySpiderLogic.TriggerAnimationEvent(m_bot.AgentEntity.EntityId, "attack"); if (Sync.IsServer) { MyMultiplayer.RaiseStaticEvent(x => MySpiderLogic.TriggerAnimationEvent, m_bot.AgentEntity.EntityId, "attack"); } m_attackPerformed = true; } else if (attackTime > 500 && !m_attackPerformed) { MyCharacter botEntity = m_bot.AgentEntity; if (botEntity != null) { Vector3D attackPosition = botEntity.WorldMatrix.Translation + botEntity.PositionComp.WorldMatrix.Forward * 2.5 + botEntity.PositionComp.WorldMatrix.Up * 1.0; m_attackBoundingSphere = new BoundingSphereD(attackPosition, 1.1); m_attackPerformed = true; List <MyEntity> hitEntities = MyEntities.GetTopMostEntitiesInSphere(ref m_attackBoundingSphere); foreach (var hitEntity in hitEntities) { //AttackEntity(hitEntity); if (hitEntity is MyCharacter && hitEntity != botEntity) { var character = hitEntity as MyCharacter; if (character.IsSitting) { continue; } var characterVolume = character.PositionComp.WorldVolume; double touchDistSq = m_attackBoundingSphere.Radius + characterVolume.Radius; touchDistSq = touchDistSq * touchDistSq; if (Vector3D.DistanceSquared(m_attackBoundingSphere.Center, characterVolume.Center) > touchDistSq) { continue; } if (character.IsDead) { var inventory = character.GetInventory(); if (inventory == null) { continue; } if (m_bot.AgentEntity == null) { continue; } var spiderInventory = m_bot.AgentEntity.GetInventory(); if (spiderInventory == null) { continue; } MyInventory.TransferAll(inventory, spiderInventory); } else { character.DoDamage(ATTACK_DAMAGE_TO_CHARACTER, MyDamageType.Bolt, updateSync: true, attackerId: botEntity.EntityId); } } else if (hitEntity is MyCubeGrid && hitEntity.Physics != null) { var grid = hitEntity as MyCubeGrid; m_tmpBlocks.Clear(); grid.GetBlocksInsideSphere(ref m_attackBoundingSphere, m_tmpBlocks); foreach (var block in m_tmpBlocks) { block.DoDamage(ATTACK_DAMAGE_TO_GRID, MyDamageType.Bolt); } m_tmpBlocks.Clear(); } } hitEntities.Clear(); } } if (attackTime > 500) { //MyRenderProxy.DebugDrawSphere(m_attackBoundingSphere.Center, (float)m_attackBoundingSphere.Radius, Color.Red, 1.0f, false); } } }
public void ChangeBlWl(bool IsWl) { MyMultiplayer.RaiseEvent(this, x => x.DoChangeBlWl, IsWl); }
void ChangeListType(byte type, bool wasAdded) { MyMultiplayer.RaiseEvent(this, x => x.DoChangeListType, type, wasAdded); }
public void RequestVoxelCutoutSphere(Vector3D center, float radius, bool createDebris, bool damage) { BeforeContentChanged = true; MyMultiplayer.RaiseEvent(RootVoxel, x => x.VoxelCutoutSphere_Implemenentation, center, radius, createDebris, damage); }
public void RequestVoxelOperationBox(BoundingBoxD box, MatrixD Transformation, byte material, OperationType Type) { BeforeContentChanged = true; MyMultiplayer.RaiseStaticEvent(s => VoxelOperationBox_Implementation, EntityId, box, Transformation, material, Type); }
/// <summary> /// Sends request to server to add item to queue. (Can be also called on server. In that case it will be local) /// </summary> /// <param name="blueprint"></param> /// <param name="ammount"></param> /// <param name="idx">idx - index to insert (-1 = last).</param> public void AddQueueItemRequest(MyBlueprintDefinitionBase blueprint, MyFixedPoint ammount, int idx = -1) { SerializableDefinitionId serializableId = blueprint.Id; MyMultiplayer.RaiseEvent(this, x => x.OnAddQueueItemRequest, idx, serializableId, ammount); }
/// <summary> /// Sends request to server to remove item from queue. (Can be also called on server. In that case it will be local) /// </summary> /// <param name="idx"></param> /// <param name="amount"></param> /// <param name="progress"></param> public void RemoveQueueItemRequest(int idx, MyFixedPoint amount, float progress = 0f) { MyMultiplayer.RaiseEvent(this, x => x.OnRemoveQueueItemRequest, idx, amount, progress); }
/// <summary> /// Transfers safely given item from inventory given as parameter to this instance. /// </summary> /// <returns>true if items were succesfully transfered, otherwise, false</returns> public override bool TransferItemsFrom(MyInventoryBase sourceInventory, IMyInventoryItem item, MyFixedPoint amount) { if (sourceInventory == null) { System.Diagnostics.Debug.Fail("Source inventory is null!"); return(false); } MyInventoryBase destinationInventory = this; if (destinationInventory == null) { System.Diagnostics.Debug.Fail("Destionation inventory is null!"); return(false); } if (item == null) { System.Diagnostics.Debug.Fail("Item is null!"); return(false); } if (amount == 0) { return(true); } bool transfered = false; if ((destinationInventory.ItemsCanBeAdded(amount, item) || destinationInventory == sourceInventory) && sourceInventory.ItemsCanBeRemoved(amount, item)) { if (Sync.IsServer) { if (destinationInventory != sourceInventory) { // try to add first and then remove to ensure this items don't disappear if (destinationInventory.Add(item, amount)) { if (sourceInventory.Remove(item, amount)) { // successfull transaction return(true); } else { // This can happend, that it can't be removed due to some lock, then we need to revert the add. destinationInventory.Remove(item, amount); } } } else { // same inventory transfer = splitting amount, need to remove first and add second if (sourceInventory.Remove(item, amount) && destinationInventory.Add(item, amount)) { return(true); } else { System.Diagnostics.Debug.Fail("Error! Unsuccesfull splitting!"); } } } else { Debug.Assert(sourceInventory != null); MyInventoryTransferEventContent eventParams = new MyInventoryTransferEventContent(); eventParams.Amount = amount; eventParams.ItemId = item.ItemId; eventParams.SourceOwnerId = sourceInventory.Entity.EntityId; eventParams.SourceInventoryId = sourceInventory.InventoryId; eventParams.DestinationOwnerId = destinationInventory.Entity.EntityId; eventParams.DestinationInventoryId = destinationInventory.InventoryId; MyMultiplayer.RaiseStaticEvent(s => InventoryBaseTransferItem_Implementation, eventParams); } } return(transfered); }
public override void ConsumeItem(MyDefinitionId itemId, MyFixedPoint amount, long consumerEntityId = 0) { SerializableDefinitionId serializableID = itemId; MyMultiplayer.RaiseEvent(this, x => x.InventoryConsumeItem_Implementation, amount, serializableID, consumerEntityId); }
public void SendCloseRequest() { MyMultiplayer.RaiseEvent(this, x => x.OnClosedRequest); }
private void RefreshMedicalRooms() { ulong playerSteamId = MySession.Static.LocalHumanPlayer != null ? MySession.Static.LocalHumanPlayer.Id.SteamId : Sync.MyId; MyMultiplayer.RaiseStaticEvent(s => RefreshMedicalRooms_Implementation, MySession.Static.LocalPlayerId, playerSteamId); }
private void StartBtn() { MyMultiplayer.RaiseEvent(this, x => x.Start); }
void OnShootOncePressed() { SyncRotationAndOrientation(); MyMultiplayer.RaiseEvent(this, x => x.ShootOncePressedEvent); }
private static void SendScriptRequest(MyStringHash stringId) { MyMultiplayer.RaiseStaticEvent(x => RunScriptRequest, stringId); }
void Sandbox.ModAPI.Ingame.IMyLargeTurretBase.SetTarget(Vector3D pos) { MyMultiplayer.RaiseEvent(this, x => x.SetTargetPosition, pos, Vector3.Zero, false); }
public override void HandleInput() { if (!m_isActive) { return; } if (!(MyScreenManager.GetScreenWithFocus() is MyGuiScreenGamePlay)) { return; } if (! (VRage.Input.MyInput.Static.ENABLE_DEVELOPER_KEYS || !MySession.Static.SurvivalMode || (MyMultiplayer.Static != null && MyMultiplayer.Static.IsAdmin(MySession.Static.LocalHumanPlayer.Id.SteamId))) ) { return; } base.HandleInput(); if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_PRESSED)) { m_startTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; } if (MyControllerHelper.IsControl(MySpaceBindingCreator.CX_CHARACTER, MyControlsSpace.PRIMARY_TOOL_ACTION, MyControlStateType.NEW_RELEASED)) { var gridBuilders = MyPrefabManager.Static.GetGridPrefab(CurrentDefinition.PrefabToThrow); Vector3D cameraPos = Vector3D.Zero; Vector3D cameraDir = Vector3D.Zero; if (USE_SPECTATOR_FOR_THROW) { cameraPos = MySpectator.Static.Position; cameraDir = MySpectator.Static.Orientation.Forward; } else { if (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity) { if (MySession.Static.ControlledEntity == null) { return; } cameraPos = MySession.Static.ControlledEntity.GetHeadMatrix(true, true).Translation; cameraDir = MySession.Static.ControlledEntity.GetHeadMatrix(true, true).Forward; } else { cameraPos = MySector.MainCamera.Position; cameraDir = MySector.MainCamera.WorldMatrix.Forward; } } var position = cameraPos + cameraDir; float deltaSeconds = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_startTime) / 1000.0f; float velocity = deltaSeconds / CurrentDefinition.PushTime * CurrentDefinition.MaxSpeed; velocity = MathHelper.Clamp(velocity, CurrentDefinition.MinSpeed, CurrentDefinition.MaxSpeed); var linearVelocity = cameraDir * velocity + MySession.Static.ControlledEntity.Entity.Physics.LinearVelocity; float mass = 0; if (CurrentDefinition.Mass.HasValue) { mass = Sandbox.Engine.Physics.MyDestructionHelper.MassToHavok(CurrentDefinition.Mass.Value); } gridBuilders[0].EntityId = MyEntityIdentifier.AllocateId(); MyMultiplayer.RaiseStaticEvent(s => MySessionComponentThrower.OnThrowMessageSuccess, gridBuilders[0], position, linearVelocity, mass, CurrentDefinition.ThrowSound); m_startTime = 0; } }
protected void InternalAddEntity( ) { try { if (AddEntityQueue.Count == 0) { return; } BaseEntity entityToAdd = AddEntityQueue.Dequeue( ); if (ExtenderOptions.IsDebugging) { ApplicationLog.BaseLog.Debug(String.Format("{0} '{1}': Adding to scene...", entityToAdd.GetType().Name, entityToAdd.DisplayName)); } //Create the backing object Type entityType = entityToAdd.GetType( ); Type internalType = (Type)BaseEntity.InvokeStaticMethod(entityType, "get_InternalType"); if (internalType == null) { throw new Exception("Could not get internal type of entity"); } entityToAdd.BackingObject = Activator.CreateInstance(internalType); //Add the backing object to the main game object manager //I don't think this is actually used anywhere? MyEntity backingObject = (MyEntity)entityToAdd.BackingObject; MyEntity newEntity = MyEntities.CreateFromObjectBuilderAndAdd(entityToAdd.ObjectBuilder); if (entityToAdd is FloatingObject) { try { //Broadcast the new entity to the clients MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( ); //TODO - Do stuff entityToAdd.ObjectBuilder = baseEntity; } catch (Exception ex) { ApplicationLog.BaseLog.Error("Failed to broadcast new floating object"); ApplicationLog.BaseLog.Error(ex); } } else { try { //Broadcast the new entity to the clients ApplicationLog.BaseLog.Info("Broadcasted entity to clients."); MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(newEntity)); //the misspelling in this function name is driving me i n s a n e } catch (Exception ex) { ApplicationLog.BaseLog.Error("Failed to broadcast new entity"); ApplicationLog.BaseLog.Error(ex); } } if (ExtenderOptions.IsDebugging) { Type type = entityToAdd.GetType( ); ApplicationLog.BaseLog.Debug(String.Format("{0} '{1}': Finished adding to scene", entityToAdd.GetType().Name, entityToAdd.DisplayName)); } } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } }
public static void RaiseStaticEvent<T1, T2, T3, T4, T5, T6>(MethodInfo method, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, EndpointId target = default(EndpointId), Vector3D? position = null) { var del = GetDelegate<IMyEventOwner, Action<T1, T2, T3, T4, T5, T6>>(method); MyMultiplayer.RaiseStaticEvent(del, arg1, arg2, arg3, arg4, arg5, arg6, target, position); }
/// <summary> /// Sends request to server to move queue item. (Can be also called on server. In that case it will be local) /// </summary> /// <param name="srcItemId"></param> /// <param name="dstIdx"></param> public void MoveQueueItemRequest(uint srcItemId, int dstIdx) { MyMultiplayer.RaiseEvent(this, x => x.OnMoveQueueItemCallback, srcItemId, dstIdx); }
public static void RaiseEvent<T1, T2>(T1 instance, MethodInfo method, T2 arg1, EndpointId target = default(EndpointId)) where T1 : IMyEventOwner { var del = GetDelegate<T1, Action<T2>> (method); MyMultiplayer.RaiseEvent(instance, del, arg1, target); }
public void CreateVoxelMeteorCrater(Vector3D center, float radius, Vector3 normal, MyVoxelMaterialDefinition material) { BeforeContentChanged = true; MyMultiplayer.RaiseEvent(RootVoxel, x => x.CreateVoxelMeteorCrater_Implementation, center, radius, normal, material.Index); }
public static void RaiseEvent<T1, T2, T3, T4, T5, T6, T7>(T1 instance, MethodInfo method, T2 arg1, T3 arg2, T4 arg3, T5 arg4, T6 arg5, T7 arg6, EndpointId target = default(EndpointId)) where T1 : IMyEventOwner { var del = GetDelegate<T1, Action<T2, T3, T4, T5, T6, T7>>(method); MyMultiplayer.RaiseEvent(instance, del, arg1, arg2, arg3, arg4, arg5, arg6, target); }
public void RequestVoxelOperationSphere(Vector3D center, float radius, byte material, OperationType Type) { BeforeContentChanged = true; MyMultiplayer.RaiseStaticEvent(s => VoxelOperationSphere_Implementation, EntityId, center, radius, material, Type); }
public static void RaiseStaticEvent<T1>(MethodInfo method, T1 arg1, EndpointId target = default(EndpointId), Vector3D? position = null) { var del = GetDelegate<IMyEventOwner, Action<T1>>(method); MyMultiplayer.RaiseStaticEvent(del, arg1, target, position); }
public void RequestVoxelOperationElipsoid(Vector3 radius, MatrixD Transformation, byte material, OperationType Type) { BeforeContentChanged = true; MyMultiplayer.RaiseStaticEvent(s => VoxelOperationElipsoid_Implementation, EntityId, radius, Transformation, material, Type); }
void Sandbox.ModAPI.Ingame.IMyLargeTurretBase.ResetTargetingToDefault() { MyMultiplayer.RaiseEvent(this, x => x.ResetTargetParams); }
void ChangeListId(SerializableDefinitionId id, bool wasAdded) { MyMultiplayer.RaiseEvent(this, x => x.DoChangeListId, id, wasAdded); }
void Sandbox.ModAPI.Ingame.IMyLargeTurretBase.TrackTarget(Vector3D pos, Vector3 velocity) { MyMultiplayer.RaiseEvent(this, x => x.SetTargetPosition, pos, velocity, true); }
void ModAPI.Ingame.IMyConveyorSorter.SetFilter(ModAPI.Ingame.MyConveyorSorterMode mode, List<ModAPI.Ingame.MyInventoryItemFilter> items) { // Update everyone else - except self MyMultiplayer.RaiseEvent(this, x => x.DoSetupFilter, mode, items); }
static MySoundBlock() { var volumeSlider = new MyTerminalControlSlider <MySoundBlock>("VolumeSlider", MySpaceTexts.BlockPropertyTitle_SoundBlockVolume, MySpaceTexts.BlockPropertyDescription_SoundBlockVolume); volumeSlider.SetLimits(0, 1.0f); volumeSlider.DefaultValue = 1; volumeSlider.Getter = (x) => x.Volume; volumeSlider.Setter = (x, v) => x.Volume = v; volumeSlider.Writer = (x, result) => result.AppendInt32((int)(x.Volume * 100.0)).Append(" %"); volumeSlider.EnableActions(); MyTerminalControlFactory.AddControl(volumeSlider); var rangeSlider = new MyTerminalControlSlider <MySoundBlock>("RangeSlider", MySpaceTexts.BlockPropertyTitle_SoundBlockRange, MySpaceTexts.BlockPropertyDescription_SoundBlockRange); rangeSlider.SetLimits(0, 500); rangeSlider.DefaultValue = 50; rangeSlider.Getter = (x) => x.Range; rangeSlider.Setter = (x, v) => x.Range = v; rangeSlider.Writer = (x, result) => result.AppendInt32((int)x.Range).Append(" m"); rangeSlider.EnableActions(); MyTerminalControlFactory.AddControl(rangeSlider); m_playButton = new MyTerminalControlButton <MySoundBlock>("PlaySound", MySpaceTexts.BlockPropertyTitle_SoundBlockPlay, MySpaceTexts.Blank, (x) => MyMultiplayer.RaiseEvent(x, y => y.PlaySound)); m_playButton.Enabled = (x) => x.IsSoundSelected; m_playButton.EnableAction(); MyTerminalControlFactory.AddControl(m_playButton); m_stopButton = new MyTerminalControlButton <MySoundBlock>("StopSound", MySpaceTexts.BlockPropertyTitle_SoundBlockStop, MySpaceTexts.Blank, (x) => { MyMultiplayer.RaiseEvent(x, y => y.StopSound); x.m_willStartSound = false; }); m_stopButton.Enabled = (x) => x.IsSoundSelected; m_stopButton.EnableAction(); MyTerminalControlFactory.AddControl(m_stopButton); m_loopableTimeSlider = new MyTerminalControlSlider <MySoundBlock>("LoopableSlider", MySpaceTexts.BlockPropertyTitle_SoundBlockLoopTime, MySpaceTexts.Blank); m_loopableTimeSlider.DefaultValue = 1f; m_loopableTimeSlider.Getter = (x) => x.LoopPeriod; m_loopableTimeSlider.Setter = (x, f) => x.LoopPeriod = f; m_loopableTimeSlider.Writer = (x, result) => MyValueFormatter.AppendTimeInBestUnit(x.LoopPeriod, result); m_loopableTimeSlider.Enabled = (x) => x.IsLoopable; m_loopableTimeSlider.Normalizer = (x, f) => x.NormalizeLoopPeriod(f); m_loopableTimeSlider.Denormalizer = (x, f) => x.DenormalizeLoopPeriod(f); m_loopableTimeSlider.EnableActions(); MyTerminalControlFactory.AddControl(m_loopableTimeSlider); var soundsList = new MyTerminalControlListbox <MySoundBlock>("SoundsList", MySpaceTexts.BlockPropertyTitle_SoundBlockSoundList, MySpaceTexts.Blank); soundsList.ListContent = (x, list1, list2) => x.FillListContent(list1, list2); soundsList.ItemSelected = (x, y) => x.SelectSound(y, true); MyTerminalControlFactory.AddControl(soundsList); }