示例#1
0
        /// <summary>
        /// Determines if two grids are attached.
        /// </summary>
        /// <param name="grid0">The starting grid.</param>
        /// <param name="grid1">The grid to search for.</param>
        /// <param name="allowedConnections">The types of connections allowed between grids.</param>
        /// <returns>True iff the grids are attached.</returns>
        public static bool IsGridAttached(IMyCubeGrid grid0, IMyCubeGrid grid1, AttachmentKind allowedConnections)
        {
            Logger.DebugLog("condition: grid0 == null", Logger.severity.FATAL, condition: grid0 == null);
            Logger.DebugLog("condition: grid1 == null", Logger.severity.FATAL, condition: grid1 == null);

            if (grid0 == grid1)
            {
                return(true);
            }

            AttachedGrid attached1 = GetFor(grid0);

            if (attached1 == null)
            {
                return(false);
            }
            AttachedGrid attached2 = GetFor(grid1);

            if (attached2 == null)
            {
                return(false);
            }

            HashSet <AttachedGrid> search = s_searchSet.Get();
            bool result = attached1.IsGridAttached(attached2, allowedConnections, search);

            search.Clear();
            s_searchSet.Return(search);
            return(result);
        }
示例#2
0
        public void RemoveModule(ProceduralModule module)
        {
            m_modulesToAdd.Remove(module);
            if (!m_modules.Remove(module))
            {
                return;
            }
            var list = m_objectListPool.Get();

            try
            {
                m_tree.GetAll(list, true);
                foreach (var x in list)
                {
                    if (x.Module == module)
                    {
                        x.RaiseRemoved();
                    }
                }
            }
            finally
            {
                m_objectListPool.Return(list);
            }
        }
        public MyRenderContext AcquireRC()
        {
            MyRenderProxy.Assert(m_isDeviceInit);
            var rc = m_pool.Get();

            rc.ClearState();
            return(rc);
        }
        public InterningBag <T> With(T id)
        {
            if (Contains(id))
            {
                return(this);
            }
            var result = Pool.Get();

            result.EnsureSize(_backingSize + 1);
            Array.Copy(_backing, result._backing, _backingSize);
            result._backing[_backingSize] = id;
            result._backingSize           = _backingSize + 1;
            result._memorizedHash         = null;
            return(Intern(result));
        }
