public static Decoration FindDeco(int autoID) { Decoration deco = null; lock (DecorationManager.DictDecos) { if (DecorationManager.DictDecos.TryGetValue(autoID, out deco)) { DecorationManager.DictDecos.Remove(autoID); } } return(deco); }
public static void DelMySelfDecos(SocketListener sl, TCPOutPacketPool pool, GameClient client, List <object> objsList) { if (null != objsList) { for (int i = 0; i < objsList.Count; i++) { Decoration deco = objsList[i] as Decoration; if (null != deco) { GameManager.ClientMgr.NotifyMySelfDelDeco(sl, pool, client, deco); } } } }
/// <summary> /// 获取一个Decoration对象 /// </summary> /// <param name="mapCode"></param> /// <param name="npcID"></param> /// <returns></returns> public static Decoration GetDecoration(int mapCode, int copyMapID, Point pos, int decoID, int maxLiveTicks, int alphaTicks) { Decoration deco = new Decoration() { AutoID = AutoDecoID++, DecoID = decoID, MapCode = mapCode, CopyMapID = copyMapID, Pos = pos, StartTicks = TimeUtil.NOW(), MaxLiveTicks = maxLiveTicks, AlphaTicks = alphaTicks, }; return(deco); }
/// <summary> /// 处理已经掉落的特效超时 /// </summary> /// <param name="client"></param> public static void ProcessAllDecos(SocketListener sl, TCPOutPacketPool pool) { List <Decoration> decorationList = new List <Decoration>(); lock (DictDecos) { foreach (var val in DictDecos.Values) { decorationList.Add(val); } } long nowTicks = TimeUtil.NOW(); Decoration decoration = null; for (int i = 0; i < decorationList.Count; i++) { decoration = decorationList[i]; if (decoration.MaxLiveTicks <= 0) //永久特效,不删除 { continue; } //判断是否超过了最大的抢时间 if (nowTicks - decoration.StartTicks < (decoration.MaxLiveTicks)) //删除 { continue; } //从内存中删除 lock (DictDecos) //先锁定 { DictDecos.Remove(decoration.AutoID); } GameManager.MapGridMgr.DictGrids[decoration.MapCode].RemoveObject(decoration); List <Object> objList = Global.GetAll9Clients(decoration); // 特效消失通知(同一个地图才需要通知) GameManager.ClientMgr.NotifyOthersDelDeco(sl, pool, objList, decoration.MapCode, decoration.AutoID); } }
/// <summary> /// 通知自己删除周围的Deco /// </summary> /// <param name="sl"></param> /// <param name="pool"></param> /// <param name="client"></param> /// <param name="objsList"></param> public static void DelMySelfDecos(SocketListener sl, TCPOutPacketPool pool, GameClient client, List <Object> objsList) { if (null == objsList) { return; } Decoration deco = null; for (int i = 0; i < objsList.Count; i++) { deco = objsList[i] as Decoration; if (null == deco) { continue; } GameManager.ClientMgr.NotifyMySelfDelDeco(sl, pool, client, deco); } }
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); } } }
protected static void NotifyNearClientsToAddSelf(Decoration deco) { List <object> objsList = Global.GetAll9Clients(deco); if (null != objsList) { GameClient client = null; for (int i = 0; i < objsList.Count; i++) { client = (objsList[i] as GameClient); if (null != client) { lock (client.ClientData.VisibleGrid9Objects) { client.ClientData.VisibleGrid9Objects[client] = 1; } GameManager.ClientMgr.NotifyMySelfNewDeco(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, client, deco); } } } }
/// <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); }