private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial) { if (Sync.IsServer == false) { return; } ProfilerShort.Begin("SpawnOrePieces"); var forward = Vector3.Normalize(m_sensor.FrontPoint - m_sensor.Center); //var pos = m_sensor.CutOutSphere.Center + forward * m_floatingObjectSpawnOffset; var pos = hitPosition - forward * m_floatingObjectSpawnRadius; BoundingSphere bsphere = new BoundingSphere(pos, m_floatingObjectSpawnRadius); while (amountItems > 0) { //new: MyFixedPoint dropAmount = amountItems; //original: MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop); MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop); amountItems -= dropAmount; var inventoryItem = new MyPhysicalInventoryItem(dropAmount, oreObjBuilder); var item = MyFloatingObjects.Spawn(inventoryItem, bsphere, null, voxelMaterial); item.Physics.LinearVelocity = MyUtils.GetRandomVector3HemisphereNormalized(forward) * MyUtils.GetRandomFloat(1.5f, 4);//original speed 5-8 item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8); } ProfilerShort.End(); }
public static MyEntity SpawnRandomStaticSmall(Vector3 position) { string materialName = GetMaterialName(); MyPhysicalInventoryItem i = new MyPhysicalInventoryItem(4 * (MyFixedPoint)MyUtils.GetRandomFloat(0f, 100f), MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(materialName)); return(Spawn(ref i, position, Vector3.Zero)); }
private InventoryDeltaInformation WriteInventory(ref InventoryDeltaInformation packetInfo, BitStream stream, byte packetId, int maxBitPosition, out bool needsSplit) { InventoryDeltaInformation sendPacketInfo = PrepareSendData(ref packetInfo, stream, maxBitPosition, out needsSplit); if (sendPacketInfo.HasChanges == false) { stream.WriteBool(false); return(sendPacketInfo); } sendPacketInfo.MessageId = packetInfo.MessageId; stream.WriteBool(true); stream.WriteUInt32(sendPacketInfo.MessageId); stream.WriteBool(sendPacketInfo.ChangedItems != null); if (sendPacketInfo.ChangedItems != null) { stream.WriteInt32(sendPacketInfo.ChangedItems.Count); foreach (var item in sendPacketInfo.ChangedItems) { stream.WriteUInt32(item.Key); stream.WriteInt64(item.Value.RawValue); } } stream.WriteBool(sendPacketInfo.RemovedItems != null); if (sendPacketInfo.RemovedItems != null) { stream.WriteInt32(sendPacketInfo.RemovedItems.Count); foreach (var item in sendPacketInfo.RemovedItems) { stream.WriteUInt32(item); } } stream.WriteBool(sendPacketInfo.NewItems != null); if (sendPacketInfo.NewItems != null) { stream.WriteInt32(sendPacketInfo.NewItems.Count); foreach (var item in sendPacketInfo.NewItems) { stream.WriteInt32(item.Key); MyPhysicalInventoryItem itemTosend = item.Value; VRage.Serialization.MySerializer.Write(stream, ref itemTosend, MyObjectBuilderSerializer.Dynamic); } } stream.WriteBool(sendPacketInfo.SwappedItems != null); if (sendPacketInfo.SwappedItems != null) { stream.WriteInt32(sendPacketInfo.SwappedItems.Count); foreach (var item in sendPacketInfo.SwappedItems) { stream.WriteInt32(item.Key); stream.WriteInt32(item.Value); } } return(sendPacketInfo); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { var builder = objectBuilder as MyObjectBuilder_FloatingObject; if (builder.Item.Amount <= 0) { // I can only prevent creation of entity by throwing exception. This might cause crashes when thrown outside of MyEntities.CreateFromObjectBuilder(). throw new ArgumentOutOfRangeException("MyPhysicalInventoryItem.Amount", string.Format("Creating floating object with invalid amount: {0}x '{1}'", builder.Item.Amount, builder.Item.PhysicalContent.GetId())); } base.Init(objectBuilder); this.Item = new MyPhysicalInventoryItem(builder.Item); this.m_modelVariant = builder.ModelVariant; InitInternal(); NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; UseDamageSystem = true; if (!MyDefinitionManager.Static.TryGetPhysicalItemDefinition(Item.GetDefinitionId(), out m_itemDefinition)) { System.Diagnostics.Debug.Fail("Creating floating object, but it's physical item definition wasn't found! - " + Item.ItemId); } m_timeFromSpawn = MySession.Static.ElapsedPlayTime; }
public static void Spawn(MyPhysicalInventoryItem item, Vector3D position, Vector3D forward, Vector3D up, MyPhysicsComponentBase motionInheritedFrom = null, Action <MyEntity> completionCallback = null) { if (MyEntities.IsInsideWorld(position)) { Vector3D vectord = forward; Vector3D vectord2 = up; Vector3D vectord3 = Vector3D.Cross(up, forward); MyPhysicalItemDefinition definition = null; if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalItemDefinition>(item.Content.GetObjectId(), out definition)) { if (definition.RotateOnSpawnX) { vectord = up; vectord2 = -forward; } if (definition.RotateOnSpawnY) { vectord = vectord3; } if (definition.RotateOnSpawnZ) { vectord2 = -vectord3; } } Spawn(item, MatrixD.CreateWorld(position, vectord, vectord2), motionInheritedFrom, completionCallback); } }
public static MyEntity SpawnRandomLarge(Vector3 position, Vector3 direction) { string materialName = GetMaterialName(); MyPhysicalInventoryItem i = new MyPhysicalInventoryItem(400 * (MyFixedPoint)MyUtils.GetRandomFloat(0f, 25f), MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(materialName)); return(Spawn(ref i, position, direction * (MIN_SPEED + MyUtils.GetRandomInt(MIN_SPEED / 2)))); }
private void ConsumeFuel(ref MyDefinitionId gasTypeId, double iceAmount) { if (((Sync.IsServer && (base.CubeGrid.GridSystems.ControlSystem != null)) && (iceAmount > 0.0)) && !MySession.Static.CreativeMode) { List <MyPhysicalInventoryItem> items = this.GetInventory(0).GetItems(); if ((items.Count > 0) && (iceAmount > 0.0)) { int num = 0; while (num < items.Count) { MatrixD?nullable; MyPhysicalInventoryItem item = items[num]; if (item.Content is MyObjectBuilder_GasContainerObject) { num++; continue; } if (iceAmount < ((float)item.Amount)) { MyFixedPoint point = MyFixedPoint.Max((MyFixedPoint)iceAmount, MyFixedPoint.SmallestPossibleValue); nullable = null; this.GetInventory(0).RemoveItems(item.ItemId, new MyFixedPoint?(point), true, false, nullable); return; } iceAmount -= (float)item.Amount; MyFixedPoint?amount = null; nullable = null; this.GetInventory(0).RemoveItems(item.ItemId, amount, true, false, nullable); } } } }
private InventoryItem GetInventoryItem(MyPhysicalInventoryItem myItem) { return(new InventoryItem() { Amount = (int)myItem.Amount, Id = myItem.Content.GetId().ToDefinitionId(), }); }
private static MyObjectBuilder_Meteor PrepareBuilder(ref MyPhysicalInventoryItem item) { var meteorBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Meteor>(); meteorBuilder.Item = item.GetObjectBuilder(); meteorBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; return(meteorBuilder); }
public override bool ContainsOperatingItem(MyPhysicalInventoryItem item) { if (m_insertedItems == null) { return(false); } return(m_insertedItems.Contains(item)); }
public static AmountedDefinitionId ToAmountedDefinition(this MyPhysicalInventoryItem i) { return(new AmountedDefinitionId() { Amount = i.Amount.ToIntSafe(), Id = i.GetDefinitionId().ToDefinitionId(), }); }
public static MyEntity Spawn(ref MyPhysicalInventoryItem item, Vector3 position, Vector3 speed) { var builder = PrepareBuilder(ref item); var meteorEntity = MyEntities.CreateFromObjectBuilderNoinit(builder, false); MyEntities.CreateFromObjectBuilderParallel(builder, true, delegate() { SetSpawnSettings(meteorEntity, position, speed); }, meteorEntity); return(meteorEntity); }
public static void Spawn(this MyPhysicalInventoryItem thisItem, MyFixedPoint amount, BoundingBoxD box, MyEntity owner = null, Action <MyEntity> completionCallback = null) { if (amount >= 0) { MatrixD identity = MatrixD.Identity; identity.Translation = box.Center; thisItem.Spawn(amount, identity, owner, entity => InitSpawned(entity, box, completionCallback)); } }
public static InventoryItem ToInventoryItem(this MyPhysicalInventoryItem myItem) { return(new InventoryItem() { Amount = (int)myItem.Amount, Id = myItem.Content.GetId().ToDefinitionId(), ItemId = myItem.ItemId, }); }
private static MyObjectBuilder_FloatingObject PrepareBuilder(ref MyPhysicalInventoryItem item) { Debug.Assert(item.Amount > 0, "FloatObject item amount must be > 0"); var floatingBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_FloatingObject>(); floatingBuilder.Item = item.GetObjectBuilder(); floatingBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; return(floatingBuilder); }
protected IMyInventoryItem CreateInventoryItem(MyDefinitionId itemDefinition, MyFixedPoint amount) { var content = MyObjectBuilderSerializer.CreateNewObject(itemDefinition) as MyObjectBuilder_PhysicalObject; System.Diagnostics.Debug.Assert(content != null, "Can not create the requested type from definition!"); MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return(inventoryItem); }
protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount) { var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition }; MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return(inventoryItem); }
public static unsafe void AddFloatingObjectAmount(MyFloatingObject obj, MyFixedPoint amount) { MyPhysicalInventoryItem item = obj.Item; MyFixedPoint * pointPtr1 = (MyFixedPoint *)ref item.Amount; pointPtr1[0] += amount; obj.Item = item; obj.Amount.Value = item.Amount; obj.UpdateInternalState(); }
public static MyObjectBuilder_FloatingObject ChangeObjectBuilder(MyComponentDefinition componentDef, MyObjectBuilder_EntityBase entityOb) { MyObjectBuilder_PhysicalObject content = MyObjectBuilderSerializer.CreateNewObject(componentDef.Id.TypeId, componentDef.Id.SubtypeName) as MyObjectBuilder_PhysicalObject; Vector3D position = (Vector3D)entityOb.PositionAndOrientation.Value.Position; MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(1, content, 1f); MyObjectBuilder_FloatingObject obj1 = PrepareBuilder(ref item); obj1.PositionAndOrientation = new MyPositionAndOrientation(position, (Vector3)entityOb.PositionAndOrientation.Value.Forward, (Vector3)entityOb.PositionAndOrientation.Value.Up); obj1.EntityId = entityOb.EntityId; return(obj1); }
private void FormatDisplayName(StringBuilder outputBuffer, MyPhysicalInventoryItem item) { var definition = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content); outputBuffer.Clear().Append(definition.DisplayNameText); if (Item.Amount != 1) { outputBuffer.Append(" ("); MyGuiControlInventoryOwner.FormatItemAmount(item, outputBuffer); outputBuffer.Append(")"); } }
public static void FormatItemAmount(MyPhysicalInventoryItem item, StringBuilder text) { var typeId = item.Content.GetType(); double amount = (double)item.Amount; if (item.Content.GetType() == typeof(MyObjectBuilder_GasContainerObject) || item.Content.GetType().BaseType == typeof(MyObjectBuilder_GasContainerObject)) { amount = ((MyObjectBuilder_GasContainerObject)item.Content).GasLevel * 100f; } FormatItemAmount(typeId, amount, text); }
public static MyEntity Spawn(MyPhysicalInventoryItem item, MatrixD worldMatrix, MyPhysicsComponentBase motionInheritedFrom = null) { var floatingBuilder = PrepareBuilder(ref item); floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); var thrownEntity = MyEntities.CreateFromObjectBuilderAndAdd(floatingBuilder); thrownEntity.Physics.ForceActivate(); ApplyPhysics(thrownEntity, motionInheritedFrom); Debug.Assert(thrownEntity.Save == true, "Thrown item will not be saved. Feel free to ignore this."); return(thrownEntity); }
private static MyObjectBuilder_FloatingObject PrepareBuilder(ref MyPhysicalInventoryItem item) { MyObjectBuilder_FloatingObject local1 = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_FloatingObject>(); local1.Item = item.GetObjectBuilder(); MyPhysicalItemDefinition physicalItemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content); local1.ModelVariant = physicalItemDefinition.HasModelVariants ? MyUtils.GetRandomInt(physicalItemDefinition.Models.Length) : 0; MyObjectBuilder_FloatingObject local2 = local1; local2.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; return(local2); }
private void TransferFromItem(MyObjectBuilder_PhysicalObject item, int count) { MyInventory targetInventory = ((MyCubeBlock)m_constructionBlock.ConstructionBlock).GetInventory(); if (targetInventory.CanItemsBeAdded(count, item.GetId())) { targetInventory.AddItems(count, item); return; } var inventoryItem = new MyPhysicalInventoryItem(count, item); MyFloatingObjects.Spawn(inventoryItem, Vector3D.Transform(m_targetBlock.Position * m_targetBlock.CubeGrid.GridSize, m_targetBlock.CubeGrid.WorldMatrix), m_targetBlock.CubeGrid.WorldMatrix.Forward, m_targetBlock.CubeGrid.WorldMatrix.Up); }
public override MyFixedPoint GetOperatingItemRemovableAmount(MyPhysicalInventoryItem item) { var index = m_insertedItems.FindIndex(x => x.Content.GetId() == item.Content.GetId()); if (m_insertedItems.IsValidIndex(index)) { var itemAmount = m_insertedItems[index].Amount; if (index == 0 && m_insertedItemUseLevel > 0) { return(itemAmount - 1); } return(itemAmount); } return(0); }
/// <summary> /// This is used mainly for compactibility issues, it takes the builder of an entity of old object representation and creates a floating object builder for it /// </summary> public static MyObjectBuilder_FloatingObject ChangeObjectBuilder(MyComponentDefinition componentDef, MyObjectBuilder_EntityBase entityOb) { var componentBuilder = MyObjectBuilderSerializer.CreateNewObject(componentDef.Id.TypeId, componentDef.Id.SubtypeName) as MyObjectBuilder_PhysicalObject; Vector3 up = entityOb.PositionAndOrientation.Value.Up; Vector3 forward = entityOb.PositionAndOrientation.Value.Forward; Vector3D position = entityOb.PositionAndOrientation.Value.Position; var item = new MyPhysicalInventoryItem((MyFixedPoint)1, componentBuilder); var floatingBuilder = PrepareBuilder(ref item); floatingBuilder.PositionAndOrientation = new MyPositionAndOrientation(position, forward, up); floatingBuilder.EntityId = entityOb.EntityId; return(floatingBuilder); }
internal void CheckAmmoInventory(MyInventoryBase inventory, MyPhysicalInventoryItem item, MyFixedPoint amount) { try { if (amount <= 0 || item.Content == null || inventory == null) { return; } var itemDef = item.Content.GetObjectId(); if (Session.AmmoDefIds.Contains(itemDef)) { Construct.RootAi?.Construct.RecentItems.Add(itemDef); } } catch (Exception ex) { Log.Line($"Exception in CheckAmmoInventory: {ex} - BlockName:{((MyEntity)inventory?.Entity)?.DebugName} - BlockMarked:{((MyCubeBlock)inventory?.Entity)?.MarkedForClose} - aiMarked:{MarkedForClose} - gridMatch:{MyGrid == ((MyCubeBlock)inventory?.Entity)?.CubeGrid} - Session:{Session != null} - item:{item.Content?.SubtypeName} - RootConstruct:{Construct?.RootAi?.Construct != null}"); } }
private static MyObjectBuilder_FloatingObject PrepareBuilder(ref MyPhysicalInventoryItem item) { Debug.Assert(item.Amount > 0, "FloatObject item amount must be > 0"); Debug.Assert(item.Scale > 0, "FloatObject item scale must be > 0"); var floatingBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_FloatingObject>(); floatingBuilder.Item = item.GetObjectBuilder(); var itemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(item.Content); floatingBuilder.ModelVariant = itemDefinition.HasModelVariants ? MyUtils.GetRandomInt(itemDefinition.Models.Length) : 0; floatingBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; return(floatingBuilder); }
internal void CheckAmmoInventory(MyInventoryBase inventory, MyPhysicalInventoryItem item, MyFixedPoint amount) { try { if (amount <= 0 || item.Content == null || inventory == null) { return; } var itemDef = item.Content.GetObjectId(); if (Session.AmmoDefIds.Contains(itemDef)) { Construct.RootAi?.Construct.RecentItems.Add(itemDef); } } catch (Exception ex) { Log.Line($"Exception in CheckAmmoInventory: {ex}"); } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { var builder = objectBuilder as MyObjectBuilder_FloatingObject; if (builder.Item.Amount <= 0) { // I can only prevent creation of entity by throwing exception. This might cause crashes when thrown outside of MyEntities.CreateFromObjectBuilder(). throw new ArgumentOutOfRangeException("MyPhysicalInventoryItem.Amount", string.Format("Creating floating object with invalid amount: {0}x '{1}'", builder.Item.Amount, builder.Item.Content.GetId())); } base.Init(objectBuilder); this.Item = new MyPhysicalInventoryItem(builder.Item); InitInternal(); NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { Entity.SyncFlag = true; base.Init(objectBuilder); var builder = (MyObjectBuilder_Meteor)objectBuilder; Item = new MyPhysicalInventoryItem(builder.Item); m_particleEffectNames[(int)MeteorStatus.InAtmosphere] = "Meteory_Fire_Atmosphere"; m_particleEffectNames[(int)MeteorStatus.InSpace] = "Meteory_Fire_Space"; InitInternal(); Entity.Physics.LinearVelocity = builder.LinearVelocity; Entity.Physics.AngularVelocity = builder.AngularVelocity; m_integrity = builder.Integrity; }
public static MyEntity Spawn(ref MyPhysicalInventoryItem item, Vector3 position, Vector3 speed) { var builder = PrepareBuilder(ref item); var meteorEntity = MyEntities.CreateFromObjectBuilder(builder); Vector3 forward = -MySector.DirectionToSunNormalized; Vector3 up = MyUtils.GetRandomVector3Normalized(); while (forward == up) up = MyUtils.GetRandomVector3Normalized(); Vector3 right = Vector3.Cross(forward, up); up = Vector3.Cross(right, forward); meteorEntity.WorldMatrix = Matrix.CreateWorld(position, forward, up); MyEntities.Add(meteorEntity); meteorEntity.Physics.RigidBody.MaxLinearVelocity = 500; meteorEntity.Physics.LinearVelocity = speed; meteorEntity.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(1.5f, 3); return meteorEntity; }
public void Init(MyObjectBuilder_ConveyorPacket builder, MyEntity parent) { Item = new MyPhysicalInventoryItem(builder.Item); LinePosition = builder.LinePosition; var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content); var ore = Item.Content as MyObjectBuilder_Ore; string model = physicalItem.Model; float scale = 1.0f; if (ore != null) { foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions()) { if (mat.MinedOre == ore.SubtypeName) { model = MyDebris.GetRandomDebrisVoxel(); scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f); break; } } } if (scale < 0.05f) scale = 0.05f; else if (scale > 1.0f) scale = 1.0f; bool entityIdAllocationSuspended = MyEntityIdentifier.AllocationSuspended; MyEntityIdentifier.AllocationSuspended = false; Init(null, model, parent, null, null); MyEntityIdentifier.AllocationSuspended = entityIdAllocationSuspended; PositionComp.Scale = scale; // Packets are serialized by conveyor lines Save = false; }
protected void RemoveOperatingItem(MyPhysicalInventoryItem item, MyFixedPoint amount) { MyMultiplayer.RaiseEvent(this, x => x.RemoveOperatingItem_Request, item.GetObjectBuilder(), amount, m_lockedByEntityId); }
private bool ThrowFloatingObjectsFunc() { var view = MySession.Static.CameraController.GetViewMatrix(); var inv = Matrix.Invert(view); //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100, var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); var scrapBuilder = MyFloatingObject.ScrapBuilder; for (int i = 1; i <= 25; i++) { var item = new MyPhysicalInventoryItem((MyRandom.Instance.Next() % 200) + 1, oreBuilder); var obj = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * i * 1.0f, inv.Forward, inv.Up); obj.Physics.LinearVelocity = inv.Forward * 50; } Vector3D scrapPos = inv.Translation; scrapPos.X += 10; for (int i = 1; i <= 25; i++) { var item = new MyPhysicalInventoryItem((MyRandom.Instance.Next() % 200) + 1, scrapBuilder); var obj = MyFloatingObjects.Spawn(item, scrapPos + inv.Forward * i * 1.0f, inv.Forward, inv.Up); obj.Physics.LinearVelocity = inv.Forward * 50; } return true; }
public static bool ItemPushRequest(IMyConveyorEndpointBlock start, MyInventory srcInventory, long playerId, MyPhysicalInventoryItem toSend, MyFixedPoint? amount = null) { var itemBuilder = toSend.Content; if (amount.HasValue) Debug.Assert(toSend.Content.TypeId == typeof(MyObjectBuilder_Ore) || toSend.Content.TypeId == typeof(MyObjectBuilder_Ingot) || MyFixedPoint.Floor(amount.Value) == amount.Value); MyFixedPoint remainingAmount = toSend.Amount; if (amount.HasValue) { remainingAmount = amount.Value; } SetTraversalPlayerId(playerId); var toSendContentId = toSend.Content.GetId(); SetTraversalInventoryItemDefinitionId(toSendContentId); if (NeedsLargeTube(toSendContentId)) { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate, IsConveyorLargePredicate); } else { PrepareTraversal(start.ConveyorEndpoint, null, IsAccessAllowedPredicate); } bool success = false; foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding) { IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner; if (owner == null) continue; for (int i = 0; i < owner.InventoryCount; ++i) { var inventory = owner.GetInventory(i); if ((inventory.GetFlags() & MyInventoryFlags.CanReceive) == 0) continue; if (inventory == srcInventory) continue; var fittingAmount = inventory.ComputeAmountThatFits(toSendContentId); fittingAmount = MyFixedPoint.Min(fittingAmount, remainingAmount); if (!inventory.CheckConstraint(toSendContentId)) continue; if (fittingAmount == 0) continue; MyInventory.Transfer(srcInventory, inventory, toSend.ItemId, -1, fittingAmount); success = true; } } return success; }
public void AddItemClient(int position, MyPhysicalInventoryItem item) { if (Sync.IsServer) { return; } if (position >= m_items.Count) { m_items.Add(item); } else { m_items.Insert(position, item); } m_usedIds.Add(item.ItemId); NotifyHudChangedInventoryItem(item.Amount, ref item, true); }
private void NotifyHudChangedInventoryItem(MyFixedPoint amount, ref MyPhysicalInventoryItem newItem, bool added) { if (MyFakes.ENABLE_HUD_PICKED_UP_ITEMS && Entity != null && (Owner is MyCharacter) && MyHud.ChangedInventoryItems.Visible) // Only adding supported now { long localPlayerId = (Owner as MyCharacter).GetPlayerIdentityId(); if (localPlayerId == MySession.Static.LocalPlayerId) MyHud.ChangedInventoryItems.AddChangedPhysicalInventoryItem(newItem, amount, added); } }
public virtual bool ContainsOperatingItem(MyPhysicalInventoryItem item) { return false; }
public void Clear(bool sync = true) { if (sync == false) { m_items.Clear(); m_usedIds.Clear(); RefreshVolumeAndMass(); return; } MyPhysicalInventoryItem[] items = new MyPhysicalInventoryItem[m_items.Count]; m_items.CopyTo(items); foreach (var it in items) { RemoveItems(it.ItemId); } }
protected virtual void InsertOperatingItem_Implementation(MyPhysicalInventoryItem item) { }
protected virtual void RemoveOperatingItem_Implementation(MyPhysicalInventoryItem item, MyFixedPoint amount) { }
public InventoryItemWrapper( MyPhysicalInventoryItem item, MyInventory inventory ) { Item = item; Inventory = inventory; }
public static MyEntity SpawnRandomLarge(Vector3 position, Vector3 direction) { MyPhysicalInventoryItem i = new MyPhysicalInventoryItem(400 * (MyFixedPoint)MyUtils.GetRandomFloat(0f, 25f), MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone")); return Spawn(ref i, position, direction * (MIN_SPEED + MyUtils.GetRandomInt(MIN_SPEED / 2))); }
public override bool HandleInput() { bool handled = false; if (m_gridDebugInfo) { LineD line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 1000); MyCubeGrid grid; Vector3I cubePos; double distance; if (MyCubeGrid.GetLineIntersection(ref line, out grid, out cubePos, out distance)) { var gridMatrix = grid.WorldMatrix; var boxMatrix = Matrix.CreateTranslation(cubePos * grid.GridSize) * gridMatrix; var block = grid.GetCubeBlock(cubePos); MyRenderProxy.DebugDrawText2D(new Vector2(), cubePos.ToString(), Color.White, 0.7f); MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(new Vector3(grid.GridSize) + new Vector3(0.15f)) * boxMatrix, Color.Red.ToVector3(), 0.2f, true, true); //int[, ,] bones = grid.Skeleton.AddCubeBones(cubePos); //Vector3 closestBone = Vector3.Zero; //Vector3I closestPoint = Vector3I.Zero; //float closestPointDist = float.MaxValue; //int closestBoneIndex = 0; //for (int x = -1; x <= 1; x += 1) //{ // for (int y = -1; y <= 1; y += 1) // { // for (int z = -1; z <= 1; z += 1) // { // int boneIndex = bones[x + 1, y + 1, z + 1]; // Vector3 bone = grid.Skeleton[boneIndex]; // var pos = boxMatrix.Translation + new Vector3(grid.GridSize / 2) * new Vector3(x, y, z); // //MyRenderProxy.DebugDrawSphere(pos, 0.2f, Color.Blue.ToVector3(), 1.0f, false); // MyRenderProxy.DebugDrawText3D(pos, String.Format("{0:G2}, {1:G2}, {2:G2}", bone.X, bone.Y, bone.Z), Color.White, 0.5f, false); // var dist = MyUtils.GetPointLineDistance(ref line, ref pos); // if (dist < closestPointDist) // { // closestPointDist = dist; // closestPoint = new Vector3I(x, y, z); // closestBoneIndex = boneIndex; // closestBone = bone; // } // } // } //} //MyRenderProxy.DebugDrawText3D(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f, String.Format("{0:G2}, {1:G2}, {2:G2}", closestBone.X, closestBone.Y, closestBone.Z), Color.Red, 0.5f, false); //var bonePos = grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]]; //MyRenderProxy.DebugDrawSphere(boxMatrix.Translation + new Vector3(grid.GridSize / 2) * closestPoint * 1.0f + bonePos, 0.5f, Color.Red.ToVector3(), 0.4f, true, true); //if (input.IsNewKeyPressed(Keys.P) && block != null) //{ // if (input.IsAnyShiftKeyPressed()) // { // grid.ResetBlockSkeleton(block); // } // else // { // grid.Skeleton[bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]] = Vector3.Zero; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // } // handled = true; //} //// Move bones to center by 0.1f //if (input.IsNewKeyPressed(Keys.OemOpenBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // grid.Skeleton[index] -= Vector3.Sign(grid.Skeleton[index]) * 0.1f; // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} //// Reduce max offset by 0.1f //if (input.IsNewKeyPressed(Keys.OemCloseBrackets)) //{ // int index = bones[closestPoint.X + 1, closestPoint.Y + 1, closestPoint.Z + 1]; // var old = Vector3.Abs(grid.Skeleton[index]); // var max = new Vector3(Math.Max(Math.Max(old.X, old.Y), old.Z)); // if (max.X > 0.1f) // { // grid.Skeleton[index] = Vector3.Clamp(grid.Skeleton[index], -max + 0.1f, max - 0.1f); // } // else // { // grid.Skeleton[index] = Vector3.Zero; // } // grid.AddDirtyBone(cubePos, closestPoint + Vector3I.One); // //grid.SetBlockDirty(block); // handled = true; //} } } if (MyInput.Static.IsAnyAltKeyPressed()) return handled; bool shift = MyInput.Static.IsAnyShiftKeyPressed(); bool ctrl = MyInput.Static.IsAnyCtrlKeyPressed(); //if (input.IsNewKeyPressed(Keys.I)) //{ // foreach (var grid in MyEntities.GetEntities().OfType<MyCubeGrid>()) // { // foreach (var block in grid.GetBlocks().ToArray()) // { // grid.DetectMerge(block.Min, block.Max); // } // } // handled = true; //} // Disabled since it is common to have normal control bound to O key. // If you ever need this again, bind it to something more complicated, like key combination. //if (input.IsNewKeyPressed(Keys.O)) //{ // m_gridDebugInfo = !m_gridDebugInfo; // handled = true; //} //for (int i = 0; i <= 9; i++) //{ // if (MyInput.Static.IsNewKeyPressed((Keys)(((int)Keys.D0) + i))) // { // string name = "Slot" + i.ToString(); // if (ctrl) // { // MySession.Static.Name = name; // MySession.Static.WorldID = MySession.GetNewWorldId(); // MySession.Static.Save(name); // } // else if (shift) // { // var path = MyLocalCache.GetSessionSavesPath(name, false, false); // if (System.IO.Directory.Exists(path)) // { // MySession.Static.Unload(); // MySession.Load(path); // } // } // handled = true; // } //} //if (MyInput.Static.IsNewKeyPressed(Keys.End)) //{ // MyMeteorShower.MeteorWave(null); //} // Disabled for god sake! //if (MyInput.Static.IsNewKeyPressed(Keys.PageUp) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = true; //} //if (MyInput.Static.IsNewKeyPressed(Keys.PageDown) && MyInput.Static.IsAnyCtrlKeyPressed()) //{ // MyReloadTestComponent.Enabled = false; //} if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad6)) { var view = MySession.Static.CameraController.GetViewMatrix(); var inv = Matrix.Invert(view); //MyPhysicalInventoryItem item = new MyPhysicalInventoryItem(100, var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); var item = new MyPhysicalInventoryItem(1, oreBuilder); var obj = MyFloatingObjects.Spawn(item, inv.Translation + inv.Forward * 1.0f, inv.Forward, inv.Up); obj.Physics.LinearVelocity = inv.Forward * 50; } if (false && MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { List<HkShape> trShapes = new List<HkShape>(); List<HkConvexShape> shapes = new List<HkConvexShape>(); List<Matrix> matrices = new List<Matrix>(); var grid = new HkGridShape(2.5f, HkReferencePolicy.None); const short size = 50; for (short x = 0; x < size; x++) { for (short y = 0; y < size; y++) { for (short z = 0; z < size; z++) { var box = new HkBoxShape(Vector3.One); grid.AddShapes(new System.Collections.Generic.List<HkShape>() { box }, new Vector3S(x, y, z), new Vector3S(x, y, z)); trShapes.Add(new HkConvexTranslateShape(box, new Vector3(x, y, z), HkReferencePolicy.None)); shapes.Add(box); matrices.Add(Matrix.CreateTranslation(new Vector3(x, y, z))); } } } var emptyGeom = new HkGeometry(new List<Vector3>(), new List<int>()); var list = new HkListShape(trShapes.ToArray(), trShapes.Count, HkReferencePolicy.None); var compressedBv = new HkBvCompressedMeshShape(emptyGeom, shapes, matrices, HkWeldingType.None); var mopp = new HkMoppBvTreeShape(list, HkReferencePolicy.None); HkShapeBuffer buf = new HkShapeBuffer(); //HkShapeContainerIterator i = compressedBv.GetIterator(buf); //int count = 0; // will be 125000 //while (i.IsValid) //{ // count++; // i.Next(); //} buf.Dispose(); var info = new HkRigidBodyCinfo(); info.Mass = 10; info.CalculateBoxInertiaTensor(Vector3.One, 10); info.MotionType = HkMotionType.Dynamic; info.QualityType = HkCollidableQualityType.Moving; info.Shape = compressedBv; var body = new HkRigidBody(info); //MyPhysics.HavokWorld.AddRigidBody(body); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad7)) { foreach (var g in MyEntities.GetEntities().OfType<MyCubeGrid>()) { foreach (var s in g.CubeBlocks.Select(s => s.FatBlock).Where(s => s != null).OfType<MyMotorStator>()) { if (s.Rotor != null) { var q = Quaternion.CreateFromAxisAngle(s.Rotor.WorldMatrix.Up, MathHelper.ToRadians(45)); s.Rotor.CubeGrid.WorldMatrix = MatrixD.CreateFromQuaternion(q) * s.Rotor.CubeGrid.WorldMatrix; } } } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad8)) { var view = MySession.Static.CameraController.GetViewMatrix(); var inv = Matrix.Invert(view); var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); var obj = new MyObjectBuilder_FloatingObject() { Item = new MyObjectBuilder_InventoryItem() { Content = oreBuilder, Amount = 1000 } }; obj.PositionAndOrientation = new MyPositionAndOrientation(inv.Translation + 2.0f * inv.Forward, inv.Forward, inv.Up); obj.PersistentFlags = MyPersistentEntityFlags2.InScene; var e = MyEntities.CreateFromObjectBuilderAndAdd(obj); e.Physics.LinearVelocity = Vector3.Normalize(inv.Forward) * 50.0f; } if (MyInput.Static.IsNewKeyPressed(MyKeys.Divide)) { } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply)) { MyDebugDrawSettings.ENABLE_DEBUG_DRAW = !MyDebugDrawSettings.ENABLE_DEBUG_DRAW; MyStructuralIntegrity.Enabled = true; MyDebugDrawSettings.DEBUG_DRAW_STRUCTURAL_INTEGRITY = true; var grids = MyEntities.GetEntities().OfType<MyCubeGrid>(); foreach (var g in grids) { if (!g.IsStatic)// || g.GetBlocks().Count < 800) //to compute only castle continue; g.CreateStructuralIntegrity(); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad1)) { var e = MyEntities.GetEntities().OfType<MyCubeGrid>().FirstOrDefault(); if (e != null) { e.Physics.RigidBody.MaxLinearVelocity = 1000; if (e.Physics.RigidBody2 != null) e.Physics.RigidBody2.MaxLinearVelocity = 1000; e.Physics.LinearVelocity = new Vector3(1000, 0, 0); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { MyPrefabManager.Static.SpawnPrefab("respawnship", MySector.MainCamera.Position, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector); } if (MyInput.Static.IsNewKeyPressed(MyKeys.Multiply) && MyInput.Static.IsAnyShiftKeyPressed()) { GC.Collect(2); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { Thread.Sleep(250); } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9)) { var obj = MySession.ControlledEntity != null ? MySession.ControlledEntity.Entity : null; if (obj != null) { const float dist = 5.0f; obj.PositionComp.SetPosition(obj.PositionComp.GetPosition() + obj.WorldMatrix.Forward * dist); } } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad4)) { IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner; if (invObject != null) { MyFixedPoint amount = 20000; var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone"); MyInventory inventory = invObject.GetInventory(0); inventory.AddItems(amount, oreBuilder); } handled = true; } //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad8)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockArmorBlock"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} //if (MyInput.Static.IsNewKeyPressed(Keys.NumPad9)) //{ // var pos = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 2; // var grid = (MyObjectBuilder_CubeGrid)MyObjectBuilderSerializer.CreateNewObject(MyObjectBuilderTypeEnum.CubeGrid); // grid.PositionAndOrientation = new MyPositionAndOrientation(pos, Vector3.Forward, Vector3.Up); // grid.CubeBlocks = new List<MyObjectBuilder_CubeBlock>(); // grid.GridSizeEnum = MyCubeSize.Large; // var block = new MyObjectBuilder_CubeBlock(); // block.BlockOrientation = MyBlockOrientation.Identity; // block.Min = Vector3I.Zero; // //var blockDefinition = Sandbox.Game.Managers.MyDefinitionManager.Static.GetCubeBlockDefinition(new CommonLib.ObjectBuilders.Definitions.MyDefinitionId(typeof(MyObjectBuilder_CubeBlock), "LargeBlockArmorBlock")); // block.SubtypeName = "LargeBlockGyro"; // grid.CubeBlocks.Add(block); // grid.LinearVelocity = MySector.MainCamera.ForwardVector * 20; // grid.PersistentFlags = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // var x = MyEntities.CreateFromObjectBuilderAndAdd(grid); //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Delete)) { int count = MyEntities.GetEntities().OfType<MyFloatingObject>().Count(); foreach (var obj in MyEntities.GetEntities().OfType<MyFloatingObject>()) { if (obj == MySession.ControlledEntity) { MySession.SetCameraController(MyCameraControllerEnum.Spectator); } obj.Close(); } handled = true; } if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.Decimal)) { foreach (var obj in MyEntities.GetEntities()) { if (obj != MySession.ControlledEntity && (MySession.ControlledEntity == null || obj != MySession.ControlledEntity.Entity.Parent) && obj != MyCubeBuilder.Static.FindClosestGrid()) obj.Close(); } handled = true; } if (MyInput.Static.IsNewKeyPressed(MyKeys.NumPad9) || MyInput.Static.IsNewKeyPressed(MyKeys.NumPad5)) { //MyCubeGrid.UserCollisions = input.IsNewKeyPressed(Keys.NumPad9); var body = MySession.ControlledEntity.Entity.GetTopMostParent().Physics; if (body.RigidBody != null) { //body.AddForce(Engine.Physics.MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, new Vector3(0, 0, 10 * body.Mass), null, null); body.RigidBody.ApplyLinearImpulse(body.Entity.WorldMatrix.Forward * body.Mass * 2); } handled = true; } //if (input.IsNewKeyPressed(Keys.J) && input.IsAnyCtrlKeyPressed()) //{ // MyGlobalInputComponent.CopyCurrentGridToClipboard(); // MyEntity addedEntity = MyGlobalInputComponent.PasteEntityFromClipboard(); // if (addedEntity != null) // { // Vector3 pos = addedEntity.GetPosition(); // pos.Z += addedEntity.WorldVolume.Radius * 1.5f; // addedEntity.SetPosition(pos); // } // handled = true; //} if (MyInput.Static.IsAnyCtrlKeyPressed() && MyInput.Static.IsNewKeyPressed(MyKeys.OemComma)) { foreach (var e in MyEntities.GetEntities().OfType<MyFloatingObject>().ToArray()) e.Close(); } return handled; }
private void RemoveOperatingItem_Event([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder, MyFixedPoint amount) { var item = new MyPhysicalInventoryItem(itemBuilder); RemoveOperatingItem_Implementation(item, amount); }
public virtual MyFixedPoint GetOperatingItemRemovableAmount(MyPhysicalInventoryItem item) { return 0; }
public void SpawnConstructionStockpile() { if (m_stockpile == null) return; Matrix worldMat = CubeGrid.WorldMatrix; int dist = (Max).RectangularDistance(Min) + 3; Vector3 a = Min; Vector3 b = Max; a *= CubeGrid.GridSize; b *= CubeGrid.GridSize; a = Vector3.Transform(a, worldMat); b = Vector3.Transform(b, worldMat); Vector3 avgPos = (a + b) / 2; Vector3 gravity = MyGravityProviderSystem.CalculateGravityInPoint(avgPos); if (gravity.Length() != 0.0f) { gravity.Normalize(); Vector3I? intersected = CubeGrid.RayCastBlocks(avgPos, avgPos + gravity * dist * CubeGrid.GridSize); if (!intersected.HasValue) { a = avgPos; } else { a = intersected.Value; a *= CubeGrid.GridSize; a = Vector3.Transform(a, worldMat); a -= gravity * CubeGrid.GridSize * 0.1f; } } var items = m_stockpile.GetItems(); foreach (var item in items) { var inventoryItem = new MyPhysicalInventoryItem(item.Amount, item.Content); MyFloatingObjects.Spawn(inventoryItem, a, worldMat.Forward, worldMat.Up, CubeGrid.Physics); } }
protected IMyInventoryItem CreateInventoryItem(MyDefinitionId itemDefinition, MyFixedPoint amount) { var content = MyObjectBuilderSerializer.CreateNewObject(itemDefinition) as MyObjectBuilder_PhysicalObject; System.Diagnostics.Debug.Assert(content != null, "Can not create the requested type from definition!"); MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return inventoryItem; }
private static void FixTransferAmount(MyInventory src, MyInventory dst, MyPhysicalInventoryItem? srcItem, bool spawn, ref MyFixedPoint remove, ref MyFixedPoint add) { Debug.Assert(Sync.IsServer); if (srcItem.Value.Amount < remove) { remove = srcItem.Value.Amount; add = remove; } if (!MySession.Static.CreativeMode && src != dst) { MyFixedPoint space = dst.ComputeAmountThatFits(srcItem.Value.Content.GetObjectId()); if (space < remove) { if (spawn) { MyEntity e = (dst.Owner as MyEntity); Matrix m = e.WorldMatrix; MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(remove - space, srcItem.Value.Content), e.PositionComp.GetPosition() + m.Forward + m.Up, m.Forward, m.Up, e.Physics); } else { remove = space; } add = space; } } }
protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount) { var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition }; MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return inventoryItem; }
private MyFixedPoint AddItemsToNewStack(MyFixedPoint amount, MyFixedPoint maxStack, MyObjectBuilder_PhysicalObject objectBuilder, uint? itemId, int index = -1) { Debug.Assert(m_items.Count < MaxItemCount, "Adding a new item beyond the max item count limit!"); MyFixedPoint addedAmount = MyFixedPoint.Min(amount, maxStack); var newItem = new MyPhysicalInventoryItem() { Amount = addedAmount, Scale = 1f, Content = objectBuilder }; newItem.ItemId = itemId.HasValue ? itemId.Value : GetNextItemID(); if (index >= 0 && index < m_items.Count) { //GR: Shift items not add to last position. Slower but more consistent with game logic m_items.Add(m_items[m_items.Count - 1]); for (int i = m_items.Count - 3; i >= index; i--) { m_items[i+1] = m_items[i]; } m_items[index] = newItem; } else { m_items.Add(newItem); } m_usedIds.Add(newItem.ItemId); if (Sync.IsServer) NotifyHudChangedInventoryItem(addedAmount, ref newItem, true); return amount - addedAmount; }
public void InsertOperatingItem(MyPhysicalInventoryItem item, long senderEntityId) { MyMultiplayer.RaiseEvent(this, x => x.InsertOperatingItem_Request, item.GetObjectBuilder(), senderEntityId); }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { Entity.SyncFlag = true; base.Init(objectBuilder); Entity.SyncObject.UpdatePosition(); var builder = (MyObjectBuilder_Meteor)objectBuilder; Item = new MyPhysicalInventoryItem(builder.Item); m_particleEffectId = MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL ? (int)MyParticleEffectsIDEnum.MeteorTrail_FireAndSmoke : (int)MyParticleEffectsIDEnum.MeteorParticle; InitInternal(); Entity.Physics.LinearVelocity = builder.LinearVelocity; Entity.Physics.AngularVelocity = builder.AngularVelocity; m_integrity = builder.Integrity; }
private void InsertOperatingItem_Event([DynamicObjectBuilder] MyObjectBuilder_InventoryItem itemBuilder) { var item = new MyPhysicalInventoryItem(itemBuilder); InsertOperatingItem_Implementation(item); }
private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial) { ProfilerShort.Begin("SpawnOrePieces"); var forward = Vector3.Normalize(m_sensor.FrontPoint - m_sensor.Center); //var pos = m_sensor.CutOutSphere.Center + forward * m_floatingObjectSpawnOffset; var pos = hitPosition - forward * m_floatingObjectSpawnRadius; BoundingSphere bsphere = new BoundingSphere(pos, m_floatingObjectSpawnRadius); while (amountItems > 0) { MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop); amountItems -= dropAmount; var inventoryItem = new MyPhysicalInventoryItem(dropAmount, oreObjBuilder); var item = MyFloatingObjects.Spawn(inventoryItem, bsphere, null, voxelMaterial); item.Physics.LinearVelocity = MyUtils.GetRandomVector3HemisphereNormalized(forward) * MyUtils.GetRandomFloat(5, 8); item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8); } ProfilerShort.End(); }
public void RemoveOperatingItem(MyPhysicalInventoryItem item, MyFixedPoint amount, long senderEntityId) { MyMultiplayer.RaiseEvent(this, x => x.RemoveOperatingItem_Request, item.GetObjectBuilder(), amount, senderEntityId); }
private static MyObjectBuilder_Meteor PrepareBuilder(ref MyPhysicalInventoryItem item) { var meteorBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Meteor>(); meteorBuilder.Item = item.GetObjectBuilder(); meteorBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; return meteorBuilder; }
public static MyEntity SpawnRandomStaticSmall(Vector3 position) { MyPhysicalInventoryItem i = new MyPhysicalInventoryItem(4 * (MyFixedPoint)MyUtils.GetRandomFloat(0f, 100f), MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>("Stone")); return Spawn(ref i, position, Vector3.Zero); }