Exemple #1
0
        //  Called when we finished harvesting current voxel
        void StartReleaseVoxel()
        {
            if (m_parentMinerShip == null || m_parentMinerShip.IsDead() || m_parentMinerShip.Inventory == null)
            {
                return;
            }

            StartImplodeCue();
            BoundingSphere explosion = new BoundingSphere(m_headPositionTransformed, MyVoxelConstants.VOXEL_SIZE_IN_METRES * 1);

            //remove decals
            MyDecals.HideTrianglesAfterExplosion(m_inVoxelMap, ref explosion);
            //cut off

            var minedMaterialsWithContents = MyVoxelGenerator.CutOutSphereFastWithMaterials(m_inVoxelMap, explosion);

            var dustEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Harvester_Finished);

            dustEffect.WorldMatrix = Matrix.CreateTranslation(m_headPositionTransformed);

            bool hudHarvestingCompletePlayed = false;
            bool harvestingFinishedAsyncSent = false;

            var minedOres = new Dictionary <int, float>();

            foreach (var minedMaterialWithContent in minedMaterialsWithContents)
            {
                MyOreRatioFromVoxelMaterial[] oreFromVoxel = MyVoxelMapOreMaterials.GetOreFromVoxelMaterial(minedMaterialWithContent.Key);
                if (oreFromVoxel != null && this.Parent == MySession.PlayerShip)
                {
                    // accumulate amounts of the same type
                    foreach (MyOreRatioFromVoxelMaterial oreRatio in oreFromVoxel)
                    {
                        float amount    = minedMaterialWithContent.Value * oreRatio.Ratio * MyHarvestingTubeConstants.MINED_CONTENT_RATIO;
                        float oldAmount = 0;
                        minedOres.TryGetValue((int)oreRatio.OreType, out oldAmount);
                        minedOres[(int)oreRatio.OreType] = amount + oldAmount;
                    }

                    if (!harvestingFinishedAsyncSent)
                    {
                        try
                        {
                            // Disabled, still unused on server
                            //var client = MySectorServiceClient.GetCheckedInstance();
                            //client.HarvestingFinishedAsync(minedMaterialWithContent.Key, (byte)(minedMaterialWithContent.Value * MyVoxelConstants.VOXEL_CONTENT_FULL_FLOAT));
                        }
                        catch (Exception)
                        {
                            Debug.Fail("Cannot send harvesting to server");
                        }
                        harvestingFinishedAsyncSent = true;
                    }

                    if (!hudHarvestingCompletePlayed)
                    {
                        hudHarvestingCompletePlayed = true;
                        MyAudio.AddCue2D(MySoundCuesEnum.HudHarvestingComplete);
                    }
                }
            }


            bool inventoryFullWarningPlayed = false;

            // add ores to inventory
            foreach (var ore in minedOres)
            {
                float amountLeft = m_parentMinerShip.Inventory.AddInventoryItem(MyMwcObjectBuilderTypeEnum.Ore, ore.Key, ore.Value, false);

                float amountAdded = ore.Value - amountLeft;
                if (amountAdded > 0f)
                {
                    MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.HarvestNotification, 3500, textFormatArguments: new object[]
                    {
                        amountAdded,
                        ((MyGuiOreHelper)MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.Ore, ore.Key)).Name
                    }
                                                                                           ));
                }

                if (amountLeft > 0f)
                {
                    MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.HarvestNotificationInventoryFull, MyGuiManager.GetFontMinerWarsRed(), 3500,
                                                                                           textFormatArguments: new object[]
                    {
                        amountLeft,
                        ((MyGuiOreHelper)MyGuiObjectBuilderHelpers.GetGuiHelper(MyMwcObjectBuilderTypeEnum.Ore, ore.Key)).Name
                    }
                                                                                           ));
                    if (!inventoryFullWarningPlayed)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.HudInventoryFullWarning);
                        inventoryFullWarningPlayed = true;
                    }
                }
            }

            StartReturningBack();
        }