public static ulong GetBattlePoints(MySlimBlock slimBlock) { Debug.Assert(slimBlock.BlockDefinition.Points > 0); ulong pts = (ulong)(slimBlock.BlockDefinition.Points > 0 ? slimBlock.BlockDefinition.Points : 1); if (slimBlock.BlockDefinition.IsGeneratedBlock) { pts = 0; } if (slimBlock.FatBlock != null) { var inventory = slimBlock.FatBlock.GetInventory(0); if (inventory != null) { foreach (var item in inventory.GetItems()) { if (item.Content is MyObjectBuilder_BlockItem) { MyObjectBuilder_BlockItem blockItem = item.Content as MyObjectBuilder_BlockItem; pts += GetBattlePoints(blockItem.BlockDefId); } } } } return(pts); }
public static ulong GetBattlePoints(MySlimBlock slimBlock) { Debug.Assert(slimBlock.BlockDefinition.BattlePoints > 0); ulong pts = (ulong)(slimBlock.BlockDefinition.BattlePoints > 0 ? slimBlock.BlockDefinition.BattlePoints : 1); // Get points from container items IMyInventoryOwner inventoryOwner = slimBlock.FatBlock as IMyInventoryOwner; if (inventoryOwner != null) { var inventory = inventoryOwner.GetInventory(0); if (inventory != null) { foreach (var item in inventory.GetItems()) { if (item.Content is MyObjectBuilder_BlockItem) { MyObjectBuilder_BlockItem blockItem = item.Content as MyObjectBuilder_BlockItem; pts += GetBattlePoints(blockItem.BlockDefId); } } } } return(pts); }
protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount) { var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition }; MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return(inventoryItem); }
private bool AddBlocks(MyCubeBlockDefinition blockDef, MyFixedPoint amount) { MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); item.BlockDefId = blockDef.Id; if (CanItemsBeAdded(amount, item.BlockDefId)) { AddItems(amount, item); return true; } return false; }
private bool AddBlock(MySlimBlock block) { if (block.FatBlock is IMyInventoryOwner) //we cannot store inventory in inventory now return false; MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); item.BlockDefId = block.BlockDefinition.Id; if (CanItemsBeAdded(1, item.BlockDefId)) { AddItems(1, item); return true; } return false; }
public static void Spawn(this MyPhysicalInventoryItem thisItem, MyFixedPoint amount, MatrixD worldMatrix, MyEntity owner, Action <MyEntity> completionCallback) { if ((amount >= 0) && (thisItem.Content != null)) { if (thisItem.Content is MyObjectBuilder_BlockItem) { if (typeof(MyObjectBuilder_CubeBlock).IsAssignableFrom((System.Type)thisItem.Content.GetObjectId().TypeId)) { MyCubeBlockDefinition definition; MyObjectBuilder_BlockItem content = thisItem.Content as MyObjectBuilder_BlockItem; MyDefinitionManager.Static.TryGetCubeBlockDefinition(content.BlockDefId, out definition); if (definition != null) { MyObjectBuilder_CubeGrid objectBuilder = MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_CubeGrid)) as MyObjectBuilder_CubeGrid; objectBuilder.GridSizeEnum = definition.CubeSize; objectBuilder.IsStatic = false; objectBuilder.PersistentFlags |= MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled; objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix); MyObjectBuilder_CubeBlock item = MyObjectBuilderSerializer.CreateNewObject(content.BlockDefId) as MyObjectBuilder_CubeBlock; if (item != null) { item.Min = (SerializableVector3I)(((definition.Size / 2) - definition.Size) + Vector3I.One); objectBuilder.CubeBlocks.Add(item); for (int i = 0; i < amount; i++) { objectBuilder.EntityId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM); item.EntityId = MyEntityIdentifier.AllocateId(MyEntityIdentifier.ID_OBJECT_TYPE.ENTITY, MyEntityIdentifier.ID_ALLOCATION_METHOD.RANDOM); Vector3D?relativeOffset = null; MyEntities.CreateFromObjectBuilderParallel(objectBuilder, true, completionCallback, null, null, relativeOffset, false, false); } } } } } else { MyPhysicalItemDefinition definition = null; if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(thisItem.Content.GetObjectId(), out definition)) { MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount, thisItem.Content, 1f), worldMatrix, owner?.Physics, completionCallback); } } } }
public static ulong GetBattlePoints(MyObjectBuilder_CubeBlock block) { ulong pts = GetBattlePoints(block.GetId()); MyObjectBuilder_CargoContainer cargoContainer = block as MyObjectBuilder_CargoContainer; if (cargoContainer != null && cargoContainer.Inventory != null) { foreach (var item in cargoContainer.Inventory.Items) { if (item.PhysicalContent is MyObjectBuilder_BlockItem) { MyObjectBuilder_BlockItem blockItem = item.PhysicalContent as MyObjectBuilder_BlockItem; pts += GetBattlePoints(blockItem.BlockDefId); } } } return(pts); }
private bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1) { if (amount == 0) return false; Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject || (MyFakes.ENABLE_COMPONENT_BLOCKS && objectBuilder is MyObjectBuilder_CubeBlock), "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; MyDefinitionId defId = objectBuilder.GetId(); if (MyFakes.ENABLE_COMPONENT_BLOCKS) { if (physicalObjectBuilder == null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = defId; } else { MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(defId); if (blockDef != null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id; } } } if (physicalObjectBuilder == null) return false; defId = physicalObjectBuilder.GetObjectId(); MyFixedPoint fittingAmount = ComputeAmountThatFits(defId); if (fittingAmount < amount) return false; if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, itemId, index); } return true; }
private bool AddBlock(MySlimBlock block) { if (!MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID && block.FatBlock != null && block.FatBlock.HasInventory) //we cannot store inventory in inventory now return false; MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); if (MyGridPickupComponent.Static != null) item.BlockDefId = MyGridPickupComponent.Static.GetBaseBlock(block.BlockDefinition.Id); else item.BlockDefId = block.BlockDefinition.Id; if (ComputeAmountThatFits(item.BlockDefId) >= 1) { AddItems(1, item); return true; } return false; }
public bool AddBlocks(MyCubeBlockDefinition blockDef, MyFixedPoint amount) { MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); item.BlockDefId = blockDef.Id; if (ComputeAmountThatFits(item.BlockDefId) >= amount) { AddItems(amount, item); return true; } return false; }
protected IMyInventoryItem CreateInventoryBlockItem(MyDefinitionId blockDefinition, MyFixedPoint amount) { var content = new MyObjectBuilder_BlockItem() { BlockDefId = blockDefinition }; MyPhysicalInventoryItem inventoryItem = new MyPhysicalInventoryItem(amount, content); return inventoryItem; }
public bool AddItems(MyFixedPoint amount, MyObjectBuilder_Base objectBuilder, uint? itemId, int index = -1, bool stack = true) { Debug.Assert(objectBuilder is MyObjectBuilder_PhysicalObject, "This type of inventory can't add other types than PhysicalObjects!"); MyObjectBuilder_PhysicalObject physicalObjectBuilder = objectBuilder as MyObjectBuilder_PhysicalObject; if (physicalObjectBuilder == null) { return false; } if (amount == 0) return false; if (!CanItemsBeAdded(amount, physicalObjectBuilder.GetObjectId())) return false; if (MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID) { MyCubeBlockDefinition blockDef = MyDefinitionManager.Static.TryGetComponentBlockDefinition(objectBuilder.GetId()); if (blockDef != null) { physicalObjectBuilder = new MyObjectBuilder_BlockItem(); (physicalObjectBuilder as MyObjectBuilder_BlockItem).BlockDefId = blockDef.Id; } } if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, physicalObjectBuilder); if (amount == 0) return false; AddItemsInternal(amount, physicalObjectBuilder, index, itemId, stack); } return true; }
private bool AddBlock(MySlimBlock block) { if (!MyFakes.ENABLE_GATHERING_SMALL_BLOCK_FROM_GRID && block.FatBlock != null && block.FatBlock.HasInventory) //we cannot store inventory in inventory now return false; MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); item.BlockDefId = block.BlockDefinition.Id; if (CanItemsBeAdded(1, item.BlockDefId)) { AddItems(1, item); return true; } return false; }
public bool AddBlocks(MyCubeBlockDefinition blockDef, MyFixedPoint amount) { MyObjectBuilder_BlockItem item = new MyObjectBuilder_BlockItem(); item.BlockDefId = blockDef.Id; if (CanItemsBeAdded(amount, item.BlockDefId)) { AddItems(amount, item); return true; } return false; }