public static bool AddDecoToMap(int mapCode, int copyMapID, Point pos, int decoID, int maxLiveTicks, int alphaTicks, bool notifyClients) { MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode]; bool result; if (null == mapGrid) { result = false; } else { Decoration deco = new Decoration { AutoID = DecorationManager.AutoDecoID++, DecoID = decoID, MapCode = mapCode, CopyMapID = copyMapID, Pos = pos, StartTicks = TimeUtil.NOW(), MaxLiveTicks = maxLiveTicks, AlphaTicks = alphaTicks }; lock (DecorationManager.DictDecos) { DecorationManager.DictDecos[deco.AutoID] = deco; } mapGrid.MoveObject(-1, -1, (int)pos.X, (int)pos.Y, deco); if (notifyClients) { DecorationManager.NotifyNearClientsToAddSelf(deco); } result = false; } return(result); }
public static void SpritePreMove(GameClient client, int fromX, int fromY, int toX, int toY, long startMoveTicks) { if (!Data.IgnoreClientPos) { client.ClientData.PosX = fromX; client.ClientData.PosY = fromY; client.ClientData.ReportPosTicks = startMoveTicks; MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[client.ClientData.MapCode]; mapGrid.MoveObject(-1, -1, fromX, fromY, client); } client.ClientData.DestPoint = new Point((double)toX, (double)toY); }
/// <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); }
/// <summary> /// 加入一个新的特效 /// </summary> /// <param name="myNpc"></param> /// <returns></returns> public static bool AddDecoToMap(int mapCode, int copyMapID, Point pos, int decoID, int maxLiveTicks, int alphaTicks, bool notifyClients) { MapGrid mapGrid = GameManager.MapGridMgr.DictGrids[mapCode]; if (null == mapGrid) { return(false); } Decoration deco = new Decoration() { AutoID = AutoDecoID++, DecoID = decoID, MapCode = mapCode, CopyMapID = copyMapID, Pos = pos, StartTicks = TimeUtil.NOW(), MaxLiveTicks = maxLiveTicks, AlphaTicks = alphaTicks, }; lock (DictDecos) { DictDecos[deco.AutoID] = deco; } //加入到地图格子中 mapGrid.MoveObject(-1, -1, (int)pos.X, (int)pos.Y, deco); //通知一下周围的人 if (notifyClients) { //对于需要及时通知的,立即刷新 NotifyNearClientsToAddSelf(deco); } return(false); }