public void RaiseNewNPCEntries(List <ActorEntity> actorEntities) { if (!actorEntities.Any()) { return; } NPCWorkerDelegate.ReplaceNPCEntities(new List <ActorEntity>(actorEntities)); Func <bool> saveToDictionary = delegate { try { var enumerable = NPCWorkerDelegate.GetUniqueNPCEntities(); foreach (var actor in actorEntities) { var exists = enumerable.FirstOrDefault(n => n.NPCID2 == actor.NPCID2); if (exists != null) { continue; } NPCWorkerDelegate.AddUniqueNPCEntity(actor); } } catch (Exception ex) { } return(true); }; saveToDictionary.BeginInvoke(null, saveToDictionary); // THIRD PARTY PluginHost.Instance.RaiseNewNPCEntries(actorEntities); }
private static void OnNewNPCEntries(object sender, ActorEntitiesEvent actorEntitiesEvent) { // delegate event from npc entities from ram, not required to subsribe // this list includes anything that is not a player or monster // this updates 10x a second and only sends data if the items are found in ram // currently there no change/new/removed event handling (looking into it) if (sender == null) { return; } var npcEntities = actorEntitiesEvent.ActorEntities; if (!npcEntities.Any()) { return; } NPCWorkerDelegate.ReplaceNPCEntities(new List <ActorEntity>(npcEntities)); Func <bool> saveToDictionary = delegate { try { var enumerable = NPCWorkerDelegate.GetUniqueNPCEntities(); foreach (var actor in npcEntities) { var exists = enumerable.FirstOrDefault(n => n.NPCID2 == actor.NPCID2); if (exists != null) { continue; } NPCWorkerDelegate.AddUniqueNPCEntity(actor); } } catch (Exception ex) { } return(true); }; saveToDictionary.BeginInvoke(null, saveToDictionary); }