Example #1
0
        /// <summary>Finalize this NPCSpawnEntry</summary>
        /// <param name="addToPool">If set to false, will not try to add it to any pool (recommended for custom NPCSpawnEntry that share a pool)</param>
        public override void FinalizeDataHolder(bool addToPool)
        {
            if (Entry == null)
            {
                Entry = NPCMgr.GetEntry(EntryId);
                if (Entry == null)
                {
                    ContentMgr.OnInvalidDBData("{0} had an invalid EntryId.", (object)this);
                    return;
                }
            }

            if (EquipmentId != 0U)
            {
                Equipment = NPCMgr.GetEquipment(EquipmentId);
            }
            if (DisplayIdOverride == 16777215U)
            {
                DisplayIdOverride = 0U;
            }
            base.FinalizeDataHolder(addToPool);
            if (MapId != MapId.End)
            {
                Entry.SpawnEntries.Add(this);
                ArrayUtil.Set(ref NPCMgr.SpawnEntries, SpawnId, this);
                if (addToPool)
                {
                    AddToPoolTemplate();
                }
            }

            if (_eventId != 0)
            {
                uint       id         = (uint)Math.Abs(_eventId);
                WorldEvent worldEvent = WorldEventMgr.GetEvent(id);
                if (worldEvent != null)
                {
                    WorldEventNPC worldEventNpc = new WorldEventNPC
                    {
                        _eventId = _eventId,
                        EventId  = id,
                        Guid     = SpawnId,
                        Spawn    = _eventId > 0
                    };
                    worldEvent.NPCSpawns.Add(worldEventNpc);
                }

                EventId = id;
            }

            foreach (NPCSpawnTypeHandler spawnTypeHandler in Entry.SpawnTypeHandlers)
            {
                if (spawnTypeHandler != null)
                {
                    spawnTypeHandler(this);
                }
            }
        }
Example #2
0
 /// <summary>
 ///   Sets this NPC's equipment to the given entry
 /// </summary>
 public void SetEquipment(NPCEquipmentEntry equipment)
 {
     for (var i = 0; i < equipment.ItemIds.Length; i++)
     {
         var itemId = equipment.ItemIds[i];
         if (itemId != 0)
         {
             var item = ItemMgr.GetTemplate(itemId);
             if (item != null)
             {
                 SheathType = item.SheathType; // TODO: How to use the sheath type of all items?
             }
             SetUInt32(UnitFields.VIRTUAL_ITEM_SLOT_ID + i, (uint)itemId);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Finalize this NPCSpawnEntry
        /// </summary>
        /// <param name="addToPool">If set to false, will not try to add it to any pool (recommended for custom NPCSpawnEntry that share a pool)</param>
        public override void FinalizeDataHolder(bool addToPool)
        {
            // set Entry
            if (Entry == null)
            {
                Entry = NPCMgr.GetEntry(EntryId);
                if (Entry == null)
                {
                    ContentMgr.OnInvalidDBData("{0} had an invalid EntryId.", this);
                    return;
                }
            }

            // fix data inconsistencies & load addon data
            if (EquipmentId != 0)
            {
                Equipment = NPCMgr.GetEquipment(EquipmentId);
            }

            // seems to be a DB issue where the id was inserted as a float
            if (DisplayIdOverride == 0xFFFFFF)
            {
                DisplayIdOverride = 0;
            }

            // do the default thing
            base.FinalizeDataHolder(addToPool);

            if (MapId != MapId.End)
            {
                // valid map
                // add to NPCEntry
                Entry.SpawnEntries.Add(this);

                // add to list of NPCSpawnEntries
                ArrayUtil.Set(ref NPCMgr.SpawnEntries, SpawnId, this);

                if (addToPool)
                {
                    // add to pool
                    AddToPoolTemplate();
                }
            }

            // Is this NPC associated with an event
            if (_eventId != 0)
            {
                // The event id loaded can be negative if this
                // entry is expected to despawn during an event
                var eventId = (uint)Math.Abs(_eventId);

                //Check if the event is valid
                var worldEvent = WorldEventMgr.GetEvent(eventId);
                if (worldEvent != null)
                {
                    // Add this NPC to the list of related spawns
                    // for the given world event
                    var eventNPC = new WorldEventNPC()
                    {
                        _eventId = _eventId, EventId = eventId, Guid = SpawnId, Spawn = _eventId > 0
                    };

                    worldEvent.NPCSpawns.Add(eventNPC);
                }
                EventId = eventId;
            }

            //if(MoveType == AIMotionGenerationType.RandomMotion)
            //CreateRandomWaypoints();

            // finished initializing, now call the hooks
            foreach (var handler in Entry.SpawnTypeHandlers)
            {
                if (handler != null)
                {
                    handler(this);
                }
            }
        }