Exemple #1
0
        /// <summary>
        /// 移除某个某个Deco
        /// </summary>
        /// <param name="mapCode"></param>
        public static void RemoveDeco(int autoID)
        {
            Decoration deco = null;

            lock (DictDecos)
            {
                if (DictDecos.TryGetValue(autoID, out deco))
                {
                    DictDecos.Remove(autoID);
                }
            }

            if (null != deco)
            {
                MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[deco.MapCode];
                if (null != mapGrid)
                {
                    //九宫格地图中移除
                    mapGrid.RemoveObject(deco);

                    //先移除,再通知
                    //NotifyNearClientsToRemoveSelf(deco);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 移除某个地图的某个npc
        /// </summary>
        /// <param name="mapCode"></param>
        public static void RemoveMapNpc(int mapCode, int npcID)
        {
            if (mapCode <= 0)
            {
                return;
            }

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode];

            if (null == mapGrid)
            {
                return;
            }

            //先循环进行地图移除通知
            foreach (var item in ListNpc)
            {
                if (item.Value.MapCode == mapCode && item.Value.NpcID == npcID)
                {
                    //九宫格地图中移除
                    mapGrid.RemoveObject(item.Value);

                    //先移除,再通知
                    //NotifyNearClientsToRemoveSelf(item.Value);

                    ListNpc.Remove(item.Key);

                    return;
                }
            }
        }
 public static void RemoveMapNpc(int mapCode, int npcID)
 {
     if (mapCode > 0)
     {
         MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode];
         if (null != mapGrid)
         {
             foreach (KeyValuePair <string, NPC> item in NPCGeneralManager.ListNpc)
             {
                 if (item.Value.MapCode == mapCode && item.Value.NpcID == npcID)
                 {
                     mapGrid.RemoveObject(item.Value);
                     NPCGeneralManager.ListNpc.Remove(item.Key);
                     break;
                 }
             }
         }
     }
 }
        public static void RemoveDeco(int autoID)
        {
            Decoration deco = null;

            lock (DecorationManager.DictDecos)
            {
                if (DecorationManager.DictDecos.TryGetValue(autoID, out deco))
                {
                    DecorationManager.DictDecos.Remove(autoID);
                }
            }
            if (null != deco)
            {
                MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[deco.MapCode];
                if (null != mapGrid)
                {
                    mapGrid.RemoveObject(deco);
                }
            }
        }
        /// <summary>
        /// 传送对象到目标位置,相当于瞬移
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="nX"></param>
        /// <param name="nY"></param>
        /// <param name="nDir"></param>
        /// <param name="?"></param>
        /// <param name="pathStr"></param>
        /// <returns></returns>
        public static Boolean TransportTo(IObject obj, int nX, int nY, Dircetions nDir, int oldMapCode, String pathStr = "")
        {
            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            if (oldMapCode > 0 && oldMapCode != obj.CurrentMapCode)
            {
                MapGrid oldMapGrid = GameManager.MapGridMgr.DictGrids[oldMapCode];
                if (oldMapGrid != null)
                {
                    oldMapGrid.RemoveObject(obj);

                    //这儿还需要通知旧九宫格对象自己的离开
                }

                //强行设置 -1
                nCurrX = -1;
                nCurrY = -1;
            }

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];

            //对象在格子间移动
            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                //对于传送移动,根本不需要移动通知,只需要九宫格通知
                //NotifyOthersMyMoving(obj, pathStr, nCurrX, nCurrY, nX, nY, nDir);

                obj.CurrentGrid = new Point(nX, nY);
                obj.CurrentDir  = nDir;

                //进行九宫格通知 --->不管在哪个地图,一旦coordinate 坐标 和 grid坐标保持一致,九宫格不会触发
                //此时,需要提前更改coordinate
                Notify9Grid(obj, true);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// 将新NPC加入地图格子,如果该地图的该格子存在旧的NPC,则将旧的NPC移除
        /// 这样既可以初始化npc,也可以替换旧的npc
        /// </summary>
        /// <param name="myNpc"></param>
        /// <returns></returns>
        public static bool AddNpcToMap(NPC myNpc)
        {
            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[myNpc.MapCode];

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

            String sNpcKey = String.Format("{0}_{1}_{2}", myNpc.MapCode, myNpc.GridPoint.X, myNpc.GridPoint.Y);

            //如果该格子存在别的NPC,则将旧的NPC移除
            NPC oldNpc = null;

            if (ListNpc.TryGetValue(sNpcKey, out oldNpc))
            {
                ListNpc.Remove(sNpcKey);
                mapGrid.RemoveObject(oldNpc);

                //先移除,再通知
                //NotifyNearClientsToRemoveSelf(oldNpc);

                LogManager.WriteLog(LogTypes.Error, string.Format("地图{0}的({1}, {2})处旧的NPC被替换", myNpc.MapCode, myNpc.GridPoint.X, myNpc.GridPoint.Y));
            }

            GameMap gameMap = GameManager.MapMgr.DictMaps[myNpc.MapCode];

            //再添加新NPC
            if (mapGrid.MoveObject(-1, -1, (int)(gameMap.MapGridWidth * myNpc.GridPoint.X), (int)(gameMap.MapGridHeight * myNpc.GridPoint.Y), myNpc))
            {
                ListNpc.Add(sNpcKey, myNpc);

                //通知一下周围的人
                //NotifyNearClientsToAddSelf(myNpc);

                return(true);
            }

            return(false);
        }
 public static void RemoveMapNpcs(int mapCode)
 {
     if (mapCode > 0)
     {
         MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode];
         if (null != mapGrid)
         {
             List <string> keysToDel = new List <string>();
             foreach (KeyValuePair <string, NPC> item in NPCGeneralManager.ListNpc)
             {
                 if (item.Value.MapCode == mapCode)
                 {
                     mapGrid.RemoveObject(item.Value);
                     keysToDel.Add(item.Key);
                 }
             }
             foreach (string key in keysToDel)
             {
                 NPCGeneralManager.ListNpc.Remove(key);
             }
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// 移除某个地图的所有npc
        /// </summary>
        /// <param name="mapCode"></param>
        public static void RemoveMapNpcs(int mapCode)
        {
            if (mapCode <= 0)
            {
                return;
            }

            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode];

            if (null == mapGrid)
            {
                return;
            }

            List <String> keysToDel = new List <string>();

            //先循环进行地图移除通知
            foreach (var item in ListNpc)
            {
                if (item.Value.MapCode == mapCode)
                {
                    //九宫格地图中移除
                    mapGrid.RemoveObject(item.Value);

                    //先移除,再通知
                    //NotifyNearClientsToRemoveSelf(item.Value);

                    keysToDel.Add(item.Key);
                }
            }

            //再移除缓存列表
            foreach (var key in keysToDel)
            {
                ListNpc.Remove(key);
            }
        }
        public static bool TransportTo(IObject obj, int nX, int nY, Dircetions nDir, int oldMapCode, string pathStr = "")
        {
            Point grid   = obj.CurrentGrid;
            int   nCurrX = (int)grid.X;
            int   nCurrY = (int)grid.Y;

            if (oldMapCode > 0 && oldMapCode != obj.CurrentMapCode)
            {
                MapGrid oldMapGrid = GameManager.MapGridMgr.DictGrids[oldMapCode];
                if (oldMapGrid != null)
                {
                    oldMapGrid.RemoveObject(obj);
                }
                nCurrX = -1;
                nCurrY = -1;
            }
            MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[obj.CurrentMapCode];
            bool    result;

            if (mapGrid.MoveObjectEx(nCurrX, nCurrY, nX, nY, obj))
            {
                obj.CurrentGrid = new Point((double)nX, (double)nY);
                obj.CurrentDir  = nDir;
                if (obj is Monster && (obj as Monster).MonsterType == 1001)
                {
                    GameManager.MonsterMgr.ChangePosition(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, obj as Monster, (int)obj.CurrentPos.X, (int)obj.CurrentPos.Y, (int)nDir, 159, 0);
                }
                ChuanQiUtils.Notify9Grid(obj, true);
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }