Esempio n. 1
0
        ////////////////

        internal EntityGroups()
        {
            LoadHooks.AddPostModLoadHook(() => {
                if (!this.IsEnabled)
                {
                    return;
                }

                this.GetItemPool();
                this.GetNPCPool();
                this.GetProjPool();

                ThreadPool.QueueUserWorkItem(_ => {
                    int _check = 0;

                    try {
                        IList <EntityGroupMatcherDefinition <Item> > itemMatchers;
                        IList <EntityGroupMatcherDefinition <NPC> > npcMatchers;
                        IList <EntityGroupMatcherDefinition <Projectile> > projMatchers;

                        lock (EntityGroups.MyLock) {
                            itemMatchers = EntityGroups.DefineItemGroups();
                            _check++;
                            npcMatchers = EntityGroups.DefineNPCGroups();
                            _check++;
                            projMatchers = EntityGroups.DefineProjectileGroups();
                            _check++;
                        }

                        this.ComputeGroups <Item>(itemMatchers, ref this.ItemGroups, ref this.GroupsPerItem);
                        _check++;
                        this.ComputeGroups <NPC>(npcMatchers, ref this.NPCGroups, ref this.GroupsPerNPC);
                        _check++;
                        this.ComputeGroups <Projectile>(projMatchers, ref this.ProjGroups, ref this.GroupsPerProj);
                        _check++;

                        this.ComputeGroups <Item>(this.CustomItemMatchers, ref this.ItemGroups, ref this.GroupsPerItem);
                        _check++;
                        this.ComputeGroups <NPC>(this.CustomNPCMatchers, ref this.NPCGroups, ref this.GroupsPerNPC);
                        _check++;
                        this.ComputeGroups <Projectile>(this.CustomProjMatchers, ref this.ProjGroups, ref this.GroupsPerProj);
                        _check++;

                        lock (EntityGroups.MyLock) {
                            this.CustomItemMatchers = null;
                            this.CustomNPCMatchers  = null;
                            this.CustomProjMatchers = null;
                            this.ItemPool           = null;
                            this.NPCPool            = null;
                            this.ProjPool           = null;
                        }

                        CustomLoadHooks.TriggerHook(EntityGroups.LoadedAllValidator, EntityGroups.MyValidatorKey);
                        _check++;
                    } catch (Exception e) {
                        LogHelpers.Warn("Initialization failed (at #" + _check + "): " + e.ToString());
                    }
                });
            });

            //LoadHooks.AddModUnloadHook( () => {
            //	lock( EntityGroups.MyLock ) { }
            //} );
        }
        ////////////////

        internal EntityGroups()
        {
            lock (EntityGroups.MyLock) {
                this._ItemGroups = new ReadOnlyDictionary <string, ReadOnlySet <int> >(this._RawItemGroups);
                this._NPCGroups  = new ReadOnlyDictionary <string, ReadOnlySet <int> >(this._RawNPCGroups);
                this._ProjGroups = new ReadOnlyDictionary <string, ReadOnlySet <int> >(this._RawProjGroups);

                this._GroupsPerItem = new ReadOnlyDictionary <int, ReadOnlySet <string> >(this._RawGroupsPerItem);
                this._GroupsPerNPC  = new ReadOnlyDictionary <int, ReadOnlySet <string> >(this._RawGroupsPerNPC);
                this._GroupsPerProj = new ReadOnlyDictionary <int, ReadOnlySet <string> >(this._RawGroupsPerProj);
            }

            Promises.Promises.AddPostModLoadPromise(() => {
                if (!this.IsEnabled)
                {
                    return;
                }

                this.GetItemPool();
                this.GetNPCPool();
                this.GetProjPool();

                ThreadPool.QueueUserWorkItem(_ => {
                    int _check = 0;

                    try {
                        IList <Tuple <string, string[], ItemMatcher> > itemMatchers;
                        IList <Tuple <string, string[], NPCMatcher> > npcMatchers;
                        IList <Tuple <string, string[], ProjMatcher> > projMatchers;

                        lock (EntityGroups.MyLock) {
                            itemMatchers = EntityGroups.DefineItemGroups();
                            _check++;
                            npcMatchers = EntityGroups.DefineNPCGroups();
                            _check++;
                            projMatchers = EntityGroups.DefineProjectileGroups();
                            _check++;
                        }

                        this.ComputeGroups <Item>(itemMatchers, ref this._RawItemGroups, ref this._RawGroupsPerItem);
                        _check++;
                        this.ComputeGroups <NPC>(npcMatchers, ref this._RawNPCGroups, ref this._RawGroupsPerNPC);
                        _check++;
                        this.ComputeGroups <Projectile>(projMatchers, ref this._RawProjGroups, ref this._RawGroupsPerProj);
                        _check++;

                        this.ComputeGroups <Item>(this.CustomItemMatchers, ref this._RawItemGroups, ref this._RawGroupsPerItem);
                        _check++;
                        this.ComputeGroups <NPC>(this.CustomNPCMatchers, ref this._RawNPCGroups, ref this._RawGroupsPerNPC);
                        _check++;
                        this.ComputeGroups <Projectile>(this.CustomProjMatchers, ref this._RawProjGroups, ref this._RawGroupsPerProj);
                        _check++;

                        lock (EntityGroups.MyLock) {
                            this.CustomItemMatchers = null;
                            this.CustomNPCMatchers  = null;
                            this.CustomProjMatchers = null;
                            this.ItemPool           = null;
                            this.NPCPool            = null;
                            this.ProjPool           = null;
                        }

                        Promises.Promises.TriggerValidatedPromise(EntityGroups.LoadedAllValidator, EntityGroups.MyValidatorKey);
                        _check++;
                    } catch (Exception e) {
                        LogHelpers.Warn("Initialization failed (at #" + _check + "): " + e.ToString());
                    }
                });
            });
        }