Ejemplo n.º 1
0
        private void ProcessDamage()
        {
            foreach (IMyEntity entity in _topEntityCache)
            {
                var grid = entity as IMyCubeGrid;
                if (grid?.Physics != null)
                {
                    if (grid.Closed || grid.MarkedForClose)
                    {
                        continue;
                    }

                    float damage = grid.GridSizeEnum == MyCubeSize.Small ? Config.SMALL_SHIP_DAMAGE : Config.LARGE_SHIP_DAMAGE;
                    if (Config.BLOCK_VOXEL_DAMAGE)
                    {
                        byte voxelId;
                        List <IMySlimBlock> vBlocks = Utilities.GetBlocksContactingVoxel(grid, _planet, out voxelId);
                        VoxelDamageItem     item;
                        if (!Config.VOXEL_IDS.TryGetValue(voxelId, out item))
                        {
                            MyLog.Default.WriteLine($"{voxelId} NOT FOUND");
                            item = Config.VOXEL_IDS.First().Value;
                        }
                        foreach (IMySlimBlock b in vBlocks)
                        {
                            _damageEntities.AddOrUpdate(b, damage * item.DamageMultiplier);
                            if (item.ParticleEffect.HasValue)
                            {
                                _blockParticles[b] = item.ParticleEffect.Value;
                            }
                        }
                    }

                    if (!Config.BLOCK_RADIATION_DAMAGE && !Config.BLOCK_ACID_RAIN && Utilities.IsEntityInsideGrid(grid))
                    {
                        continue;
                    }

                    //if (BLOCK_ACID_RAIN && IsEntityCovered(grid, sphere.Center))
                    //{
                    //    //MyAPIGateway.Utilities.ShowMessage("GRID COVERED", grid.DisplayName);
                    //    continue;
                    //}

                    var blocks = new List <IMySlimBlock>();
                    grid.GetBlocks(blocks);

                    Vector3D offset = Vector3D.Zero;
                    if (Config.BLOCK_ACID_RAIN)
                    {
                        Vector3D direction = grid.WorldVolume.Center - _sphere.Center;
                        direction.Normalize();
                        offset = direction;
                    }

                    if (Config.BLOCK_ACID_RAIN || Config.BLOCK_RADIATION_DAMAGE)
                    {
                        for (var i = 0; i < Math.Max(1, blocks.Count * 0.3); i++)
                        {
                            IMySlimBlock block;
                            if (Config.BLOCK_ACID_RAIN)
                            {
                                block = Utilities.GetRandomSkyFacingBlock(grid, blocks, offset, true);
                            }
                            else
                            {
                                block = Utilities.GetRandomExteriorBlock(grid, blocks);
                            }

                            if (block == null)
                            {
                                continue;
                            }

                            _damageEntities.AddOrUpdate(block, damage);
                            //blocks.Remove(block);
                            //QueueInvoke(() =>
                            //            {
                            //                if (block != null && !block.Closed())
                            //                    block.DoDamage(damage, _damageHash, true);
                            //            });
                        }
                    }

                    continue;
                }

                var floating = entity as IMyFloatingObject;
                if (floating != null)
                {
                    if (floating.Closed || floating.MarkedForClose)
                    {
                        continue;
                    }

                    if (Config.BLOCK_RADIATION_DAMAGE)
                    {
                        _damageEntities.AddOrUpdate(floating, Config.SMALL_SHIP_DAMAGE);
                    }

                    if (Config.BLOCK_ACID_RAIN && !(Utilities.IsEntityCovered(floating, _sphere.Center) || Utilities.IsFullyInsideVoxel(floating, _planet)))
                    {
                        _damageEntities.AddOrUpdate(floating, Config.SMALL_SHIP_DAMAGE);
                    }

                    Vector3D pos = floating.GetPosition();
                    Vector3D s   = _planet.GetClosestSurfacePointGlobal(ref pos);
                    if (Vector3D.DistanceSquared(pos, s) <= 4)
                    {
                        MyVoxelMaterialDefinition mat = _planet.GetMaterialAt_R(ref s);
                        VoxelDamageItem           vox;
                        if (Config.VOXEL_IDS.TryGetValue(mat.Index, out vox))
                        {
                            _damageEntities.AddOrUpdate(floating, Config.LARGE_SHIP_DAMAGE * vox.DamageMultiplier);
                        }
                    }
                }
            }

            if (Config.BLOCK_ACID_RAIN && Config.DRAW_RAIN)
            {
                SendDrawQueue();
            }
        }