private MyFracturedPiece AllocatePiece() { ProfilerShort.Begin("AllocCounter"); m_allocatedThisFrame++; var fp = MyEntities.CreateEntity(new MyDefinitionId(typeof(MyObjectBuilder_FracturedPiece))) as MyFracturedPiece; fp.Physics = new MyPhysicsBody(fp, RigidBodyFlag.RBF_DEBRIS); fp.Physics.CanUpdateAccelerations = true; ProfilerShort.End(); return(fp); }
protected override void Hit() { if (!MyMultiplayerModApi.Static.IsServer) { return; } var harvestable = Target.Entity?.Get <EquiHarvestableComponent>(); if (harvestable == null) { return; } EquiHarvestableComponentDefinition.Data data; if (!harvestable.TryHarvest(Item.GetDefinition(), out data)) { return; } base.UpdateDurability(-1); if (data.LootTable == null) { return; } var lootBag = MyEntities.CreateEntity(_definition.LootBag); var inv = lootBag.Get <MyInventoryBase>(); if (inv == null) { return; } inv.GenerateLuckyContent(data.LootTable, new LuckyLoot.LootContext(_definition.LuckMultiplier, _definition.LuckAddition)); if (_definition.OutputInventory != MyStringHash.NullOrEmpty) { var myInventory = Holder.Get <MyInventoryBase>(_definition.OutputInventory); if (myInventory != null) { for (var index = 0; index < inv.Items.Count; index++) { var item = inv.Items[index]; var fits = Math.Min(item.Amount, myInventory.ComputeAmountThatFits(item.DefinitionId)); if (fits <= 0 || !myInventory.AddItems(item.DefinitionId, fits)) { continue; } item.Amount -= fits; if (item.Amount > 0) { continue; } index--; inv.Remove(item); } } } if (inv.Items.Count > 0) { MyEntities.Add(lootBag); } }