Exemplo n.º 1
0
        public bool RemoveObject(LevelObject obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (m_LevelObjects.Remove(obj.m_UniqueID))
            {
                obj.Release();

                if (obj.m_Type == LevelObject.Type.ENTRANCE)
                {
                    IEnumerable <LevelObject> toUpdate = GetAllObjectsByType(LevelObject.Type.ENTRANCE)
                                                         .Where(obj2 => ((EntranceObject)obj2).m_EntranceID > ((EntranceObject)obj).m_EntranceID);
                    foreach (LevelObject entrance in toUpdate)
                    {
                        ((EntranceObject)entrance).m_EntranceID--;
                    }
                }
                else if (obj.m_Type == LevelObject.Type.PATH_NODE)
                {
                    UpdatePathsNodeRemoved((PathPointObject)obj);
                }

                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool RemoveObject(LevelObject obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (m_LevelObjects.Remove(obj.m_UniqueID))
            {
                obj.Release();

                if (obj.m_Type == LevelObject.Type.ENTRANCE)
                {
                    IEnumerable <LevelObject> toUpdate = GetAllObjectsByType(LevelObject.Type.ENTRANCE)
                                                         .Where(obj2 => ((EntranceObject)obj2).m_EntranceID >= ((EntranceObject)obj).m_EntranceID);
                    foreach (LevelObject entrance in toUpdate)
                    {
                        ((EntranceObject)entrance).m_EntranceID--;
                    }
                }
                else if (obj.m_Type == LevelObject.Type.VIEW)
                {
                    IEnumerable <LevelObject> toUpdate = GetAllObjectsByType(LevelObject.Type.VIEW)
                                                         .Where(obj2 => ((ViewObject)obj2).m_ViewID >= ((ViewObject)obj).m_ViewID);
                    foreach (LevelObject view in toUpdate)
                    {
                        ((ViewObject)view).m_ViewID--;
                    }
                }
                else if (obj.m_Type == LevelObject.Type.PATH_NODE)
                {
                    UpdatePathsNodeRemoved((PathPointObject)obj);
                }
                else if (obj.m_Type == LevelObject.Type.PATH)
                {
                    if (obj.Parameters[1] < 1)
                    {
                        return(true);
                    }
                    //remove the paths nodes
                    List <LevelObject> toRemove = GetAllObjectsByType(LevelObject.Type.PATH_NODE)
                                                  .Where(obj2 => ((PathPointObject)obj2).ParentPath == ((PathObject)obj).m_PathID).ToList();
                    if (toRemove.Count > 0)
                    {
                        for (int i = toRemove.Count - 1; i >= 0; i--)
                        {
                            Console.WriteLine("PathID: " + ((PathPointObject)toRemove[i]).ParentPath);
                            toRemove[i].Release();
                            m_LevelObjects.Remove(toRemove[i].m_UniqueID);
                        }
                    }

                    //shift the following paths
                    IEnumerable <LevelObject> toUpdate = GetAllObjectsByType(LevelObject.Type.PATH)
                                                         .Where(obj2 => ((PathObject)obj2).m_PathID >= ((PathObject)obj).m_PathID);
                    int maxNodeId = obj.Parameters[0];
                    foreach (PathObject path in toUpdate)
                    {
                        path.m_PathID--;
                        path.Parameters[0] = (ushort)maxNodeId;
                        path.GenerateProperties();
                        maxNodeId += path.Parameters[1];
                    }

                    // Update Node ID's and parentPaths of following path nodes
                    int gapSize = obj.Parameters[1];
                    IEnumerable <LevelObject> followingPathNodes = GetAllObjectsByType(LevelObject.Type.PATH_NODE).
                                                                   Where(obj0 => ((PathPointObject)obj0).m_NodeID >= obj.Parameters[0] + gapSize);
                    foreach (PathPointObject node in followingPathNodes)
                    {
                        node.m_NodeID -= gapSize;
                        node.ParentPath--;
                    }
                }

                return(true);
            }
            return(false);
        }