public override bool OnHitAsProjectile(CellFace?cellFace, ComponentBody componentBody, WorldItem worldItem)
        {
            BulletBlock.BulletType bulletType = BulletBlock.GetBulletType(Terrain.ExtractData(worldItem.Value));
            bool result = true;

            if (cellFace.HasValue)
            {
                int   cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z);
                int   num       = Terrain.ExtractContents(cellValue);
                Block obj       = BlocksManager.Blocks[num];
                if (worldItem.Velocity.Length() > 30f)
                {
                    m_subsystemExplosions.TryExplodeBlock(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z, cellValue);
                }
                if (obj.Density >= 1.5f && worldItem.Velocity.Length() > 30f)
                {
                    float num2        = 1f;
                    float minDistance = 8f;
                    if (bulletType == BulletBlock.BulletType.BuckshotBall)
                    {
                        num2        = 0.25f;
                        minDistance = 4f;
                    }
                    if (m_random.Float(0f, 1f) < num2)
                    {
                        m_subsystemAudio.PlayRandomSound("Audio/Ricochets", 1f, m_random.Float(-0.2f, 0.2f), new Vector3(cellFace.Value.X, cellFace.Value.Y, cellFace.Value.Z), minDistance, autoDelay: true);
                        result = false;
                    }
                }
            }
            return(result);
        }
Example #2
0
        public override void ProcessInventoryItem(IInventory inventory, int slotIndex, int value, int count, int processCount, out int processedValue, out int processedCount)
        {
            processedValue = value;
            processedCount = count;
            if (processCount == 1)
            {
                int data = Terrain.ExtractData(inventory.GetSlotValue(slotIndex));
                MusketBlock.LoadState  loadState  = MusketBlock.GetLoadState(data);
                BulletBlock.BulletType?bulletType = MusketBlock.GetBulletType(data);
                switch (loadState)
                {
                case MusketBlock.LoadState.Empty:
                    loadState  = MusketBlock.LoadState.Gunpowder;
                    bulletType = null;
                    break;

                case MusketBlock.LoadState.Gunpowder:
                    loadState  = MusketBlock.LoadState.Wad;
                    bulletType = null;
                    break;

                case MusketBlock.LoadState.Wad:
                {
                    loadState = MusketBlock.LoadState.Loaded;
                    int data2 = Terrain.ExtractData(value);
                    bulletType = BulletBlock.GetBulletType(data2);
                    break;
                }
                }
                processedValue = 0;
                processedCount = 0;
                inventory.RemoveSlotItems(slotIndex, 1);
                inventory.AddSlotItems(slotIndex, Terrain.MakeBlockValue(212, 0, MusketBlock.SetBulletType(MusketBlock.SetLoadState(data, loadState), bulletType)), 1);
            }
        }