示例#5
0
        void EntityAdded(IMyEntity ent)
        {
            try
            {
                var grid = ent as MyCubeGrid;
                if (grid != null && grid.CreatePhysics)
                {
                    var logic = GridLogicLookup.GetValueOrDefault(grid.EntityId, null);
                    if (logic != null)
                    {
                        logic.Reset();
                        logic.Init(grid);
                    }
                    else
                    {
                        logic = LogicPool.Get();
                        logic.Init(grid);

                        GridLogic.Add(logic);
                        GridLogicLookup.Add(grid.EntityId, logic);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#6
0
文件: Log.cs 项目: keleios/WeaponCore
        public static void Init(string name, Session session, bool defaultInstance = true)
        {
            try
            {
                var filename = name + ".log";
                if (_instances.ContainsKey(name))
                {
                    return;
                }
                RenameFileInLocalStorage(filename, name + $"-{DateTime.Now:MM-dd-yy_HH-mm-ss}.log", typeof(LogInstance));

                if (defaultInstance)
                {
                    _defaultInstance = name;
                }
                var instance = _logPool.Get();

                instance.Session = session;
                _instances[name] = instance;

                instance.TextWriter = MyAPIGateway.Utilities.WriteFileInLocalStorage(filename, typeof(LogInstance));
                Line($"Logging Started", name);
            }
            catch (Exception e)
            {
                MyAPIGateway.Utilities.ShowNotification(e.Message, 5000);
            }
        }
示例#7
0
 /// <summary>
 /// Prefetches planetary voxel physics along a ray
 /// </summary>
 /// <param name="ray">ray to prefetch</param>
 /// <param name="force">force a new prefetch task</param>
 public static void PrefetchRay(ref LineD ray, bool force = false)
 {
     // Force is second so we still update the cache for forced
     if (!_raycastPrefetchCache.IsItemPresent(ray.GetHash(),
                                              (int)MyAPIGateway.Session.ElapsedPlayTime.TotalSeconds) || force)
     {
         var voxelHits = _voxelCache.Get();
         try
         {
             MyGamePruningStructure.GetVoxelMapsOverlappingRay(ref ray, voxelHits);
             foreach (var e in voxelHits)
             {
                 var planet = (e.Element?.RootVoxel ?? e.Element) as MyPlanet;
                 // This needs to be done for all voxel maps. To bad we can't.
                 planet?.PrefetchShapeOnRay(ref ray);
             }
         }
         finally
         {
             voxelHits.Clear();
             if (_voxelCache.Count <= 1)
             {
                 _voxelCache.Return(voxelHits);
             }
         }
     }
 }
示例#8
0
        private static void MessageHandler(byte[] bytes)
        {
            var m = _messagePool.Get();

            m.CompressedData = bytes;
            _processing.Add(m);
        }
示例#9
0
        public MyUpdateData()
        {
            m_frameDataPool   = new MyConcurrentPool <MyUpdateFrame>(5, true);
            m_updateDataQueue = new MyConcurrentQueue <MyUpdateFrame>(5);

            CurrentUpdateFrame = m_frameDataPool.Get();
        }
示例#10
0
        public MyUpdateData()
        {
            m_frameDataPool = new MyConcurrentPool<MyUpdateFrame>(5, true);
            m_updateDataQueue = new MyConcurrentQueue<MyUpdateFrame>(5);

            CurrentUpdateFrame = m_frameDataPool.Get();
        }
示例#11
0
        public static IMyPlayer GetPlayerById(this IMyPlayerCollection collection, long id)
        {
            var list = PlayerListPool.Get();

            try
            {
                list.Clear();
                collection.GetPlayers(list, (x) => x.IdentityId == id);
                return(list.Count > 0 ? list[0] : null);
            }
            finally
            {
                list.Clear();
                PlayerListPool.Return(list);
            }
        }
示例#12
0
        internal static MyQuery CreateTimestampQuery()
        {
            var q = m_timestampQueries.Get();

            q.LazyInit(QueryType.Timestamp);
            return(q);
        }
示例#13
0
        internal static MyQuery CreateDisjointQuery()
        {
            var q = m_disjointQueries.Get();

            q.LazyInit(QueryType.TimestampDisjoint);
            return(q);
        }
示例#14
0
        //internal static MyConcurrentQueue<DeviceContext> m_intialized = new MyConcurrentQueue<DeviceContext>(PoolSize);

        static internal MyRenderContext AcquireRC()
        {
            var result = m_pool.Get();

            result.LazyInitialize();
            return(result);
        }
示例#15
0
        internal void Init(Projectile p, MyConcurrentPool <Fragment> fragPool)
        {
            for (int i = 0; i < p.Info.AmmoDef.Shrapnel.Fragments; i++)
            {
                var frag = fragPool.Get();
                frag.System             = p.Info.System;
                frag.Ai                 = p.Info.Ai;
                frag.AmmoDef            = p.Info.System.AmmoTypes[p.Info.AmmoDef.Const.ShrapnelId].AmmoDef;
                frag.Target             = p.Info.Target.Entity;
                frag.Overrides          = p.Info.Overrides;
                frag.WeaponId           = p.Info.WeaponId;
                frag.MuzzleId           = p.Info.MuzzleId;
                frag.FiringCube         = p.Info.Target.FiringCube;
                frag.Guidance           = p.Info.EnableGuidance;
                frag.Origin             = !Vector3D.IsZero(p.Info.Hit.LastHit) ? p.Info.Hit.LastHit : p.Position;
                frag.OriginUp           = p.Info.OriginUp;
                frag.WeaponRng          = p.Info.WeaponRng;
                frag.IsFiringPlayer     = p.Info.IsFiringPlayer;
                frag.ClientSent         = p.Info.ClientSent;
                frag.PredictedTargetPos = p.PredictedTargetPos;
                frag.Velocity           = p.Velocity;
                frag.DeadSphere         = p.DeadSphere;
                frag.LockOnFireState    = p.Info.LockOnFireState;
                frag.IgnoreShield       = p.Info.ShieldBypassed && p.Info.AmmoDef.Const.ShieldDamageBypassMod > 0;
                var dirMatrix = Matrix.CreateFromDir(p.Info.Direction);
                var posValue  = MathHelper.ToRadians(MathHelper.Clamp(p.Info.AmmoDef.Shrapnel.Degrees, 0, 360));
                posValue *= 0.5f;
                var randomFloat1 = (float)(frag.WeaponRng.TurretRandom.NextDouble() * posValue);
                var randomFloat2 = (float)(frag.WeaponRng.TurretRandom.NextDouble() * MathHelper.TwoPi);
                frag.WeaponRng.TurretCurrentCounter += 2;
                var mutli = p.Info.AmmoDef.Shrapnel.Reverse ? -1 : 1;

                var shrapnelDir = Vector3.TransformNormal(mutli * -new Vector3(
                                                              MyMath.FastSin(randomFloat1) * MyMath.FastCos(randomFloat2),
                                                              MyMath.FastSin(randomFloat1) * MyMath.FastSin(randomFloat2),
                                                              MyMath.FastCos(randomFloat1)), dirMatrix);

                frag.Direction     = shrapnelDir;
                frag.PrimeEntity   = null;
                frag.TriggerEntity = null;
                if (frag.AmmoDef.Const.PrimeModel && frag.AmmoDef.Const.PrimeEntityPool.Count > 0)
                {
                    frag.PrimeEntity = frag.AmmoDef.Const.PrimeEntityPool.Get();
                }

                if (frag.AmmoDef.Const.TriggerModel && p.Info.System.Session.TriggerEntityPool.Count > 0)
                {
                    frag.TriggerEntity = p.Info.System.Session.TriggerEntityPool.Get();
                }

                if (frag.AmmoDef.Const.PrimeModel && frag.PrimeEntity == null || frag.AmmoDef.Const.TriggerModel && frag.TriggerEntity == null)
                {
                    p.Info.System.Session.FragmentsNeedingEntities.Add(frag);
                }

                Sharpnel.Add(frag);
            }
        }
示例#16
0
        /// <summary>
        /// Commits current frame as atomic operation and prepares new frame
        /// </summary>
        public void CommitUpdateFrame()
        {
            VRage.Library.Utils.MyTimeSpan lastUpdateTimestamp = CurrentUpdateFrame.UpdateTimestamp;

            CurrentUpdateFrame.Processed = false;
            m_updateDataQueue.Enqueue(CurrentUpdateFrame);
            CurrentUpdateFrame = m_frameDataPool.Get();

            CurrentUpdateFrame.UpdateTimestamp = lastUpdateTimestamp;
        }
示例#17
0
        internal void Init(Projectile p, MyConcurrentPool <Fragment> fragPool)
        {
            for (int i = 0; i < p.Info.AmmoDef.Shrapnel.Fragments; i++)
            {
                var frag = fragPool.Get();

                frag.System             = p.Info.System;
                frag.Ai                 = p.Info.Ai;
                frag.AmmoDef            = p.Info.System.WeaponAmmoTypes[p.Info.AmmoDef.Const.ShrapnelId].AmmoDef;
                frag.Target             = p.Info.Target.Entity;
                frag.Overrides          = p.Info.Overrides;
                frag.WeaponId           = p.Info.WeaponId;
                frag.MuzzleId           = p.Info.MuzzleId;
                frag.FiringCube         = p.Info.Target.FiringCube;
                frag.Guidance           = p.Info.EnableGuidance;
                frag.Origin             = !Vector3D.IsZero(p.Hit.HitPos) ? p.Hit.HitPos : p.Position;
                frag.OriginUp           = p.Info.OriginUp;
                frag.Seed               = p.Info.Seed;
                frag.PredictedTargetPos = p.PredictedTargetPos;
                frag.Velocity           = p.Velocity;
                var dirMatrix = Matrix.CreateFromDir(p.Info.Direction);
                var posValue  = MathHelper.ToRadians(MathHelper.Clamp(p.Info.AmmoDef.Shrapnel.Degrees, 0, 360));
                posValue *= 0.5f;
                var randomFloat1 = MyUtils.GetRandomFloat(0.0f, posValue);
                var randomFloat2 = MyUtils.GetRandomFloat(0.0f, MathHelper.TwoPi);

                var mutli = p.Info.AmmoDef.Shrapnel.Reverse ? -1 : 1;

                var shrapnelDir = Vector3.TransformNormal(mutli * -new Vector3(
                                                              MyMath.FastSin(randomFloat1) * MyMath.FastCos(randomFloat2),
                                                              MyMath.FastSin(randomFloat1) * MyMath.FastSin(randomFloat2),
                                                              MyMath.FastCos(randomFloat1)), dirMatrix);

                frag.Direction = shrapnelDir;

                frag.PrimeEntity   = null;
                frag.TriggerEntity = null;
                if (frag.AmmoDef.Const.PrimeModel && frag.AmmoDef.Const.PrimeEntityPool.Count > 0)
                {
                    frag.PrimeEntity = frag.AmmoDef.Const.PrimeEntityPool.Get();
                }

                if (frag.AmmoDef.Const.TriggerModel && p.Info.Ai.Session.TriggerEntityPool.Count > 0)
                {
                    frag.TriggerEntity = p.Info.Ai.Session.TriggerEntityPool.Get();
                }

                if (frag.AmmoDef.Const.PrimeModel && frag.PrimeEntity == null || frag.AmmoDef.Const.TriggerModel && frag.TriggerEntity == null)
                {
                    p.Info.Ai.Session.FragmentsNeedingEntities.Add(frag);
                }

                Sharpnel.Add(frag);
            }
        }
示例#18
0
        private static void MessageHandler(byte[] bytes)
        {
            var m = _messagePool.Get();

            m.CompressedData = bytes;
#if TORCH
            m.SenderId = MyEventContext.Current.Sender.Value;
#endif

            _processing.Add(m);
        }
示例#19
0
        private void UpdateEffect(HitEntity hitEnt, ProInfo info)
        {
            if (info.AmmoDef.Const.AreaEffect == PullField || info.AmmoDef.Const.AreaEffect == PushField)
            {
                PushPull(hitEnt, info);
                return;
            }

            var grid = hitEnt.Entity as MyCubeGrid;

            if (grid == null || grid.MarkedForClose)
            {
                return;
            }

            if (IsServer)
            {
                Dictionary <AreaEffectType, GridEffect> effects;
                var attackerId = info.Target.FiringCube.EntityId;
                if (_gridEffects.TryGetValue(grid, out effects))
                {
                    GridEffect gridEffect;
                    if (effects.TryGetValue(info.AmmoDef.AreaEffect.AreaEffect, out gridEffect))
                    {
                        gridEffect.Damage    += info.AmmoDef.Const.AreaEffectDamage;
                        gridEffect.Ai         = info.Ai;
                        gridEffect.AttackerId = attackerId;
                        gridEffect.Hits++;
                        var hitPos = hitEnt.HitPos ?? info.Hit.SurfaceHit;
                        gridEffect.HitPos = (gridEffect.HitPos + hitPos) / 2;
                    }
                }
                else
                {
                    effects = GridEffectsPool.Get();
                    var gridEffect = GridEffectPool.Get();
                    gridEffect.System     = info.System;
                    gridEffect.Damage     = info.AmmoDef.Const.AreaEffectDamage;
                    gridEffect.Ai         = info.Ai;
                    gridEffect.AmmoDef    = info.AmmoDef;
                    gridEffect.AttackerId = attackerId;
                    gridEffect.Hits++;
                    var hitPos = hitEnt.HitPos ?? info.Hit.SurfaceHit;

                    gridEffect.HitPos = hitPos;
                    effects.Add(info.AmmoDef.AreaEffect.AreaEffect, gridEffect);
                    _gridEffects.Add(grid, effects);
                }
            }

            info.BaseHealthPool = 0;
            info.BaseDamagePool = 0;
        }
示例#20
0
        private static MyTuple <float?, IMyTerminalBlock> TAPI_ClosestShieldInLine(LineD line, bool onlyIfOnline)
        {
            var segment = SegmentPool.Get();

            MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref line, segment, MyEntityQueryType.Dynamic);
            var ray = new RayD(line.From, line.Direction);

            var closest = float.MaxValue;
            IMyTerminalBlock closestShield = null;

            for (int i = 0; i < segment.Count; i++)
            {
                var ent = segment[i].Element;
                if (ent == null || ent.Physics != null && !ent.Physics.IsPhantom)
                {
                    continue;
                }
                ShieldGridComponent c;
                if (Session.Instance.IdToBus.TryGetValue(ent.EntityId, out c) && c.DefenseShields != null)
                {
                    if (onlyIfOnline && (!c.DefenseShields.DsState.State.Online || c.DefenseShields.DsState.State.Lowered))
                    {
                        continue;
                    }
                    var s             = c.DefenseShields;
                    var intersectDist = CustomCollision.IntersectEllipsoid(s.DetectMatrixOutsideInv, s.DetectMatrixOutside, ray);
                    if (!intersectDist.HasValue)
                    {
                        continue;
                    }
                    var ellipsoid = intersectDist ?? 0;
                    if (ellipsoid > line.Length || ellipsoid > closest || CustomCollision.PointInShield(ray.Position, s.DetectMatrixOutsideInv))
                    {
                        continue;
                    }
                    closest       = ellipsoid;
                    closestShield = s.Shield;
                }
            }
            segment.Clear();
            SegmentPool.Return(segment);
            var response = new MyTuple <float?, IMyTerminalBlock>();

            if (closestShield == null)
            {
                response.Item1 = null;
                response.Item2 = null;
                return(response);
            }
            response.Item1 = closest;
            response.Item2 = closestShield;
            return(response);
        }
示例#21
0
        Message GetMessage(int size)
        {
            var msg = m_messagePool.Get();

            if (msg.Data == null)
            {
                msg.Data = new byte[Math.Max(256, size)];
            }
            else if (msg.Data.Length < size)
            {
                Array.Resize(ref msg.Data, size);
            }
            return(msg);
        }
示例#22
0
        void AddTool(IMyAutomaticRifleGun rifle)
        {
            PaintGunItem item = itemPool.Get();

            if (!item.Init(rifle))
            {
                itemPool.Return(item);
                return;
            }

            Tools.Add(item);
            ToolSpawned?.Invoke(item);

            SetUpdateMethods(UPDATE_METHODS, true);
        }
示例#23
0
        private static bool Conflicts(MyObjectBuilder_CubeGrid grid)
        {
            // Credits for this to KSH GitHub.
            var gridSize = MyDefinitionManager.Static.GetCubeSize(grid.GridSizeEnum);
            var localBb  = new BoundingBox(Vector3.MaxValue, Vector3.MinValue);

            foreach (var block in grid.CubeBlocks)
            {
                MyCubeBlockDefinition definition;
                if (!MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out definition))
                {
                    continue;
                }
                MyBlockOrientation ori = block.BlockOrientation;
                var blockSize          = Vector3.TransformNormal(new Vector3(definition.Size) * gridSize, ori);
                blockSize = Vector3.Abs(blockSize);

                var minCorner = new Vector3(block.Min) * gridSize - new Vector3(gridSize / 2);
                var maxCorner = minCorner + blockSize;

                localBb.Include(minCorner);
                localBb.Include(maxCorner);
            }

            var worldAABB = ((BoundingBoxD)localBb).TransformFast(grid.PositionAndOrientation?.GetMatrix() ?? MatrixD.Identity);
            var list      = m_entityListPool.Get();

            list.Clear();
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref worldAABB, list);
            foreach (var k in list)
            {
                var g     = k as IMyCubeGrid;
                var voxel = (k as IMyVoxelBase)?.PositionComp;
                if (g != null && g.WorldAABB.Intersects(worldAABB))
                {
                    return(true);
                }
                if (voxel != null && voxel.WorldVolume.Intersects(worldAABB))
                {
                    return(true);
                }
            }
            list.Clear();
            return(false);
        }
        public void OnDeviceInit()
        {
            m_pool = new MyConcurrentPool<MyRenderContext>(m_poolSize, true);
            
            // Initialize all RCs
            m_tmpList.Clear();
            int poolSize = m_pool.Count;
            for (int i = 0; i < poolSize; i++)
            {
                MyRenderContext rc = m_pool.Get();
                m_tmpList.Add(rc);
                rc.Initialize();
            }
            foreach (var rc in m_tmpList)
                m_pool.Return(rc);
            m_tmpList.Clear();

            m_isDeviceInit = true;
        }
示例#25
0
        public void OnDeviceInit()
        {
            m_pool = new MyConcurrentPool <MyRenderContext>(MaxDeferredRCsCount, true);

            // Initialize all RCs
            m_tmpList.Clear();
            int poolSize = m_pool.Count;

            for (int i = 0; i < poolSize; i++)
            {
                MyRenderContext rc = m_pool.Get();
                m_tmpList.Add(rc);
                rc.Initialize();
            }
            foreach (var rc in m_tmpList)
            {
                m_pool.Return(rc);
            }
            m_tmpList.Clear();

            m_isDeviceInit = true;
        }
示例#26
0
        public static void Init(string name, bool defaultInstance = true)
        {
            try
            {
                if (_instances.ContainsKey(name))
                {
                    return;
                }

                if (defaultInstance)
                {
                    _defaultInstance = name;
                }
                var instance = _logPool.Get();
                _instances[name] = instance;
                MyAPIGateway.Utilities.ShowNotification(name, 5000);
                instance.TextWriter = MyAPIGateway.Utilities.WriteFileInLocalStorage(name, typeof(LogInstance));
            }
            catch (Exception e)
            {
                MyAPIGateway.Utilities.ShowNotification(e.Message, 5000);
            }
        }
示例#27
0
 /// <summary>
 /// Commits current frame as atomic operation and prepares new frame
 /// </summary>
 public void CommitUpdateFrame()
 {
     CurrentUpdateFrame.Processed = false;
     m_updateDataQueue.Enqueue(CurrentUpdateFrame);
     CurrentUpdateFrame = m_frameDataPool.Get();
 }
 public ReturnHandle(MyConcurrentPool <T> pool)
 {
     _pool  = pool;
     Handle = pool.Get();
 }
示例#29
0
 public Particle GetPooledParticle()
 {
     return(particlePool.Get());
 }
示例#30
0
        private static string[] ParseArguments(string data, int offset = 0)
        {
            var list    = ArgsListPool.Get();
            var builder = ArgBuilderPool.Get();

            try
            {
                list.Clear();
                builder.Clear();
                char?currentQuote = null;

                var escaped = false;
                for (var head = offset; head < data.Length; head++)
                {
                    var ch = data[head];
                    if (ch == '\\' && !escaped)
                    {
                        escaped = true;
                        continue;
                    }
                    if (!escaped && (ch == '\'' || ch == '"'))
                    {
                        if (currentQuote.HasValue && currentQuote == ch)
                        {
                            currentQuote = null;
                        }
                        else if (!currentQuote.HasValue)
                        {
                            currentQuote = ch;
                        }
                        continue;
                    }
                    if (escaped)
                    {
                        switch (ch)
                        {
                        case '\\':
                        case '\'':
                        case '"':
                        case ' ':
                            break;

                        case 't':
                            ch = '\t';
                            break;

                        case 'n':
                            ch = '\n';
                            break;

                        case 'r':
                            ch = '\r';
                            break;

                        default:
                            throw new ArgumentException("Invalid escape sequence: \\" + ch);
                        }
                    }
                    if (!escaped && !currentQuote.HasValue && ch == ' ')
                    {
                        list.Add(builder.ToString());
                        builder.Clear();
                        continue;
                    }
                    builder.Append(ch);
                    escaped = false;
                }
                if (currentQuote.HasValue)
                {
                    throw new ArgumentException("Unclosed quote " + currentQuote.Value);
                }
                if (escaped)
                {
                    throw new ArgumentException("Can't end with an escape sequence");
                }
                list.Add(builder.ToString());
                return(list.ToArray());
            }
            finally
            {
                list.Clear();
                builder.Clear();
                ArgsListPool.Return(list);
                ArgBuilderPool.Return(builder);
            }
        }
示例#31
0
        private void UpdateEffect(HitEntity hitEnt, ProInfo info)
        {
            var grid = hitEnt.Entity as MyCubeGrid;

            if (grid == null || grid.MarkedForClose)
            {
                return;
            }
            Dictionary <AreaEffectType, GridEffect> effects;
            var attackerId = info.AmmoDef.DamageScales.Shields.Type == ShieldDef.ShieldType.Bypass ? grid.EntityId : info.Target.FiringCube.EntityId;
            var found      = false;

            if (_gridEffects.TryGetValue(grid, out effects))
            {
                GridEffect gridEffect;
                if (effects.TryGetValue(info.AmmoDef.AreaEffect.AreaEffect, out gridEffect))
                {
                    found                 = true;
                    gridEffect.Damage    += info.AreaEffectDamage;
                    gridEffect.Ai         = info.Ai;
                    gridEffect.AttackerId = attackerId;
                    gridEffect.Hits++;
                    if (hitEnt.HitPos != null)
                    {
                        gridEffect.HitPos = hitEnt.HitPos.Value / gridEffect.Hits;
                    }
                }
            }

            if (!found)
            {
                if (effects == null)
                {
                    effects = GridEffectsPool.Get();
                }
                GridEffect gridEffect;
                if (effects.TryGetValue(info.AmmoDef.AreaEffect.AreaEffect, out gridEffect))
                {
                    gridEffect.Damage    += info.AreaEffectDamage;
                    gridEffect.Ai         = info.Ai;
                    gridEffect.AmmoDef    = info.AmmoDef;
                    gridEffect.AttackerId = attackerId;
                    gridEffect.Hits++;
                    if (hitEnt.HitPos != null)
                    {
                        gridEffect.HitPos += hitEnt.HitPos.Value / gridEffect.Hits;
                    }
                }
                else
                {
                    gridEffect            = GridEffectPool.Get();
                    gridEffect.System     = info.System;
                    gridEffect.Damage     = info.AreaEffectDamage;
                    gridEffect.Ai         = info.Ai;
                    gridEffect.AmmoDef    = info.AmmoDef;
                    gridEffect.AttackerId = attackerId;
                    gridEffect.Hits++;
                    if (hitEnt.HitPos != null)
                    {
                        gridEffect.HitPos = hitEnt.HitPos.Value;
                    }
                    effects.Add(info.AmmoDef.AreaEffect.AreaEffect, gridEffect);
                }
                _gridEffects.Add(grid, effects);
            }
            info.BaseHealthPool = 0;
            info.BaseDamagePool = 0;
        }
示例#32
0
 internal static DelegateWork GetInstance()
 {
     return(instances.Get());
 }